ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
ComponentInstaller\Installer Class Reference

Component Installer for Composer. More...

+ Inheritance diagram for ComponentInstaller\Installer:
+ Collaboration diagram for ComponentInstaller\Installer:

Public Member Functions

 supports ($packageType)
 
 getComponentPath (PackageInterface $package)
 Gets the destination Component directory. More...
 
 getComponentDir ()
 Retrieves the Installer's provided component directory. More...
 
 removeCode (PackageInterface $package)
 Remove both the installed code and files from the Component directory. More...
 
 removeComponent (PackageInterface $package)
 Remove a Component's files from the Component directory. More...
 
 installCode (PackageInterface $package)
 Before installing the Component, be sure its destination is clear first. More...
 

Protected Member Functions

 initializeVendorDir ()
 Initialize the Component directory, as well as the vendor directory. More...
 

Protected Attributes

 $componentDir
 The location where Components are to be installed. More...
 

Detailed Description

Component Installer for Composer.

Definition at line 22 of file Installer.php.

Member Function Documentation

◆ getComponentDir()

ComponentInstaller\Installer::getComponentDir ( )

Retrieves the Installer's provided component directory.

Definition at line 113 of file Installer.php.

References $config.

114  {
115  $config = $this->composer->getConfig();
116  return $config->has('component-dir') ? $config->get('component-dir') : 'components';
117  }

◆ getComponentPath()

ComponentInstaller\Installer::getComponentPath ( PackageInterface  $package)

Gets the destination Component directory.

Parameters
PackageInterface$package
Returns
string The path to where the final Component should be installed.

Definition at line 69 of file Installer.php.

References array.

70  {
71  // Parse the pretty name for the vendor and package name.
72  $name = $prettyName = $package->getPrettyName();
73  if (strpos($prettyName, '/') !== false) {
74  list($vendor, $name) = explode('/', $prettyName);
75  unset($vendor);
76  }
77 
78  // First look for an override in root package's extra, then try the package's extra
79  $rootPackage = $this->composer->getPackage();
80  $rootExtras = $rootPackage ? $rootPackage->getExtra() : array();
81  $customComponents = isset($rootExtras['component']) ? $rootExtras['component'] : array();
82 
83  if (isset($customComponents[$prettyName]) && is_array($customComponents[$prettyName])) {
84  $component = $customComponents[$prettyName];
85  }
86  else {
87  $extra = $package->getExtra();
88  $component = isset($extra['component']) ? $extra['component'] : array();
89  }
90 
91  // Allow the component to define its own name.
92  if (isset($component['name'])) {
93  $name = $component['name'];
94  }
95 
96  // Find where the package should be located.
97  return $this->getComponentDir() . DIRECTORY_SEPARATOR . $name;
98  }
Create styles array
The data for the language used.
getComponentDir()
Retrieves the Installer's provided component directory.
Definition: Installer.php:113

◆ initializeVendorDir()

ComponentInstaller\Installer::initializeVendorDir ( )
protected

Initialize the Component directory, as well as the vendor directory.

Definition at line 103 of file Installer.php.

104  {
105  $this->componentDir = $this->getComponentDir();
106  $this->filesystem->ensureDirectoryExists($this->componentDir);
107  parent::initializeVendorDir();
108  }
getComponentDir()
Retrieves the Installer's provided component directory.
Definition: Installer.php:113

◆ installCode()

ComponentInstaller\Installer::installCode ( PackageInterface  $package)

Before installing the Component, be sure its destination is clear first.

Parameters
PackageInterface$package

Definition at line 147 of file Installer.php.

References array.

148  {
149  $this->removeComponent($package);
150  parent::installCode($package);
151  }
removeComponent(PackageInterface $package)
Remove a Component's files from the Component directory.
Definition: Installer.php:136

◆ removeCode()

ComponentInstaller\Installer::removeCode ( PackageInterface  $package)

Remove both the installed code and files from the Component directory.

Parameters
PackageInterface$package

Definition at line 124 of file Installer.php.

125  {
126  $this->removeComponent($package);
127  parent::removeCode($package);
128  }
removeComponent(PackageInterface $package)
Remove a Component's files from the Component directory.
Definition: Installer.php:136

◆ removeComponent()

ComponentInstaller\Installer::removeComponent ( PackageInterface  $package)

Remove a Component's files from the Component directory.

Parameters
PackageInterface$package
Returns
bool

Definition at line 136 of file Installer.php.

References $path.

137  {
138  $path = $this->getComponentPath($package);
139  return $this->filesystem->remove($path);
140  }
getComponentPath(PackageInterface $package)
Gets the destination Component directory.
Definition: Installer.php:69
$path
Definition: aliased.php:25

◆ supports()

ComponentInstaller\Installer::supports (   $packageType)

Components are supported by all packages. This checks wheteher or not the entire package is a "component", as well as injects the script to act on components embedded in packages that are not just "component" types.

Definition at line 37 of file Installer.php.

38  {
39  // Components are supported by all package types. We will just act on
40  // the root package's scripts if available.
41  $rootPackage = isset($this->composer) ? $this->composer->getPackage() : null;
42  if (isset($rootPackage)) {
43  // Ensure we get the root package rather than its alias.
44  while ($rootPackage instanceof AliasPackage) {
45  $rootPackage = $rootPackage->getAliasOf();
46  }
47 
48  // Make sure the root package can override the available scripts.
49  if (method_exists($rootPackage, 'setScripts')) {
50  $scripts = $rootPackage->getScripts();
51  // Act on the "post-autoload-dump" command so that we can act on all
52  // the installed packages.
53  $scripts['post-autoload-dump']['component-installer'] = 'ComponentInstaller\\Installer::postAutoloadDump';
54  $rootPackage->setScripts($scripts);
55  }
56  }
57 
58  // State support for "component" package types.
59  return $packageType == 'component';
60  }

Field Documentation

◆ $componentDir

ComponentInstaller\Installer::$componentDir
protected

The location where Components are to be installed.

Definition at line 28 of file Installer.php.


The documentation for this class was generated from the following file: