123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace ClassPreloader;
- use Parser\AbstractNodeVisitor;
- /**
- * Class loader configuration object
- */
- class Config implements \IteratorAggregate
- {
- /**
- * @var array Array of AbstractNodeVisitor objects that visit nodes
- */
- protected $visitors = array();
- /**
- * @var array Array of file names
- */
- protected $filenames = array();
- /**
- * @var array Array of exclusive filters
- */
- protected $exclusiveFilters = array();
- /**
- * @var array Array of inclusive filters
- */
- protected $inclusiveFilters = array();
- /**
- * Set the filenames owned by the config
- *
- * @param array $filenames File name
- *
- * @return self
- */
- public function addFile($filename)
- {
- $this->filenames[] = $filename;
- return $this;
- }
- /**
- * Get an array of file names that satisfy any added filters
- *
- * @return array
- */
- public function getFilenames()
- {
- $filenames = array();
- foreach ($this->filenames as $f) {
- foreach ($this->inclusiveFilters as $filter) {
- if (!preg_match($filter, $f)) {
- continue 2;
- }
- }
- foreach ($this->exclusiveFilters as $filter) {
- if (preg_match($filter, $f)) {
- continue 2;
- }
- }
- $filenames[] = $f;
- }
- return $filenames;
- }
- /**
- * Get an iterator for the filenames
- *
- * @return \ArrayIterator
- */
- public function getIterator()
- {
- return new \ArrayIterator($this->getFilenames());
- }
- /**
- * Add a filter used to filter out classes matching a specific pattern
- *
- * @param string $pattern Regular expression pattern
- *
- * @return self
- */
- public function addExclusiveFilter($pattern)
- {
- $this->exclusiveFilters[] = $pattern;
- return $this;
- }
- /**
- * Add a filter used to grab only file names matching the pattern
- *
- * @param string $pattern Regular expression pattern
- *
- * @return self
- */
- public function addInclusiveFilter($pattern)
- {
- $this->inclusiveFilters[] = $pattern;
- return $this;
- }
- /**
- * Add a visitor that will visit each node when traversing the node list
- * of each file.
- *
- * @param AbstractNodeVisitor $visitor Node visitor
- *
- * @return self
- */
- public function addVisitor(AbstractNodeVisitor $visitor)
- {
- $this->visitors[] = $visitor;
- return $this;
- }
- /**
- * Get an array of node visitors
- *
- * @return array
- */
- public function getVisitors()
- {
- return $this->visitors;
- }
- }
|