public function getCollection() { $collection = new RoutingCollection(); foreach ($this->routings as $route) { list($methods, $path, $source) = $route; $collection->add($methods, $path, $source); } return $collection; }
/** * @param \PSX\Loader\RoutingCollection $collection * @param \ReflectionClass $class */ protected function parseClass(RoutingCollection $collection, ReflectionClass $class) { $methods = $class->getMethods(); foreach ($methods as $method) { if ($method->isPublic()) { $doc = AnnotationParser::parse($method->getDocComment()); $httpMethod = $doc->getFirstAnnotation('httpMethod'); $path = $doc->getFirstAnnotation('path'); if (!empty($httpMethod) && !empty($path)) { $allowed = explode('|', $httpMethod); $source = $class->getName() . '::' . $method->getName(); $collection->add($allowed, $path, $source); } } } }
public function getCollection() { if ($this->_collection === null) { $collection = new RoutingCollection(); $lines = file($this->file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as $line) { $line = trim(str_replace("\t", ' ', $line)); if (!empty($line) && $line[0] != '#') { $line = preg_replace('/([\\s]{1,})/', ' ', $line); $parts = explode(' ', $line); $allowed = isset($parts[0]) ? explode('|', $parts[0]) : array(); $path = isset($parts[1]) ? $parts[1] : null; $class = isset($parts[2]) ? $parts[2] : null; if (!empty($allowed) && !empty($path) && !empty($class)) { $collection->add($allowed, $path, $class); } } } $this->_collection = $collection; } return $this->_collection; }