PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundles/Symfony/Bundle/AsseticBundle/Factory/AssetFactory.php

https://bitbucket.org/cryofrost/portal
PHP | 97 lines | 51 code | 14 blank | 32 comment | 8 complexity | 521a2e1f7ac67d7e3aea804fc9c0efa1 MD5 | raw file
Possible License(s): Apache-2.0, JSON, LGPL-2.1, LGPL-2.0, LGPL-3.0, BSD-3-Clause, BSD-2-Clause
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\AsseticBundle\Factory;
  11. use Assetic\Factory\AssetFactory as BaseAssetFactory;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  14. use Symfony\Component\HttpKernel\KernelInterface;
  15. /**
  16. * Loads asset formulae from the filesystem.
  17. *
  18. * @author Kris Wallsmith <kris@symfony.com>
  19. */
  20. class AssetFactory extends BaseAssetFactory
  21. {
  22. private $kernel;
  23. private $container;
  24. private $parameterBag;
  25. /**
  26. * Constructor.
  27. *
  28. * @param KernelInterface $kernel The kernel is used to parse bundle notation
  29. * @param ContainerInterface $container The container is used to load the managers lazily, thus avoiding a circular dependency
  30. * @param ParameterBagInterface $parameterBag The container parameter bag
  31. * @param string $baseDir The base directory for relative inputs
  32. * @param Boolean $debug The current debug mode
  33. */
  34. public function __construct(KernelInterface $kernel, ContainerInterface $container, ParameterBagInterface $parameterBag, $baseDir, $debug = false)
  35. {
  36. $this->kernel = $kernel;
  37. $this->container = $container;
  38. $this->parameterBag = $parameterBag;
  39. parent::__construct($baseDir, $debug);
  40. }
  41. /**
  42. * Adds support for bundle notation file and glob assets and parameter placeholders.
  43. *
  44. * FIXME: This is a naive implementation of globs in that it doesn't
  45. * attempt to support bundle inheritance within the glob pattern itself.
  46. */
  47. protected function parseInput($input, array $options = array())
  48. {
  49. $input = $this->parameterBag->resolveValue($input);
  50. // expand bundle notation
  51. if ('@' == $input[0] && false !== strpos($input, '/')) {
  52. // use the bundle path as this asset's root
  53. $bundle = substr($input, 1);
  54. if (false !== $pos = strpos($bundle, '/')) {
  55. $bundle = substr($bundle, 0, $pos);
  56. }
  57. $options['root'] = array($this->kernel->getBundle($bundle)->getPath());
  58. // canonicalize the input
  59. if (false !== $pos = strpos($input, '*')) {
  60. // locateResource() does not support globs so we provide a naive implementation here
  61. list($before, $after) = explode('*', $input, 2);
  62. $input = $this->kernel->locateResource($before).'*'.$after;
  63. } else {
  64. $input = $this->kernel->locateResource($input);
  65. }
  66. }
  67. return parent::parseInput($input, $options);
  68. }
  69. protected function createAssetReference($name)
  70. {
  71. if (!$this->getAssetManager()) {
  72. $this->setAssetManager($this->container->get('assetic.asset_manager'));
  73. }
  74. return parent::createAssetReference($name);
  75. }
  76. protected function getFilter($name)
  77. {
  78. if (!$this->getFilterManager()) {
  79. $this->setFilterManager($this->container->get('assetic.filter_manager'));
  80. }
  81. return parent::getFilter($name);
  82. }
  83. }