Slide 1

Slide 1 text

5 Years With Lessons learned during an Open Source adventure

Slide 2

Slide 2 text

Paweł Jędrzejewski Created Sylius Co-Founded LAKION Co-Organizing PHPers Łódź

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

I need my own framework. @pjedrzejewski

Slide 5

Slide 5 text

@pjedrzejewski

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Great! Let’s make a bundle. BundlegeneratorGeneratorBundle @pjedrzejewski

Slide 10

Slide 10 text

Lesson #1 Clicking a shiny banner is not always a bad idea. It can change your life in many posiKve ways. @pjedrzejewski

Slide 11

Slide 11 text

Lesson #1 Time is the only resource that maNers. Save yours and reuse. Focus on what you do best. PS. Use Bundles for the rest. @pjedrzejewski

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Lesson #2 Websites for friends and family do not magically maintain and fix themselves. @pjedrzejewski

Slide 14

Slide 14 text

DEPLOY

Slide 15

Slide 15 text

Lesson #3 You rarely need to create a bundle. Do not use them as namespaces. @pjedrzejewski

Slide 16

Slide 16 text

„A bundle is simply a structured set of files within a directory that implement a single feature.” @pjedrzejewski

Slide 17

Slide 17 text

In 95% of cases you need AppBundle. @pjedrzejewski

Slide 18

Slide 18 text

What is a good bundle? @pjedrzejewski

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Packagist is great, but Symfony could use a fresh bundles catalog. @pjedrzejewski

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Few words about upgrading Symfony. Doing that since 2.0. @pjedrzejewski

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

2.0 -> 2.1 was easy. 2.1 -> 2.3 was hard. (forms) 2.3 -> 2.8 was smooth. 2.8 -> 3.0 was… hard, but it was our fault. @pjedrzejewski

Slide 26

Slide 26 text

Lesson #4 Upgrade. If your project does not have resources for a Symfony upgrade, there is something much bigger broken than compaKbility. @pjedrzejewski

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

5m54.83s (678.72Mb) PHP 7 & Symfony 2.8 vs 4m38.20s (52.28Mb) PHP 7 & Symfony 3.2 13m6.17s (1.61Gb) PHP 5.6 & Symfony 2.8 vs 10m34.61s (96.04Mb) PHP 5.6 & Symfony 3.2 @pjedrzejewski

Slide 29

Slide 29 text

Lesson #5 Be careful with sub requests. They are great, but loops are dangerous. @pjedrzejewski

Slide 30

Slide 30 text

routing.yml app_partial_render_reviews: path: /_partial/render-reviews defaults: _controller: app.controller.reviews:renderAction homepage.html.twig {{ render(path(”app_partial_render_views”, {’limit’: 3)) }} security.yml access_control: - { path: "^/_partial.*", ip: 127.0.0.1 }

Slide 31

Slide 31 text

routing.yml app_reviews_index: path: /reviews defaults: _controller: app.controller.reviews:renderAction template: „@FooBar/Reviews/index.html.twig app_reviews_overview: path: /overview defaults: _controller: app.controller.reviews:renderAction template: „@FooBar/Reviews/_overview.html.twig limit: 5

Slide 32

Slide 32 text

public function renderAction($template, $limit = 3) { $reviews = …; return $this->templating->renderResponse($template, [’reviews’ => $reviews]); }

Slide 33

Slide 33 text

Migrating away from legacy It should always be a step-by-step process. Just wrap your legacy app with Symfony. Is full migraKon worth it? @pjedrzejewski

Slide 34

Slide 34 text

public function legacyAction() { $legacyFile = '/path/to/legacy-app/search.php'; ob_start(); include($legacyFile); $content = ob_get_clean(); return new Response($content); }

Slide 35

Slide 35 text

Lesson #6 Do not push for a migraKon when not needed. Be smart about it. @pjedrzejewski

Slide 36

Slide 36 text

Migrating away from legacy hNps:/ /www.theodo.fr/blog/2015/01/wrap-up-your- legacy-applicaKon-with-symfony/ @pjedrzejewski

Slide 37

Slide 37 text

Symfony FORMS Retrospective With great power comes great responsibility and yeah, processing forms is damn hard. @pjedrzejewski

Slide 38

Slide 38 text

$form = new Form('customer', $customer); $form->add(new TextField('name')); $form->add(new IntegerField(‚age')); $form->bind($this->get('request')- >request->get('customer'));

Slide 39

Slide 39 text

class TaskType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder->add('task'); $builder->add('dueDate', null, array(…)); } public function getName() { return 'task'; } }

Slide 40

Slide 40 text

use Symfony\Component\OptionsResolver\OptionsResolverInterface; public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'validation_groups' => array('registration'), )); }

Slide 41

Slide 41 text

$form = $this->createFormBuilder($task) ->add('task', TextType::class) ->add('dueDate', DateType::class) ->getForm();

Slide 42

Slide 42 text

Lesson #7 Appreciate Symfony forms. @pjedrzejewski

Slide 43

Slide 43 text

$builder->setDataLocked(false); @pjedrzejewski

Slide 44

Slide 44 text

Make a new form type, they are quite cheap now. Super-generic types are expensive. @pjedrzejewski

Slide 45

Slide 45 text

Lesson #8 CRUD is great, but can be misused. AdminGenerators are great, but assuming too much can go wrong. @pjedrzejewski

Slide 46

Slide 46 text

Integrating Symfony apps • API IntegraKons • Single-Kernel (Sylius + eZ Publish) • hNp:/ /stackphp.com/ @pjedrzejewski

Slide 47

Slide 47 text

IntegraKng 2 Symfony apps, even via API is much nicer. Similar tools and approaches make it easy. Even details like directory structure.

Slide 48

Slide 48 text

IDS are not unique enough If you applicaKon will integrate or share data with others. Unique codes will be your friend. @pjedrzejewski

Slide 49

Slide 49 text

Single Kernel Integration Throw 2 Symfony apps in a single kernel, possible! @pjedrzejewski

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

$ git clone [email protected]:netgen/ezplatform- sylius.git $ cd ezplatform-sylius $ composer install $ php app/console --env=prod sylius:install $ php app/console --env=prod ezplatform:install clean $ php app/console --env=prod assetic:dump $ php app/console --env=prod ezsylius:user:connect

Slide 53

Slide 53 text

application contained in a bundle You can contain an enKre applicaKon in a bundle. Do not do it upfront, just apply good pracKces. @pjedrzejewski

Slide 54

Slide 54 text

// AppKernel.php $bundles = array( new Sylius\Bundle\ShopBundle\SyliusShopBundle(), ); # config.yml imports: - { resource: "@SyliusShopBundle/Resources/config/ app/config.yml" } # routing.yml sylius_shop: resource: "@SyliusShopBundle/Resources/config/ routing.yml"

Slide 55

Slide 55 text

Lesson #9 Symfony’s architecture allows for integraKons on a new level. @pjedrzejewski

Slide 56

Slide 56 text

State machines are awesome Relying on a state machine for business logic makes your life simpler. hNps:/ /engineering.shopify.com/17488160-why- developers-should-be-force-fed-state-machines @pjedrzejewski

Slide 57

Slide 57 text

Open source is … EASY? We are just too busy doing it. Sharing more knowledge about Open Source pracKce, project maintenance and contribuKng is something we should work on. @pjedrzejewski

Slide 58

Slide 58 text

OPEN SOURCE CANVAS Lean Canvas for Open Source projects @pjedrzejewski

Slide 59

Slide 59 text

Open Source Canvas (Lean Canvas, but less scary for devs) DEVELOPER SEGMENTS BENEFITS

Slide 60

Slide 60 text

350+ Code contributors over 3,100,000 Downloads 600+ Translators 250 Pull Requests last month Over 19,000 Travis-CI Builds

Slide 61

Slide 61 text

BETA Sylius v1.0.0-beta.1 is around the corner… @pjedrzejewski

Slide 62

Slide 62 text

@pjedrzejewski @Sylius @Lakion pjedrzejewski.com sylius.org lakion.com THANK YOU !