Skip to content

Commit

Permalink
Update changes on the Slim repository
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Sep 15, 2017
1 parent 1d2348b commit aadcb71
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/SlimServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class SlimServiceProvider extends AbstractServiceProvider
* @var array
*/
protected $aliases = [
Collection::class => 'settings',
Request::class => 'request',
RequestInterface::class => 'request',
ServerRequestInterface::class => 'request',
Expand All @@ -60,6 +59,8 @@ class SlimServiceProvider extends AbstractServiceProvider
'outputBuffering' => 'append',
'determineRouteBeforeAppMiddleware' => false,
'displayErrorDetails' => false,
'addContentLengthHeader' => true,
'routerCacheFile' => false,
];

/**
Expand Down Expand Up @@ -89,7 +90,7 @@ public function register()
});

$this->container->share('response', function () {
$headers = new Headers(['Content-Type' => 'text/html']);
$headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
$response = new Response(200, $headers);

return $response->withProtocolVersion($this->container->get('settings')['httpVersion']);
Expand All @@ -102,7 +103,9 @@ public function register()
}

$router = (new Router)->setCacheFile($routerCacheFile);
$router->setContainer($this->container);
if (method_exists($router, 'setContainer')) {
$router->setContainer($this->container);
}

return $router;
});
Expand Down
14 changes: 7 additions & 7 deletions src/Strategies/AutoWiringStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

namespace Jenssegers\Lean\Strategies;

use League\Container\Container;
use League\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Interfaces\InvocationStrategyInterface;

class AutoWiringStrategy implements InvocationStrategyInterface
{
/**
* @var Container
* @var ContainerInterface
*/
protected $container;

/**
* AutoWiring constructor.
*
* @param Container $container
* @param ContainerInterface $container
*/
public function __construct(Container $container)
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
Expand All @@ -28,10 +28,10 @@ public function __construct(Container $container)
* Invoke a route callable with request, response and all route parameters
* as individual arguments.
*
* @param array|callable $callable
* @param array|callable $callable
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $routeArguments
* @param ResponseInterface $response
* @param array $routeArguments
*
* @return mixed
*/
Expand Down
17 changes: 15 additions & 2 deletions tests/SlimServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

use Jenssegers\Lean\SlimServiceProvider;
use League\Container\Container;
use Slim\Interfaces\InvocationStrategyInterface;

class SlimServiceProviderTest extends PHPUnit_Framework_TestCase
{
/**
* @var Container
*/
private $container;

/**
* @var SlimServiceProvider
*/
private $provider;

public function setUp()
{
$this->container = new Container;
Expand Down Expand Up @@ -54,8 +65,10 @@ public function testHasRouter()
public function testHasFoundHandler()
{
$this->assertTrue($this->container->has('foundHandler'));
$this->assertInstanceOf(Jenssegers\Lean\Strategies\AutoWiringStrategy::class,
$this->container->get('foundHandler'));
$this->assertInstanceOf(
InvocationStrategyInterface::class,
$this->container->get('foundHandler')
);
}

public function testHasPhpErrorHandler()
Expand Down

0 comments on commit aadcb71

Please sign in to comment.