/** * Retrieve a service from the manager by name * * Allows passing an array of options to use when creating the instance. * createFromInvokable() will use these and pass them to the instance * constructor if not null and a non-empty array. * * @param string $name * @param array $options * @param bool $usePeeringServiceManagers * @return object */ public function get($name, $options = array(), $usePeeringServiceManagers = true) { if (!$this->has($name) && !class_exists($name)) { $class = sprintf('%s\\%s\\%s', __NAMESPACE__, $this->subNamespace, ucfirst($name)); if (!class_exists($class)) { $class = sprintf('Zend\\Mvc\\Router\\%s\\%s', $this->subNamespace, ucfirst($name)); } $name = $class; } return parent::get($name, $options, $usePeeringServiceManagers); }
/** * @dataProvider shippedRoutes */ public function testDoesNotInvokeDiForShippedRoutesUsingShortName($routeName, $options) { // Setup route plugin manager $routes = new RoutePluginManager(); foreach ($this->shippedRoutes() as $name => $info) { $routes->setInvokableClass($name, $info[0]); } // Add DI abstract factory $di = new Di(); $diAbstractFactory = new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI); $routes->addAbstractFactory($diAbstractFactory); $shortName = substr($routeName, strrpos($routeName, '\\') + 1); $this->assertTrue($routes->has($shortName)); try { $route = $routes->get($shortName, $options); $this->assertInstanceOf($routeName, $route); } catch (\Exception $e) { $messages = array(); do { $messages[] = $e->getMessage() . "\n" . $e->getTraceAsString(); } while ($e = $e->getPrevious()); $this->fail(implode("\n\n", $messages)); } }
public function testLoadNonExistentRoute() { $routes = new RoutePluginManager(); $this->setExpectedException('Zend\\ServiceManager\\Exception\\ServiceNotFoundException'); $routes->get('foo'); }