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

Symfony Components and its ecosystem

Symfony Components and its ecosystem

Overview of Symfony components, their evolution and use cases.

Talk given for the Seattle PHP User Group
https://www.meetup.com/seaphp/events/238913883/

Avatar for Albert Jessurum

Albert Jessurum

May 09, 2017

More Decks by Albert Jessurum

Other Decks in Programming

Transcript

  1. NOT THE ONLY KID IN THE BLOCK https://hoa-project.net http://auraphp.com/ https://thephpleague.com/

    https://packages.zendframework.com/ https://github.com/ziadoz/awesome-php AND MANY MORE...
  2. IF YOU KNOW WHAT FRAMEWORK YOU'RE GOING TO USE BEFORE

    SOMEONE DESCRIBES THE PROBLEM THAT YOU'RE GOING TO SOLVE, YOU'RE DOING IT WRONG http://blog.ircmaxell.com/2012/01/microphp-fallacy.html ~ ANTHONY FERRARA (@IRCMAXELL)
  3. Asset BrowserKit Cache ClassLoader Config Console CssSelector Debug DependencyInjection Dotenv

    DomCrawler EventDispatcher ExpressionLanguage Filesystem Finder Form HttpFoundation HttpKernel Intl Ldap OptionsResolver Process PropertyAccess PropertyInfo Routing Security Serializer Stopwatch Templating Translation Validator VarDumper Workflow Yaml PHPUnit Bridge
  4. Asset BrowserKit Cache ClassLoader Config Console CssSelector Debug DependencyInjection Dotenv

    DomCrawler EventDispatcher ExpressionLanguage Filesystem Finder Form HttpFoundation HttpKernel Intl Ldap OptionsResolver Process PropertyAccess PropertyInfo Routing Security Serializer Stopwatch Templating Translation Validator VarDumper Workflow Yaml PHPUnit Bridge
  5. TEXT CONSOLE COMPONENT ▸ Any CLI applications ▸ Cron scripts

    ▸ Batch scripts ▸ Amazing user interaction
  6. TEXT DOTENV COMPONENT ▸ The twelve factor app. https://12factor.net/ (highly

    recommended read!) ▸ Parses .env files ▸ Makes variables parsed available via get_env(), $_ENV or $_SERVER
  7. BROWSER KIT, DOMCRAWLER AND CSSSELECTOR COMPONENT CRAWLER TRIO BROWSERKIT ▸

    Client to make requests, and interact with the page. ▸ Simple use cases (testing). ▸ Do not as an http client (Use Guzzle). DOMCRAWLER ▸ Allows you to parse and traverse through the DOM with XPATH CSSSELECTOR ▸ jQuery like syntax to parse through the DOMs
  8. TEXT PROPERTYACCESS COMPONENT ▸ Read and write from objects or

    arrays ▸ Uses string notation ▸ Array: [value] ▸ Object: object.foo ▸ $object->getFoo();
 $object->isFoo();
 $object->hasFoo();
 $object->__get('foo');
 $object->foo;
  9. TEXT FINDER COMPONENT ▸ Find files with a fluent interface

    ▸ Find by name ▸ Exclude files and directories
  10. https://speakerdeck.com/hhamon/dont-reinvent-the-wheel-with-symfony2-components // Filter by name $finder->directories()->name('Tests'); $finder->files()->name('*.php'); $finder->files()->name('/\.php$/'); $finder->files()->notName('*.rb'); //

    Filter by size $finder->files()->size('< 1.5K'); $finder->files()->size('>= 1K')->size('<= 2K'); // Filter by date $finder->date('since yesterday'); // Limiting the depth $finder->depth('== 0'); $finder->depth('< 3');
  11. GET /hello/hugo?p=2 HTTP/1.1 Host: say.hello.com Accept: text/html Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 Cookie:

    username=hhamon User-Agent: Mozilla/5.0 Firefox/16.0 $path = $_SERVER['REQUEST_URI']; $page = isset($_GET['p']) ? $_GET['p'] : 1; $cookie = $_COOKIE['username']; $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $agent = $_SERVER['HTTP_USER_AGENT']; Request https://speakerdeck.com/hhamon/dont-reinvent-the-wheel-with-symfony2-components
  12. GET /hello/hugo?p=2 HTTP/1.1 Host: say.hello.com Accept: text/html Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 Cookie:

    username=hhamon User-Agent: Mozilla/5.0 Firefox/16.0 use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); $path = $request->getPathInfo(); $page = $request->query->get('p', 1); $cookie = $request->cookies->get('username'); $lang = $request->getPreferredLanguage(); $agent = $request->server->get('USER_AGENT'); Request https://speakerdeck.com/hhamon/dont-reinvent-the-wheel-with-symfony2-components
  13. HTTP/1.1 200 OK Date: Fri, 02 Nov 2012 02:14:17 GMT

    Cache-Control: private, max-age=90 Set-Cookie: username=anonymous; Content-Type: text/html; charset=UTF-8 Hello Hugo! Response header('HTTP/1.1 200 OK'); header('Cache-Control: private, max-age=90'); setcookie('username', 'anonymous'); echo 'Hello Hugo!'; https://speakerdeck.com/hhamon/dont-reinvent-the-wheel-with-symfony2-components
  14. HTTP/1.1 200 OK Date: Fri, 02 Nov 2012 02:14:17 GMT

    Cache-Control: private, max-age=90 Set-Cookie: username=anonymous; Content-Type: text/html; charset=UTF-8 Hello Hugo! Response use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Response; $username = new Cookie('username', $name); $response = new Response('Hello Hugo!'); $response->setMaxAge(90); $response->headers->setCookie($username); $response->send(); https://speakerdeck.com/hhamon/dont-reinvent-the-wheel-with-symfony2-components
  15. use Symfony\Component\HttpFoundation\Response; $response = new Response(); $response->setCharset('UTF-8'); $response->setEtag('abcdef'); $response->headers->set('Content-Type', 'application/json');

    if ($response->isNotModified($request)) { $response->send(); } $response->setContent('{ "name": "John Doe"}'); $response->setStatusCode(200); $response->setPublic(); $response->setSharedMaxAge(3600); $response->prepare($request); $response->send(); Caching https://speakerdeck.com/hhamon/dont-reinvent-the-wheel-with-symfony2-components
  16. Session Management use Symfony\Component\HttpFoundation\Session; $storage = new Storage\Handler\NativeSessionStorage(); $session =

    new Session\Session($storage); $session->start(); // Saving data into the session $session->set('cart', array(1, 2, 3)); $cart = $session->get('cart'); $session->save(); https://speakerdeck.com/hhamon/dont-reinvent-the-wheel-with-symfony2-components
  17. TEXT OPTIONSRESOLVER COMPONENT ▸ array_replace on steroids ▸ Required options

    ▸ Default values ▸ Validation ▸ Normalization
  18. USEFUL READS: CREATE YOUR OWN FRAMEWORK FROM FLAT PHP TO

    SYMFONY http://symfony.com/doc/current/introduction/from_flat_php_to_symfony2.html http://symfony.com/doc/current/create_framework/index.html