ComponentInstaller\Installer::getComponentPath PHP Méthode

getComponentPath() public méthode

Gets the destination Component directory.
public getComponentPath ( Composer\Package\PackageInterface $package ) : string
$package Composer\Package\PackageInterface
Résultat string The path to where the final Component should be installed.
    public function getComponentPath(PackageInterface $package)
    {
        // Parse the pretty name for the vendor and package name.
        $name = $prettyName = $package->getPrettyName();
        if (strpos($prettyName, '/') !== false) {
            list($vendor, $name) = explode('/', $prettyName);
            unset($vendor);
        }
        // First look for an override in root package's extra, then try the package's extra
        $rootPackage = $this->composer->getPackage();
        $rootExtras = $rootPackage ? $rootPackage->getExtra() : array();
        $customComponents = isset($rootExtras['component']) ? $rootExtras['component'] : array();
        if (isset($customComponents[$prettyName]) && is_array($customComponents[$prettyName])) {
            $component = $customComponents[$prettyName];
        } else {
            $extra = $package->getExtra();
            $component = isset($extra['component']) ? $extra['component'] : array();
        }
        // Allow the component to define its own name.
        if (isset($component['name'])) {
            $name = $component['name'];
        }
        // Find where the package should be located.
        return $this->getComponentDir() . DIRECTORY_SEPARATOR . $name;
    }

Usage Example

Exemple #1
0
 /**
  * Tests the Installer's getComponentPath function.
  *
  * @param $expected
  *   The expected install path for the package.
  * @param $package
  *   The package to test upon.
  *
  * @dataProvider providerGetComponentPath
  *
  * @see \ComponentInstaller\Installer::getComponentPath()
  */
 public function testGetComponentPath($expected, $package)
 {
     // Construct the mock objects.
     $installer = new Installer($this->io, $this->composer, 'component');
     $loader = new ArrayLoader();
     // Test the results.
     $result = $installer->getComponentPath($loader->load($package));
     $this->assertEquals($this->componentDir . '/' . $expected, $result);
 }