Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

StarTutorial.com:
Sending Email with SES in CakePHP 3
Dec 08, 2016 @ 09:31:21

The StarTutorial site has a new article posted showing you how to send email via SES in a CakePHP 3 application. SES is a service from Amazon Web Services that makes it simpler to send emails, the Simple Email Service (SES).

In this tutorial, we will show you how to set up CakePHP 3 to send email with AWS SES via SMTP. In our opinion, integrating AWS SES with CakePHP 3 by SMTP is more straightforward comparing to API.

They start off with the creation of the "EmailTransport" profile configuration dropped into the main application configuration file (defining connection and credential information). They then show how to create an "email profile" telling the framework to use the SES service definition. Finally they offer some advice about using the SES service on a Google Cloud instance and how to work around some of their port restrictions. CakePHP takes care of the rest, automatically understanding how to work with SES and using it transparently as the mailing service when you send your emails.

tagged: cakephp3 tutorial email aws ses send email configuration googlecloud

Link: https://www.startutorial.com/articles/view/sending-email-with-ses-in-cakephp-3

Master Zend Framework:
How To Automate Projects Using Composer Scripts
Dec 06, 2016 @ 12:08:01

The Master Zend Framework site has posted a new tutorial showing you how to automate your projects with Composer, making use of the "scripts" section to add commands that can be automatically executed via a "composer" command line call.

Here, in the second part of the series, we’ll look at the scripts section of composer.json. If you’ve never heard of this section, it provides a way to automate tasks in your project.

Perhaps you think that this is unnecessary, as there is already such a wealth of tools available; including Make, Ant, Phing, and so on. But I see a place for having automation in Composer — though at first I didn’t.

Why? Because you can bring everything that much closer together. Because you can keep everything in a very tidy, organized, and well-structured way.

He starts with a brief overview of how the "scripts" section of the composer.json configuration works. He also shows examples of setting up scripts for code sniffing, running tests and generating test coverage reports. He also shows how to run these commands via the Composer command line and an the use of event handlers (like "post-install-cmd") to execute things at a certain point in the install/update process. He finishes off the post with an example from Zend Expressive calling an "Automation" to clear out the contents of the caches.

tagged: automate composer project scripts configuration tutorial event

Link: http://www.masterzendframework.com/series/tooling/composer/automation-scripts/

Master Zend Framework:
How to Simplify Expressive Configuration with Interop-Config
Nov 17, 2016 @ 09:58:59

On the Master Zend Framework site there's a tutorial posted showing you how to simplify your Zend Expressive configuration with the help of the interop-config package.

Zend Expressive (and Zend Framework) are great frameworks, ones designed not to constrain you in almost any way. You’re in charge. You set the scene. You make it do just what you want it to do. Unlike other frameworks, you’re not bound to work with a specific way. You’re free to work in, almost, whatever way you want. But that comes at a price.

Consequently, using Zend Expressive can give you too much freedom — especially when it comes to configuration. That’s why I was happy to hear about Interop-Config some time ago from my friend Sandro Keil.

Interop-Config is a library which helps ensure that you have a valid configuration for your code. It can provide default options, as well as enforce mandatory options, ensuring that it has a well laid out structure, and is easy to understand.

He starts by briefly talking about the package itself and what kinds of features it brings along with it. The tutorial then shows how to get the package installed and a simple base configuration. With that in place it then shows you how to access this configuration via the "ConfigurationTrait" and a "dimensions" method. From there you can then easily get configuration data from the DI container (and see if it exists with a "canRetrieveOptions" method). The post finishes up showing you how to add default values, making options mandatory and a bit about defensive programming methodologies in using the tool.

tagged: zendexpressive configuration interopconfig package tutorial zendframework

Link: http://www.masterzendframework.com/simplify-expressive-configuration-with-interop-config/

SitePoint PHP Blog:
Hashicorp’s Packer – Is It Something for PHP Developers?
Nov 15, 2016 @ 11:38:24

The SitePoint PHP blog has a new article posted taking a look at Packer (from Hashicorp) and if it's something that's relevant to a PHP developer's needs. Packer is a tool that makes it easier to machine images that can be reused across platforms based on a single configuration.

If you do a lot of server work for your clients or on the job, along with development work, then yes. Packer can help you a lot.

If you are only a developer and don’t really do much work on the server directly, then no. Packer won’t be very helpful.

That being said, it is wise for any PHP developer to learn the basics of creating server environments. You will run into these technologies in your career in one way or another (everything you create runs on them!). This specialized knowledge will help your career in the future for sure! At a minimum, you’ll understand your dev-ops colleagues and the work they do much better.

The article starts with a "look back in time" to when server setup was more manual and server admins/developers had to go in and change configurations/update software by hand. From there they move forward to the changes that virtualized servers made possible followed quickly by tools like Vagrant. Vagrant makes it easier to create and configure virtual machines so why would you need something like Packer? The article provides a summary of the features that Packer provides and how its overall workflow operates.

With all this information under your belt, the tutorial then starts in on using the Packer tool:

  • installing the Packer software
  • creating a new server instance
  • setting up the JSON configuration
  • the build process
  • working with provisioners
  • installing the VM with VirtualBox

The environment is now all set up and configured so the next step is, naturally, installing a PHP-based application. They opt for a basic Symfony demo application, showing how to change the configuration to pull it in and set everything up.

tagged: hashicorp developer packer tutorial configuration vagrant server setup

Link: https://www.sitepoint.com/hashicorps-packer-is-it-something-for-php-developers/

SitePoint PHP Blog:
Mail Logging in Laravel 5.3: Extending the Mail Driver
Sep 26, 2016 @ 11:54:40

On the SitePoint PHP blog there's a new tutorial posted by Younes Rafie looking at logging of mail handling in Laravel by extending the already included driver with your own updates.

One of the many goodies Laravel offers is mailing. You can easily configure and send emails through multiple popular services, and it even includes a logging helper for development.

[...] Laravel also provides a good starting point for sending mails during the development phase using the log driver, and in production using smtp, sparkpost, mailgun, etc. This seems fine in most cases, but it can’t cover all the available services! In this tutorial, we’re going to learn how to extend the existing mail driver system to add our own.

They start by helping you create the service provider used to log the mail information to a database table (the DBMailProvider). The extend the existing mail provider class and set it up to register the Swift Mailer provider if the configuration for the mailer is not set to "db". The the tutorial shows how to update the provider to override the swift.mailer instance in the application dependency injection container and include the code to override the "send" method. A migration is created to hold the mail data and a matching Emails model is used to save the mail results.

tagged: laravel email logging database tutorial driver swiftmailer configuration

Link: https://www.sitepoint.com/mail-logging-in-laravel-5-3-extending-the-mail-driver/

Gary Hockin:
ConfigAbstractFactory in ZendServiceManager
Sep 02, 2016 @ 10:31:16

Gary Hockin has a post to his site today introducing you to the new ConfigAbstractFactory class to work with ZendServiceManager in Zend Framework applications. The library helps make the creation of configuration service factories easier than having to write them in code.

I wanted to introduce the new ConfigAbstractFactory that has been written for ZendServiceManager 3 and got merged to develop today and will be included in the next 3.2.0 release of the ServiceManager.

[...] Laravel has shown us that developer usability is a real thing and that by making things easier for your target audience you gain traction and Good Things Happen. This is why in response to an issue on the Service Manager repository, I’ve written the catchily named Config Abstract Factory. Essentially, it allows you to create service factories from configuration rather than having to write all the code.

He talks about being a fan of the "configuration over magic" approach the Zend Framework has and how, with this new new library, it makes it even easier to directly link configuration files and the objects created based on their contents. He gives a simple example of a UserServiceFactory, first showing the "old" way of handling it then how to shift over to the new abstract handler just defining the same setup in the module configuration.

tagged: configuration abstract factory class servicemanager zendframework

Link: https://blog.hock.in/2016/09/02/configabstractfactory-in-zendservicemanager/

SitePoint PHP Blog:
Local Composer for Everyone! A Conference-Friendly Satis Setup
Aug 30, 2016 @ 11:13:30

On the SitePoint PHP blog editor Bruno Skvorc has posted a tutorial showing you how to set up the Packagist alternative, Satis, in a local network configuration instead of requiring users to still access the external web.

While preparing my technical materials for WebSummerCamp, I realized my workshop would rely on a fairly stable internet connection, as we’d have a lot of ground to cover and a lot of packages to install. Rather than rely on the gods of live demos, or pre-installing everything and ruining the experience, I picked another route.

In this post, I’ll show you how to set up a local Satis instance and have it host the packages over the network it’s currently on, so that everyone who’s also connected to it can put the address into composer.json as a custom repository source, and retrieve all packages from your machine locally – no internet connection required!

He then shows you how to set up the system on a Homestead Improved VM locally, cloning Satis inside of it. He includes an example of the configuration of his required packages and how to build the local repository using this setup. Then, using the built-in PHP web server, he shows the result of the setup and how to access it from other machines. Finally, a few updates are required to the user's composer.json to use the local versions instead of the normal remote connection for the package downloads.

tagged: composer satis local network tutorial setup configuration example

Link: https://www.sitepoint.com/local-composer-for-everyone-a-conference-friendly-satis-setup/

Matthew Weier O'Phinney:
Using Composer to Autoload ZF Modules
Aug 18, 2016 @ 09:50:11

Matthew Weier O'Phinney has a new post to his site showing you how to can use Composer to autoload Zend Framework modules right along with the rest of the ZF components.

One aspect of Zend Framework 3, we paid particular focus on was leveraging the Composer ecosystem. We now provide a number of Composer plugins for handling things such as initial project installation, registering installed modules with the application, and more. It's the "more" I particularly want to talk about.

With ZF2, we were able to realize the ability to install third-party modules into existing applications, enabling a module ecosystem. [...] For the v3 release, we wanted to solve this if we could. We were able to do so via a Composer plugin, zend-component-installer.

This allows ZF module authors to add details into the "extra" section of their Composer configuration, making it so the plugin understands how to load the module automatically. They've also created a package to help do the same for Apigility applications and lets you remove any calls to "getAutoloaderConfig" in your modules.

tagged: zendframework autoload composer zf3 apigility configuration extra package

Link: https://mwop.net/blog/2016-08-17-zf-composer-autoloading.html

Master Zend Framework:
How To Simplify Zend Expressive Configuration with ConfigProviders
Aug 15, 2016 @ 12:42:19

The Master Zend Framework site has a new tutorial posted helping you simplify the configuration on your Zend Expressive application with the help of ConfigProviders, a handy feature that lets you split up the configuration into logical "chunks" as PHP classes.

Given Zend Framework’s design (and accompanying flexible nature), this [configuration complexity] can easily be the case if we’re not careful. [...] Specifically, we’ll likely end up with a config/autoload directory polluted with a plethora of configuration, including for dependencies, routing, and middleware.

[...] As it turns out, this was something which was already identified by other developers, including the Zend Framework contributors. [...] In there, he mentioned ConfigProvider classes as a simple way of enabling ZendForm ViewHelpers, which aren’t enabled by default in Zend Expressive. As I looked at the composition of the file, I realized that this was the answer I needed to solve the configuration issue I created for myself.

A screencast is included in the post showing off the solution but the code an explanation are below that as well for those more interested in reading than watching a video. He walks you through the creation of the configuration provider including setting up the dependency configuration, updating the route handling and, finally, actually using the provider in your global configuration.

tagged: zendexpressive configuration provider configprovider tutorial screencast example

Link: http://www.masterzendframework.com/configproviders-classes/

Steve Azzopardi:
Setting up GrumPHP with Laravel
Aug 02, 2016 @ 12:17:11

On his Medium blog Steve Azzopardi has a tutorial showing you how to install and use the GrumPHP tool to evaluate the quality of the code in your Laravel-based codebase.

First of lets go through what is GrumPHP and how it can help in our workflow to make pull requests less “Code Check Styles” and more proper architecture review. There are specifically built tools for code style checks such as nitpick or styleCI, but even tools like these will only help you after you push your code to GitHub. GrumPHP will do all the style checks and other tasks, such as run PHPunit before you do a commit.

He expects a few prerequisites to already be installed but they're pretty minimal (basically Composer and Git). He then makes a brand new Laravel application and (optionally) sets up a development environment in a Vagrant VM. Next he pulls in GrumPHP and executes it, showing the happy green "grump" as there's no code defined to test. Next he adds in PSR-2 format testing with PHP_CodeSniffer and shows the unhappy red "grump" that results from bad code. He then adds in PHPUnit testing and adds in a gulp task to load other required resources.

tagged: grumphp testing laravel tutorial installation configuration

Link: https://medium.com/@steveazz/setting-up-grumphp-with-laravel-202f158e9862#.id38p25bs