public function testServiceManagerRespectsSharedFlagWhenRetrievingFromPeeredServiceManager()
 {
     $this->serviceManager->setInvokableClass('foo', 'PPI\\FrameworkTest\\ServiceManager\\Fixtures\\Foo');
     $this->serviceManager->setShared('foo', false);
     $childManager = new ServiceManager(new Config());
     $childManager->addPeeringServiceManager($this->serviceManager);
     $childManager->setRetrieveFromPeeringManagerFirst(false);
     $this->assertNotSame($childManager->get('foo'), $childManager->get('foo'));
 }
示例#2
0
 /**
  *
  * Perform the matching of a route and return a set of routing parameters if a valid one is found.
  * Otherwise exceptions get thrown
  *
  * @param RequestInterface $request
  * @return array
  *
  * @throws \Exception
  */
 protected function handleRouting(RequestInterface $request)
 {
     $this->router = $this->serviceManager->get('Router');
     $this->router->warmUp($this->getCacheDir());
     try {
         // Lets load up our router and match the appropriate route
         $parameters = $this->router->matchRequest($request);
         if (!empty($parameters)) {
             if (null !== $this->logger) {
                 $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->router->parametersToString($parameters)));
             }
         }
     } catch (ResourceNotFoundException $e) {
         $routeUri = $this->router->generate('Framework_404');
         $parameters = $this->router->matchRequest($request::create($routeUri));
     } catch (\Exception $e) {
         throw $e;
     }
     $parameters['_route_params'] = $parameters;
     return $parameters;
 }
示例#3
0
 /**
  * Perform the matching of a route and return a set of routing parameters if a valid one is found.
  * Otherwise exceptions get thrown
  *
  * @return array
  *
  * @throws \Exception
  */
 protected function handleRouting()
 {
     $this->router = $this->serviceManager->get('Router');
     $this->router->warmUp($this->getCacheDir());
     try {
         // Lets load up our router and match the appropriate route
         $parameters = $this->router->matchRequest($this->getRequest());
         if (!empty($parameters)) {
             if (null !== $this->logger) {
                 $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->router->parametersToString($parameters)));
             }
             $parameters['_route_params'] = $parameters;
             $this->getRequest()->attributes->add($parameters);
             return $parameters;
         }
     } catch (ResourceNotFoundException $e) {
         // Lets grab the 'Framework 404' route and dispatch it.
         //            try {
         //                $baseUrl = $this->router->getContext()->getBaseUrl();
         //                $routeUri = $this->router->generate($this->options['404RouteName']);
         //
         //                // We need to strip /myapp/public/404 down to /404, so our matchRoute() to work.
         //                if (!empty($baseUrl) && ($pos = strpos($routeUri, $baseUrl)) !== false) {
         //                    $routeUri = substr_replace($routeUri, '', $pos, strlen($baseUrl));
         //                }
         //
         //                // @todo handle a 502 here
         //
         //            } catch (\Exception $e) {
         throw new \Exception('Unable to load 404 page. An internal error occurred');
         //            }
     } catch (\Exception $e) {
         throw $e;
     }
 }