Introduction
This bundle allows to locate composer vendor packages inside a Symfony project.
It interprets the composer.json
in your project root to find the correct vendor
base directory., (*1)
The vendor location is configured with a compiler pass, so the path lookup is
stored in DI definition cache., (*2)
Installation
composer require hylianshield/vendor-locator-bundle:^1.0
Add the following bundle to the app kernel., (*3)
<?php
use HylianShield\VendorLocatorBundle\HylianShieldVendorLocatorBundle;
//...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = [
// ...
new HylianShieldVendorLocatorBundle()
];
// ...
}
// ...
}
Make sure to flush the cache, to activate the compiler pass., (*4)
Usage
The file locator service is available as service hylianshield.file_locator.vendor
., (*5)
With this service, one can find files relative to the vendor directory:, (*6)
<?php
/** @var \Symfony\Component\Config\FileLocatorInterface $locator */
$locator = $this->get('hylianshield.file_locator.vendor');
echo $locator->locate('hylianshield/vendor-locator-bundle');
Outputs:, (*7)
/path/to/symfony/vendor/hylianshield/vendor-locator-bundle