SlideShare una empresa de Scribd logo
1 de 160
Descargar para leer sin conexión
The Wonderful World of the
                        Symfony Components

                               by your friend:

                               Ryan Weaver
                               @weaverryan




Friday, September 28, 12
Who is this dude?
         • That “Docs” guy
         • KnpLabs US - Symfony consulting, training, Kumbaya
         • Writer for KnpUniversity.com
               screencasts
         • Husband of the much more
                talented @leannapelham



                             knplabs.com
   @weaverryan               github.com/weaverryan
Friday, September 28, 12
Intro

                           Life before components
                              (The Desert of the Real)




Friday, September 28, 12
Symfony consists of 23
                           individual components




Friday, September 28, 12
Components are available
                        via Composer




Friday, September 28, 12
Snooze...




Friday, September 28, 12
Who Cares?




Friday, September 28, 12
1

                            We Suck at Sharing
                           and that sucks for you



   @weaverryan
Friday, September 28, 12
Including External Libraries
                       is Depressing




Friday, September 28, 12
The Big Bummer :(

                   • How do I autoload their files?
                   • Does their library depend on anything else?
                   • How do I even store their files in my project?




   @weaverryan
Friday, September 28, 12
Include a Zend Framework 1
               component in symfony1



Friday, September 28, 12
Friday, September 28, 12
manually download the
                            library and commit it
                               into your project




Friday, September 28, 12
if you don’t want the
                           WHOLE library, carefully
                           delete everything except
                           the dependent components




Friday, September 28, 12
autoloading is completely
                           custom ... blah gross!




Friday, September 28, 12
2
                           Components are the key to
                           mastering your framework



   @weaverryan
Friday, September 28, 12
3

                           If PHP is big, we’ll thrive
                           If PHP is small, we’ll die



   @weaverryan
Friday, September 28, 12
Communities




                                                 http://www.flickr.com/photos/kitty-kat/




                           PHP is Huge! Right?

   @weaverryan
Friday, September 28, 12
PHP > Ruby




   @weaverryan
Friday, September 28, 12
Fragmentation




                                         http://www.flickr.com/photos/slpunk99/7329609744


                       But fragmentation makes us tiny, isolated, and
                                 misguided trend-setters
   @weaverryan
Friday, September 28, 12
PHP frameworks < Rails




   @weaverryan
Friday, September 28, 12
I don’t want a damned
                              CakePHP Plugin!



                                      CakePHP



                                          CodeIgniter

   @weaverryan
Friday, September 28, 12
Fragmentation
                   • More information we have to know
                   • Difficult to hire
                   • Disjointed forums, StackOverflow
                   • Interoperability? What’s that?



   @weaverryan
Friday, September 28, 12
Components are shareable
                     across all of PHP



Friday, September 28, 12
Act 1

                           Making Sharing Sexy



Friday, September 28, 12
PHP Framework
                           Interoperability Group


                              http://www.php-fig.org/

Friday, September 28, 12
The United Nations of PHP




Friday, September 28, 12
(A)

              The Problem of Autoloading



Friday, September 28, 12
My Autoloader doesn’t like
                                  your PHPs
         • The symfony1 autoloader doesn’t know where ZF1
         classes live. The Zf1 autoloader doesn’t know where
         symfony1 classes live

         • Each library has its own autoloader that you must
         discover, configure and use




   @weaverryan
Friday, September 28, 12
like a town where every
                 store has its own currency



Friday, September 28, 12
From The Mountain:
              PSR-0 Class Naming Conventions


      “Thou shalt name your classes by
      following a predictable pattern”


   @weaverryan
Friday, September 28, 12
class:
      sfRequest

      path:
      lib/vendor/symfony/???idk




Friday, September 28, 12
class:
     SymfonyComponentHttpFoundationRequest

       path:
       vendor/symfony/src/Symfony/Component/
       HttpFoundation/Request.php




Friday, September 28, 12
use SymfonyComponentClassLoaderUniversalClassLoader;


 $loader = new UniversalClassLoader();
 $loader->registerNamespaces(array(
     'Zend' => __DIR__.'/path/to/zf'
 ));

 $loader->register();




Friday, September 28, 12
(B)

                  Managing Vendors in your
                          project



Friday, September 28, 12
Composer


Friday, September 28, 12
1) Composer.json

 {
                  "require": {
                      "zendframework/ldap": "2.0.x-dev"
                  }
 }




Friday, September 28, 12
2) Composer.phar


 $ curl -s https://getcomposer.org/installer | php

 $ php composer.phar install




Friday, September 28, 12
3) Use It

 require 'vendor/autoload.php';

 use ZendLdapLdap;

 $options = array(...);
 $ldap = new Ldap($options);


Friday, September 28, 12
Friday, September 28, 12
Act 2

              Your friendly, neighborhood
                 Symfony Components



Friday, September 28, 12
The Symfony Components
                  • HttpFoundation        • OptionsResolver
                  • HttpKernel            • Console
                  • Event Dispatcher      • Filesystem
                  • Routing               • Finder
                  • CSSSelector           • Locale
                  • DomCrawler            • Process
                  • BrowserKit            • Serializer
                  • Config                • Templating
                  • Yaml                  • Form
                  • DependencyInjection   • Translation
                  • Security              • Validator
   @weaverryan
Friday, September 28, 12
The Symfony Components
                  • HttpFoundation       • OptionsResolver
                  • HttpKernel           • Console
                  • Event Dispatcher     • Filesystem
                  • Routing              • Finder
                  • CSSSelector          • Locale
                  • DomCrawler         The Process
                                         • “Framework”
                  • BrowserKit           • Serializer
                                         Components
                  • Config               • Templating
                  • Yaml                 • Form
                  • DependencyInjection • Translation
                  • Security             • Validator
   @weaverryan
Friday, September 28, 12
Level 1

                           HttpFoundation
                           symfony/http-foundation




Friday, September 28, 12
Fun to Install!
                      {
                           "require": {
         1                     "symfony/http-foundation": "2.1.x-dev"
                           }
                      }


        2             php composer.phar install

                     <?php
                     // your app
        3
                     require 'vendor/autoload.php';

     @weaverryan
Friday, September 28, 12
?           ?
                Request        ?                Response
                  /foo             ?           <h1>Hi!</h1>
                               ?           ?

                            Mystery
                           PHP Code


     @weaverryan
Friday, September 28, 12
The Request




Friday, September 28, 12
GET /foo?p=v1 HTTP/1.1
                           Host: knplabs.com
                           Accept: text/html
                           User-Agent: Mozilla/5.0


  // /foo?p=v1
  $uri = $_SERVER['REQUEST_URI'];
  $p = isset($_GET['p']) ? $_GET['p'] : '';
  $host = $_SERVER['HTTP_HOST'];
  $accept = $_SERVER['HTTP_ACCEPT'];
  $ua = $_SERVER['HTTP_USER_AGENT'];

Friday, September 28, 12
GET /foo?p=v1 HTTP/1.1
                           Host: knplabs.com
                           Accept: text/html
                           User-Agent: Mozilla/5.0

  use SymfonyComponentHttpFoundationRequest;
  $request = Request::createFromGlobals();

  $uri = $request->getPathInfo(); /foo
  $p = $request->query->get('p');
  $host = $request->getHost();
  $accept = $request->headers->get('Accept');

Friday, September 28, 12
The Response




Friday, September 28, 12
HTTP/1.1 200 OK
     Date: Tue, 04 Jun 2011 21:05:05 GMT
     Content-Type: text/html
     Set-Cookie:foo=fooval; path=/; httponly

     <h1>Foo!</h1>



    header('Content-Type', 'text/html');
    setcookie('foo', 'fooval');
    echo '<h1>Foo!</h1>';


Friday, September 28, 12
HTTP/1.1 200 OK
     Date: Tue, 04 Jun 2011 21:05:05 GMT
     Content-Type: text/html
     Set-Cookie:foo=fooval; path=/; httponly

     <h1>Foo!</h1>

  use SymfonyComponentHttpFoundationResponse;
  use SymfonyComponentHttpFoundationCookie;

  $response = new Response('<h1>Foo!</h1>');
  $cookie = new Cookie('foo', 'fooval');
  $response->headers->setCookie($cookie);

  $response->send();
Friday, September 28, 12
A Mini Framework




Friday, September 28, 12
// not dependable!
     $uri = $_SERVER['REQUEST_URI'];

     ob_start();
     if ($uri == '/') {
         echo 'Homepage! o/';
     } else {
         echo 'sad missing page :/';
     }

     header('X-TOKEN: Foo');

     ob_end_flush();
Friday, September 28, 12
Symfony3
$req = Request::createFromGlobals();

if ($req->getPathInfo() == '/') {
    $res = new Response('Homepage! o/');
} else {
    $res = new Response('sad missing page :/');
}

$res->headers->set('X-SECRET', 'Foo');

$res->send();


Friday, September 28, 12
Get some learning about
                                HttpFoundation

       • Docs: http://bit.ly/sf2-http-foundation
       • Code: http://bit.ly/sf2-http-foundation-code
       • API: http://bit.ly/sf2-http-foundation-api



   @weaverryan
Friday, September 28, 12
Level 2

                            HttpKernel
                           symfony/http-kernel




Friday, September 28, 12
Request
           Framework


                            ? Determine ?
                             the controller
                               ?

                               Execute it


                                     Response
                           Flush the Response
   @weaverryan
Friday, September 28, 12
Framework:

                    A pattern for converting a
                     request into a response


Friday, September 28, 12
Request
           Framework


                            ? Determine ?
                             the controller
                               ?

                               Execute it


                                     Response
                           Flush the Response
   @weaverryan
Friday, September 28, 12
Request
            HttpKernel


                            ? Determine ?
                             the controller
                               ?

                               Execute it


                                     Response
                           Flush the Response
   @weaverryan
Friday, September 28, 12
$kernel = new HttpKernel(...);
   $request = Request::createFromGlobals();
   $response = $kernel->handle($request);
   $response->send();

                           There be magic inside!



Friday, September 28, 12
These lines execute your
                        Symfony application


                           (hint, see - web/app.php)
Friday, September 28, 12
... and Drupal 8 too ...




Friday, September 28, 12
Yea, this is abstract

                              Stay Tuned...



Friday, September 28, 12
Level 3

                           EventDispatcher
                           symfony/event-dispatcher




Friday, September 28, 12
A classic “observer pattern”

                                      Tell me when Liz
                                        gets to work


                           Listener
                                                Event
                                             Dispatcher
                           Listener

                                       Tell me when Liz
                                         gets to work
   @weaverryan
Friday, September 28, 12
• Event Dispatcher: a classic “observer pattern”
                                      Yo! I’m at
                                        work!


            Listener
                               Event
                            Dispatcher
            Listener



   @weaverryan
Friday, September 28, 12
• Event Dispatcher: a classic “observer pattern”

                             Liz is at
                              work!

            Listener
                               Event
                            Dispatcher
            Listener

                              Liz is at
                               work!
   @weaverryan
Friday, September 28, 12
• Event Dispatcher: a classic “observer pattern”

                      She’s the best
                        around!

            Listener
                                          Event
                                       Dispatcher
            Listener

                         I’m totally
                      going to go talk
                         with her!!
Friday, September 28, 12
Level 4

                             Routing
                           symfony/routing




Friday, September 28, 12
Url
                  Router


                           Match against
                             a route
                                Route


                             Return info
                           about the route
                                      Route




   @weaverryan
Friday, September 28, 12
$loader = new ClosureLoader();
       $router = new Router($loader, function() {
           $collection = new RouteCollection();

                      $route = new Route('/blog/{slug}');
                      $collection->add('blog', $route);

                      return $collection;
       });
       $results = $router->match('/blog/sflive');

       array(
           'slug' => 'sflive',
           '_route' => 'blog',
       )
Friday, September 28, 12
$loader = new ClosureLoader();
       $router = new Router($loader, function() {
           $collection = new RouteCollection();

                   $route = new Route('/blog/{slug}', array(
                       '_controller' => 'SomeBundle:Blog:show'
                   ));
                   $collection->add('blog', $route);

                   return $collection;
       });
       $results = $router->match('/blog/sflive');

       array(
           '_controller' => 'SomeBundle:Blog:show',
           'slug' => 'sflive',
           '_route' => 'blog'
       )
Friday, September 28, 12
Input: Request Information


                           Output: An array of info


Friday, September 28, 12
Level 5

                           A “Framework”




Friday, September 28, 12
$kernel = new HttpKernel(...);
   $request = Request::createFromGlobals();
   $response = $kernel->handle($request);
   $response->send();




Friday, September 28, 12
HttpKernel::handle()
                                HttpFoundation

                                       +
                                EventDispatcher

                                       +
                               Routing (optional)
                                       =
                                  Framework
     @weaverryan
Friday, September 28, 12
HttpKernel::handle()
                                     Request

                                        +
                                Determine Controller

                                        +
                           Controller Returns a Response
                                        =
                                     Response
     @weaverryan
Friday, September 28, 12
Homework:
                           Hack your Framework

                           ... or do Karaoke later... your call



Friday, September 28, 12
HttpKernel::handleRaw()
 private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
 {
     // request
     $event = new GetResponseEvent($this, $request, $type);
     $this->dispatcher->dispatch(KernelEvents::REQUEST, $event);

     if ($event->hasResponse()) {
         return $this->filterResponse($event->getResponse(), $request, $type);
     }

     // load controller
                           The kewlest code I know about... seriously
     if (false === $controller = $this->resolver->getController($request)) {
         throw new NotFoundHttpException('Unable to find the controller);
     }

     $event = new FilterControllerEvent($this, $controller, $request, $type);
     $this->dispatcher->dispatch(KernelEvents::CONTROLLER, $event);
     $controller = $event->getController();

     //            ... returns a response
 }

     @weaverryan
Friday, September 28, 12
step/var_dump()die; the core

     • SymfonyComponentHttpKernelHttpKernel::handle()
                 http://bit.ly/sf2-http-kernel-code

     • Symfony Framework Important Classes
                 SymfonyComponentHttpKernelEventListenerRouterListener
                   - Executes the routing

                 SymfomyBundleFrameworkBundleControllerControllerResolver
                   - Parses _controller and instantiates the controller object

     @weaverryan
Friday, September 28, 12
Timeline of events in the Symfony Framework

                                           kernel.request



                                           kernel.controller




                                          kernel.response



Friday, September 28, 12
Profile events in the Symfony Framework




Friday, September 28, 12
The Symfony Components
                  • HttpFoundation        • OptionsResolver
                     Awesome
                  • HttpKernel            • Console
                  • Event Dispatcher      • Filesystem
                        Tools
                  • Routing               • Finder
                  • CSSSelector           • Locale
                  • DomCrawler            • Process
                  • BrowserKit            • Serializer
                  • Config                • Templating
                  • Yaml                  • Form
                  • DependencyInjection   • Translation
                  • Security              • Validator
   @weaverryan
Friday, September 28, 12
Now with more
    Windows Love!
                               Process

                           symfony/process
Friday, September 28, 12
Find Symfony’s Process on Packagist.org
                           {
                               "require": {
            1
                                   "symfony/process": "2.1.x-dev"
                               }
                           }


            2              php composer.phar install


                           <?php
                           // your app
            3
                           require 'vendor/autoload.php';

     @weaverryan
Friday, September 28, 12
External Script to Cook Dinner
         <?php
         // dinner.php

         for ($i = 1; $i <= 3; $i++) {
             sleep(1);
             echo sprintf("Cooking... %sn", $i);
         }

         echo "DING! n";




Friday, September 28, 12
Run the script synchronously




Friday, September 28, 12
// app.php
         require 'vendor/autoload.php';

         use SymfonyComponentProcessProcess;

         $process = new Process('php dinner.php');
         // if dinner takes longer than 5 seconds
         // to cook, freak out!
         $process->setTimeout(5);

        $process->run(function($type, $buffer) {
            echo $buffer;
        });

        // executed after the command finishes
        if (!$process->isSuccessful()) {
            throw new Exception('Process misbehaved')
        }
Friday, September 28, 12
Friday, September 28, 12
Run the script asynchronously




Friday, September 28, 12
$process = new Process('php dinner.php');
                  $process->start();

                  // do more work here
                  echo "WORKING!!! n";

                  while ($process->isRunning()) {
                      // wait for the process to finish
                  };
                  echo $process->getOutput();




Friday, September 28, 12
Interacting via Stdin




Friday, September 28, 12
$process = new Process('php dinner.php');
                     $process->setStdin('turkey');




                               “turkey” is read from Stdin
Friday, September 28, 12
Handling things that blow up!
    $process = new Process('php dinner.php');
    $process->run(function($type, $buffer) {
        if ($type == 'err') {
            // perhaps do some logging?
            echo $buffer;
        }
    });

    if (!$process->isSuccessful()) {
        echo sprintf(
            "Process failed! Exit code %s, '%s'n",
            $process->getExitCode(),
            $process->getExitCodeText()
        );
    }

Friday, September 28, 12
Find out more about Process


                    • Docs: http://bit.ly/sf2-process
                    • Code: http://bit.ly/sf2-process-code
                    • API: http://bit.ly/sf2-process-api



   @weaverryan
Friday, September 28, 12
@kriswallsmith

                                       SPORK!
    $manager = new SporkProcessManager();
    $manager->fork(function() {
        // do something in another process!
        return 'Hello from '.getmypid();
    })->then(function(SporkFork $fork) {
        // do something in the parent process afterwards
        echo "{$fork->getPid()} says '{$fork->getResult()}'";
    });

                               Fork yourself some more PHP

                           https://github.com/kriswallsmith/spork

Friday, September 28, 12
Finder

                           symfony/finder



Friday, September 28, 12
From the Fablog
      use SymfonyComponentsFinderFinder;
       
      $s3 = new Zend_Service_Amazon_S3($key, $secret);
      $s3->registerStreamWrapper("s3");
       
      $finder = new Finder();
      $finder->name('photos*')
          ->size('< 100K')
          ->date('since 1 hour ago');
      foreach ($finder->in('s3://bucket-name') as $file) {
          // do something
       
          print $file->getFilename()."n";
      }
       
      http://fabien.potencier.org/article/44/php-iterators-and-
                        streams-are-awesome
Friday, September 28, 12
Find(er) out more about Finder


                    • Docs: http://bit.ly/sf2-finder
                    • Code: http://bit.ly/sf2-finder-code
                    • API: http://bit.ly/sf2-finder-api



   @weaverryan
Friday, September 28, 12
New in 2.1!
                                Filesystem

                            symfony/filesystem



Friday, September 28, 12
Find Symfony’s Filesystem on Packagist.org
                           {
                               "require": {
            1                      "symfony/filesystem": "2.1.x-dev"
                               }
                           }



            2              php composer.phar update symfony/filesystem


                           <?php
                           // your app
            3
                           require 'vendor/autoload.php';

     @weaverryan
Friday, September 28, 12
// ...

          use SymfonyComponentFilesystemFilesystem;

          $filesystem = new Filesystem();
          $filesystem->copy(
              'cowboy.jpg',
              's3://my-bucket/cowboy.jpg'
          );
          $filesystem->copy(
              's3://my-bucket/rodeo.mov',
              'rodeo.mov'
          );
          $filesystem->mirror(
              'thumbnails',
              's3://my-bucket/thumbnails'
          );
Friday, September 28, 12
// ...

         use SymfonyComponentFilesystemFilesystem;
         use SymfonyComponentFinderFinder;

         $finder = new Finder();
         $finder->name('*.jpg')
             ->date('since 1 hour ago');
             ->in('thumbs');
         $filesystem = new Filesystem();
         $filesystem->chmod($finder, 0777);




Friday, September 28, 12
// ...

     use SymfonyComponentFilesystemFilesystem;

     $filesystem = new Filesystem();
     $filesystem->touch('foo.txt');
     $filesystem->chmod('foo.txt', 0777);
     $filesystem->symlink('/some/dir', '/symlink/target')




Friday, September 28, 12
Find out more about Filesystem


                     • Docs: http://bit.ly/sf2-filesystem
                     • Code: http://bit.ly/sf2-filesystem-code
                     • API: http://bit.ly/sf2-filesystem-api



   @weaverryan
Friday, September 28, 12
Console

                           symfony/console




Friday, September 28, 12
Friday, September 28, 12
<?php
      // command.php

      $loader = require 'vendor/autoload.php';
      $loader->add('App', __DIR__);

      use SymfonyComponentConsoleApplication;
      use AppCommandEchoCommand;

      $app = new Application();
      $app->add(new EchoCommand());
      $app->run();


Friday, September 28, 12
namespace AppCommand;

 use SymfonyComponentConsoleCommandCommand;
 use SymfonyComponentConsoleInputInputInterface;
 use SymfonyComponentConsoleOutputOutputInterface;

 class EchoCommand extends Command
 {
     protected function configure()
     {
         $this->setName('echo')->addArgument('msg');
     }

            public function execute(
                InputInterface $input,
                OutputInterface $output)
            {
                $output->writeln('Yo '.$input->getArgument('msg'));
            }
 }

Friday, September 28, 12
Output with pretty colors




Friday, September 28, 12
Find out more about Command

       • Docs http://bit.ly/sf2-console
       • Code http://bit.ly/sf2-console-code
       • API http://api.symfony.com/master/namespaces.html
                   -> and search for “Console”




   @weaverryan
Friday, September 28, 12
If you download Composer
              in the next 5 minutes, we’ll
                  throw in a special gift!



Friday, September 28, 12
CssSelector + DomCrawler

                           symfony/css-selector
                           symfony/dom-crawler


Friday, September 28, 12
require 'vendor/autoload.php';
  use SymfonyComponentDomCrawlerCrawler;

  $html = <<<'HTML'
  <!DOCTYPE html>
  <html>
      <body>
          <p class="message">Hello World!</p>
          <p>Hello Crawler!</p>
      </body>
  </html>
  HTML;

  $crawler = new Crawler($html);

  $crawler->filter('p')->eq(0)->attr('class');
  $crawler->filter('p')->eq(1)->text();

Friday, September 28, 12
Goutte!




Friday, September 28, 12
Config

                           symfony/config



Friday, September 28, 12
Config

        • Load configuration from many formats (YAML,
        PHP files, XML)

        • Config Validation
        • Caching for parsed config



   @weaverryan
Friday, September 28, 12
Validator

                           symfony/validator



Friday, September 28, 12
Shh... a little setup




Friday, September 28, 12
require 'vendor/autoload.php';

  use SymfonyComponentValidatorValidator;
  use SymfonyComponentValidatorMappingClassMetadataFactory;
  use SymfonyComponentValidatorConstraintValidatorFactory;

  // a little setup
  $metadata = new ClassMetadataFactory();
  $constraintFactory = new ConstraintValidatorFactory();
  $validator = new Validator($metadata, $constraintFactory);




Friday, September 28, 12
use SymfonyComponentValidatorConstraintsEmail;

  $value = 'ryan[AT]knplabs.com';
  $email = new Email();
  $email->message = 'Invalid! You entered {{ value }}';
  $errors = $validator->validateValue($value, $email);

  if (count($errors) > 0) {
      echo strtr(
          $errors[0]->getMessageTemplate(),
          $errors[0]->getMessageParameters()
      );
  }




Friday, September 28, 12
34 Core Validators and counting
                  • String length                     See the “Reference”
                  • Regular expressions
                                                      section of the docs
                  • Ip addresses
                  • Dates
                  • Collections
                  • File size, mime-type, etc
                  ... and the brand new Luhn validator
                  for credit card numbers thanks to
                  @merk ----------------------------------->

   @weaverryan
Friday, September 28, 12
But wait there’s more!




Friday, September 28, 12
More Components
                           • DependencyInjection
                           • Security
                           • OptionsResolver
                           • Locale
                           • Serializer
                           • Templating
                           • Form
                           • Translation


   @weaverryan
Friday, September 28, 12
Many components are easy




Friday, September 28, 12
Some are still wtf-hard




Friday, September 28, 12
(cough) Security (cough)




Friday, September 28, 12
Documentation
                           Documentation
                           Documentation



Friday, September 28, 12
The Security Component


              https://github.com/symfony/symfony-docs/pull/1604

                            WIP by @matthiasnoback

Friday, September 28, 12
Act 3

                           Kicking ass in the new
                              PHP eco-system



Friday, September 28, 12
The PHP Ecosphere
                       Symfony is only one part of the picture

                    • Symfony
                    • Zend Framework
                    • EZ Components
                    • Drupal
                    • ...
                    • Individuals

                  What other stuff exists?

   @weaverryan
Friday, September 28, 12
How do we find good
                                libraries?



Friday, September 28, 12
Friday, September 28, 12
Friday, September 28, 12
Some Favorites




Friday, September 28, 12
Mink
                                  behat/mink
                            http://mink.behat.org/




                             By @everzet, written on
                           Fabien’s childhood computer
Friday, September 28, 12
Command a browser, find elements, click
                     them, and fill out forms

$driver = new BehatMinkDriverSahiDriver('firefox');
$session->visit('http://my_project.dev/some_page.php');

$page = $session->getPage();

$anchor = $page->find('css', '.something');
$anchor->click();

// get the content of the new page
echo $page->getContent();


Friday, September 28, 12
Monolog
                                     monolog/monolog
                           https://github.com/Seldaek/monolog




                                    Your Friend Jordi

Friday, September 28, 12
A Logger, where bells and whistles
                                     come standard
   use MonologLogger;
   use MonologHandlerStreamHandler;
   use MonologHandlerFirePHPHandler;

   // Create the logger
   $logger = new Logger('my_logger');
   $logger->pushHandler(new StreamHandler(
       __DIR__.'/my_app.log'
   ));
   $logger->pushHandler(new FirePHPHandler());

   $logger->addInfo('My logger is now ready');

Friday, September 28, 12
Zend Framework 2


                            They have some stuff




Friday, September 28, 12
Yay Find More!




Friday, September 28, 12
Epilogue

                            4 Reasons to get
                           silly-excited about
                                the Future

Friday, September 28, 12
1) Look for Participation &
                        Consolidation




Friday, September 28, 12
Shared Building-blocks

                 • Drupal
                 • phpBB
                 • Midgard
                 • Zikula
                 • ez Publish 5
                 • ...

   @weaverryan
Friday, September 28, 12
Less Library Duplication?

                 • Zend/Form           • Symfony/Form
                 • Zend/Serializer     • Symfony/Serializer
                 • Zend/Http           • Symfony/HttpFoundation
                 • Zend/EventManager   • Symfony/EventDispatcher
                 • Zend/Log            • Monlog
                 • Zend/Navigation     • KnpMenu
                 • ...                 • ...


   @weaverryan
Friday, September 28, 12
2) More high quality,
                 community-grown libraries




Friday, September 28, 12
Solving 1 specific problem
                    is a low barrier to entry




Friday, September 28, 12
Find them, fork them.




Friday, September 28, 12
Write their docs :)




Friday, September 28, 12
Programmers that write
                               docs get hugs




Friday, September 28, 12
3) Easier upgrades




Friday, September 28, 12
4) Grow your Community




Friday, September 28, 12
Solutions exist outside of
                         your framework



Friday, September 28, 12
Fabien will not come to your
      house and tell you about them



Friday, September 28, 12
Cast your vote by using the
          best libraries and improving
                      them


Friday, September 28, 12
and realize the power of
                  the entire PHP community



Friday, September 28, 12
Thanks...
                           Ryan Weaver
                           @weaverryan




Friday, September 28, 12
... and we love you!
                              https://joind.in/7218




                                Ryan Weaver
                                @weaverryan




        Ryan Weaver
        @weaverryan
Friday, September 28, 12

Más contenido relacionado

Destacado

Get Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP StreamsGet Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP StreamsDavey Shafik
 
Techniques d'accélération des pages web
Techniques d'accélération des pages webTechniques d'accélération des pages web
Techniques d'accélération des pages webJean-Pierre Vincent
 
Automation using-phing
Automation using-phingAutomation using-phing
Automation using-phingRajat Pandit
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP GeneratorsMark Baker
 
The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)Matthias Noback
 
Top tips my_sql_performance
Top tips my_sql_performanceTop tips my_sql_performance
Top tips my_sql_performanceafup Paris
 
Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Marcello Duarte
 
Why elasticsearch rocks!
Why elasticsearch rocks!Why elasticsearch rocks!
Why elasticsearch rocks!tlrx
 
Writing infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLWriting infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLGabriele Bartolini
 
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015Bruno Boucard
 
L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)Arnauld Loyer
 
Performance serveur et apache
Performance serveur et apachePerformance serveur et apache
Performance serveur et apacheafup Paris
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016CiaranMcNulty
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersKacper Gunia
 

Destacado (20)

Elastic Searching With PHP
Elastic Searching With PHPElastic Searching With PHP
Elastic Searching With PHP
 
Get Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP StreamsGet Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP Streams
 
Techniques d'accélération des pages web
Techniques d'accélération des pages webTechniques d'accélération des pages web
Techniques d'accélération des pages web
 
Diving deep into twig
Diving deep into twigDiving deep into twig
Diving deep into twig
 
Automation using-phing
Automation using-phingAutomation using-phing
Automation using-phing
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)
 
Top tips my_sql_performance
Top tips my_sql_performanceTop tips my_sql_performance
Top tips my_sql_performance
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015
 
Why elasticsearch rocks!
Why elasticsearch rocks!Why elasticsearch rocks!
Why elasticsearch rocks!
 
Writing infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLWriting infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQL
 
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
 
L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)
 
Caching on the Edge
Caching on the EdgeCaching on the Edge
Caching on the Edge
 
Performance serveur et apache
Performance serveur et apachePerformance serveur et apache
Performance serveur et apache
 
Behat 3.0 meetup (March)
Behat 3.0 meetup (March)Behat 3.0 meetup (March)
Behat 3.0 meetup (March)
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 

Similar a The Wonderful World of Symfony Components

Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...NETWAYS
 
Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...Puppet
 
GitHub Notable OSS Project
GitHub  Notable OSS ProjectGitHub  Notable OSS Project
GitHub Notable OSS Projectroumia
 
Puppet Conf 2012 - Managing Network Devices with Puppet
Puppet Conf 2012 - Managing Network Devices with PuppetPuppet Conf 2012 - Managing Network Devices with Puppet
Puppet Conf 2012 - Managing Network Devices with PuppetNan Liu
 
Testing Drupal with Ghosts and Gherkin
Testing Drupal  with Ghosts and GherkinTesting Drupal  with Ghosts and Gherkin
Testing Drupal with Ghosts and GherkinPhase2
 
Welcome to the Symfony2 World - FOSDEM 2013
 Welcome to the Symfony2 World - FOSDEM 2013 Welcome to the Symfony2 World - FOSDEM 2013
Welcome to the Symfony2 World - FOSDEM 2013Lukas Smith
 
Software Libraries And Numbers
Software Libraries And NumbersSoftware Libraries And Numbers
Software Libraries And NumbersRobert Reiz
 
[T3CON12CA] TYPO3 Phoenix - The Current State
[T3CON12CA] TYPO3 Phoenix - The Current State[T3CON12CA] TYPO3 Phoenix - The Current State
[T3CON12CA] TYPO3 Phoenix - The Current StateChristian Müller
 
PuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That WasPuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That WasWalter Heck
 
PuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That WasPuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That WasOlinData
 
Cloudstack talk
Cloudstack talkCloudstack talk
Cloudstack talkbodepd
 
Aligning Continuous Integration Deployment: Automated Validation of OpenStack...
Aligning Continuous Integration Deployment: Automated Validation of OpenStack...Aligning Continuous Integration Deployment: Automated Validation of OpenStack...
Aligning Continuous Integration Deployment: Automated Validation of OpenStack...Atlassian
 
Symfony - Introduction
Symfony - IntroductionSymfony - Introduction
Symfony - IntroductionPiers Warmers
 
HH.JS - State of the Automation
HH.JS - State of the AutomationHH.JS - State of the Automation
HH.JS - State of the AutomationAdam Christian
 
Workshop: Introduction to the Disruptor
Workshop: Introduction to the DisruptorWorkshop: Introduction to the Disruptor
Workshop: Introduction to the DisruptorTrisha Gee
 
Cloud Foundry and Ubuntu - 2012
Cloud Foundry and Ubuntu - 2012Cloud Foundry and Ubuntu - 2012
Cloud Foundry and Ubuntu - 2012Patrick Chanezon
 

Similar a The Wonderful World of Symfony Components (20)

Node jsworkshop
Node jsworkshopNode jsworkshop
Node jsworkshop
 
Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...
 
Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...Building scalable applications while scaling your infrastructure by rhommel l...
Building scalable applications while scaling your infrastructure by rhommel l...
 
GitHub Notable OSS Project
GitHub  Notable OSS ProjectGitHub  Notable OSS Project
GitHub Notable OSS Project
 
Puppet Conf 2012 - Managing Network Devices with Puppet
Puppet Conf 2012 - Managing Network Devices with PuppetPuppet Conf 2012 - Managing Network Devices with Puppet
Puppet Conf 2012 - Managing Network Devices with Puppet
 
Testing Drupal with Ghosts and Gherkin
Testing Drupal  with Ghosts and GherkinTesting Drupal  with Ghosts and Gherkin
Testing Drupal with Ghosts and Gherkin
 
JRubyConf 2009
JRubyConf 2009JRubyConf 2009
JRubyConf 2009
 
Welcome to the Symfony2 World - FOSDEM 2013
 Welcome to the Symfony2 World - FOSDEM 2013 Welcome to the Symfony2 World - FOSDEM 2013
Welcome to the Symfony2 World - FOSDEM 2013
 
Software Libraries And Numbers
Software Libraries And NumbersSoftware Libraries And Numbers
Software Libraries And Numbers
 
[T3CON12CA] TYPO3 Phoenix - The Current State
[T3CON12CA] TYPO3 Phoenix - The Current State[T3CON12CA] TYPO3 Phoenix - The Current State
[T3CON12CA] TYPO3 Phoenix - The Current State
 
PuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That WasPuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
 
PuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That WasPuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
PuppetCamp SEA @ Blk 71 - Puppet: The Year That Was
 
100% JS
100% JS100% JS
100% JS
 
Taming the rabbit
Taming the rabbitTaming the rabbit
Taming the rabbit
 
Cloudstack talk
Cloudstack talkCloudstack talk
Cloudstack talk
 
Aligning Continuous Integration Deployment: Automated Validation of OpenStack...
Aligning Continuous Integration Deployment: Automated Validation of OpenStack...Aligning Continuous Integration Deployment: Automated Validation of OpenStack...
Aligning Continuous Integration Deployment: Automated Validation of OpenStack...
 
Symfony - Introduction
Symfony - IntroductionSymfony - Introduction
Symfony - Introduction
 
HH.JS - State of the Automation
HH.JS - State of the AutomationHH.JS - State of the Automation
HH.JS - State of the Automation
 
Workshop: Introduction to the Disruptor
Workshop: Introduction to the DisruptorWorkshop: Introduction to the Disruptor
Workshop: Introduction to the Disruptor
 
Cloud Foundry and Ubuntu - 2012
Cloud Foundry and Ubuntu - 2012Cloud Foundry and Ubuntu - 2012
Cloud Foundry and Ubuntu - 2012
 

Más de Ryan Weaver

Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoRyan Weaver
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017Ryan Weaver
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Ryan Weaver
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatRyan Weaver
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexRyan Weaver
 
Silex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonySilex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonyRyan Weaver
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itRyan Weaver
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsRyan Weaver
 
A PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appA PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appRyan Weaver
 
Symfony2: Get your project started
Symfony2: Get your project startedSymfony2: Get your project started
Symfony2: Get your project startedRyan Weaver
 
Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkRyan Weaver
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkRyan Weaver
 
Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Ryan Weaver
 
Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with TwigRyan Weaver
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 MinutesRyan Weaver
 
Dependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear youDependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear youRyan Weaver
 
The Art of Doctrine Migrations
The Art of Doctrine MigrationsThe Art of Doctrine Migrations
The Art of Doctrine MigrationsRyan Weaver
 

Más de Ryan Weaver (19)

Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
Silex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonySilex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender Symfony
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 
A PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appA PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 app
 
Symfony2: Get your project started
Symfony2: Get your project startedSymfony2: Get your project started
Symfony2: Get your project started
 
Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP Framework
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 Framework
 
Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)
 
Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with Twig
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 Minutes
 
Dependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear youDependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear you
 
The Art of Doctrine Migrations
The Art of Doctrine MigrationsThe Art of Doctrine Migrations
The Art of Doctrine Migrations
 

Último

Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 

Último (20)

Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 

The Wonderful World of Symfony Components

  • 1. The Wonderful World of the Symfony Components by your friend: Ryan Weaver @weaverryan Friday, September 28, 12
  • 2. Who is this dude? • That “Docs” guy • KnpLabs US - Symfony consulting, training, Kumbaya • Writer for KnpUniversity.com screencasts • Husband of the much more talented @leannapelham knplabs.com @weaverryan github.com/weaverryan Friday, September 28, 12
  • 3. Intro Life before components (The Desert of the Real) Friday, September 28, 12
  • 4. Symfony consists of 23 individual components Friday, September 28, 12
  • 5. Components are available via Composer Friday, September 28, 12
  • 8. 1 We Suck at Sharing and that sucks for you @weaverryan Friday, September 28, 12
  • 9. Including External Libraries is Depressing Friday, September 28, 12
  • 10. The Big Bummer :( • How do I autoload their files? • Does their library depend on anything else? • How do I even store their files in my project? @weaverryan Friday, September 28, 12
  • 11. Include a Zend Framework 1 component in symfony1 Friday, September 28, 12
  • 13. manually download the library and commit it into your project Friday, September 28, 12
  • 14. if you don’t want the WHOLE library, carefully delete everything except the dependent components Friday, September 28, 12
  • 15. autoloading is completely custom ... blah gross! Friday, September 28, 12
  • 16. 2 Components are the key to mastering your framework @weaverryan Friday, September 28, 12
  • 17. 3 If PHP is big, we’ll thrive If PHP is small, we’ll die @weaverryan Friday, September 28, 12
  • 18. Communities http://www.flickr.com/photos/kitty-kat/ PHP is Huge! Right? @weaverryan Friday, September 28, 12
  • 19. PHP > Ruby @weaverryan Friday, September 28, 12
  • 20. Fragmentation http://www.flickr.com/photos/slpunk99/7329609744 But fragmentation makes us tiny, isolated, and misguided trend-setters @weaverryan Friday, September 28, 12
  • 21. PHP frameworks < Rails @weaverryan Friday, September 28, 12
  • 22. I don’t want a damned CakePHP Plugin! CakePHP CodeIgniter @weaverryan Friday, September 28, 12
  • 23. Fragmentation • More information we have to know • Difficult to hire • Disjointed forums, StackOverflow • Interoperability? What’s that? @weaverryan Friday, September 28, 12
  • 24. Components are shareable across all of PHP Friday, September 28, 12
  • 25. Act 1 Making Sharing Sexy Friday, September 28, 12
  • 26. PHP Framework Interoperability Group http://www.php-fig.org/ Friday, September 28, 12
  • 27. The United Nations of PHP Friday, September 28, 12
  • 28. (A) The Problem of Autoloading Friday, September 28, 12
  • 29. My Autoloader doesn’t like your PHPs • The symfony1 autoloader doesn’t know where ZF1 classes live. The Zf1 autoloader doesn’t know where symfony1 classes live • Each library has its own autoloader that you must discover, configure and use @weaverryan Friday, September 28, 12
  • 30. like a town where every store has its own currency Friday, September 28, 12
  • 31. From The Mountain: PSR-0 Class Naming Conventions “Thou shalt name your classes by following a predictable pattern” @weaverryan Friday, September 28, 12
  • 32. class: sfRequest path: lib/vendor/symfony/???idk Friday, September 28, 12
  • 33. class: SymfonyComponentHttpFoundationRequest path: vendor/symfony/src/Symfony/Component/ HttpFoundation/Request.php Friday, September 28, 12
  • 34. use SymfonyComponentClassLoaderUniversalClassLoader; $loader = new UniversalClassLoader(); $loader->registerNamespaces(array( 'Zend' => __DIR__.'/path/to/zf' )); $loader->register(); Friday, September 28, 12
  • 35. (B) Managing Vendors in your project Friday, September 28, 12
  • 37. 1) Composer.json { "require": { "zendframework/ldap": "2.0.x-dev" } } Friday, September 28, 12
  • 38. 2) Composer.phar $ curl -s https://getcomposer.org/installer | php $ php composer.phar install Friday, September 28, 12
  • 39. 3) Use It require 'vendor/autoload.php'; use ZendLdapLdap; $options = array(...); $ldap = new Ldap($options); Friday, September 28, 12
  • 41. Act 2 Your friendly, neighborhood Symfony Components Friday, September 28, 12
  • 42. The Symfony Components • HttpFoundation • OptionsResolver • HttpKernel • Console • Event Dispatcher • Filesystem • Routing • Finder • CSSSelector • Locale • DomCrawler • Process • BrowserKit • Serializer • Config • Templating • Yaml • Form • DependencyInjection • Translation • Security • Validator @weaverryan Friday, September 28, 12
  • 43. The Symfony Components • HttpFoundation • OptionsResolver • HttpKernel • Console • Event Dispatcher • Filesystem • Routing • Finder • CSSSelector • Locale • DomCrawler The Process • “Framework” • BrowserKit • Serializer Components • Config • Templating • Yaml • Form • DependencyInjection • Translation • Security • Validator @weaverryan Friday, September 28, 12
  • 44. Level 1 HttpFoundation symfony/http-foundation Friday, September 28, 12
  • 45. Fun to Install! { "require": { 1 "symfony/http-foundation": "2.1.x-dev" } } 2 php composer.phar install <?php // your app 3 require 'vendor/autoload.php'; @weaverryan Friday, September 28, 12
  • 46. ? ? Request ? Response /foo ? <h1>Hi!</h1> ? ? Mystery PHP Code @weaverryan Friday, September 28, 12
  • 48. GET /foo?p=v1 HTTP/1.1 Host: knplabs.com Accept: text/html User-Agent: Mozilla/5.0 // /foo?p=v1 $uri = $_SERVER['REQUEST_URI']; $p = isset($_GET['p']) ? $_GET['p'] : ''; $host = $_SERVER['HTTP_HOST']; $accept = $_SERVER['HTTP_ACCEPT']; $ua = $_SERVER['HTTP_USER_AGENT']; Friday, September 28, 12
  • 49. GET /foo?p=v1 HTTP/1.1 Host: knplabs.com Accept: text/html User-Agent: Mozilla/5.0 use SymfonyComponentHttpFoundationRequest; $request = Request::createFromGlobals(); $uri = $request->getPathInfo(); /foo $p = $request->query->get('p'); $host = $request->getHost(); $accept = $request->headers->get('Accept'); Friday, September 28, 12
  • 51. HTTP/1.1 200 OK Date: Tue, 04 Jun 2011 21:05:05 GMT Content-Type: text/html Set-Cookie:foo=fooval; path=/; httponly <h1>Foo!</h1> header('Content-Type', 'text/html'); setcookie('foo', 'fooval'); echo '<h1>Foo!</h1>'; Friday, September 28, 12
  • 52. HTTP/1.1 200 OK Date: Tue, 04 Jun 2011 21:05:05 GMT Content-Type: text/html Set-Cookie:foo=fooval; path=/; httponly <h1>Foo!</h1> use SymfonyComponentHttpFoundationResponse; use SymfonyComponentHttpFoundationCookie; $response = new Response('<h1>Foo!</h1>'); $cookie = new Cookie('foo', 'fooval'); $response->headers->setCookie($cookie); $response->send(); Friday, September 28, 12
  • 53. A Mini Framework Friday, September 28, 12
  • 54. // not dependable! $uri = $_SERVER['REQUEST_URI']; ob_start(); if ($uri == '/') { echo 'Homepage! o/'; } else { echo 'sad missing page :/'; } header('X-TOKEN: Foo'); ob_end_flush(); Friday, September 28, 12
  • 55. Symfony3 $req = Request::createFromGlobals(); if ($req->getPathInfo() == '/') { $res = new Response('Homepage! o/'); } else { $res = new Response('sad missing page :/'); } $res->headers->set('X-SECRET', 'Foo'); $res->send(); Friday, September 28, 12
  • 56. Get some learning about HttpFoundation • Docs: http://bit.ly/sf2-http-foundation • Code: http://bit.ly/sf2-http-foundation-code • API: http://bit.ly/sf2-http-foundation-api @weaverryan Friday, September 28, 12
  • 57. Level 2 HttpKernel symfony/http-kernel Friday, September 28, 12
  • 58. Request Framework ? Determine ? the controller ? Execute it Response Flush the Response @weaverryan Friday, September 28, 12
  • 59. Framework: A pattern for converting a request into a response Friday, September 28, 12
  • 60. Request Framework ? Determine ? the controller ? Execute it Response Flush the Response @weaverryan Friday, September 28, 12
  • 61. Request HttpKernel ? Determine ? the controller ? Execute it Response Flush the Response @weaverryan Friday, September 28, 12
  • 62. $kernel = new HttpKernel(...); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); There be magic inside! Friday, September 28, 12
  • 63. These lines execute your Symfony application (hint, see - web/app.php) Friday, September 28, 12
  • 64. ... and Drupal 8 too ... Friday, September 28, 12
  • 65. Yea, this is abstract Stay Tuned... Friday, September 28, 12
  • 66. Level 3 EventDispatcher symfony/event-dispatcher Friday, September 28, 12
  • 67. A classic “observer pattern” Tell me when Liz gets to work Listener Event Dispatcher Listener Tell me when Liz gets to work @weaverryan Friday, September 28, 12
  • 68. • Event Dispatcher: a classic “observer pattern” Yo! I’m at work! Listener Event Dispatcher Listener @weaverryan Friday, September 28, 12
  • 69. • Event Dispatcher: a classic “observer pattern” Liz is at work! Listener Event Dispatcher Listener Liz is at work! @weaverryan Friday, September 28, 12
  • 70. • Event Dispatcher: a classic “observer pattern” She’s the best around! Listener Event Dispatcher Listener I’m totally going to go talk with her!! Friday, September 28, 12
  • 71. Level 4 Routing symfony/routing Friday, September 28, 12
  • 72. Url Router Match against a route Route Return info about the route Route @weaverryan Friday, September 28, 12
  • 73. $loader = new ClosureLoader(); $router = new Router($loader, function() { $collection = new RouteCollection(); $route = new Route('/blog/{slug}'); $collection->add('blog', $route); return $collection; }); $results = $router->match('/blog/sflive'); array( 'slug' => 'sflive', '_route' => 'blog', ) Friday, September 28, 12
  • 74. $loader = new ClosureLoader(); $router = new Router($loader, function() { $collection = new RouteCollection(); $route = new Route('/blog/{slug}', array( '_controller' => 'SomeBundle:Blog:show' )); $collection->add('blog', $route); return $collection; }); $results = $router->match('/blog/sflive'); array( '_controller' => 'SomeBundle:Blog:show', 'slug' => 'sflive', '_route' => 'blog' ) Friday, September 28, 12
  • 75. Input: Request Information Output: An array of info Friday, September 28, 12
  • 76. Level 5 A “Framework” Friday, September 28, 12
  • 77. $kernel = new HttpKernel(...); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); Friday, September 28, 12
  • 78. HttpKernel::handle() HttpFoundation + EventDispatcher + Routing (optional) = Framework @weaverryan Friday, September 28, 12
  • 79. HttpKernel::handle() Request + Determine Controller + Controller Returns a Response = Response @weaverryan Friday, September 28, 12
  • 80. Homework: Hack your Framework ... or do Karaoke later... your call Friday, September 28, 12
  • 81. HttpKernel::handleRaw() private function handleRaw(Request $request, $type = self::MASTER_REQUEST) {     // request     $event = new GetResponseEvent($this, $request, $type);     $this->dispatcher->dispatch(KernelEvents::REQUEST, $event);     if ($event->hasResponse()) {         return $this->filterResponse($event->getResponse(), $request, $type);     }     // load controller The kewlest code I know about... seriously     if (false === $controller = $this->resolver->getController($request)) {         throw new NotFoundHttpException('Unable to find the controller);     }     $event = new FilterControllerEvent($this, $controller, $request, $type);     $this->dispatcher->dispatch(KernelEvents::CONTROLLER, $event);     $controller = $event->getController();     // ... returns a response } @weaverryan Friday, September 28, 12
  • 82. step/var_dump()die; the core • SymfonyComponentHttpKernelHttpKernel::handle() http://bit.ly/sf2-http-kernel-code • Symfony Framework Important Classes SymfonyComponentHttpKernelEventListenerRouterListener - Executes the routing SymfomyBundleFrameworkBundleControllerControllerResolver - Parses _controller and instantiates the controller object @weaverryan Friday, September 28, 12
  • 83. Timeline of events in the Symfony Framework kernel.request kernel.controller kernel.response Friday, September 28, 12
  • 84. Profile events in the Symfony Framework Friday, September 28, 12
  • 85. The Symfony Components • HttpFoundation • OptionsResolver Awesome • HttpKernel • Console • Event Dispatcher • Filesystem Tools • Routing • Finder • CSSSelector • Locale • DomCrawler • Process • BrowserKit • Serializer • Config • Templating • Yaml • Form • DependencyInjection • Translation • Security • Validator @weaverryan Friday, September 28, 12
  • 86. Now with more Windows Love! Process symfony/process Friday, September 28, 12
  • 87. Find Symfony’s Process on Packagist.org { "require": { 1 "symfony/process": "2.1.x-dev" } } 2 php composer.phar install <?php // your app 3 require 'vendor/autoload.php'; @weaverryan Friday, September 28, 12
  • 88. External Script to Cook Dinner <?php // dinner.php for ($i = 1; $i <= 3; $i++) { sleep(1); echo sprintf("Cooking... %sn", $i); } echo "DING! n"; Friday, September 28, 12
  • 89. Run the script synchronously Friday, September 28, 12
  • 90. // app.php require 'vendor/autoload.php'; use SymfonyComponentProcessProcess; $process = new Process('php dinner.php'); // if dinner takes longer than 5 seconds // to cook, freak out! $process->setTimeout(5); $process->run(function($type, $buffer) { echo $buffer; }); // executed after the command finishes if (!$process->isSuccessful()) { throw new Exception('Process misbehaved') } Friday, September 28, 12
  • 92. Run the script asynchronously Friday, September 28, 12
  • 93. $process = new Process('php dinner.php'); $process->start(); // do more work here echo "WORKING!!! n"; while ($process->isRunning()) { // wait for the process to finish }; echo $process->getOutput(); Friday, September 28, 12
  • 94. Interacting via Stdin Friday, September 28, 12
  • 95. $process = new Process('php dinner.php'); $process->setStdin('turkey'); “turkey” is read from Stdin Friday, September 28, 12
  • 96. Handling things that blow up! $process = new Process('php dinner.php'); $process->run(function($type, $buffer) { if ($type == 'err') { // perhaps do some logging? echo $buffer; } }); if (!$process->isSuccessful()) { echo sprintf( "Process failed! Exit code %s, '%s'n", $process->getExitCode(), $process->getExitCodeText() ); } Friday, September 28, 12
  • 97. Find out more about Process • Docs: http://bit.ly/sf2-process • Code: http://bit.ly/sf2-process-code • API: http://bit.ly/sf2-process-api @weaverryan Friday, September 28, 12
  • 98. @kriswallsmith SPORK! $manager = new SporkProcessManager(); $manager->fork(function() { // do something in another process! return 'Hello from '.getmypid(); })->then(function(SporkFork $fork) { // do something in the parent process afterwards echo "{$fork->getPid()} says '{$fork->getResult()}'"; }); Fork yourself some more PHP https://github.com/kriswallsmith/spork Friday, September 28, 12
  • 99. Finder symfony/finder Friday, September 28, 12
  • 100. From the Fablog use SymfonyComponentsFinderFinder;   $s3 = new Zend_Service_Amazon_S3($key, $secret); $s3->registerStreamWrapper("s3");   $finder = new Finder(); $finder->name('photos*') ->size('< 100K') ->date('since 1 hour ago'); foreach ($finder->in('s3://bucket-name') as $file) { // do something   print $file->getFilename()."n"; }   http://fabien.potencier.org/article/44/php-iterators-and- streams-are-awesome Friday, September 28, 12
  • 101. Find(er) out more about Finder • Docs: http://bit.ly/sf2-finder • Code: http://bit.ly/sf2-finder-code • API: http://bit.ly/sf2-finder-api @weaverryan Friday, September 28, 12
  • 102. New in 2.1! Filesystem symfony/filesystem Friday, September 28, 12
  • 103. Find Symfony’s Filesystem on Packagist.org { "require": { 1 "symfony/filesystem": "2.1.x-dev" } } 2 php composer.phar update symfony/filesystem <?php // your app 3 require 'vendor/autoload.php'; @weaverryan Friday, September 28, 12
  • 104. // ... use SymfonyComponentFilesystemFilesystem; $filesystem = new Filesystem(); $filesystem->copy( 'cowboy.jpg', 's3://my-bucket/cowboy.jpg' ); $filesystem->copy( 's3://my-bucket/rodeo.mov', 'rodeo.mov' ); $filesystem->mirror( 'thumbnails', 's3://my-bucket/thumbnails' ); Friday, September 28, 12
  • 105. // ... use SymfonyComponentFilesystemFilesystem; use SymfonyComponentFinderFinder; $finder = new Finder(); $finder->name('*.jpg') ->date('since 1 hour ago'); ->in('thumbs'); $filesystem = new Filesystem(); $filesystem->chmod($finder, 0777); Friday, September 28, 12
  • 106. // ... use SymfonyComponentFilesystemFilesystem; $filesystem = new Filesystem(); $filesystem->touch('foo.txt'); $filesystem->chmod('foo.txt', 0777); $filesystem->symlink('/some/dir', '/symlink/target') Friday, September 28, 12
  • 107. Find out more about Filesystem • Docs: http://bit.ly/sf2-filesystem • Code: http://bit.ly/sf2-filesystem-code • API: http://bit.ly/sf2-filesystem-api @weaverryan Friday, September 28, 12
  • 108. Console symfony/console Friday, September 28, 12
  • 110. <?php // command.php $loader = require 'vendor/autoload.php'; $loader->add('App', __DIR__); use SymfonyComponentConsoleApplication; use AppCommandEchoCommand; $app = new Application(); $app->add(new EchoCommand()); $app->run(); Friday, September 28, 12
  • 111. namespace AppCommand; use SymfonyComponentConsoleCommandCommand; use SymfonyComponentConsoleInputInputInterface; use SymfonyComponentConsoleOutputOutputInterface; class EchoCommand extends Command { protected function configure() { $this->setName('echo')->addArgument('msg'); } public function execute( InputInterface $input, OutputInterface $output) { $output->writeln('Yo '.$input->getArgument('msg')); } } Friday, September 28, 12
  • 112. Output with pretty colors Friday, September 28, 12
  • 113. Find out more about Command • Docs http://bit.ly/sf2-console • Code http://bit.ly/sf2-console-code • API http://api.symfony.com/master/namespaces.html -> and search for “Console” @weaverryan Friday, September 28, 12
  • 114. If you download Composer in the next 5 minutes, we’ll throw in a special gift! Friday, September 28, 12
  • 115. CssSelector + DomCrawler symfony/css-selector symfony/dom-crawler Friday, September 28, 12
  • 116. require 'vendor/autoload.php'; use SymfonyComponentDomCrawlerCrawler; $html = <<<'HTML' <!DOCTYPE html> <html> <body> <p class="message">Hello World!</p> <p>Hello Crawler!</p> </body> </html> HTML; $crawler = new Crawler($html); $crawler->filter('p')->eq(0)->attr('class'); $crawler->filter('p')->eq(1)->text(); Friday, September 28, 12
  • 118. Config symfony/config Friday, September 28, 12
  • 119. Config • Load configuration from many formats (YAML, PHP files, XML) • Config Validation • Caching for parsed config @weaverryan Friday, September 28, 12
  • 120. Validator symfony/validator Friday, September 28, 12
  • 121. Shh... a little setup Friday, September 28, 12
  • 122. require 'vendor/autoload.php'; use SymfonyComponentValidatorValidator; use SymfonyComponentValidatorMappingClassMetadataFactory; use SymfonyComponentValidatorConstraintValidatorFactory; // a little setup $metadata = new ClassMetadataFactory(); $constraintFactory = new ConstraintValidatorFactory(); $validator = new Validator($metadata, $constraintFactory); Friday, September 28, 12
  • 123. use SymfonyComponentValidatorConstraintsEmail; $value = 'ryan[AT]knplabs.com'; $email = new Email(); $email->message = 'Invalid! You entered {{ value }}'; $errors = $validator->validateValue($value, $email); if (count($errors) > 0) { echo strtr( $errors[0]->getMessageTemplate(), $errors[0]->getMessageParameters() ); } Friday, September 28, 12
  • 124. 34 Core Validators and counting • String length See the “Reference” • Regular expressions section of the docs • Ip addresses • Dates • Collections • File size, mime-type, etc ... and the brand new Luhn validator for credit card numbers thanks to @merk -----------------------------------> @weaverryan Friday, September 28, 12
  • 125. But wait there’s more! Friday, September 28, 12
  • 126. More Components • DependencyInjection • Security • OptionsResolver • Locale • Serializer • Templating • Form • Translation @weaverryan Friday, September 28, 12
  • 127. Many components are easy Friday, September 28, 12
  • 128. Some are still wtf-hard Friday, September 28, 12
  • 129. (cough) Security (cough) Friday, September 28, 12
  • 130. Documentation Documentation Documentation Friday, September 28, 12
  • 131. The Security Component https://github.com/symfony/symfony-docs/pull/1604 WIP by @matthiasnoback Friday, September 28, 12
  • 132. Act 3 Kicking ass in the new PHP eco-system Friday, September 28, 12
  • 133. The PHP Ecosphere Symfony is only one part of the picture • Symfony • Zend Framework • EZ Components • Drupal • ... • Individuals What other stuff exists? @weaverryan Friday, September 28, 12
  • 134. How do we find good libraries? Friday, September 28, 12
  • 138. Mink behat/mink http://mink.behat.org/ By @everzet, written on Fabien’s childhood computer Friday, September 28, 12
  • 139. Command a browser, find elements, click them, and fill out forms $driver = new BehatMinkDriverSahiDriver('firefox'); $session->visit('http://my_project.dev/some_page.php'); $page = $session->getPage(); $anchor = $page->find('css', '.something'); $anchor->click(); // get the content of the new page echo $page->getContent(); Friday, September 28, 12
  • 140. Monolog monolog/monolog https://github.com/Seldaek/monolog Your Friend Jordi Friday, September 28, 12
  • 141. A Logger, where bells and whistles come standard use MonologLogger; use MonologHandlerStreamHandler; use MonologHandlerFirePHPHandler; // Create the logger $logger = new Logger('my_logger'); $logger->pushHandler(new StreamHandler( __DIR__.'/my_app.log' )); $logger->pushHandler(new FirePHPHandler()); $logger->addInfo('My logger is now ready'); Friday, September 28, 12
  • 142. Zend Framework 2 They have some stuff Friday, September 28, 12
  • 143. Yay Find More! Friday, September 28, 12
  • 144. Epilogue 4 Reasons to get silly-excited about the Future Friday, September 28, 12
  • 145. 1) Look for Participation & Consolidation Friday, September 28, 12
  • 146. Shared Building-blocks • Drupal • phpBB • Midgard • Zikula • ez Publish 5 • ... @weaverryan Friday, September 28, 12
  • 147. Less Library Duplication? • Zend/Form • Symfony/Form • Zend/Serializer • Symfony/Serializer • Zend/Http • Symfony/HttpFoundation • Zend/EventManager • Symfony/EventDispatcher • Zend/Log • Monlog • Zend/Navigation • KnpMenu • ... • ... @weaverryan Friday, September 28, 12
  • 148. 2) More high quality, community-grown libraries Friday, September 28, 12
  • 149. Solving 1 specific problem is a low barrier to entry Friday, September 28, 12
  • 150. Find them, fork them. Friday, September 28, 12
  • 151. Write their docs :) Friday, September 28, 12
  • 152. Programmers that write docs get hugs Friday, September 28, 12
  • 153. 3) Easier upgrades Friday, September 28, 12
  • 154. 4) Grow your Community Friday, September 28, 12
  • 155. Solutions exist outside of your framework Friday, September 28, 12
  • 156. Fabien will not come to your house and tell you about them Friday, September 28, 12
  • 157. Cast your vote by using the best libraries and improving them Friday, September 28, 12
  • 158. and realize the power of the entire PHP community Friday, September 28, 12
  • 159. Thanks... Ryan Weaver @weaverryan Friday, September 28, 12
  • 160. ... and we love you! https://joind.in/7218 Ryan Weaver @weaverryan Ryan Weaver @weaverryan Friday, September 28, 12