Skip to content

Instantly share code, notes, and snippets.

@jm42
Created June 30, 2016 12:56
Show Gist options
  • Save jm42/2c9c477166c9326fc138f6efd211adc1 to your computer and use it in GitHub Desktop.
Save jm42/2c9c477166c9326fc138f6efd211adc1 to your computer and use it in GitHub Desktop.
Applicacion w/Auryn
<?php
namespace Aix;
use Auryn\Injector;
use Telegraph\DispatcherFactory;
use Telegraph\DispatcherInterface;
class Aix
{
/**
* @var Injector
*/
private $injector;
public function __construct(Injector $injector = null)
{
$this->injector = $injector ?: new Injector;
}
public function configure(array $config)
{
array_walk($config, function($config) {
$this->injector->execute($config);
});
}
public function run(array $queue)
{
$this->injector->define(DispatcherFactory::class, [$queue, function($spec) {
return $this->injector->make($spec);
}]);
$this->injector->execute([DispatcherInterface::class, 'dispatch']);
}
}
namespace Aix\Config;
use Auryn\Injector;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use Kambo\HttpMessage\ServerRequest;
use Kambo\HttpMessage\Factories\Enviroment\ServerRequestFactory;
use Kambo\HttpMessage\Enviroment\Enviroment;
use Telegraph\Dispatcher;
use Telegraph\DispatcherInterface;
use Telegraph\DispatcherFactory;
class AurynConfig
{
public function __invoke(Injector $injector)
{
}
}
class HttpMessageConfig
{
public function __invoke(Injector $injector)
{
$injector->alias(RequestInterface::class, ServerRequest::class);
$injector->delegate(ServerRequestInterface::class, [ServerRequestFactory::class, 'fromEnviroment']);
$injector->delegate(Enviroment::class, function() {
var_export($_SERVER);
return new Enviroment($_SERVER, fopen('php://input', 'w+'), $_COOKIE, $_FILES);
});
}
}
class TelegraphConfig
{
public function __invoke(Injector $injector)
{
$injector->alias(DispatcherInterface::class, Dispatcher::class);
$injector->delegate(Dispatcher::class, [DispatcherFactory::class, 'newInstance']);
}
}
{
"require": {
"rdlowrey/auryn": "dev-master",
"kambo/httpmessage": "dev-master",
"telegraph/telegraph": "1.x-dev",
"telegraph/middleware": "1.x-dev"
},
"autoload": {
"classmap": ["app.php"]
},
"minimum-stability": "dev"
}
<?php
require __DIR__ . '/vendor/autoload.php';
$app = new Aix\Aix;
$app->configure([
Aix\Config\AurynConfig::class,
Aix\Config\HttpMessageConfig::class,
Aix\Config\TelegraphConfig::class,
]);
$app->run([
Telegraph\Middleware\ResponseSender::class,
Telegraph\Middleware\ExceptionHandler::class,
Telegraph\Middleware\JsonContentHandler::class,
//Aix\Handler\ActionHandler::class,
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment