Last active
January 2, 2016 08:59
-
-
Save BlackScorp/8280227 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
//Module.php | |
namespace CheeseAgent\Core; | |
use \Silex\ServiceProviderInterface; | |
use \Silex\Application; | |
use \Symfony\Component\HttpFoundation\Response; | |
use \Symfony\Component\HttpFoundation\Request; | |
use \Symfony\Component\HttpKernel\KernelEvents; | |
use \CheeseAgent\Core\Value\Gender; | |
class Module implements ServiceProviderInterface { | |
public function boot(Application $app) { | |
} | |
public function register(Application $app) { | |
$app['interaction.registrationFormView'] = $app->share(function($app) { | |
return new Context\Guest\RegistrationFormViewContext($app['repository.bodypart'], $app['repository.selectedLook']); | |
}); | |
$app->get('/test', 'interaction.registrationFormView') | |
->convert('request', function($request) use ($app) { | |
return new \CheeseAgent\Core\Request\RegistrationFormViewRequest($app['initialGender']); | |
}); | |
$app->before(function (Request $request) { | |
$request->attributes->set('request', $request); | |
}); | |
$app['resolver'] = $app->share($app->extend('resolver', function ($resolver, $app) { | |
$resolver = new ControllerResolver($resolver, $app); | |
return $resolver; | |
})); | |
} | |
return $app; | |
} | |
//bootstrap.php | |
use \Silex\Application; | |
use \Silex\Provider\ServiceControllerServiceProvider; | |
use \Silex\Provider\DoctrineServiceProvider; | |
use \Silex\Provider\SessionServiceProvider; | |
use \Mustache\Silex\Provider\MustacheServiceProvider; | |
use \Igorw\Silex\ConfigServiceProvider; | |
$app = new Application(); | |
$app->register(new CheeseAgent\Core\Module()); | |
return $app; | |
//controller resolver | |
namespace CheeseAgent\Core; | |
use \Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; | |
use \Symfony\Component\HttpFoundation\Request; | |
use \Pimple; | |
class ControllerResolver implements ControllerResolverInterface { | |
protected $resolver; | |
protected $container; | |
public function __construct(ControllerResolverInterface $resolver, Pimple $container) { | |
$this->resolver = $resolver; | |
$this->container = $container; | |
} | |
public function getController(Request $request) { | |
$controller = $request->attributes->get('_controller', null); | |
if (!is_string($controller) || !isset($this->container[$controller]) || !method_exists($this->container[$controller], 'invoke')) { | |
throw new \InvalidArgumentException(sprintf('Invalid interaction "%s".', $controller)); | |
} | |
$convertedRequest = $request->attributes->get('request'); | |
var_dump($convertedRequest); //httpfoundation/request | |
return $this->container[$controller]->invoke($request); | |
} | |
public function getArguments(Request $request, $controller) { | |
return $this->resolver->getArguments($request, $controller); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment