Reputation: 8616
From a bundle shorthand string like "AcmeExampleBundle"
is there a Symfony service I can use to resolve this to the directory path to that bundle's root, e.g. "/path/to/site/src/acme/ExampleBundle"
I need to do this for any bundle, without knowing in advance what the bundle is in advance, or if it even exists.
Upvotes: 0
Views: 299
Reputation: 13891
Your AcmeExampleBundle.php
class extends the Symfony\Component\HttpKernel\Bundle\Bundle base class which provides a getPath() method. You can use this method to get the bundle directory path. It returns the bundle absolute path as a string.
If your real need is to locate a given resource in your bundle, you can use the kernel
service which provides a locateResource() method that returns the given resource file path.
Example:
$path = $container->get('kernel')->locateResource('@AcmeExampleBundle/path/to/your/file.xxx');
Upvotes: 1