/**
  * @expectedException \InvalidArgumentException
  */
 public function testSettingInvalidBasePath()
 {
     $this->router->setBasePath(['invalid']);
 }
Example #2
0
 /**
  * This function registers the default services that Slim needs to work.
  *
  * All services are shared - that is, they are registered such that the
  * same instance is returned on subsequent calls.
  *
  * @param array $userSettings Associative array of application settings
  *
  * @return void
  */
 private function registerDefaultServices($userSettings)
 {
     $defaultSettings = $this->defaultSettings;
     /**
      * This service MUST return an array or an
      * instance of \ArrayAccess.
      *
      * @param Container $c
      *
      * @return array|\ArrayAccess
      */
     $this['settings'] = function ($c) use($userSettings, $defaultSettings) {
         return array_merge($defaultSettings, $userSettings);
     };
     /**
      * This service MUST return a shared instance
      * of \Slim\Interfaces\Http\EnvironmentInterface.
      *
      * @param Container $c
      *
      * @return EnvironmentInterface
      */
     if (!isset($this['environment'])) {
         $this['environment'] = function ($c) {
             return new Environment($_SERVER);
         };
     }
     /**
      * PSR-7 Request object
      *
      * @param Container $c
      *
      * @return ServerRequestInterface
      */
     if (!isset($this['request'])) {
         $this['request'] = function ($c) {
             return Request::createFromEnvironment($c['environment']);
         };
     }
     /**
      * PSR-7 Response object
      *
      * @param Container $c
      *
      * @return ResponseInterface
      */
     if (!isset($this['response'])) {
         $this['response'] = function ($c) {
             $headers = new Headers(['Content-Type' => 'text/html']);
             $response = new Response(200, $headers);
             return $response->withProtocolVersion($c['settings']['httpVersion']);
         };
     }
     /**
      * This service MUST return a SHARED instance
      * of \Slim\Interfaces\RouterInterface.
      *
      * @param Container $c
      *
      * @return RouterInterface
      */
     if (!isset($this['router'])) {
         $this['router'] = function ($c) {
             $router = new Router();
             $uri = $c['request']->getUri();
             if (is_callable([$uri, 'getBasePath'])) {
                 $router->setBasePath($uri->getBasePath());
             }
             return $router;
         };
     }
     /**
      * This service MUST return a SHARED instance
      * of \Slim\Interfaces\InvocationStrategyInterface.
      *
      * @param Container $c
      *
      * @return InvocationStrategyInterface
      */
     if (!isset($this['foundHandler'])) {
         $this['foundHandler'] = function ($c) {
             return new RequestResponse();
         };
     }
     /**
      * This service MUST return a callable
      * that accepts three arguments:
      *
      * 1. Instance of \Psr\Http\Message\ServerRequestInterface
      * 2. Instance of \Psr\Http\Message\ResponseInterface
      * 3. Instance of \Exception
      *
      * The callable MUST return an instance of
      * \Psr\Http\Message\ResponseInterface.
      *
      * @param Container $c
      *
      * @return callable
      */
     if (!isset($this['errorHandler'])) {
         $this['errorHandler'] = function ($c) {
             return new Error();
         };
     }
     /**
      * This service MUST return a callable
      * that accepts two arguments:
      *
      * 1. Instance of \Psr\Http\Message\ServerRequestInterface
      * 2. Instance of \Psr\Http\Message\ResponseInterface
      *
      * The callable MUST return an instance of
      * \Psr\Http\Message\ResponseInterface.
      *
      * @param Container $c
      *
      * @return callable
      */
     if (!isset($this['notFoundHandler'])) {
         $this['notFoundHandler'] = function ($c) {
             return new NotFound();
         };
     }
     /**
      * This service MUST return a callable
      * that accepts three arguments:
      *
      * 1. Instance of \Psr\Http\Message\ServerRequestInterface
      * 2. Instance of \Psr\Http\Message\ResponseInterface
      * 3. Array of allowed HTTP methods
      *
      * The callable MUST return an instance of
      * \Psr\Http\Message\ResponseInterface.
      *
      * @param Container $c
      *
      * @return callable
      */
     if (!isset($this['notAllowedHandler'])) {
         $this['notAllowedHandler'] = function ($c) {
             return new NotAllowed();
         };
     }
     /**
      * Instance of \Slim\Interfaces\CallableResolverInterface
      *
      * @param Container $c
      *
      * @return CallableResolverInterface
      */
     if (!isset($this['callableResolver'])) {
         $this['callableResolver'] = function ($c) {
             return new CallableResolver($c);
         };
     }
 }