dev-master
9999999-devAllows to drop in Silex project
Apache
The Requires
- php >=5.3.0
- symfony/framework-bundle 2.1.*
by Boris Mikhaylov
silex
Allows to drop in Silex project
Silex is a great framework for small application. Overall simplicity, elegancy of routing and power of underlying symfony components are playing key roles here., (*1)
However, what if you started a project with a few features in mind, but it has grown a lot more since then? Services declarations now take a few hundred lines. Controllers are bloated even though you separate them into mounted controllers. You find yourself reimplementing providers for most symfony2 components and bundles. And now you wish you had started with symfony2 all along., (*2)
One of the possible solutions is to completely port application to symfony2. But if you don't want to put on hold development of your application, this route is rather difficult and time consuming., (*3)
This bundle solves the problem by seamlessly integrating Silex application into Symfony2., (*4)
Here's what you get:, (*5)
silex.auto_integrator
composer.json
"kagux/symfony2-silex-integration-bundle": "dev-master"
to composer.json
``` json
"require": {
"php": ">=5.3.3",
"silex/silex": "1.0.",
"symfony/symfony": "2.1.",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.0.",
"twig/extensions": "1.0.",
"symfony/assetic-bundle": "2.1.",
"symfony/swiftmailer-bundle": "2.1.",
"symfony/monolog-bundle": "2.1.",
"sensio/distribution-bundle": "2.1.",
"sensio/framework-extra-bundle": "2.1.",
"sensio/generator-bundle": "2.1.",
"jms/security-extra-bundle": "1.2.",
"jms/di-extra-bundle": "1.1.",
"kagux/symfony2-silex-integration-bundle": "dev-master"
}, (*6)
+ Run `php composer.php update` + Register KaguxSilexIntegrationBundle in `/app/AppKernel.php` ``` php public function registerBundles() { $bundles = array( ... new Kagux\SilexIntegrationBundle\KaguxSilexIntegrationBundle() ); .... }
KaguxLegacyAppBundle
``` php namespace Kagux\LegacyAppBundle\Application;, (*7)
use Silex\Application;, (*8)
class ApplicationFactory { /** * @throws \Exception * @return \Silex\Application */ public function create() { $app=new Application; $app->get('/silex', function() use ($app) { return 'Hello, world!'; }); return $app; }, (*9)
}, (*10)
+ Define a service for your Silex application ``` yaml parameters: silex.application.class: Silex\Application silex.application.factory.class: Kagux\LegacyAppBundle\Application\ApplicationFactory services: silex.application.factory: class: %silex.application.factory.class% legacy.silex.application: class: %silex.application.class% factory_service: silex.application.factory factory_method: create
config.yml
``` yaml
kagux_silex_integration:
app_service: legacy.silex.application, (*11)
+ Create routing file in your bundle `/src/Kagux/LegacyAppBundle/Resources/config/routing.yml` ``` yaml legacy_silex_application: resource: . type: silex
/app/config/routing.yml
yaml
kagux_legacy_app:
resource: "@KaguxLegacyAppBundle/Resources/config/routing.yml"
prefix: /
, (*12)
That should be it. At this point, if you browse your_site.com/silex
you will see 'Hello, world!'., (*13)
Allows to drop in Silex project
Apache
silex