Slide 1

Slide 1 text

Zend Framework 2 and Symfony2: Zend Framework 2 and Symfony2: The Perfect Team The Perfect Team Stefan Koopmanschap, Enrico Zimuel

Slide 2

Slide 2 text

About us ● Stefan Koopmanschap ● Enterpreneur: Ingewikkeld and Techademy ● Symfony Community Manager ● Co-Founder PHPBenelux, now PFZ.nl ● [email protected] ● Enrico Zimuel ● Software Engineer at Zend Technologies ● Zend Framework Core Team ● Co-founder PUG Turin ● [email protected]

Slide 3

Slide 3 text

PHP frameworks ● Symfony and Zend Framework are the most used PHP frameworks worldwide ● Both offer a tons of features that can improve the development of web applications ● Modular architectures and high quality PHP code (SoC + SOLID principles) ● Why don't use it together to get the best features of both?

Slide 4

Slide 4 text

Religion war? ZF sucks! Symfony? Oh My!

Slide 5

Slide 5 text

Instead of think about ZF2 || Symfony 2 think about ZF2 && Symfony 2

Slide 6

Slide 6 text

PSR-* ● Framework interoperability standards ● Meant to make it easier to work with multiple frameworks ● Naming standards and coding standards ● For instance: Only one autoloader! ● https://github.com/php-fig/fig-standards

Slide 7

Slide 7 text

PSR-0 Naming guidelines Directory structure

Slide 8

Slide 8 text

PSR-1 Coding standards

Slide 9

Slide 9 text

PSR-2 Code style

Slide 10

Slide 10 text

PSR-next Caching Documentation standard (Docblock)

Slide 11

Slide 11 text

Composer ● Composer (getcomposer.org) can help the management of projects that use ZF2 and Symfony2 – Select your favorite ZF2 and Symfony2 components using composer.json – $ php composer.phar install – Components installed in /vendor – Include the /vendor/autoload.php in your PHP code, that's it!

Slide 12

Slide 12 text

Easily Integrate Zend Framework 2 and Other Libraries Using Composer Ryan Weaver Thursday 8:00 AM Room 209

Slide 13

Slide 13 text

How to integrate How to integrate Zend Framework 2 in Symfony 2 Zend Framework 2 in Symfony 2

Slide 14

Slide 14 text

composer create-project symfony/framework-standard-edition project

Slide 15

Slide 15 text

Composer.json "repositories": [ { "type": "composer", "url": "http://packages.zendframework.com/" } ],

Slide 16

Slide 16 text

Composer.json "require": { "php": ">=5.3.3", "symfony/symfony": "2.2.*", (...) "zendframework/zend-crypt": "2.0.*" },

Slide 17

Slide 17 text

composer update

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Now let's get to work

Slide 20

Slide 20 text

Register Crypt class as service

Slide 21

Slide 21 text

src/ZendCon/CryptBundle/Resources/config/services.xml

Slide 22

Slide 22 text

src/ZendCon/CryptBundle/Controller/CryptController.php src/ZendCon/CryptBundle/Resources/views/Crypt/index.html.twig

Slide 23

Slide 23 text

http://zendcon.local/crypt

Slide 24

Slide 24 text

src/ZendCon/CryptBundle/Controller/CryptController.php src/ZendCon/CryptBundle/Resources/views/Crypt/check.html.twig

Slide 25

Slide 25 text

http://zendcon.local/crypt

Slide 26

Slide 26 text

Other (better?) solutions ● Do validation in Entity ● Use Symfony2 Validator

Slide 27

Slide 27 text

BlockCipher

Slide 28

Slide 28 text

src/ZendCon/CryptBundle/Controller/CryptController.php src/ZendCon/CryptBundle/Resources/views/Crypt/blockcipher.html.twig

Slide 29

Slide 29 text

http://zendcon.local/crypt/block

Slide 30

Slide 30 text

Some stuff I won't show... ● Zend\Barcode ● Zend\Captcha ● Zend\Feed ● Zend\I18n ● ZendService_*

Slide 31

Slide 31 text

How to integrate How to integrate Symfony2 in Zend Framework 2 Symfony2 in Zend Framework 2

Slide 32

Slide 32 text

How to use Symfony2 in ZF2 ● Use composer.json to include the Symfony2 components ● Execute the update (or install) command of composer ● The Symfony2 composer will be installed in /vendor ● MVC approach: ● Register the Symfony2 components in the ServiceManager ● “Standard” approach: ● Use the Symfony2 components directly (instantiate the class and use it)

Slide 33

Slide 33 text

composer.json { "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.0.*", "symfony/yaml": "2.2.*", "symfony/dom-crawler": "2.2.*", }, "autoload": { "psr-0": { "Application": "module/Application/src" } } }

Slide 34

Slide 34 text

Symfony component as a service // a module config "module/SomeModule/config/module.config.php" return array( 'service_manager' => array( 'services' => array( // Keys are the service names // Values are objects 'YamlParser' => new Symfony\Component\Yaml\Parser(), 'DomCrawler' => new Symfony\Component\DomCrawler\Crawler(), // ... ), ) );

Slide 35

Slide 35 text

Symfony component as a factory // a module config "module/SomeModule/config/module.config.php" return array( 'service_manager' => array( 'factories' => array( // Keys are the service names. // Valid values include names of classes implementing // FactoryInterface, instances of classes implementing // FactoryInterface, or any PHP callbacks 'YamlParser' => 'Symfony\Component\Yaml\Parser', 'DomCrawler' => 'Symfony\Component\DomCrawler\Crawler', // ... ), ) );

Slide 36

Slide 36 text

Use a service in a Controller class AlbumController extends AbstractActionController { public function indexAction() { $sm = $this->getServiceLocator(); $yamlParser = $sm->get('YamlParser'); $domCrawler = $sm->get('DomCrawler'); } // ... }

Slide 37

Slide 37 text

Symfony 2 components ● Some components useful for ZF2 users: – BrowserKit (simulates a web browser) – CssSelector – Filesystem – Finder (file search) – OptionsResolver – Process (executes commands in sub-processes) – Serializer (handle serializing data structures) – YAML parser

Slide 38

Slide 38 text

Concluding Concluding

Slide 39

Slide 39 text

To integrate ● PSR / Framework Interoperability ● Composer ● Pick your components ● Don't stop at Zend Framework/Symfony ● Don't Reinvent The Wheel!

Slide 40

Slide 40 text

Where to go? http://packagist.org

Slide 41

Slide 41 text

Thanks! http://framework.zend.com Give feedback: https://joind.in/7035 http://www.symfony.com