From bc21814de100a2a4c75ca0a8a13b8eafdce39253 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 13 Feb 2020 11:34:51 +0100 Subject: [PATCH 1/8] Add documentation for sending emails with Symfony on GAE --- appengine/php72/symfony-framework/README.md | 71 ++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index e8eedf9d90..8aa9239c09 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -265,12 +265,76 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi `https://YOUR_PROJECT_ID.appspot.com/en/logging/notice` and `https://YOUR_PROJECT_ID.appspot.com/en/logging/exception` +## Send emails + +As stated in the [Migration guide from PHP 5.x to 7.x][cloud-migration] the Mail API or App Engine has been removed. +The recommended way to send emails is to use a third-party mail provider such as [Sendgrid][sendgrid], [Mailgun][mailgun] or [Mailjet][mailjet]. +Hosting your application on GAE, most of these providers will offer you up to 30,000 emails per month and you will be charged only if you send more. +You will have the possibility to track your email delivery and benefit from all the feature of a real email broadcasting system. + +### Install + +First you need to install the mailer component: + +``` +composer require symfony/mailer +``` + +Then depending on the provider you chose, you need to add the additional component, [Symfony mailer documentation][symfony-mailer] +will give you all the specific per provider but here is an example with Mailgun: + +``` +composer require symfony/mailgun-mailer +``` + +This recipe will automatically add the following ENV variable to your .env file: + +``` +# Will be provided by mailgun once your account will be created +MAILGUN_KEY= xxxxxx +# Should be your Mailgun MX record +MAILGUN_DOMAIN= mg.yourdomain.com +# Region is mandatory if you chose server outside the US otherwise your domain will not be found +MAILER_DSN=mailgun://$MAILGUN_KEY:$MAILGUN_DOMAIN@default?region=eu +``` + +From that point, you just need to create your account and first domain adding all the DNS Records. +[Mailgun documentation][mailgun-add-domain] will lead you through these steps. + +You can now send emails in Controller and Service as usual: +``` +// src/Controller/MailerController.php +namespace App\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Email; + +class MailerController extends AbstractController +{ + /** + * @Route("/email") + */ + public function sendEmail(MailerInterface $mailer) + { + $email = (new Email()) + ->from('hello@example.com') + ->to('you@example.com') + ->subject('Time for Symfony Mailer!') + ->text('Sending emails is fun again!'); + + $mailer->send($email); + } +} +``` + [cloud-sdk]: https://cloud.google.com/sdk/ [cloud-build]: https://cloud.google.com/cloud-build/ [cloud-sql]: https://cloud.google.com/sql/docs/ [cloud-sql-create]: https://cloud.google.com/sql/docs/mysql/create-instance [cloud-sql-install]: https://cloud.google.com/sql/docs/mysql/connect-external-app#install -[cloud-sql-apis]:https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro +[cloud-sql-apis]: https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro +[cloud-migration]: https://cloud.google.com/appengine/docs/standard/php7/php-differences?hl=en#migrating_from_the_app_engine_php_sdk [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects [enable-billing]: https://support.google.com/cloud/answer/6293499?hl=en [symfony]: http://symfony.com @@ -280,5 +344,10 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi [symfony-secret]: http://symfony.com/doc/current/reference/configuration/framework.html#secret [symfony-env]: https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments [symfony-override-cache]: https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory +[symfony-mailer]: https://symfony.com/doc/current/mailer.html [stackdriver-logging-ui]: https://console.cloud.google.com/logs [stackdriver-errorreporting-ui]: https://console.cloud.google.com/errors +[sendgrid]: https://sendgrid.com/ +[mailgun]: https://www.mailgun.com/ +[mailjet]: https://www.mailjet.com/ +[mailgun-add-domain]: https://help.mailgun.com/hc/en-us/articles/203637190-How-Do-I-Add-or-Delete-a-Domain- From 4f00ce4daaf0832541276be0c5f73b71bc6c9ae1 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 13 Feb 2020 12:03:10 +0100 Subject: [PATCH 2/8] Revert "Add documentation for sending emails with Symfony on GAE" This reverts commit bc21814de100a2a4c75ca0a8a13b8eafdce39253. --- appengine/php72/symfony-framework/README.md | 71 +-------------------- 1 file changed, 1 insertion(+), 70 deletions(-) diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index 8aa9239c09..e8eedf9d90 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -265,76 +265,12 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi `https://YOUR_PROJECT_ID.appspot.com/en/logging/notice` and `https://YOUR_PROJECT_ID.appspot.com/en/logging/exception` -## Send emails - -As stated in the [Migration guide from PHP 5.x to 7.x][cloud-migration] the Mail API or App Engine has been removed. -The recommended way to send emails is to use a third-party mail provider such as [Sendgrid][sendgrid], [Mailgun][mailgun] or [Mailjet][mailjet]. -Hosting your application on GAE, most of these providers will offer you up to 30,000 emails per month and you will be charged only if you send more. -You will have the possibility to track your email delivery and benefit from all the feature of a real email broadcasting system. - -### Install - -First you need to install the mailer component: - -``` -composer require symfony/mailer -``` - -Then depending on the provider you chose, you need to add the additional component, [Symfony mailer documentation][symfony-mailer] -will give you all the specific per provider but here is an example with Mailgun: - -``` -composer require symfony/mailgun-mailer -``` - -This recipe will automatically add the following ENV variable to your .env file: - -``` -# Will be provided by mailgun once your account will be created -MAILGUN_KEY= xxxxxx -# Should be your Mailgun MX record -MAILGUN_DOMAIN= mg.yourdomain.com -# Region is mandatory if you chose server outside the US otherwise your domain will not be found -MAILER_DSN=mailgun://$MAILGUN_KEY:$MAILGUN_DOMAIN@default?region=eu -``` - -From that point, you just need to create your account and first domain adding all the DNS Records. -[Mailgun documentation][mailgun-add-domain] will lead you through these steps. - -You can now send emails in Controller and Service as usual: -``` -// src/Controller/MailerController.php -namespace App\Controller; - -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Mailer\MailerInterface; -use Symfony\Component\Mime\Email; - -class MailerController extends AbstractController -{ - /** - * @Route("/email") - */ - public function sendEmail(MailerInterface $mailer) - { - $email = (new Email()) - ->from('hello@example.com') - ->to('you@example.com') - ->subject('Time for Symfony Mailer!') - ->text('Sending emails is fun again!'); - - $mailer->send($email); - } -} -``` - [cloud-sdk]: https://cloud.google.com/sdk/ [cloud-build]: https://cloud.google.com/cloud-build/ [cloud-sql]: https://cloud.google.com/sql/docs/ [cloud-sql-create]: https://cloud.google.com/sql/docs/mysql/create-instance [cloud-sql-install]: https://cloud.google.com/sql/docs/mysql/connect-external-app#install -[cloud-sql-apis]: https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro -[cloud-migration]: https://cloud.google.com/appengine/docs/standard/php7/php-differences?hl=en#migrating_from_the_app_engine_php_sdk +[cloud-sql-apis]:https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects [enable-billing]: https://support.google.com/cloud/answer/6293499?hl=en [symfony]: http://symfony.com @@ -344,10 +280,5 @@ class MailerController extends AbstractController [symfony-secret]: http://symfony.com/doc/current/reference/configuration/framework.html#secret [symfony-env]: https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments [symfony-override-cache]: https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory -[symfony-mailer]: https://symfony.com/doc/current/mailer.html [stackdriver-logging-ui]: https://console.cloud.google.com/logs [stackdriver-errorreporting-ui]: https://console.cloud.google.com/errors -[sendgrid]: https://sendgrid.com/ -[mailgun]: https://www.mailgun.com/ -[mailjet]: https://www.mailjet.com/ -[mailgun-add-domain]: https://help.mailgun.com/hc/en-us/articles/203637190-How-Do-I-Add-or-Delete-a-Domain- From e7c52ba99173060ed16700d32d46828469898747 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 13 Feb 2020 12:04:02 +0100 Subject: [PATCH 3/8] Add documentation about sending email with Symfony on GAE --- appengine/php72/symfony-framework/README.md | 71 ++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index e8eedf9d90..8aa9239c09 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -265,12 +265,76 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi `https://YOUR_PROJECT_ID.appspot.com/en/logging/notice` and `https://YOUR_PROJECT_ID.appspot.com/en/logging/exception` +## Send emails + +As stated in the [Migration guide from PHP 5.x to 7.x][cloud-migration] the Mail API or App Engine has been removed. +The recommended way to send emails is to use a third-party mail provider such as [Sendgrid][sendgrid], [Mailgun][mailgun] or [Mailjet][mailjet]. +Hosting your application on GAE, most of these providers will offer you up to 30,000 emails per month and you will be charged only if you send more. +You will have the possibility to track your email delivery and benefit from all the feature of a real email broadcasting system. + +### Install + +First you need to install the mailer component: + +``` +composer require symfony/mailer +``` + +Then depending on the provider you chose, you need to add the additional component, [Symfony mailer documentation][symfony-mailer] +will give you all the specific per provider but here is an example with Mailgun: + +``` +composer require symfony/mailgun-mailer +``` + +This recipe will automatically add the following ENV variable to your .env file: + +``` +# Will be provided by mailgun once your account will be created +MAILGUN_KEY= xxxxxx +# Should be your Mailgun MX record +MAILGUN_DOMAIN= mg.yourdomain.com +# Region is mandatory if you chose server outside the US otherwise your domain will not be found +MAILER_DSN=mailgun://$MAILGUN_KEY:$MAILGUN_DOMAIN@default?region=eu +``` + +From that point, you just need to create your account and first domain adding all the DNS Records. +[Mailgun documentation][mailgun-add-domain] will lead you through these steps. + +You can now send emails in Controller and Service as usual: +``` +// src/Controller/MailerController.php +namespace App\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Email; + +class MailerController extends AbstractController +{ + /** + * @Route("/email") + */ + public function sendEmail(MailerInterface $mailer) + { + $email = (new Email()) + ->from('hello@example.com') + ->to('you@example.com') + ->subject('Time for Symfony Mailer!') + ->text('Sending emails is fun again!'); + + $mailer->send($email); + } +} +``` + [cloud-sdk]: https://cloud.google.com/sdk/ [cloud-build]: https://cloud.google.com/cloud-build/ [cloud-sql]: https://cloud.google.com/sql/docs/ [cloud-sql-create]: https://cloud.google.com/sql/docs/mysql/create-instance [cloud-sql-install]: https://cloud.google.com/sql/docs/mysql/connect-external-app#install -[cloud-sql-apis]:https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro +[cloud-sql-apis]: https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro +[cloud-migration]: https://cloud.google.com/appengine/docs/standard/php7/php-differences?hl=en#migrating_from_the_app_engine_php_sdk [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects [enable-billing]: https://support.google.com/cloud/answer/6293499?hl=en [symfony]: http://symfony.com @@ -280,5 +344,10 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi [symfony-secret]: http://symfony.com/doc/current/reference/configuration/framework.html#secret [symfony-env]: https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments [symfony-override-cache]: https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory +[symfony-mailer]: https://symfony.com/doc/current/mailer.html [stackdriver-logging-ui]: https://console.cloud.google.com/logs [stackdriver-errorreporting-ui]: https://console.cloud.google.com/errors +[sendgrid]: https://sendgrid.com/ +[mailgun]: https://www.mailgun.com/ +[mailjet]: https://www.mailjet.com/ +[mailgun-add-domain]: https://help.mailgun.com/hc/en-us/articles/203637190-How-Do-I-Add-or-Delete-a-Domain- From fcc99cde0e1f8a522b9568b60bdad2c5a004186e Mon Sep 17 00:00:00 2001 From: Sethbass Date: Thu, 13 Feb 2020 12:23:27 +0100 Subject: [PATCH 4/8] Revert "Add documentation about sending email with Symfony on GAE" This reverts commit e7c52ba99173060ed16700d32d46828469898747. --- appengine/php72/symfony-framework/README.md | 71 +-------------------- 1 file changed, 1 insertion(+), 70 deletions(-) diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index 8aa9239c09..e8eedf9d90 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -265,76 +265,12 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi `https://YOUR_PROJECT_ID.appspot.com/en/logging/notice` and `https://YOUR_PROJECT_ID.appspot.com/en/logging/exception` -## Send emails - -As stated in the [Migration guide from PHP 5.x to 7.x][cloud-migration] the Mail API or App Engine has been removed. -The recommended way to send emails is to use a third-party mail provider such as [Sendgrid][sendgrid], [Mailgun][mailgun] or [Mailjet][mailjet]. -Hosting your application on GAE, most of these providers will offer you up to 30,000 emails per month and you will be charged only if you send more. -You will have the possibility to track your email delivery and benefit from all the feature of a real email broadcasting system. - -### Install - -First you need to install the mailer component: - -``` -composer require symfony/mailer -``` - -Then depending on the provider you chose, you need to add the additional component, [Symfony mailer documentation][symfony-mailer] -will give you all the specific per provider but here is an example with Mailgun: - -``` -composer require symfony/mailgun-mailer -``` - -This recipe will automatically add the following ENV variable to your .env file: - -``` -# Will be provided by mailgun once your account will be created -MAILGUN_KEY= xxxxxx -# Should be your Mailgun MX record -MAILGUN_DOMAIN= mg.yourdomain.com -# Region is mandatory if you chose server outside the US otherwise your domain will not be found -MAILER_DSN=mailgun://$MAILGUN_KEY:$MAILGUN_DOMAIN@default?region=eu -``` - -From that point, you just need to create your account and first domain adding all the DNS Records. -[Mailgun documentation][mailgun-add-domain] will lead you through these steps. - -You can now send emails in Controller and Service as usual: -``` -// src/Controller/MailerController.php -namespace App\Controller; - -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Mailer\MailerInterface; -use Symfony\Component\Mime\Email; - -class MailerController extends AbstractController -{ - /** - * @Route("/email") - */ - public function sendEmail(MailerInterface $mailer) - { - $email = (new Email()) - ->from('hello@example.com') - ->to('you@example.com') - ->subject('Time for Symfony Mailer!') - ->text('Sending emails is fun again!'); - - $mailer->send($email); - } -} -``` - [cloud-sdk]: https://cloud.google.com/sdk/ [cloud-build]: https://cloud.google.com/cloud-build/ [cloud-sql]: https://cloud.google.com/sql/docs/ [cloud-sql-create]: https://cloud.google.com/sql/docs/mysql/create-instance [cloud-sql-install]: https://cloud.google.com/sql/docs/mysql/connect-external-app#install -[cloud-sql-apis]: https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro -[cloud-migration]: https://cloud.google.com/appengine/docs/standard/php7/php-differences?hl=en#migrating_from_the_app_engine_php_sdk +[cloud-sql-apis]:https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects [enable-billing]: https://support.google.com/cloud/answer/6293499?hl=en [symfony]: http://symfony.com @@ -344,10 +280,5 @@ class MailerController extends AbstractController [symfony-secret]: http://symfony.com/doc/current/reference/configuration/framework.html#secret [symfony-env]: https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments [symfony-override-cache]: https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory -[symfony-mailer]: https://symfony.com/doc/current/mailer.html [stackdriver-logging-ui]: https://console.cloud.google.com/logs [stackdriver-errorreporting-ui]: https://console.cloud.google.com/errors -[sendgrid]: https://sendgrid.com/ -[mailgun]: https://www.mailgun.com/ -[mailjet]: https://www.mailjet.com/ -[mailgun-add-domain]: https://help.mailgun.com/hc/en-us/articles/203637190-How-Do-I-Add-or-Delete-a-Domain- From 0683a7ed89c3e6d8e87e19aab1011217f3a7f28f Mon Sep 17 00:00:00 2001 From: Sethbass Date: Thu, 13 Feb 2020 12:24:26 +0100 Subject: [PATCH 5/8] Add documentation about sending emails with Symfony on GAE --- appengine/php72/symfony-framework/README.md | 71 ++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index e8eedf9d90..8aa9239c09 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -265,12 +265,76 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi `https://YOUR_PROJECT_ID.appspot.com/en/logging/notice` and `https://YOUR_PROJECT_ID.appspot.com/en/logging/exception` +## Send emails + +As stated in the [Migration guide from PHP 5.x to 7.x][cloud-migration] the Mail API or App Engine has been removed. +The recommended way to send emails is to use a third-party mail provider such as [Sendgrid][sendgrid], [Mailgun][mailgun] or [Mailjet][mailjet]. +Hosting your application on GAE, most of these providers will offer you up to 30,000 emails per month and you will be charged only if you send more. +You will have the possibility to track your email delivery and benefit from all the feature of a real email broadcasting system. + +### Install + +First you need to install the mailer component: + +``` +composer require symfony/mailer +``` + +Then depending on the provider you chose, you need to add the additional component, [Symfony mailer documentation][symfony-mailer] +will give you all the specific per provider but here is an example with Mailgun: + +``` +composer require symfony/mailgun-mailer +``` + +This recipe will automatically add the following ENV variable to your .env file: + +``` +# Will be provided by mailgun once your account will be created +MAILGUN_KEY= xxxxxx +# Should be your Mailgun MX record +MAILGUN_DOMAIN= mg.yourdomain.com +# Region is mandatory if you chose server outside the US otherwise your domain will not be found +MAILER_DSN=mailgun://$MAILGUN_KEY:$MAILGUN_DOMAIN@default?region=eu +``` + +From that point, you just need to create your account and first domain adding all the DNS Records. +[Mailgun documentation][mailgun-add-domain] will lead you through these steps. + +You can now send emails in Controller and Service as usual: +``` +// src/Controller/MailerController.php +namespace App\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Email; + +class MailerController extends AbstractController +{ + /** + * @Route("/email") + */ + public function sendEmail(MailerInterface $mailer) + { + $email = (new Email()) + ->from('hello@example.com') + ->to('you@example.com') + ->subject('Time for Symfony Mailer!') + ->text('Sending emails is fun again!'); + + $mailer->send($email); + } +} +``` + [cloud-sdk]: https://cloud.google.com/sdk/ [cloud-build]: https://cloud.google.com/cloud-build/ [cloud-sql]: https://cloud.google.com/sql/docs/ [cloud-sql-create]: https://cloud.google.com/sql/docs/mysql/create-instance [cloud-sql-install]: https://cloud.google.com/sql/docs/mysql/connect-external-app#install -[cloud-sql-apis]:https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro +[cloud-sql-apis]: https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro +[cloud-migration]: https://cloud.google.com/appengine/docs/standard/php7/php-differences?hl=en#migrating_from_the_app_engine_php_sdk [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects [enable-billing]: https://support.google.com/cloud/answer/6293499?hl=en [symfony]: http://symfony.com @@ -280,5 +344,10 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi [symfony-secret]: http://symfony.com/doc/current/reference/configuration/framework.html#secret [symfony-env]: https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments [symfony-override-cache]: https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory +[symfony-mailer]: https://symfony.com/doc/current/mailer.html [stackdriver-logging-ui]: https://console.cloud.google.com/logs [stackdriver-errorreporting-ui]: https://console.cloud.google.com/errors +[sendgrid]: https://sendgrid.com/ +[mailgun]: https://www.mailgun.com/ +[mailjet]: https://www.mailjet.com/ +[mailgun-add-domain]: https://help.mailgun.com/hc/en-us/articles/203637190-How-Do-I-Add-or-Delete-a-Domain- From fa680cf08f20ed0268a5b23d8cfaeb77c3b8c60d Mon Sep 17 00:00:00 2001 From: Sethbass Date: Mon, 24 Feb 2020 07:33:20 +0100 Subject: [PATCH 6/8] Integrate suggestions from Brent --- appengine/php72/symfony-framework/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index 8aa9239c09..3a06056ff9 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -267,7 +267,6 @@ the [Stackdriver Error Reporting UI][stackdriver-errorreporting-ui]! If you copi ## Send emails -As stated in the [Migration guide from PHP 5.x to 7.x][cloud-migration] the Mail API or App Engine has been removed. The recommended way to send emails is to use a third-party mail provider such as [Sendgrid][sendgrid], [Mailgun][mailgun] or [Mailjet][mailjet]. Hosting your application on GAE, most of these providers will offer you up to 30,000 emails per month and you will be charged only if you send more. You will have the possibility to track your email delivery and benefit from all the feature of a real email broadcasting system. @@ -280,8 +279,7 @@ First you need to install the mailer component: composer require symfony/mailer ``` -Then depending on the provider you chose, you need to add the additional component, [Symfony mailer documentation][symfony-mailer] -will give you all the specific per provider but here is an example with Mailgun: +For this example, we will use `Mailgun`. To use a different mail provider, see the [Symfony mailer documentation][symfony-mailer]. ``` composer require symfony/mailgun-mailer @@ -310,7 +308,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Email; -class MailerController extends AbstractController +class ExampleController extends AbstractController { /** * @Route("/email") From ceaa3b36875c3e20f2934163cd1e78038d6807a3 Mon Sep 17 00:00:00 2001 From: Sethbass Date: Thu, 5 Mar 2020 15:45:24 +0100 Subject: [PATCH 7/8] Add 2 tutorials as specified in #1039 --- appengine/php72/symfony-framework/README.md | 156 ++++++++++++++++++ .../src/Entity/ExampleEntity.php | 125 ++++++++++++++ .../GoogleCloudStorageServiceFactory.php | 36 ++++ 3 files changed, 317 insertions(+) create mode 100644 appengine/php72/symfony-framework/src/Entity/ExampleEntity.php create mode 100644 appengine/php72/symfony-framework/src/Factory/GoogleCloudStorageServiceFactory.php diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index 3a06056ff9..5c4afdad86 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -326,6 +326,156 @@ class ExampleController extends AbstractController } ``` +## Session Management + +As for the logs and the cache, you can not write session file on App Engine. This might create unexpected disconnections from your app. +Fortunately, Symfony provides a way to handle this persisting the session in the database. +We recommend to use the Symfony PDOSessionHandler so the session data will be persisted in the database instead of files. +Here is the detailed [documentation][symfony-pdo-session-storage], and we will lead you through those simple steps. + +### Configuration + +Modify your Framework configuration in config/packages/framework.yaml and change the parameters under session to be the following: + +``` +session: + handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler + cookie_secure: auto + cookie_samesite: lax + # Adjust the max lifetime to your need + gc_maxlifetime: 36000 +``` + +You should then activate the service in config/services.yaml. + +``` + Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler: + arguments: + - !service { class: PDO, factory: ['@database_connection', 'getWrappedConnection'] } + # If you get transaction issues (e.g. after login) uncomment the line below + # - { lock_mode: 1 } +``` + +### Database update + +In order to make it work, you will need to update your database with the missing table and fields. +Connect to your database and execute the following query (MySQL example): + +``` +CREATE TABLE `sessions` ( + `sess_id` VARCHAR(128) NOT NULL PRIMARY KEY, + `sess_data` BLOB NOT NULL, + `sess_time` INTEGER UNSIGNED NOT NULL, + `sess_lifetime` INTEGER UNSIGNED NOT NULL +) COLLATE utf8mb4_bin, ENGINE = InnoDB; +``` + +You are now all set, the session will be persisted in the database and your users will remain authenticated. + +## Upload files + +Pre-requisites: +In order to write files on App Engine you will need to use a Storage Bucket, so you have to [enable the Storage API][cloud-enable-api-storage]. +On top of that, you will need a service account having the Role Storage Admin, once this service account created you can download the private key in JSON format. + +### Install all the bundles + +First thing you will need is the [Google Cloud Storage for PHP][cloud-storage-php] package which will communicate with the Storage API: +``` + composer require google/cloud-storage +``` + +You will need the Google_client class from the [Google APIs Client Library for PHP][cloud-api-client]. + +``` + composer require google/apiclient:"^2.0" +``` + +You can then install the [KnpGaufretteBundle][knp-gaufrette] which will automate the communication with Google Storage: + +``` + composer require knplabs/knp-gaufrette-bundle +``` + +To make it even easier, we use the famous [VichUploaderBundle][vich-uploader]: + +``` + composer require vich/uploader-bundle +``` + +### Create an Uploadable Entity + +You can modify the [`src/Entity/ExampleEntity`](src/Entity/ExampleEntity.php) to your need and be careful that the field updatedAt is changed when the file is set. + +### Configuration + +Installing the Google Cloud API Client Library you should automatically add the following keys to your .env: + +``` + # If you want to have Read and write access to your repository + GOOGLE_CLOUD_STORAGE_SCOPE='https://www.googleapis.com/auth/devstorage.full_control' + GCS_PRIVATE_KEY_LOCATION='path_to_your_service_account_private_key.json' + BUCKET_NAME='your-bucket-name' + GOOGLE_CLOUD_PROJECT='your-project-id' +``` + +You will need to create a Factory to create a Google Client, check the [`src/Factory/GoogleCloudStorageServiceFactory`](src/Factory/GoogleCloudStorageServiceFactory.php) for reference. + +Then in your config/services.yaml you need to activate those 2 services, Google_Client_Storage will just use the Factory above to create the client: + +``` + app.google_cloud_storage_factory: + class: App\Factory\GoogleCloudStorageServiceFactory + arguments: + - '%env(GOOGLE_CLOUD_STORAGE_SCOPE)%' + - '%kernel.project_dir%/%env(GCS_PRIVATE_KEY_LOCATION)%' + + app.google_cloud_storage.service: + class: Google_Service_Storage + factory: ['@app.google_cloud_storage_factory', createService] +``` + +Finally you will have to configure KNPGaufrette and VichUploader, here is the logic: + +``` + # in your config/packages/knp_gaufrette.yaml + knp_gaufrette: + stream_wrapper: ~ + adapters: + # Each type of file to be uploaded in your app will need an adapter and a filesystem + image_adapter: + google_cloud_storage: + service_id: 'app.google_cloud_storage.service' + bucket_name: '%env(BUCKET_NAME)%' + options: + directory: 'your-directory-in-your-bucket' + + filesystems: + image_filesystem: + adapter: image_adapter + alias: image_filesystem +``` + +``` + # in your config/packages/vich_uploader.yaml + vich_uploader: + db_driver: orm + # This is how you connect VichUploader to KnpGaufrette + storage: gaufrette + # Each type of file needs its own mapping + mappings: + # See the method @Vich\UploadableField src/Entity/ExampleEntity + example_mapping: + uri_prefix: '/your-upload-directory' + # this is how you specify the correct Gaufrette filesystem + upload_destination: image_filesystem + # the name is not mandatory this one generates a unique ID instead of using your file name + namer: Vich\UploaderBundle\Naming\UniqidNamer +``` + +So every time an ExampleEntity will be persisted, the file will be automatically uploaded in your bucket. + + [cloud-sdk]: https://cloud.google.com/sdk/ [cloud-build]: https://cloud.google.com/cloud-build/ [cloud-sql]: https://cloud.google.com/sql/docs/ @@ -333,6 +483,9 @@ class ExampleController extends AbstractController [cloud-sql-install]: https://cloud.google.com/sql/docs/mysql/connect-external-app#install [cloud-sql-apis]: https://console.cloud.google.com/apis/library/sqladmin.googleapis.com/?pro [cloud-migration]: https://cloud.google.com/appengine/docs/standard/php7/php-differences?hl=en#migrating_from_the_app_engine_php_sdk +[cloud-enable-api-storage]: https://console.cloud.google.com/flows/enableapi?apiid=storage_api +[cloud-api-client]: https://github.com/googleapis/google-api-php-client +[cloud-storage-php]: https://github.com/googleapis/google-cloud-php-storage [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects [enable-billing]: https://support.google.com/cloud/answer/6293499?hl=en [symfony]: http://symfony.com @@ -343,9 +496,12 @@ class ExampleController extends AbstractController [symfony-env]: https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments [symfony-override-cache]: https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory [symfony-mailer]: https://symfony.com/doc/current/mailer.html +[symfony-pdo-session-storage]: https://symfony.com/doc/current/doctrine/pdo_session_storage.html [stackdriver-logging-ui]: https://console.cloud.google.com/logs [stackdriver-errorreporting-ui]: https://console.cloud.google.com/errors [sendgrid]: https://sendgrid.com/ [mailgun]: https://www.mailgun.com/ [mailjet]: https://www.mailjet.com/ [mailgun-add-domain]: https://help.mailgun.com/hc/en-us/articles/203637190-How-Do-I-Add-or-Delete-a-Domain- +[vich-uploader]: https://github.com/dustin10/VichUploaderBundle +[knp-gaufrette]: https://github.com/KnpLabs/KnpGaufretteBundle diff --git a/appengine/php72/symfony-framework/src/Entity/ExampleEntity.php b/appengine/php72/symfony-framework/src/Entity/ExampleEntity.php new file mode 100644 index 0000000000..5c0e7672a0 --- /dev/null +++ b/appengine/php72/symfony-framework/src/Entity/ExampleEntity.php @@ -0,0 +1,125 @@ +updatedAt = new DateTime(); + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getImage() + { + return $this->image; + } + + /** + * @param string + */ + public function setImage($image) + { + $this->image = $image; + } + + /** + * @return File + */ + public function getImageFile() + { + return $this->imageFile; + } + + /** + * @param File + * @return ExampleEntity + */ + public function setImageFile(File $file = null) + { + $this->imageFile = $file; + + /** + * Important to update at least one field with Doctrine otherwise the listeners are called and file is lost. + */ + if ($file) { + $this->updatedAt = new DateTime(); + } + + return $this; + } + + /** + * @return DateTime + */ + public function getUpdatedAt() + { + return $this->updatedAt; + } + + /** + * @param DateTime + * @return ExampleEntity + */ + public function setUpdatedAt($updatedAt) + { + $this->updatedAt = $updatedAt; + return $this; + } +} diff --git a/appengine/php72/symfony-framework/src/Factory/GoogleCloudStorageServiceFactory.php b/appengine/php72/symfony-framework/src/Factory/GoogleCloudStorageServiceFactory.php new file mode 100644 index 0000000000..cb5c2e5793 --- /dev/null +++ b/appengine/php72/symfony-framework/src/Factory/GoogleCloudStorageServiceFactory.php @@ -0,0 +1,36 @@ +scope = $scope; + $this->keyLocation = $keyLocation; + } + + /** + * @return Google_Service_Storage + */ + public function createService() { + $client = new Google_Client(); + $client->setAuthConfig($this->keyLocation); + $client->setScopes([$this->scope]); + return new Google_Service_Storage($client); + } +} From f29b0f3be999d6915d65566e6b3a016ec762bf26 Mon Sep 17 00:00:00 2001 From: Sethbass Date: Fri, 6 Mar 2020 08:47:24 +0100 Subject: [PATCH 8/8] Changes for the first tutorial --- appengine/php72/symfony-framework/README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/appengine/php72/symfony-framework/README.md b/appengine/php72/symfony-framework/README.md index 5c4afdad86..fbfcf34cd1 100644 --- a/appengine/php72/symfony-framework/README.md +++ b/appengine/php72/symfony-framework/README.md @@ -328,17 +328,15 @@ class ExampleController extends AbstractController ## Session Management -As for the logs and the cache, you can not write session file on App Engine. This might create unexpected disconnections from your app. -Fortunately, Symfony provides a way to handle this persisting the session in the database. -We recommend to use the Symfony PDOSessionHandler so the session data will be persisted in the database instead of files. -Here is the detailed [documentation][symfony-pdo-session-storage], and we will lead you through those simple steps. +To persist sessions across multiple App Engine instances, you'll need to use a database. +Fortunately, Symfony provides a way to handle this using [PDO session storage][symfony-pdo-session-storage]. ### Configuration -Modify your Framework configuration in config/packages/framework.yaml and change the parameters under session to be the following: +Modify your Framework configuration in `config/packages/framework.yaml` and change the parameters under session to be the following: ``` -session: + session: handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler cookie_secure: auto cookie_samesite: lax @@ -346,7 +344,7 @@ session: gc_maxlifetime: 36000 ``` -You should then activate the service in config/services.yaml. +You should then activate the service in `config/services.yaml. ``` Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler: @@ -358,10 +356,11 @@ You should then activate the service in config/services.yaml. ### Database update -In order to make it work, you will need to update your database with the missing table and fields. -Connect to your database and execute the following query (MySQL example): +Next, add the `sessions` table to your database by connecting to your database and +executing the following query: ``` +# MySQL Query CREATE TABLE `sessions` ( `sess_id` VARCHAR(128) NOT NULL PRIMARY KEY, `sess_data` BLOB NOT NULL, @@ -469,7 +468,7 @@ Finally you will have to configure KNPGaufrette and VichUploader, here is the lo uri_prefix: '/your-upload-directory' # this is how you specify the correct Gaufrette filesystem upload_destination: image_filesystem - # the name is not mandatory this one generates a unique ID instead of using your file name + # the namer is not mandatory, this one generates a unique ID instead of using your file name namer: Vich\UploaderBundle\Naming\UniqidNamer ```