Share
Embed
Transcript
69 slides
-
Join us for a week of Symfony, November 19-23, at
the Beurs van Berlage: • November 19-20: 2-day pre- conference workshops • November 21-22: 2-day conference (3 tracks and 1 Unconference) • November 23: 1-day Hackday Get an exclusive 10% discount on your registration using the code: SFC19PHPAMS Code available until June 26 2019 amsterdam2019.symfony.com -
Come to meet the international Symfony and PHP communities! Become
a Sponsor of the event! Support the framework and get visibility for your company during the conference! Contact us: [email protected] 1,000+ attendees and 30+ speakers will be there during our 2-day conference! -
What is Symfony 4? A new developer experience On a
rock solid foundation From micro-style to monolith and prototypes -
Symfony Local Web Server $ symfony server:start -d # open
in the browser $ symfony open:local # tail the logs $ symfony server:log -
• PHP-FPM (concurrent requests) • HTTP 2 • TLS •
Local domain names • No dependencies / single binary (MacOS, Linux, and Windows) • Manages background commands (Encore, Messenger, ...) • Consolidated logs (PHP , Web server, app, background commands) • Docker integration (and SymfonyCloud) • Multiple versions of PHP • HTTP Link/pre-load/push support Symfony Local Web Server -
$ symfony new demo $ symfony new demo --cloud --debug
# Want to try Symfony 5.0 (dev version)? $ symfony new demo --version=dev-master Creating a new project -
$ symfony security:check Does not call https://security.symfony.com/ Clones and caches
https://github.com/FriendsOfPHP/security-advisories/ -
Symfony 2+/3+ Monolog Bundle SwiftMailer Bundle Polyfill Util Polyfill PHP
7.0 Polyfill PHP 5.6 Polyfill Mbstring Polyfill Intl ICU Polyfill APCu PHPUnit Bridge Debug Bundle Framework Bundle Security Bundle Twig Bundle WebProfiler Bundle WebServer Bundle Doctrine Bridge Monolog Bridge Twig Bridge Monolog Doctrine (11) SecurityChecker Generator Bundle ParamHandler FrameworkExtra Bundle Distribution Bundle Asset BrowserKit Cache ClassLoader Config Console CssSelector Debug DependencyInjection DomCrawler Dotenv EventDispatcher ExpressionLanguage Filesystem Finder Form HttpFoundation HttpKernel Inflector Intl Ldap OptionsResolver Process PropertyAccess PropertyInfo Routing Security Serializer Stopwatch Templating Translation Validator VarDumper WebLink Workflow Yaml 4 bridges 15 librairies 11 bundles 42 components SwiftMailer -
Symfony 4+/5+ Polyfill Mbstring Framework Bundle Cache Config Debug DependencyInjection
Dotenv EventDispatcher Filesystem Finder HttpFoundation HttpKernel Routing Yaml 0 bridges 1 library 1 bundle 13 components Flex -
$ symfony new demo # Forms are ❌ disabled as
symfony/form is not installed $ composer req form # Forms are automatically ✅ enabled as symfony/form is installed + Auto-configuration + No manual changes + Better performance -
Parameter Class constant Environment variable Can be provided by a
third party ("standard") ❌ ❌ ✅ Can be changed without cache:clear ❌ ❌ ✅ Easy to use in code ❌ ✅ Can be changed without redeploy ❌ ✅ Can be different in dev and prod ✅ ❌ ✅ Can be stored outside of a Git repo ✅ ❌ ✅ Rich type support via processors Example Configure behavior Configure behavior Configure infrastructure -
$ composer req twig Adding Twig + Controller as a
service + No manual changes + No configuration + Auto-wiring Productivity++ -
Adding a Twig Extension Where do I store the Twig
extension class? Which file do I need to change to register it? Which tag do I need to use? How do I declare a tag in YAML? Which interface/class do I need to implement/ extend? It’s too complex. What about doing it the dirty way and do it in the controller instead? hmm, ok -
$ ./bin/console make:twig-extension Adding a Twig Extension Add your logic
in the generated class… DONE! -
Full Automation works for… • Twig extensions • Event listeners
• Doctrine entities/repositories • Commands • Voters • Registration form system • … -
You can use PHP templates But Twig benefits from a
fully maintained integration -
A great example of how we leverage the "new" Symfony
infrastructure -
$ composer req symfony/mailer Sending emails use Symfony\Component\Mailer\MailerInterface; public function
index(MailerInterface $mailer) { $mailer->send( (new Email()) ->from('[email protected]') ->to('[email protected]') ->subject('Some subject') ->text('Some text...') ); MAILER_DSN=smtp://localhost + No configuration + No manual changes + Auto-wiring + Env vars -
Sending emails use Symfony\Component\Mailer\MailerInterface; public function index(MailerInterface $mailer) { $mailer->send(
(new TemplatedEmail()) ->from('[email protected]') ->to('[email protected]') ->subject('Some subject') ->htmlTemplate('@emails/welcome.html.twig') ->context([ 'city' => 'Tunis' ]) ); -
$ composer req twig/inky-extension twig/cssinliner-extension Sending emails {% apply inky|inline_css(source("@zurb/stylesheets/main.css"))
%} <container> <row class="header"> <columns> <spacer size="16"></spacer> <h4 class="text-center">Symfony Connect</h4> </columns> </row> <row> <columns> <spacer size="32"></spacer> <center><img width="100px" src="{{ email.image("@images/symfony.png") }}"></center> <spacer size="16"></spacer> <h1 class="text-center">Forgot Your Password?</h1> <spacer size="16"></spacer> <p class="text-center">It happens. Click the link below to reset it.</p> <button class="large expand" href="#">Reset Password</button> <hr/> <p><small><center><a href="#">unsubscribe here</a>.</small></center></p> </columns> </row> </container> {% endapply %} -
I want to send rich and responsive emails from my
controller via my provider's API -
$ composer req mailgun-mailer MAILER_DSN=http://$MAILGUN_KEY:$MAILGUN_DOMAIN@mailgun Sending emails Amazon SES Google
Gmail Mandrill Mailgun Postmark Sendgrid -
I want to send rich and responsive emails from my
controller via my provider's API asynchronously -
$ composer req messenger framework: messenger: transports: email: "doctrine://default" routing:
Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ ./bin/console messenger:consume $ symfony run -d ./bin/console messenger:consume -vv Sending emails Go to the background -
I want to send rich and responsive emails from my
controller via my provider's API asynchronously with AMQP -
At this point, think about how you would do it
with Symfony 3.4 Here, we have not written a single line of code and barely changed the configuration -
I want to send rich and responsive emails from my
controller via my provider's API asynchronously with AMQP -
framework: messenger: transports: email: "%env(RABBITMQ_DSN)%" routing: Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ docker-compose
up -d Sending emails rabbitmq: image: rabbitmq ports: - 5672 docker-compose.yml Symfony Local Web Server Env vars "auto-wiring" Local port is random -
I want to send rich and responsive emails from my
controller via my provider's API asynchronously with AMQP and manage failures gracefully -
framework: messenger: transports: email: dsn: "%env(RABBITMQ_DSN)%" retry_strategy: max_retries: 3 routing:
Symfony\Component\Mailer\Messenger\SendEmailMessage: email Sending emails -
framework: messenger: failure_transport: failed transports: failed: 'doctrine://default?queue_name=failed' email: dsn: "%env(RABBITMQ_DSN)%"
retry_strategy: max_retries: 3 routing: Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ symfony server:log $ ./bin/console messenger:failed:show $ ./bin/console messenger:failed:retry Sending emails -
I want to send rich and responsive emails from my
controller via my provider's API asynchronously with AMQP and manage failures gracefully without Docker -
$ symfony project:init $ symfony deploy $ symfony log --worker=send_emails
all Sending emails rabbitmq: type: rabbitmq:3.7 disk: 1500 .symfony/services.yaml .symfony.cloud.yaml runtime: extensions: [ "amqp" ] relationships: rabbitmq: "rabbitmq:rabbitmq" workers: send_emails: commands: start: | set -x -e (>&2 symfony-deploy) bin/console messenger:consume -vv email Production ready -
$ symfony tunnel:open Sending emails Symfony Local Web Server Env
vars "auto-wiring" .symfony.cloud.yaml relationships: rabbitmq: "rabbitmq:rabbitmq" Development ready framework: messenger: transports: email: "%env(RABBITMQ_DSN)%" -
Experience The new Components: http-client, messenger, mailer, container, ... Concepts:
Flex, auto-configuration, env vars, ... Tools: Symfony CLI, SymfonyCloud, Docker -
is a fantastic set of low-level building blocks that you
can assemble to develop powerful high-level features easily -
What about the future? Nobody knows, it depends on you
... so, what have you done so far for Symfony 4.4?