vendor/codeages/plugin-bundle/Locator/ThemeFileLocator.php line 30

Open in your IDE?
  1. <?php
  2. namespace Codeages\PluginBundle\Locator;
  3. use Symfony\Component\Config\FileLocator as BaseFileLocator;
  4. use Codeages\PluginBundle\System\PluginableHttpKernelInterface;
  5. class ThemeFileLocator extends BaseFileLocator
  6. {
  7.     private $kernel;
  8.     private $path;
  9.     public function __construct(PluginableHttpKernelInterface $kernel$path null, array $paths = array())
  10.     {
  11.         $this->kernel $kernel;
  12.         if (null !== $path) {
  13.             $this->path $path;
  14.             $paths[] = $path;
  15.         }
  16.         $themeDir $this->kernel->getPluginConfigurationManager()->getActiveThemeDirectory();
  17.         $paths array_merge(array($themeDir), $paths);
  18.         parent::__construct($paths);
  19.     }
  20.     public function locate($file$currentPath null$first true)
  21.     {
  22.         if (isset($file[0]) && '@' === $file[0]) {
  23.             return $this->locateResource($file$this->path$first);
  24.         }
  25.         return parent::locate($file$currentPath$first);
  26.     }
  27.     protected function locateResource($name$dir null$first true)
  28.     {
  29.         if (false !== strpos($name'..')) {
  30.             throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).'$name));
  31.         }
  32.         $bundleName substr($name1);
  33.         $path '';
  34.         if (false !== strpos($bundleName'/')) {
  35.             list($bundleName$path) = explode('/'$bundleName2);
  36.         }
  37.         $isResource === strpos($path'Resources') && null !== $dir;
  38.         $overridePath substr($path9);
  39.         $resourceBundle null;
  40.         $bundles $this->kernel->getBundle($bundleNamefalse);
  41.         $files = array();
  42.         $themeDir $this->kernel->getPluginConfigurationManager()->getActiveThemeDirectory();
  43.         foreach ($bundles as $bundle) {
  44.             $lookupFiles = array();
  45.             if ($themeDir) {
  46.                 $lookupFiles[] = sprintf('%s/views/%s/%s'$themeDir$bundle->getName(), substr($overridePath7));
  47.                 // @todo this will remove in future.
  48.                 $lookupFiles[] = sprintf('%s/%s/%s'$themeDir$bundle->getName(), substr($overridePath1));
  49.             }
  50.             $lookupFiles[] = $dir.'/'.$bundle->getName().$overridePath;
  51.             foreach ($lookupFiles as $file) {
  52.                 if ($isResource && file_exists($file)) {
  53.                     if (null !== $resourceBundle) {
  54.                         throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
  55.                             $file,
  56.                             $resourceBundle,
  57.                             $dir.'/'.$bundles[0]->getName().$overridePath
  58.                         ));
  59.                     }
  60.                     if ($first) {
  61.                         return $file;
  62.                     }
  63.                     $files[] = $file;
  64.                 }
  65.             }
  66.             if (file_exists($file $bundle->getPath().'/'.$path)) {
  67.                 if ($first && !$isResource) {
  68.                     return $file;
  69.                 }
  70.                 $files[] = $file;
  71.                 $resourceBundle $bundle->getName();
  72.             }
  73.         }
  74.         if (count($files) > 0) {
  75.             return $first && $isResource $files[0] : $files;
  76.         }
  77.         throw new \InvalidArgumentException(sprintf('Unable to find file "%s".'$name));
  78.     }
  79. }