public function testAlias() { $container = new \League\Container\Container(); $container->add('config', ['directions' => ['default' => []]]); $container->addServiceProvider('Laasti\\Directions\\Providers\\LeagueDirectionsProvider'); $this->assertInstanceOf('Laasti\\Directions\\Router', $container->get('directions.routers.default')); $this->assertInstanceOf('Laasti\\Directions\\Router', $container->get('Laasti\\Directions\\RouterInterface')); }
public function __construct() { $routes = (require_once base_path() . '/routes.php'); $container = new \League\Container\Container(); $container->add('Application'); $this->router = new \League\Route\RouteCollection($container); foreach ($routes as $route) { $this->router->addRoute($route['method'], $route['url'], $route['controller']); } }
public function testContainerResolver() { $container = new \League\Container\Container(); $middleware = $this->getMock('Laasti\\Stack\\Middleware\\PrepareableInterface'); $middleware2 = $this->getMock('Laasti\\Stack\\Middleware\\PrepareableInterface'); $resolver = new Stack\ContainerResolver($container, $middleware); $container->add('MyMiddleware', $middleware); $stack = new Stack\Stack($resolver); //Use key from container $stack->push('MyMiddleware'); //Should still work $stack->push($middleware2); $responseMessage = 'Test response'; $this->expectOutputString($responseMessage); $middleware->expects($this->exactly(1))->method('prepare')->will($this->returnValue(new Response($responseMessage))); $middleware2->expects($this->exactly(0))->method('prepare')->will($this->returnValue(new Response($responseMessage))); $stack->execute(new Request()); }
<?php $container = new League\Container\Container(); /* Response */ $container->share('response', \Zend\Diactoros\Response::class); /* Request */ $container->share('request', function () { return \Zend\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); }); /* Emitter */ $container->share('emitter', Zend\Diactoros\Response\SapiEmitter::class); /* Template Engine */ $container->share('templater', function () { return new \League\Plates\Engine(__DIR__ . '/../resources/views'); }); /* Controllers */ $container->add(\Gulchuk\Controllers\Frontend\PageController::class)->withArguments(['request', 'response']); $container->add(\Gulchuk\Controllers\Frontend\BlogController::class)->withArguments(['request', 'response']); $container->add(\Gulchuk\Controllers\AuthController::class)->withArguments(['request', 'response']); $container->add(\Gulchuk\Controllers\Backend\DashboardController::class)->withArguments(['request', 'response']); return $container;