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

Barry van Veen:
Package development: run a package from a local directory
Jan 31, 2018 @ 09:22:03

Barry van Veen has a quick post on his site showing the Composer users out there how they can use a package from a local directory without having to go through the hassle of pushing it and adding it to Packagist.

Suppose you run a website and want to split part of it into a package with its own repository. You start a new repository and check it out on your development machine. But now you want to see how the website and your new package integrate. How to go about this?

This article explains how you can require a package from a local path into your project with Composer. This way you can run a local copy of a repository and test any changes you make. Because the local repo will be symlinked changes are shared in real-time, there is no need for intermediate committing and updating.

He shows how to update your composer.json configuration's repositories section to add an entry with a "type" value of "path". This then points to the location on the filesystem where the package resides. Then it's just a matter of requiring the dev-develop branch and the code will be treated just like any other package. He also includes a section showing how to handle things when symlinking fails, a problem that usually happens on Windows for VM users. Usually it's related to a permissions error for whatever user is running the VM.

tagged: package local path composer configuration symlink repository devdevelop

Link: https://barryvanveen.nl/blog/44-package-development-run-a-package-from-a-local-directory

Sarfraz Ahmed:
Laravel: Automatic Vendor Cleanup Command
Jan 25, 2018 @ 09:42:47

In a post to his site Sarfraz Ahmed shares a command that can be used in a Laravel application (via artisan) to clean up unnecessary files from packages that you may have installed.

When installing composer packages, they come up with lot of useless files and folders such as .git, tests, readme.md and more. When project becomes bigger with many packages, this junk takes considerable disk space. Since I work with Laravel framework most of the time, I created a command that allows me to automatically delete all these junk files whenever I happen to install or update composer packages.

He lists out the patterns the command matches by default including "tests", "readme*" and "*.log". There's a long list of items and, having worked with several packages, I can tell you that most of the files caught by this need to be removed anyway. He has posted the code on GitHub and provides some examples of the command line calls and how it can be called automatically.

Another package that does something similar but allows the package itself to define the files to remove is the composerclean library that is executed as a Composer command rather than an artisan command.

tagged: composer laravel automatic clean method artisan

Link: http://codeinphp.github.io/post/laravel-automatic-vendor-cleanup-command/

Keith Mifsud:
PHP Software Development Workflow
Jan 22, 2018 @ 12:30:02

In a post to his site Keith Mifsud shares his recommendations around a good workflow for developing PHP applications. Composer and GitHub play a part in the process as does the use of Git and your IDE of choice.

Continuing from the previous post Developing a Command Bus in PHP, we will look into how to get started in setting up our composer library project. Although my PHP software development workflow does vary slightly from project to project, most steps are more or less the same. Whether your project is the result of a successful proposal or you want to build an open source composer package like we’re doing here, this post will guide you in working with PHP the right way. If you are learning PHP from scratch and find that I am missing some intermediary steps or making assumptions, please feel welcome to comment below and I’ll be more than happy to explain in more detail.

He then walks through the steps in the process, each with explanation (and screenshots where appropriate):

  • Getting organized and planning the application features
  • Creating the GitHub repository and setting up the Kanban board
  • Defining a release milestone
  • Setting up a local Homestead instance for development
  • Setting up Git and your IDE

The final step is to create the composer.json configuration file that defines the basic information about the project, any dependencies and the autoloading paths.

tagged: software development workflow example process composer

Link: https://keith-mifsud.me/php-software-development-workflow

Joe Ferguson:
How to move a dependency to Composer while requiring an old version
Jan 17, 2018 @ 09:54:24

In a new post to his site Joe Ferguson shows you how to move a dependency over to Composer but still require the older version, possibly one that's already included in the codebase as a checked-in source.

A common problem I run into with older applications are dependencies that have been added and loaded from the application’s repository. You would often see a “libraries” folder with a “className.php” type file. If you’re lucky you’ll have the entire folder of the dependency including the release notes to be able to find out exactly what version you’re using.

[...] What if the author hasn’t tagged our older version? Maybe they converted the repository to git from subversion or some other system? You have to go digging into the commit history to find the commit you want to match your current version.

He includes the Composer configuration required for both examples (loading the older version and loading by commit ID) as well as the addition of the "minimum-stability" option. This option allows you to pull directly from the "master" branch if you need to - just be sure to define exact versions of other dependencies otherwise you'll get dev versions of them too.

tagged: composer dependency version old tutorial commit master

Link: https://www.joeferguson.me/how-to-move-a-dependency-to-composer-while-requiring-an-old-version/

Martin Hujer:
Have you tried Composer Scripts? You may not need Phing.
Jan 15, 2018 @ 11:14:13

In a new post to his site Martin Hujer shows you that, with the help of the "script" ability in Composer, you may not need a build tool like Phing. The scripts functionality allows you to execute custom scripts as a part of the Composer workflow, enhancing the management functionality it already provides.

Phing is a great tool (I'm using it as well), but in this article, I want to show you that some projects may not need it. Composer contains a powerful feature called "Scripts", which can be used to create a simple build script.

In his example, he shows how to integrate a run of the PHP_CodeSniffer quality assurance tool as a part of your Composer configuration. This makes it possible to run a command like composer run-script phpcs and automatically run the checks. He then builds on this simple example and creates a more complex build script that still runs PHP_CodeSniffer but also executes PHPUnit tests. He post also shows how to run Composer in a command and how to document each command. There are also a few handy tips included around running Composer on Windows, listing the current scripts and executing custom callbacks to code.

tagged: composer build scripts tutorial example phing phpcodesniffer phpunit

Link: https://blog.martinhujer.cz/have-you-tried-composer-scripts/

Martin Hujer:
17 Tips for Using Composer Efficiently
Jan 05, 2018 @ 09:25:31

Martin Hujer has written up a guide for the Composer users out there (you do use Composer, right?) sharing seventeen tips for using it effectively to manage the dependencies in your applications.

Although most PHP developers know how to use Composer, not all of them are using it efficiently or in a best possible way. So I decided to summarize things which are important for my everyday workflow.

The philosophy of most of the tips is "Play it safe", which means that if there are more ways how to handle something, I would use the approach which is least error-prone.

His tips include:

  • Be aware of differences between a "project" and a "library"
  • Use version ranges for libraries dependencies
  • Run Travis CI builds with different versions of dependencies
  • Do not attempt to merge composer.lock when rebasing or merging
  • Update dependencies safely
  • You can define other types of dependencies in composer.json

Each item in the list comes with a summary and an example of the configuration related to the tip. Most of them are small tweaks to the configuration you're probably already using but there are definitely some nice "hidden gems" in there.

tagged: composer tips effective top17 configuration dependency

Link: https://blog.martinhujer.cz/17-tips-for-using-composer-efficiently/

Fabien Potencier:
Symfony 4: Unpack the Packs
Jan 04, 2018 @ 11:53:47

Fabien Potencier of the Symfony project has a post on his site that introduces Symfony Packs, groupings of useful packages that can enhance the functionality of your application without having to manually load each package individually.

We get a lot of positive feedback on Symfony 4. You love the new directory structure. You love the simplicity of using services without configuring anything. And you love the automation that Flex provides. It makes me happy and proud.

[...] But one issue I hear sometimes is that it is more complex to start a new project. [...] You loved the simplicity of starting a project with the Symfony Standard Edition. Is it nostalgia? Perhaps. Would it be possible to get the best of both world? Certainly!

The Packs are "metapackages" that Composer uses to bundle dependencies together that relate either in functionality or as defined by a custom configuration. The article gives an example using the symfony/orm-pack pack and talks about how you can use it as-is or you can "unpack" it into its separate packages and automatically update the composer.json with the result.

tagged: symfony symfony4 pack composer metapackage introduction

Link: http://fabien.potencier.org/symfony4-unpack-the-packs.html

Rob Allen:
Using Composer packages with OpenWhisk
Jan 03, 2018 @ 09:41:55

Rob Allen has a post to his site for the OpenWhisk (a serverless cloud platform) users out there that want to use Composer to install dependencies required by your application.

When creating new OpenWhisk actions in PHP, It's likely that you'll want to take advantage of the rich ecosystem of Composer packages on Packagist.org.

The OpenWhisk PHP runtime has you covered with some pre-installed Composer packages and also the ability to upload your own using a zip file.

He starts by mentioning the two packages that come installed by default: Guzzle and the ramsey/uuid library. He then gets into the upload of your own project files as a ZIP file and how to install the package locally, bundle it up into this archive and push it using the wsk command line tool.

tagged: composer package openwhisk serverless architecture packagist guzzle uuid tutorial

Link: https://akrabat.com/using-composer-packages-with-openwhisk/

Tomas Votruba:
Composer Local Packages for Dummies
Dec 28, 2017 @ 10:17:27

In a post to his site Tomas Votruba provides a guide "for dummies" to using local packages along side your remote packages via Composer.

I wrote about pros and cons of local packages before. After year of using this in practice and mentorings I polished this approach to even simpler version that is easy to start with.

[...] There is no need to use Github, love open-source, understand package design or understand composer beyond PSR-4. No symlink issues, no forgotten composer update. Anyone can start using this!

The "dummy" packages he creates are essentially a simulation of a Composer package just in a different location (under a "packages" directory). This can then be autoloaded via the same Composer configuration you already use without too much trouble.

tagged: package dummy composer autoload tutorial

Link: https://www.tomasvotruba.cz/blog/2017/12/25/composer-local-packages-for-dummies/

Knp University:
The Flex composer.json File
Dec 26, 2017 @ 11:51:50

For those looking to make the move up to Symfony 4 and Flex the Knp University site has a new post that sheds some light on the composer.json configuration for Flex and how to use it to install a complete Symfony 4 application.

We need to make our composer.json file look like the one from symfony/skeleton. Actually, go to "Releases", find the latest release, and then click to browse the files. Now we can see the stable composer.json contents.

So... yea, this one file is all you need to start a new project. That's crazy! Flex builds the project structure around it.

The article then talks about the major changes including dropping the symfony/symfony package, how to synchronize the rest of the composer.json and autoloading updates. It ends with a brief mention of how to then scaffold out the full application structure - one command, a Composer update.

tagged: composer symfony4 symfonyflex tutorial update changes

Link: https://knpuniversity.com/screencast/symfony4-upgrade/flex-composer.json