PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/kriswallsmith/assetic/src/Assetic/Asset/GlobAsset.php

https://bitbucket.org/pyneff/symfony2
PHP | 111 lines | 67 code | 21 blank | 23 comment | 6 complexity | 34a3a85e1ab1257377cb83dee979503f MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, BSD-3-Clause, BSD-2-Clause
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2012 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Asset;
  11. use Assetic\Util\PathUtils;
  12. use Assetic\Filter\FilterInterface;
  13. /**
  14. * A collection of assets loaded by glob.
  15. *
  16. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  17. */
  18. class GlobAsset extends AssetCollection
  19. {
  20. private $globs;
  21. private $initialized;
  22. /**
  23. * Constructor.
  24. *
  25. * @param string|array $globs A single glob path or array of paths
  26. * @param array $filters An array of filters
  27. * @param string $root The root directory
  28. */
  29. public function __construct($globs, $filters = array(), $root = null, array $vars = array())
  30. {
  31. $this->globs = (array) $globs;
  32. $this->initialized = false;
  33. parent::__construct(array(), $filters, $root, $vars);
  34. }
  35. public function all()
  36. {
  37. if (!$this->initialized) {
  38. $this->initialize();
  39. }
  40. return parent::all();
  41. }
  42. public function load(FilterInterface $additionalFilter = null)
  43. {
  44. if (!$this->initialized) {
  45. $this->initialize();
  46. }
  47. parent::load($additionalFilter);
  48. }
  49. public function dump(FilterInterface $additionalFilter = null)
  50. {
  51. if (!$this->initialized) {
  52. $this->initialize();
  53. }
  54. return parent::dump($additionalFilter);
  55. }
  56. public function getLastModified()
  57. {
  58. if (!$this->initialized) {
  59. $this->initialize();
  60. }
  61. return parent::getLastModified();
  62. }
  63. public function getIterator()
  64. {
  65. if (!$this->initialized) {
  66. $this->initialize();
  67. }
  68. return parent::getIterator();
  69. }
  70. public function setValues(array $values)
  71. {
  72. parent::setValues($values);
  73. $this->initialized = false;
  74. }
  75. /**
  76. * Initializes the collection based on the glob(s) passed in.
  77. */
  78. private function initialize()
  79. {
  80. foreach ($this->globs as $glob) {
  81. $glob = PathUtils::resolvePath($glob, $this->getVars(), $this->getValues());
  82. if (false !== $paths = glob($glob)) {
  83. foreach ($paths as $path) {
  84. $this->add(new FileAsset($path, array(), $this->getSourceRoot()));
  85. }
  86. }
  87. }
  88. $this->initialized = true;
  89. }
  90. }