PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/gruenwaldt/loquitur-web
PHP | 113 lines | 69 code | 20 blank | 24 comment | 7 complexity | b6913e6b80c9dbf04b9d44fce000530a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2013 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\Filter\FilterInterface;
  12. use Assetic\Util\VarUtils;
  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. * @param array $vars
  29. */
  30. public function __construct($globs, $filters = array(), $root = null, array $vars = array())
  31. {
  32. $this->globs = (array) $globs;
  33. $this->initialized = false;
  34. parent::__construct(array(), $filters, $root, $vars);
  35. }
  36. public function all()
  37. {
  38. if (!$this->initialized) {
  39. $this->initialize();
  40. }
  41. return parent::all();
  42. }
  43. public function load(FilterInterface $additionalFilter = null)
  44. {
  45. if (!$this->initialized) {
  46. $this->initialize();
  47. }
  48. parent::load($additionalFilter);
  49. }
  50. public function dump(FilterInterface $additionalFilter = null)
  51. {
  52. if (!$this->initialized) {
  53. $this->initialize();
  54. }
  55. return parent::dump($additionalFilter);
  56. }
  57. public function getLastModified()
  58. {
  59. if (!$this->initialized) {
  60. $this->initialize();
  61. }
  62. return parent::getLastModified();
  63. }
  64. public function getIterator()
  65. {
  66. if (!$this->initialized) {
  67. $this->initialize();
  68. }
  69. return parent::getIterator();
  70. }
  71. public function setValues(array $values)
  72. {
  73. parent::setValues($values);
  74. $this->initialized = false;
  75. }
  76. /**
  77. * Initializes the collection based on the glob(s) passed in.
  78. */
  79. private function initialize()
  80. {
  81. foreach ($this->globs as $glob) {
  82. $glob = VarUtils::resolve($glob, $this->getVars(), $this->getValues());
  83. if (false !== $paths = glob($glob)) {
  84. foreach ($paths as $path) {
  85. if (is_file($path)) {
  86. $this->add(new FileAsset($path, array(), $this->getSourceRoot()));
  87. }
  88. }
  89. }
  90. }
  91. $this->initialized = true;
  92. }
  93. }