Slide 1

Slide 1 text

The Traveling Symfony Circus by your friend: Ryan Weaver @weaverryan Thursday, May 23, 13

Slide 2

Slide 2 text

Who is this Hipster? • That “Docs” guy • KnpLabs US - Symfony consulting, training, Kumbaya • Writer for KnpUniversity.com screencasts knplabs.com github.com/weaverryan @weaverryan Thursday, May 23, 13

Slide 3

Slide 3 text

Who is this Hipster? • That “Docs” guy • KnpLabs US - Symfony consulting, training, Kumbaya • Writer for KnpUniversity.com screencasts • Husband of the much more talented @leannapelham knplabs.com github.com/weaverryan @weaverryan Thursday, May 23, 13

Slide 4

Slide 4 text

Adventures with Symfony! Jan - May Thursday, May 23, 13

Slide 5

Slide 5 text

Symfony and I California Burlington, VT Thursday, May 23, 13

Slide 6

Slide 6 text

Vancouver California Symfony and I Thursday, May 23, 13

Slide 7

Slide 7 text

Portland San Diego Symfony and I Thursday, May 23, 13

Slide 8

Slide 8 text

Intro Symphony: So popular, recruiters misspell it less! (the good news) Thursday, May 23, 13

Slide 9

Slide 9 text

Intro Reasons to be happy as a Symfony Developer (the good news) Thursday, May 23, 13

Slide 10

Slide 10 text

PHP: We, the unexpected generation of *quality* @weaverryan A Thursday, May 23, 13

Slide 11

Slide 11 text

Cooperation Composer Other Libraries Drupal Aura Packages Symfony Components Symfony Framework AWS SDK Some random library you wrote! Thursday, May 23, 13

Slide 12

Slide 12 text

Interoperability Thursday, May 23, 13

Slide 13

Slide 13 text

PSR: PHP Standards Repository @weaverryan • PSR0 - Thou shalt name your classes, namespaces and directories in a sane way • PSR1 - Thou shalt use these coding standards • PSR2 - Thou shalt probably use these other coding standards too • PSR3 - Thou shalt create loggers that implement this interface http://www.php-fig.org/ Thursday, May 23, 13

Slide 14

Slide 14 text

Gone: Symfony’s LoggerInterface Here: Psr\Log\LoggerInterface Thursday, May 23, 13

Slide 15

Slide 15 text

Quality Thursday, May 23, 13

Slide 16

Slide 16 text

Quality Interfaces Dependency Injection Thursday, May 23, 13

Slide 17

Slide 17 text

Quality Interfaces Dependency Injection Service-Oriented Architecture Thursday, May 23, 13

Slide 18

Slide 18 text

Symfony2: Moving like a bat out of heck @weaverryan B Thursday, May 23, 13

Slide 19

Slide 19 text

How can we measure the progress of Symfony? Thursday, May 23, 13

Slide 20

Slide 20 text

while (true) { $fabien->mergePullRequests(); sleep(8); } 2010 Thursday, May 23, 13

Slide 21

Slide 21 text

while (true) { $fabien->mergePullRequests(); sleep(6); } 2011 Thursday, May 23, 13

Slide 22

Slide 22 text

while (true) { $fabien->mergePullRequests(); sleep(4); } 2012 Thursday, May 23, 13

Slide 23

Slide 23 text

while (true) { $fabien->mergePullRequests(); // sleep(4); } 2013 Thursday, May 23, 13

Slide 24

Slide 24 text

http://symfony.com/blog/category/living-on-the-edge Thursday, May 23, 13

Slide 25

Slide 25 text

Symfony: Playing on a big Stage @weaverryan C Thursday, May 23, 13

Slide 26

Slide 26 text

Symfony powers an increasing number of large websites Thursday, May 23, 13

Slide 27

Slide 27 text

Symfony components are used in an increasing number of open source projects Thursday, May 23, 13

Slide 28

Slide 28 text

Symfony Components @weaverryan • Drupal • phpBB • eZ publish • Magento (Twig) • Joomla (Yaml) • Flow3 • Laravel • Zikula • Propel • Behat • Foxycart Thursday, May 23, 13

Slide 29

Slide 29 text

Drupal Hug a Drupaler today http://images.free-extras.com/pics/k/kitten_hug-1451.jpg ... and tell them about Composer ... Thursday, May 23, 13

Slide 30

Slide 30 text

The Main Event Symfony: Why - despite my previous slides - we haven’t all retired to a beach yet (the bad news) Thursday, May 23, 13

Slide 31

Slide 31 text

10 Lessons from touring like a Symfony Country Music Star http://www.weavercountry.com/ Thursday, May 23, 13

Slide 32

Slide 32 text

The Symfony Framework is too Hard @weaverryan 1 Thursday, May 23, 13

Slide 33

Slide 33 text

How we see Symfony @weaverryan 1) Front Controller 2) Container is built 3) Kernel handles the request, fires events 4) Routing returns attributes 5) Resolver finds the controller gets its args 6) Controller is executed, returns a Response 7) A few more events fire, Response is sent HttpKernel: http://bit.ly/httpkernel Thursday, May 23, 13

Slide 34

Slide 34 text

How a newcomer sees Symfony @weaverryan 1) app_dev.php (wtf is this?) 2) ??? routing? _controller, which points to a file somewhere? 3) Some magic ->render() method from an indexAction function I found? 4) some other things, I have no idea. There are like 20 dirs and 50 YAML files 5) #%$!ing class not found error! 6) Profit! Thursday, May 23, 13

Slide 35

Slide 35 text

The Symfony Framework is *not* hard Thursday, May 23, 13

Slide 36

Slide 36 text

So what’s going on? Thursday, May 23, 13

Slide 37

Slide 37 text

#1) Symfony Frameworkisms @weaverryan • _controller: MainBundle:Default:index • MainBundle:Default:index.html.twig • @MainBundle/Resources/config/routing.yml • arguments: [@router, %foo_param%] Thursday, May 23, 13

Slide 38

Slide 38 text

#2) Namespaces @weaverryan • Namespaces are long • People forget the “namespace” • People forget the “use” statement • The autoloader can’t give you useful debugging information Thursday, May 23, 13

Slide 39

Slide 39 text

This causes the most errors for beginners... by far Thursday, May 23, 13

Slide 40

Slide 40 text

#3) Configuration @weaverryan #4) Directory Structure #5) Shortcuts Thursday, May 23, 13

Slide 41

Slide 41 text

return $this->render( 'DemoBundle:Default:index.html.twig' ); Symfony2 Controller Thursday, May 23, 13

Slide 42

Slide 42 text

$templating = $this->container ->get('templating'); return $templating->renderResponse( 'DemoBundle:Default:index.html.twig' ); w/o shortcut method Thursday, May 23, 13

Slide 43

Slide 43 text

use Symfony\Component\HttpFoundation\Response; $templating = $this->container ->get('templating'); $html = $templating->render( 'DemoBundle:Default:index.html.twig' ); return new Response($html); w/o auto-Response creation Thursday, May 23, 13

Slide 44

Slide 44 text

use Symfony\Component\HttpFoundation\Response; $loader = new \Twig_Loader_Filesystem( __DIR__.'/templates' ); $twig = new \Twig_Environment($loader); $html = $templating->render('index.twig'); return new Response($html); w/o the container Thursday, May 23, 13

Slide 45

Slide 45 text

Which level “framework” is best for advertising? Thursday, May 23, 13

Slide 46

Slide 46 text

Which level “framework” is best for teaching? Thursday, May 23, 13

Slide 47

Slide 47 text

Sf\WootBundle\Controller\FooController::indexAction SfWootBundle:Foo:index Use Shortcuts ... but know first that you don’t need to _controller: Thursday, May 23, 13

Slide 48

Slide 48 text

http://knpuniversity.com/screencast/question-answer-day The first 4 hours, directory structure, Frameworkisms Thursday, May 23, 13

Slide 49

Slide 49 text

Yell from a Mountain: The Symfony Framework is only 2 things Thursday, May 23, 13

Slide 50

Slide 50 text

1) A Routing-Controller, Request-Response Flow e.g. for /foo, execute the fooAction function, then I’ll put PHP code there to make a page *every* framework does this... in pretty much exactly the same way Thursday, May 23, 13

Slide 51

Slide 51 text

2) A bunch of optional objects to help you build that page Thursday, May 23, 13

Slide 52

Slide 52 text

Teaching Symfony @weaverryan • Avoid Symfony Framework’isms initially • Do things the long way, *then* opt into shortcuts • Start small (Silex!) • Remind people that routing+controller is 50% and everything else is totally optional Thursday, May 23, 13

Slide 53

Slide 53 text

The Symfony Framework is too fat @weaverryan 2 Thursday, May 23, 13

Slide 54

Slide 54 text

The smaller we make Symfony, the faster a user will understand it Thursday, May 23, 13

Slide 55

Slide 55 text

Let’s create the SymfonyOnAVeganNoGMODietEdition Thursday, May 23, 13

Slide 56

Slide 56 text

The Standard Edition comes with bundles to help you Thursday, May 23, 13

Slide 57

Slide 57 text

Kill them! http://upload.wikimedia.org/wikipedia/commons/6/65/Pac-Man_Cutscene.svg Thursday, May 23, 13

Slide 58

Slide 58 text

public function registerBundles() { $bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\...\SwiftmailerBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\...\SensioFrameworkExtraBundle(), new SfLive\WootBundle\SfLiveWootBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { $bundles[] = new Symfony\...\WebProfilerBundle(); $bundles[] = new Sensio\...\SensioDistributionBundle(); $bundles[] = new Sensio\...\SensioGeneratorBundle(); } return $bundles; } Thursday, May 23, 13

Slide 59

Slide 59 text

public function registerBundles() { $bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\...\SwiftmailerBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\...\SensioFrameworkExtraBundle(), new SfLive\WootBundle\SfLiveWootBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { $bundles[] = new Symfony\...\WebProfilerBundle(); $bundles[] = new Sensio\...\SensioDistributionBundle(); $bundles[] = new Sensio\...\SensioGeneratorBundle(); } return $bundles; } Thursday, May 23, 13

Slide 60

Slide 60 text

public function registerBundles() { $bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new SfLive\WootBundle\SfLiveWootBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { $bundles[] = new Symfony\...\WebProfilerBundle(); } return $bundles; } Thursday, May 23, 13

Slide 61

Slide 61 text

What *is* the Symfony Framework @weaverryan 1) A simple Routing-Controller, Request- Response Flow (HttpKernel) 2) A DI container with (optional) pre-built services for your convenience 3) (Optional) Shortcuts and other Symfony-isms that speed-up development Thursday, May 23, 13

Slide 62

Slide 62 text

Opt-in to your level of Shortcuts/Symfonyisms Thursday, May 23, 13

Slide 63

Slide 63 text

Simplify first, add in things in later if you need them Thursday, May 23, 13

Slide 64

Slide 64 text

Thar be WTF on your Timeline! @weaverryan 3 Thursday, May 23, 13

Slide 65

Slide 65 text

Thursday, May 23, 13

Slide 66

Slide 66 text

??? Thursday, May 23, 13

Slide 67

Slide 67 text

Initialization time @weaverryan Symfony\Component\HttpKernel\Kernel::boot() • Initialize and boot the bundles (~several ms) • Building and instantiating the container (depends) Thursday, May 23, 13

Slide 68

Slide 68 text

What? Time Affects prod? Boot the bundles ~1-5ms Yes Rebuild the container? ~1-300ms No! Ok! Build the container ~500ms-seconds No! Instantiate the container <1ms Yes Building and Instantiating the Container Thursday, May 23, 13

Slide 69

Slide 69 text

??? Thursday, May 23, 13

Slide 70

Slide 70 text

kernel.request.loading @weaverryan • The amount of time it takes to instantiate your listeners • How lightweight are your event listeners to construct? Thursday, May 23, 13

Slide 71

Slide 71 text

Events inside the Profiler Thursday, May 23, 13

Slide 72

Slide 72 text

JMSDebuggingBundle Thursday, May 23, 13

Slide 73

Slide 73 text

Solution? Thursday, May 23, 13

Slide 74

Slide 74 text

1) Inject the Container Thursday, May 23, 13

Slide 75

Slide 75 text

2) Lazy Services (Symfony 2.3) Thursday, May 23, 13

Slide 76

Slide 76 text

Heavy Service Debugging @weaverryan • If a service is heavy to instantiate, there’s no good way (yet) to see that • Heavy instantiation is hidden in event “loading” statements, the firewall, and the controller • Having 1000 services is ok, but do you really know how many are being instantiated on each request? Thursday, May 23, 13

Slide 77

Slide 77 text

Vote Boo-urns on ACL’s! @weaverryan 4 Thursday, May 23, 13

Slide 78

Slide 78 text

How do I enforce that a comment is only editable by its owner *or* an “admin” user? Thursday, May 23, 13

Slide 79

Slide 79 text

@weaverryan http://symfony.com/doc/current/cookbook/security/acl.html Thursday, May 23, 13

Slide 80

Slide 80 text

@weaverryan http://symfony.com/doc/current/cookbook/security/acl.html • Creates a new, generic table setup to that stores a relationship between an object, a user, and what that user can do with the object • Written to be highly efficient • And you should (probably) never use it! Thursday, May 23, 13

Slide 81

Slide 81 text

@weaverryan http://symfony.com/doc/current/cookbook/security/acl.html • Creates a new, generic table setup to that stores a relationship between an object, a user, and what that user can do with the object • Written to be highly efficient •Bah! Seriously, don’t use it! Thursday, May 23, 13

Slide 82

Slide 82 text

The relationship between the object and the user that defines access probably already exists Thursday, May 23, 13

Slide 83

Slide 83 text

User A Comment Can this user edit this comment? ??? Thursday, May 23, 13

Slide 84

Slide 84 text

User A Comment Scenario1: The user wrote the comment Comment->getUser(): User A YES! Thursday, May 23, 13

Slide 85

Slide 85 text

User A Comment Scenario2: The user is a super admin Roles: ROLE_SUPER_ADMIN YES! Thursday, May 23, 13

Slide 86

Slide 86 text

User A Comment Scenario3: Otherwise... No :/ Thursday, May 23, 13

Slide 87

Slide 87 text

Writing code to describe this logic is very easy. Thursday, May 23, 13

Slide 88

Slide 88 text

Voters @weaverryan public function editAction($slug) { $blog = // ... $sc = $this->container ->get('security.context'); if (!$sc->isGranted('EDIT', $blog)) { throw new AccessDeniedException(); } } Thursday, May 23, 13

Slide 89

Slide 89 text

Voters @weaverryan $sc->isGranted('EDIT', $blog) 1) Symfony iterates over “voters” and asks each of they know how to decide access for a Blog object and the “attribute” EDIT 2) A voter can deny, granted, or “abstain” from voting 3) And you can actually pass an arbitrary object to the voters Thursday, May 23, 13

Slide 90

Slide 90 text

Core Voters @weaverryan Voter Votes if... Access if... RoleVoter ROLE_* attributes Does the user have this role? RoleHierarchyVoter ROLE_* attributes Does the user have a role by looking at role hierarchies AuthenticatedVoter IS_AUTHENTICATED_* How *trusted* is the user’s authentication (e.g. remember me)? Thursday, May 23, 13

Slide 91

Slide 91 text

Core Voters @weaverryan Voter Votes if... Access if... RoleVoter ROLE_* attributes Does the user have this role? RoleHierarchyVoter ROLE_* attributes Does the user have a role by looking at role hierarchies AuthenticatedVoter IS_AUTHENTICATED_* How *trusted* is the user’s authentication (e.g. remember me)? None of these make use of an object if you pass one Thursday, May 23, 13

Slide 92

Slide 92 text

Add your own Voter use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; class CommentVoter implements VoterInterface { public function supportsAttribute($attribute) { return $attribute == 'EDIT'; } public function supportsClass($class) { $commentClass = 'Sf\WootBundle\Entity\Comment'; return $commentClass === $class || is_subclass_of($class, $commentClass); } } Thursday, May 23, 13

Slide 93

Slide 93 text

Add your own Voter use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; class CommentVoter implements VoterInterface { public function supportsAttribute($attribute) { return $attribute == 'EDIT'; } public function supportsClass($class) { $commentClass = 'Sf\WootBundle\Entity\Comment'; return $commentClass === $class || is_subclass_of($class, $commentClass); } } Invent some attribute(s) that you will ask on Thursday, May 23, 13

Slide 94

Slide 94 text

Add your own Voter use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; class CommentVoter implements VoterInterface { public function supportsAttribute($attribute) { return $attribute == 'EDIT'; } public function supportsClass($class) { $commentClass = 'Sf\WootBundle\Entity\Comment'; return $commentClass === $class || is_subclass_of($class, $commentClass); } } Decide which object(s) we will use when asking permission Thursday, May 23, 13

Slide 95

Slide 95 text

Add your own Voter use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Doctrine\ORM\EntityManager; class CommentVoter implements VoterInterface { // ... public function vote(TokenInterface $token, $object, array $attributes) { // ... awesome business logic here! } } Comment object array containing EDIT Thursday, May 23, 13

Slide 96

Slide 96 text

Add your own Voter public function vote(TokenInterface $token, $object, array $attributes) { // ... details: checking if we support this attribute, object, etc if (in_array('ROLE_SUPER_ADMIN', $token->getRoles())) { return self::ACCESS_GRANTED; } // get the user, force to null if we're anonymous $user = ($token->getUser() instanceof User) ? $token->getUser() : null; if ($object->getOwner() && $object->getOwner() == $user) { return self::ACCESS_GRANTED; } return VoterInterface::ACCESS_DENIED; } Thursday, May 23, 13

Slide 97

Slide 97 text

@weaverryan • Use existing relationships to enforce authorization • Write simple business logic in a voter • Enforce in your controller at a very high level • Unit test them Voters $sc->isGranted('EDIT', $blog) Thursday, May 23, 13

Slide 98

Slide 98 text

@weaverryan • Voters are loaded with the firewall (on every request), but you might not use a voter • Minimize the work it takes to instantiate them Performance Implications Thursday, May 23, 13

Slide 99

Slide 99 text

Lightweight instantiation private $container; public function __construct(ContainerInterface $c) { $this->container = $c; } private function getHeavyService() { return $this->container->get('heavy_service'); } Thursday, May 23, 13

Slide 100

Slide 100 text

Or use lazy/proxy services (Symfony 2.3) Thursday, May 23, 13

Slide 101

Slide 101 text

Voters are simple services that contain your business logic Thursday, May 23, 13

Slide 102

Slide 102 text

Get Wild and Crazy and Simple with Form Variables @weaverryan 5 Thursday, May 23, 13

Slide 103

Slide 103 text

public function editAction($id) { $favrtpgrmr = // ... $form = $this->createFormBuilder($favrtpgrmr) ->add('name', 'text') ->getForm() ; // form processing return $this->render( '...:edit.html.twig', array( 'form' => $form->createView(), )); } Thursday, May 23, 13

Slide 104

Slide 104 text

{{ form_errors(form) }} {{ form_row(form.name) }} {{ form_rest(form) }} Thursday, May 23, 13

Slide 105

Slide 105 text

Every form field has variables, which give you everything you need to render things Thursday, May 23, 13

Slide 106

Slide 106 text

{{ dump(form.name.vars) }} Thursday, May 23, 13

Slide 107

Slide 107 text

Most form_* functions take an array of “variables” as an argument Thursday, May 23, 13

Slide 108

Slide 108 text

{{ form_row(form.name, { 'label': 'First Name', 'value': 'Fabien', 'label_attr': { 'class': 'first-name' } }) }} Thursday, May 23, 13

Slide 109

Slide 109 text

Simpler? Thursday, May 23, 13

Slide 110

Slide 110 text

Or render the field (or part of) all by yourself: Thursday, May 23, 13

Slide 111

Slide 111 text

{{ form.name.vars.label }} {% for error in form.name.vars.errors %} {{ error.message }} {% endfor %}
Thursday, May 23, 13

Slide 112

Slide 112 text

Variables are available when you’re theming Thursday, May 23, 13

Slide 113

Slide 113 text

{% block form_row %}
{{ form_label(form) }} {{ form_errors(form) }} {{ form_widget(form) }}
{% endblock form_row %} Thursday, May 23, 13

Slide 114

Slide 114 text

Not sure what variables you have when theming? Thursday, May 23, 13

Slide 115

Slide 115 text

{% block form_row %} {{ dump() }} {% endblock form_row %} Thursday, May 23, 13

Slide 116

Slide 116 text

Having trouble rendering a form? Simplify. Variables. Thursday, May 23, 13

Slide 117

Slide 117 text

Get to know HttpKernel: all the cool kids are doing it @weaverryan 6 Thursday, May 23, 13

Slide 118

Slide 118 text

HttpKernel @weaverryan Symfony’s component that converts a request into a response $response = $kernel->handle($request); At the heart of Symfony Framework Thursday, May 23, 13

Slide 119

Slide 119 text

HttpKernel @weaverryan Symfony’s component that converts a request into a response $response = $kernel->handle($request); At the heart of Symfony Framework, Drupal, Zikula, EzPublisher Thursday, May 23, 13

Slide 120

Slide 120 text

How does it work? Thursday, May 23, 13

Slide 121

Slide 121 text

You have to do your homework http://fabien.potencier.org/article/50/framework Thursday, May 23, 13

Slide 122

Slide 122 text

Learn a framework by building a simple framework on great tools Thursday, May 23, 13

Slide 123

Slide 123 text

Playing Telephone with ESI @weaverryan 7 Thursday, May 23, 13

Slide 124

Slide 124 text

@weaverryan Welcome to Foo Break your site down into many small “fragments” Thursday, May 23, 13

Slide 125

Slide 125 text

{{ render(controller('ABundle:Default:menu')) }} {{ render(controller('ABundle:Default:article')) }} {{ render(controller('ABundle:Default:sidebar')) }} Each fragment is its own controller - can be rendered independently Thursday, May 23, 13

Slide 126

Slide 126 text

@weaverryan Welcome to Foo /content /side /menu Think of each fragment as having its own URL Thursday, May 23, 13

Slide 127

Slide 127 text

@weaverryan Welcome to Foo /content /side /menu ... and even that each could be rendering in HTML, JSON, etc Thursday, May 23, 13

Slide 128

Slide 128 text

If a page is many individual fragments, what combines these into a finished product? Thursday, May 23, 13

Slide 129

Slide 129 text

Rendering Strategies @weaverryan • Inline • ESI • HInclude Thursday, May 23, 13

Slide 130

Slide 130 text

Browser Cache App Inline ESI HInclude Request Request Response Request Thursday, May 23, 13

Slide 131

Slide 131 text

{{ render(controller('ABundle:Default:menu')) }} Inline
Thursday, May 23, 13

Slide 132

Slide 132 text

{{ render_esi(controller('ABundle:Default:menu')) }} ESI Cache Layer makes another request for only the fragment Thursday, May 23, 13

Slide 133

Slide 133 text

Browser Cache App Inline ESI HInclude Request Request Response Request Thursday, May 23, 13

Slide 134

Slide 134 text

{{ render_hinclude(controller('ABundle:Default:menu')) }} HInclude Browser makes another request for only the fragment Thursday, May 23, 13

Slide 135

Slide 135 text

Browser Cache App Inline ESI HInclude Request Request Response Request Thursday, May 23, 13

Slide 136

Slide 136 text

ESI lets you cache each fragment independently Thursday, May 23, 13

Slide 137

Slide 137 text

It’s easy, use it! Thursday, May 23, 13

Slide 138

Slide 138 text

... except that you can’t see what’s happening at the cache layer Thursday, May 23, 13

Slide 139

Slide 139 text

Browser Cache App Inline ESI HInclude Request Request Response Request Combines the ESI responses I had no idea he (-->) just did that Thursday, May 23, 13

Slide 140

Slide 140 text

Debug and Develop using Symfony’s AppCache Thursday, May 23, 13

Slide 141

Slide 141 text

X-Symfony-Cache @weaverryan Each fragment has its own information Thursday, May 23, 13

Slide 142

Slide 142 text

X-Symfony-Cache @weaverryan ... you can also copy each URL into your browser Thursday, May 23, 13

Slide 143

Slide 143 text

X-Symfony-Cache @weaverryan Thursday, May 23, 13

Slide 144

Slide 144 text

Think about your application in small, simple fragments that can be rendered independently Thursday, May 23, 13

Slide 145

Slide 145 text

SOA and call it a day @weaverryan 8 Thursday, May 23, 13

Slide 146

Slide 146 text

What we teach in a training @weaverryan • Routing • Controllers • Twig • Assetic • Using Forms • Doctrine • etc • Namespaces • Creating services • Dependency Injection • OO best practices • Dividing logic into small, focused classes • Composer Thursday, May 23, 13

Slide 147

Slide 147 text

@weaverryan • Namespaces • Creating services • Dependency Injection • OO best practices • Dividing logic into small, focused classes • Composer Thursday, May 23, 13

Slide 148

Slide 148 text

If you do these things well Thursday, May 23, 13

Slide 149

Slide 149 text

You have my permission to use CakePHP Thursday, May 23, 13

Slide 150

Slide 150 text

But why would you? Thursday, May 23, 13

Slide 151

Slide 151 text

Moar Decoupling @weaverryan 9 Thursday, May 23, 13

Slide 152

Slide 152 text

Smaller and Smaller Pieces @weaverryan • Coupled Libraries can’t be used by others • Big libraries are hard to figure out Thursday, May 23, 13

Slide 153

Slide 153 text

Smaller and Smaller Pieces @weaverryan • Can Symfony Bundles be broken into “bridge” libraries and used by Drupal? • Can Drupal modules be broken into libraries and used by all of PHP? Thursday, May 23, 13

Slide 154

Slide 154 text

Example: GuzzleBundle @weaverryan • Adds web profiler information about how many HTTP requests were made • The web profiler will be available in Drupal8. Could the bundle be a bridge that works for both? Thursday, May 23, 13

Slide 155

Slide 155 text

Moar Coupling! @weaverryan 10 Thursday, May 23, 13

Slide 156

Slide 156 text

Too Many Pieces @weaverryan • Decoupling gives us the building block • But we still need a guide on how to make all the pieces sing together Thursday, May 23, 13

Slide 157

Slide 157 text

Examples @weaverryan • Install FOSUserBundle, SonataAdminBundle and configure everything to quickly have generated admin with a login • REST API: Integrate FOSRestBundle, JSMSerializerBundle, NelmioApiDocBundle, FSCHateoasBundle, HautelookTemplatedUriBundle • Common Security Flows: OAuth, authentication against an API Thursday, May 23, 13

Slide 158

Slide 158 text

Epilogue 4 Bits of Homework Thursday, May 23, 13

Slide 159

Slide 159 text

1) Remove Layers • Opt into your shortcuts • Teach people the “raw” and long way of doing things first • Teach people the principles Thursday, May 23, 13

Slide 160

Slide 160 text

2) Emphasize Service-Oriented Architecture over Symfony Thursday, May 23, 13

Slide 161

Slide 161 text

3) Challenge Symfony Thursday, May 23, 13

Slide 162

Slide 162 text

3) Challenge Symfony • Documentation • Error Messages • Bundle README’s and Tutorials • Integration of many tools • How “Common” can things be done? • How easy is it to use a single component • Where can Frameworkisms be made optional or more transparent? Thursday, May 23, 13

Slide 163

Slide 163 text

Share your solutions Thursday, May 23, 13

Slide 164

Slide 164 text

We want to be the best, use the best Thursday, May 23, 13

Slide 165

Slide 165 text

Finally... Thursday, May 23, 13

Slide 166

Slide 166 text

4) Sit with a Drupal developer at lunch today Thursday, May 23, 13

Slide 167

Slide 167 text

Woh, thanks! Ryan Weaver @weaverryan Thursday, May 23, 13

Slide 168

Slide 168 text

... and we <3 you! Ryan Weaver @weaverryan https://joind.in/8668 Ryan Weaver @weaverryan Thursday, May 23, 13

Slide 169

Slide 169 text

Coupon: HIPSTER KnpUniversity.com @weaveryan @KnpUniversity Thursday, May 23, 13