-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added minimum set-up to handle requests
- Loading branch information
Showing
22 changed files
with
549 additions
and
8 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
DependencyInjection/CompilerPass/RoutingResolverCompilerPass.php
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,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the gnugat/micro-framework-bundle package. | ||
* | ||
* (c) Loïc Faugeron <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gnugat\MicroFrameworkBundle\DependencyInjection\CompilerPass; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class RoutingResolverCompilerPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (false === $container->hasDefinition('routing.resolver')) { | ||
return; | ||
} | ||
$routingResolver = $container->getDefinition('routing.resolver'); | ||
$taggedServices = $container->findTaggedServiceIds('routing.loader'); | ||
foreach ($taggedServices as $id => $attributes) { | ||
$routingResolver->addMethodCall('addLoader', array(new Reference($id))); | ||
} | ||
} | ||
} |
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,115 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the gnugat/micro-framework-bundle package. | ||
* | ||
* (c) Loïc Faugeron <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gnugat\MicroFrameworkBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\Config\Loader\LoaderResolver; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class GnugatMicroFrameworkExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$fileLocator = new FileLocator(__DIR__.'/../Resources/config'); | ||
$loader = new DirectoryLoader($container, $fileLocator); | ||
$loader->setResolver(new LoaderResolver(array( | ||
new YamlFileLoader($container, $fileLocator), | ||
$loader, | ||
))); | ||
$loader->load('services/'); | ||
|
||
$this->configureRoutingParameters($container); | ||
$this->configureClassesToCompile(); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
*/ | ||
private function configureRoutingParameters(ContainerBuilder $container) | ||
{ | ||
if (false === $container->hasParameter('router.resource')) { | ||
$container->setParameter('router.resource', '%kernel.root_dir%/config/routings'); | ||
} | ||
if (false === $container->hasParameter('router.resource_type')) { | ||
$container->setParameter('router.resource_type', 'directory'); | ||
} | ||
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.name').ucfirst($container->getParameter('kernel.environment'))); | ||
} | ||
|
||
/** | ||
* Run `bin/what-classes-to-compile.sh` to have an idea of what to add here. | ||
*/ | ||
private function configureClassesToCompile() | ||
{ | ||
$this->addClassesToCompile(array( | ||
'Gnugat\\MicroFrameworkBundle\\GnugatMicroFrameworkBundle', | ||
'Gnugat\\MicroFrameworkBundle\\Service\\ServiceControllerResolver', | ||
|
||
'Symfony\\Component\\ClassLoader\\ClassCollectionLoader', | ||
|
||
'Symfony\\Component\\Config\\ConfigCache', | ||
'Symfony\\Component\\Config\\FileLocator', | ||
'Symfony\\Component\\Config\\Loader\\DelegatingLoader', | ||
'Symfony\\Component\\Config\\Loader\\LoaderResolver', | ||
'Symfony\\Component\\Config\\Loader\\Loader', | ||
'Symfony\\Component\\Config\\Loader\\FileLoader', | ||
'Symfony\\Component\\Config\\Resource\\SelfCheckingResourceChecker', | ||
'Symfony\\Component\\Config\\ResourceCheckerConfigCache', | ||
'Symfony\\Component\\Config\\ResourceCheckerConfigCacheFactory', | ||
|
||
'Symfony\\Component\\DependencyInjection\\Container', | ||
|
||
'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher', | ||
'Symfony\\Component\\EventDispatcher\\Event', | ||
'Symfony\\Component\\EventDispatcher\\EventDispatcher', | ||
|
||
'Symfony\\Component\\HttpFoundation\\FileBag', | ||
'Symfony\\Component\\HttpFoundation\\HeaderBag', | ||
'Symfony\\Component\\HttpFoundation\\ServerBag', | ||
'Symfony\\Component\\HttpFoundation\\ParameterBag', | ||
'Symfony\\Component\\HttpFoundation\\Request', | ||
'Symfony\\Component\\HttpFoundation\\RequestStack', | ||
'Symfony\\Component\\HttpFoundation\\Response', | ||
'Symfony\\Component\\HttpFoundation\\ResponseHeaderBag', | ||
|
||
'Symfony\\Component\\HttpKernel\\Bundle\\Bundle', | ||
'Symfony\\Component\\HttpKernel\\Config\\FileLocator', | ||
'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver', | ||
'Symfony\\Component\\HttpKernel\\HttpKernel', | ||
'Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent', | ||
'Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent', | ||
'Symfony\\Component\\HttpKernel\\Event\\FinishRequestEvent', | ||
'Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent', | ||
'Symfony\\Component\\HttpKernel\\Event\\KernelEvent', | ||
'Symfony\\Component\\HttpKernel\\Event\\PostResponseEvent', | ||
'Symfony\\Component\\HttpKernel\\EventListener\\ResponseListener', | ||
'Symfony\\Component\\HttpKernel\\EventListener\\RouterListener', | ||
'Symfony\\Component\\HttpKernel\\KernelEvents', | ||
|
||
'Symfony\\Component\\Routing\\Loader\\XmlFileLoader', | ||
'Symfony\\Component\\Routing\\Loader\\YamlFileLoader', | ||
'Symfony\\Component\\Routing\\Loader\\PhpFileLoader', | ||
'Symfony\\Component\\Routing\\Loader\\DirectoryLoader', | ||
'Symfony\\Component\\Routing\\Loader\\ObjectRouteLoader', | ||
'Symfony\\Component\\Routing\\Loader\\DependencyInjection\\ServiceRouterLoader', | ||
'Symfony\\Component\\Routing\\RequestContext', | ||
'Symfony\\Component\\Routing\\Router', | ||
'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', | ||
)); | ||
} | ||
} |
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,3 @@ | ||
services: | ||
service_container: | ||
synthetic: true |
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,5 @@ | ||
services: | ||
event_dispatcher: | ||
class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher | ||
arguments: | ||
- "@service_container" |
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,4 @@ | ||
services: | ||
request_stack: | ||
class: Symfony\Component\HttpFoundation\RequestStack | ||
|
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,47 @@ | ||
services: | ||
http_kernel: | ||
class: Symfony\Component\HttpKernel\HttpKernel | ||
arguments: | ||
- "@event_dispatcher" | ||
- "@service_controller_resolver" | ||
- "@request_stack" | ||
|
||
kernel: | ||
synthetic: true | ||
|
||
service_controller_resolver: | ||
class: Gnugat\MicroFrameworkBundle\Service\ServiceControllerResolver | ||
public: false | ||
arguments: | ||
- "@service_container" | ||
- "@controller_resolver" | ||
|
||
controller_resolver: | ||
class: Symfony\Component\HttpKernel\Controller\ControllerResolver | ||
public: false | ||
|
||
file_locator: | ||
class: Symfony\Component\HttpKernel\Config\FileLocator | ||
public: false | ||
arguments: | ||
- "@kernel" | ||
- "%kernel.root_dir%/Resources" | ||
|
||
### | ||
# EventListener | ||
### | ||
response_listener: | ||
class: Symfony\Component\HttpKernel\EventListener\ResponseListener | ||
arguments: | ||
- "%kernel.charset%" | ||
tags: | ||
- { name: "kernel.event_subscriber" } | ||
|
||
router_listener: | ||
class: Symfony\Component\HttpKernel\EventListener\RouterListener | ||
arguments: | ||
- "@router" | ||
- "@request_stack" | ||
- "@router.request_context" | ||
tags: | ||
- { name: kernel.event_subscriber } |
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,81 @@ | ||
parameters: | ||
router.options: | ||
cache_dir: "%kernel.cache_dir%" | ||
debug: "%kernel.debug%" | ||
resource_type: "%router.resource_type%" | ||
generator_cache_class: "%router.cache_class_prefix%UrlGenerator" | ||
matcher_cache_class: "%router.cache_class_prefix%UrlMatcher" | ||
|
||
services: | ||
router: | ||
class: Symfony\Component\Routing\Router | ||
public: false | ||
arguments: | ||
- "@routing.loader" | ||
- "%router.resource%" | ||
- "%router.options%" | ||
- "@router.request_context" | ||
calls: | ||
- [ setConfigCacheFactory, ["@config_cache_factory"] ] | ||
|
||
routing.loader: | ||
class: Symfony\Component\Config\Loader\DelegatingLoader | ||
public: false | ||
arguments: | ||
- "@routing.resolver" | ||
|
||
routing.resolver: | ||
class: Symfony\Component\Config\Loader\LoaderResolver | ||
public: false | ||
|
||
router.request_context: | ||
class: Symfony\Component\Routing\RequestContext | ||
public: false | ||
|
||
config_cache_factory: | ||
class: Symfony\Component\Config\ResourceCheckerConfigCacheFactory | ||
public: false | ||
arguments: [] | ||
|
||
### | ||
# Routing Loaders | ||
### | ||
routing.loader.xml: | ||
class: Symfony\Component\Routing\Loader\XmlFileLoader | ||
public: false | ||
arguments: | ||
- "@file_locator" | ||
tags: | ||
- { name: routing.loader } | ||
|
||
routing.loader.yml: | ||
class: Symfony\Component\Routing\Loader\YamlFileLoader | ||
public: false | ||
arguments: | ||
- "@file_locator" | ||
tags: | ||
- { name: routing.loader } | ||
|
||
routing.loader.php: | ||
class: Symfony\Component\Routing\Loader\PhpFileLoader | ||
public: false | ||
arguments: | ||
- "@file_locator" | ||
tags: | ||
- { name: routing.loader } | ||
|
||
routing.loader.directory: | ||
class: Symfony\Component\Routing\Loader\DirectoryLoader | ||
public: false | ||
arguments: | ||
- "@file_locator" | ||
tags: | ||
- { name: routing.loader } | ||
|
||
routing.loader.service: | ||
class: Symfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoader | ||
public: false | ||
arguments: | ||
- "@service_container" | ||
tags: | ||
- { name: routing.loader } |
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,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the gnugat/micro-framework-bundle package. | ||
* | ||
* (c) Loïc Faugeron <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gnugat\MicroFrameworkBundle\Service; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Resolves controllers defined as services (service:method notation). | ||
*/ | ||
class ServiceControllerResolver implements ControllerResolverInterface | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @var ControllerResolverInterface | ||
*/ | ||
private $controllerResolver; | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
* @param ControllerResolverInterface $parser | ||
*/ | ||
public function __construct(ContainerInterface $container, ControllerResolverInterface $controllerResolver) | ||
{ | ||
$this->container = $container; | ||
$this->controllerResolver = $controllerResolver; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getController(Request $request) | ||
{ | ||
$parts = explode(':', $request->attributes->get('_controller', '')); | ||
if (2 !== count($parts)) { | ||
return $this->controllerResolver->getController($request); | ||
} | ||
|
||
return array($this->container->get($parts[0]), $parts[1]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getArguments(Request $request, $controller) | ||
{ | ||
return $this->controllerResolver->getArguments($request, $controller); | ||
} | ||
} |
Oops, something went wrong.