Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Symfony without bundles

Symfony without bundles

Why your application code doesn’t need bundles.

Avatar for Aleš Šarkanj

Aleš Šarkanj

June 30, 2016

More Decks by Aleš Šarkanj

Other Decks in Programming

Transcript

  1. Aleš Šarkanj @alsar Symfony without bundles Why your application code

    doesn’t need bundles Symfony User Group Slovenia 30.6.2016
  2. 5 A bundle is similar to a plugin in other

    software, but even better. The key diference is that everything is a bundle in Symfony, including both the core framework functionality and the code written for your application. Bundles are frst-class citizens in Symfony. symfony.com/doc/current/book/bundles.html
  3. 9 Reusable (standalone) bundles meant to be shared across many

    projects vendor/ Application-specifc bundles only used to build your application src/
  4. 11

  5. 57 A typical bundle inside src/ is not a real

    bundle Those are just directories grouped together inside a bundle directory
  6. 76 # app/config/config.yml doctrine: orm: entity_managers: default: mappings: Core: type:

    yml prefix: Core dir: %kernel.root_dir%/app/config/mapping/Core is_bundle: false Foo: type: annotation prefix: Foo dir: %kernel.root_dir%/../src/Core/Model is_bundle: false
  7. 85

  8. 90 class AppKernel extends Kernel { [...] protected function buildContainer()

    { $containerBuilder = parent::buildContainer(); $containerBuilder->addCompilerPass(new ExampleCompilerPass()); return $containerBuilder; }
  9. 92 class AppConfiguration implements ConfigurationInterface { public function getConfigTreeBuilder() {

    $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('app'); $rootNode->children() ->scalarNode('edit_interval')->isRequired()->end() ->booleanNode('foo')->isRequired()->end() ->end(); return $treeBuilder; } }
  10. 94 class AppExtension extends Extension { public function load(array $configs,

    ContainerBuilder $container) { $configuration = new AppConfiguration(); $config = $this->processConfiguration($configuration, $configs); $d = new Definition(); $d->setClass('DateInterval'); $d->addArgument($config['edit_interval']); $container->setDefinition('edit_interval', $d); } public function getAlias() { return 'app'; } }
  11. 96 class AppKernel extends Kernel { [...] protected function prepareContainer(ContainerBuilder

    $container) { parent::prepareContainer($container); $container->registerExtension(new AppExtension()); } }
  12. 97