queue = new PriorityQueue(); } /** * Return count of attached resolvers * * @return int */ public function count() { return $this->queue->count(); } /** * IteratorAggregate: return internal iterator * * @return PriorityQueue */ public function getIterator() { return $this->queue; } /** * Attach a resolver * * @param Resolver $resolver * @param int $priority * @return AggregateResolver */ public function attach(Resolver $resolver, $priority = 1) { $this->queue->insert($resolver, $priority); return $this; } /** * Resolve a template/pattern name to a resource the renderer can consume * * @param string $name * @param null|Renderer $renderer * @return false|string */ public function resolve($name, Renderer $renderer = null) { $this->lastLookupFailure = false; $this->lastSuccessfulResolver = null; if (0 === count($this->queue)) { $this->lastLookupFailure = static::FAILURE_NO_RESOLVERS; return false; } foreach ($this->queue as $resolver) { $resource = $resolver->resolve($name, $renderer); if ($resource) { // Resource found; return it $this->lastSuccessfulResolver = $resolver; return $resource; } } $this->lastLookupFailure = static::FAILURE_NOT_FOUND; return false; } /** * Return the last successful resolver, if any * * @return Resolver */ public function getLastSuccessfulResolver() { return $this->lastSuccessfulResolver; } /** * Get last lookup failure * * @return false|string */ public function getLastLookupFailure() { return $this->lastLookupFailure; } }