-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test app for backward compatibility
- Loading branch information
Showing
8 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Rougin\Slytherin\Application; | ||
use Rougin\Slytherin\Component\Collector; | ||
use Rougin\Slytherin\Container\Container; | ||
|
||
$root = dirname(dirname(__DIR__)); | ||
|
||
require $root . '/vendor/autoload.php'; | ||
|
||
$items = array(); | ||
|
||
$items[] = 'Rougin\Slytherin\Fixture\Components\CollectionComponent'; | ||
$items[] = 'Rougin\Slytherin\Fixture\Components\DebuggerComponent'; | ||
$items[] = 'Rougin\Slytherin\Fixture\Components\DispatcherComponent'; | ||
$items[] = 'Rougin\Slytherin\Fixture\Components\HttpComponent'; | ||
$items[] = 'Rougin\Slytherin\Fixture\Components\SingleComponent'; | ||
|
||
$container = new Container; | ||
|
||
$components = Collector::get($container, $items, $globals); | ||
|
||
var_dump($components); | ||
|
||
$app = new Application($components); | ||
|
||
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Rougin\Slytherin\Previous\Handlers; | ||
|
||
class Hello | ||
{ | ||
public function __invoke($request, $response, $next = null) | ||
{ | ||
$response = $next($request, $response); | ||
|
||
$response->getBody()->write('Hello from middleware'); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello world! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello {{ name }}! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use Rougin\Slytherin\Dispatching\Router; | ||
|
||
$name = 'Rougin\Slytherin\Previous\Routes'; | ||
|
||
$router = new Router; | ||
|
||
$router->addRoute('GET', '/', [ "$name\Hello", 'index' ]); | ||
|
||
$router->addRoute('GET', '/hi/:name', [ "$name\Hello", 'hi' ]); | ||
|
||
// Add the middlewares to a specified route --------------- | ||
$items = array('Rougin\Slytherin\Previous\Handlers\Hello'); | ||
|
||
$router->addRoute('GET', '/hello', function () {}, $items); | ||
// -------------------------------------------------------- | ||
|
||
return $router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Rougin\Slytherin\Previous\Routes; | ||
|
||
use Rougin\Slytherin\Template\RendererInterface; | ||
|
||
class Hello | ||
{ | ||
protected $renderer; | ||
|
||
public function __construct(RendererInterface $renderer) | ||
{ | ||
$this->renderer = $renderer; | ||
} | ||
|
||
public function index() | ||
{ | ||
return $this->renderer->render('Greet'); | ||
} | ||
|
||
public function hi($name) | ||
{ | ||
return $this->renderer->render('Hello', compact('name')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
use Rougin\Slytherin\Application; | ||
use Rougin\Slytherin\ComponentCollection; | ||
use Rougin\Slytherin\Dispatching\Dispatcher; | ||
use Rougin\Slytherin\ErrorHandler\Whoops; | ||
use Rougin\Slytherin\IoC\Auryn; | ||
use Rougin\Slytherin\Middleware\StratigilityMiddleware; | ||
use Rougin\Slytherin\Template\RendererInterface; | ||
use Rougin\Slytherin\Template\Twig; | ||
use Zend\Diactoros\Response; | ||
use Zend\Diactoros\ServerRequestFactory; | ||
use Zend\Stratigility\MiddlewarePipe; | ||
|
||
$root = dirname(dirname(__DIR__)); | ||
|
||
require $root . '/vendor/autoload.php'; | ||
|
||
$component = new ComponentCollection; | ||
|
||
// Initialize the RendererInterface ------------ | ||
$views = (string) realpath(__DIR__ . '/Plates'); | ||
$loader = new Twig_Loader_Filesystem($views); | ||
$twig = new Twig(new Twig_Environment($loader)); | ||
$renderer = RendererInterface::class; | ||
// --------------------------------------------- | ||
|
||
// Initialize the DependencyInjectorInterface --- | ||
$auryn = new Auryn(new \Auryn\Injector); | ||
// Create an alias for the RendererInterface --- | ||
$auryn->share($twig); | ||
$auryn->alias($renderer, get_class($twig)); | ||
// --------------------------------------------- | ||
$component->setDependencyInjector($auryn); | ||
// ---------------------------------------------- | ||
|
||
// Initialize the ErrorHandlerInterface --- | ||
$whoops = new Whoops(new \Whoops\Run); | ||
$component->setErrorHandler($whoops); | ||
// ---------------------------------------- | ||
|
||
// Initialize the ServerRequestInterface and ResponseInterface --- | ||
$request = ServerRequestFactory::fromGlobals(); | ||
$response = new Response; | ||
$component->setHttp($request, $response); | ||
// --------------------------------------------------------------- | ||
|
||
// Initialize the routing dispatcher interface ----- | ||
$router = require realpath(__DIR__ . '/Router.php'); | ||
$dispatcher = new Dispatcher($router, $response); | ||
$component->setDispatcher($dispatcher); | ||
// ------------------------------------------------- | ||
|
||
// Initialize the middleware ------------------- | ||
$pipe = new MiddlewarePipe; | ||
$middleware = new StratigilityMiddleware($pipe); | ||
$component->setMiddleware($middleware); | ||
// --------------------------------------------- | ||
|
||
// Initialize then run the Application --- | ||
$app = new Application($component); | ||
|
||
$app->run(); | ||
// --------------------------------------- |