PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/Leimz/leimzwebsite
PHP | 101 lines | 60 code | 18 blank | 23 comment | 6 complexity | 6f2901934044dcb2bf30fecff6f57b75 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 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. /**
  13. * A collection of assets loaded by glob.
  14. *
  15. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  16. */
  17. class GlobAsset extends AssetCollection
  18. {
  19. private $globs;
  20. private $initialized;
  21. /**
  22. * Constructor.
  23. *
  24. * @param string|array $globs A single glob path or array of paths
  25. * @param array $filters An array of filters
  26. * @param string $root The root directory
  27. */
  28. public function __construct($globs, $filters = array(), $root = null)
  29. {
  30. $this->globs = (array) $globs;
  31. $this->initialized = false;
  32. parent::__construct(array(), $filters, $root);
  33. }
  34. public function all()
  35. {
  36. if (!$this->initialized) {
  37. $this->initialize();
  38. }
  39. return parent::all();
  40. }
  41. public function load(FilterInterface $additionalFilter = null)
  42. {
  43. if (!$this->initialized) {
  44. $this->initialize();
  45. }
  46. parent::load($additionalFilter);
  47. }
  48. public function dump(FilterInterface $additionalFilter = null)
  49. {
  50. if (!$this->initialized) {
  51. $this->initialize();
  52. }
  53. return parent::dump($additionalFilter);
  54. }
  55. public function getLastModified()
  56. {
  57. if (!$this->initialized) {
  58. $this->initialize();
  59. }
  60. return parent::getLastModified();
  61. }
  62. public function getIterator()
  63. {
  64. if (!$this->initialized) {
  65. $this->initialize();
  66. }
  67. return parent::getIterator();
  68. }
  69. /**
  70. * Initializes the collection based on the glob(s) passed in.
  71. */
  72. private function initialize()
  73. {
  74. foreach ($this->globs as $glob) {
  75. if (false !== $paths = glob($glob)) {
  76. foreach ($paths as $path) {
  77. $this->add(new FileAsset($path, array(), $this->getSourceRoot()));
  78. }
  79. }
  80. }
  81. $this->initialized = true;
  82. }
  83. }