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

Sebastian De Deyne:
TypeScript With Laravel Mix
May 25, 2017 @ 10:21:16

In a post to his site Sebastian De Deyne shows how to use Laravel Mix to work with Typescript right alongside other packages and libraries included in your mix configuration.

In a recent Spatie project we decided to give TypeScript a shot for the business critical part of a new application. TypeScript provides static analysis to reduce the chance of introducing bugs, to have self-documenting code, and to improve our tooling (autocompletion!)

We've been happily using Laravel Mix since it's release with Laravel 5.4. Luckily, extending Mix isn't too hard with some webpack knowledge. [...] As long as you've configured an appropriate loader, you could import anything from a plain old JavaScript file to an animated gif. This means that if we want to support TypeScript with Laravel Mix, we don't need to change any configuration, we only need to add the ability to bundle TypeScript files.

The remainder of the article is broken down into the four steps (and a bonus) for getting Mix and TypeScript playing together nicely:

  • Install The Necessary Dependencies
  • Configure TypeScript
  • Configure Laravel Mix
  • Write Some TypeScript!

The bonus at the end shows how to use this working setup to go one step further and use TypeScript in the Vue.js components in your Laravel application.

tagged: laravel laravelmix typescript combination tutorial configuration

Link: https://sebastiandedeyne.com/posts/2017/typescript-with-laravel-mix

Symfony Blog:
The new Symfony 3.3 Service Configuration Changes Explained
May 23, 2017 @ 10:15:27

On the Symfony blog, there's an article posted by Ryan Weaver helping to explain the new service configuration changes that are included with version 3.3 of the framework.

In less than 2 weeks, Symfony 3.3 will be released. It comes with a lot of new stuff, but there is one feature that stands out: the new service configuration. I am very excited about these changes: they're designed to accelerate development, make Symfony easier to learn and encourage best-practices (e.g. injecting specific dependencies instead of using $container->get())... without sacrificing predictability and stability.

The post includes an example of what the new configuration file format will look like and briefly explains some of the changes. For those interested in a more in-depth look, they also link to this page in the Symfony documentation that goes through the changes step by step. It covers the autowiring by default, autoload of services, controllers being registered as services and more. If you're planning on making the move up to v3.3 when it's released (or sometime after) definitely check out this guide to make the transition easier.

tagged: symfony framework service configuration changes explained documentation

Link: http://symfony.com/doc/master/service_container/3.3-di-changes.html

Zend Framework Blog:
Manage your application with zend-config-aggregator
Apr 20, 2017 @ 16:09:14

The Zend Framework blog has a new post sharing a method for managing your application's configurations with the help of the zend-config-aggregator package, a product of work on the Zend Expressive framework.

With the rise of PHP middleware, many developers are creating custom application architectures, and running into an issue many frameworks already solve: how to allow runtime configuration of the application.

configuration is often necessary, even in custom applications. [...] Faced with this reality, you then have a new problem: how can you configure your application, as well as aggregate configuration from other sources?

As part of the Expressive initiative, we now offer a standalone solution for you: zend-config-aggregator

The post walks you through the installation of the package and introduces some of the included configuration providers. The tutorial then shows how to put the component to use, aggregating several different kinds of configuration files. It also shows how to use caching on the results and auto-enabling third party and custom providers.

tagged: zendexpressive configuration aggregation component tutorial

Link: https://framework.zend.com/blog/2017-04-20-config-aggregator.html

Adam Culp:
Easy Docker dev environments for PHP with CloudEstuary
Apr 17, 2017 @ 15:14:09

Adam Culp has written up a new post to his site showing you how to use the CloudEstuary service to easily create Docker development environments for your day to day work.

Lately I’ve been messing around with Docker, and specifically with containerizing PHP applications to perform quick services, such as static analysis of PHP code, compatibility of existing PHP code to specific versions of PHP, and performing security checks on PHP libraries included in my projects. However, I’ve not created a development environment for my projects using Docker.

[...] But today I found another way [besides using Vagrant]. A way to easily create PHP development environments with Docker. The fine folks at CloudEstuary have created an easy to use web-based tool to create PHP development environments (yml files) for use with Docker-compose.

He then walks you through the process of creating a new environment, selecting the framework to be installed by default and other "add-ons" to be include (it also allows for the addition of workers). After clicking on the "Generate Docker Compose" button the service spits out the YAML configuration file you can then use to create the environment. There's a few tweaks he recommends making to the config and, finally, the command to use the configuration and bring the environment up.

tagged: docker cloudestuary service compose tutorial configuration

Link: http://www.geekyboy.com/archives/1321

Zend Framework Blog:
Using Configuration-Driven Routes in Expressive
Apr 05, 2017 @ 12:21:26

The Zend Framework blog continues their series of posts looking at the Zend Expressive framework with this latest tutorial showing you how to use configuration-driven routing instead of routes defined in just code.

Expressive 1 used configuration-driven pipelines and routing; Expressive 2 switches to use programmatic pipelines and routes instead. The programmatic approach was chosen as many developers have indicated they find it easier to understand and easier to read, and ensures they do not have any configuration conflicts.

However, there are times you may want to use configuration. For example, when you are writing re-usable modules, it's often easier to provide configuration for routed middleware, than to expect users to cut-and-paste examples, or use features such as delegator factories.

Fortunately, starting in Expressive 2, we offer a couple different mechanisms to support configuration-driven pipelines and routing.

They start by pointing out the result of the Expressive v1 to v2 migration tool (enabling v2's pipeline handling) and a warning that there could be issues as the programmatic declarations still remain. The tutorial then gets into some of the drawbacks of going configuration-only but shows how, with just a bit of extra code, those can be someone relieved. An example is included showing a configuration provider that, from the functionality itself, defines the routes and injects them into the current application (using injectRoutesFromConfig).

tagged: zendframework zendexpressive configuration route pipeline migration provider tutorial

Link: https://framework.zend.com/blog/2017-03-30-expressive-config-routes.html

Adam Wathan:
Detecting Out of Sync Mocks in Mockery
Apr 05, 2017 @ 11:14:41

Adam Wathan has shared a new post on his site with advice on finding out-of-date mocks when using the Mockery mocking tool in your testing.

If you're not careful, it's easy to find yourself in a situation where a test double has gotten out of sync with the actual class or interface it's mocking.

In this quick screencast (taken from my Test-Driven Laravel course), I walk through how I use a little-known Mockery feature to help track down these issues and make sure I'm not mocking methods that don't exist.

The quick screencast (about 4 minutes) gives an example of locating the issue when a "Ticket" class is refactored. While the tests still pass, it can cause issues in testing and can be difficult to find. Mockery comes with a configuration option (in 1.0 alpha) to disable the mocking of methods that don't exist on the original object. He shows how to disable this feature and what the resulting error looks like when the tests are run.

tagged: mockery screencast unittest mock sync class disable configuration

Link: https://adamwathan.me/2017/04/03/detecting-out-of-sync-mocks-in-mockery/

BugSnag:
Building maintainable PHP apps using Composer
Apr 03, 2017 @ 12:14:02

The BugSnag blog has a post by guest author Graham Campbell sharing some best practices when using Composer in your PHP applications. It's written mainly for those that haven't used Composer much yet and want to get started quickly and easily.

Composer has made big waves in the PHP community in recent years. Thanks to Composer’s creators, Jordi Boggiano and Nils Adermann, Composer has become the absolute backbone of PHP’s package infrastructure today.

In this blog post, we shall be introducing Composer, from the ground up. We will see what packages are, how they should be versioned, and how to install them into your application. Learn about Composer and never look back!

He starts out by defining what a package is in the world of Composer and how it differs from a "library". He then briefly touches on the early days of the tool before showing how to get it installed and creating your first "composer.json" configuration file. He then gets into one of the more tricky subjects when dealing with Composer and packages - versioning. Finally he covers a few of his suggested best practices when using Composer including defining your own package installation constraints and how the autoloading works to your benefit.

tagged: composer bestpractices introduction configuration package library tool

Link: https://blog.bugsnag.com/best-practices-using-composer/

Rob Allen:
Using CircleCI for a PHP project
Apr 03, 2017 @ 09:56:20

In a post to his site Rob Allen shares a basic setup for using Circle CI with a PHP project for continuous integration. Circle CI provides the resources to build your project and perform tasks such as run unit tests or even deploy the resulting code to the production environment.

For a new client project, I've decided to use CircleCI to run my tests every time I push to GitHub. This turned out to be quite easy; this is how I did it.

He shares the contents of his .circleci/config.yml configuration file creating a Docker environment each time the build is executed, installing the required software, executing Composer install and running PHPCS and PHPUnit tests. He shares an example of the output from a build and how he hooked in Slack to receive notifications when the builds were complete (and pass/fail status).

tagged: circleci service continuous integration project tutorial configuration docker

Link: https://akrabat.com/using-circleci-for-a-php-project/

Stefan Koopmanschap:
Sculpin and Docker
Mar 22, 2017 @ 12:49:05

Stefan Koopmanschap has written up a tutorial on his site introducing the use of Docker and Sculpin to create an easily reproducible and manageable blogging setup.

I've been running this blog on Sculpin for quite a while now, and I'm quite happy with how that works. We've been in a process of migrating some of our websites off a standard VPS towards a setup with Docker, Gitlab CI and Rancher. I've now migrated some websites, which is relatively easy, but most of those sites were dynamic PHP websites. Migrating a site that generates static HTML and running that is a slightly different thing. Here's how I ended up doing it.

First he covers his old setup - essentially the manual run of a shell command to generate the latest version of a the static Sculpin site. He decided to update the process and help makes things more automatic using Docker and a Gitlab pipeline flow. He then documents his attempts and configuration options as he built up the Docker configuration he wanted. This ultimately resulted in a Docker setup that installed PHP and Nginx to serve up the site, Composer to load in the required dependencies (like Sculpin) and the commands to "deploy" the latest version of the site publicly.

tagged: sculpin docker setup configuration tutorial dockerfile php7

Link: https://leftontheweb.com/blog/2017/03/18/sculpin-and-docker/

Nikola Posa:
Keep PhpStorm metadata away from project sources
Mar 15, 2017 @ 11:54:57

In a new post to his site Nikola Posa shows the PHPStorm users out there how to keep metadata about your projects away from the source (the content in the ./idea directory it creates by default).

I fell in love with PhpStorm only few months ago ago when I switched from NetBeans, my favorite IDE by then. One thing that I was missing from the very start is the ability to separate project metadata (.idea/ directory) from sources, because I like to keep away everything that is unnecessary from my project directory, as well as from the .gitignore file. It turned out that something like that is possible, but in contrast to NetBeans it's not so evident and requires a little more effort

It's a pretty simple four step process and he shows what settings to change:

  • Create new project in a directory where you would usually keep metadata
  • Open Settings / Preferences dialog and click on Directories node
  • Click Add Content Root button and select project sources directory
  • Remove content root that keeps project metadata

Screenshots are also included for each step to help make sure you're in the right place at all times.

tagged: phpstorm metadata project source setting configuration

Link: http://blog.nikolaposa.in.rs/2017/03/09/phpstorm-metadata-away-from-project-sources/