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

Maintain Slim PHP MVC Frameworks with a Layered Structure
Apr 07, 2017 @ 11:17:53

The Toptal.com blog has a tutorial posted by Elvira Sheina showing you how to keep a framework project "slim" and manageable in a MVC pattern using a "layered" structure. This structure adds a few extra components to the traditional MVC design to keep functionality cleaner and easier to maintain.

Fat controllers and models: an inevitable problem for most large-scale projects based on MVC frameworks such as Yii and Laravel. The primary thing that fattens controllers and models is the Active Record, a powerful and essential component of such frameworks.

She starts by talking about one of the main issues in MVC applications - "fat" controllers. In this example the controllers contain the bulk of the logic for the application making it difficult to modify and potentially reuse in other places. This is particularly bad when the Active Record pattern is used and the problem of it violating the SRP (Single Responsibility Principle of SOLID development). Instead she promotes the idea of the "layered" design using controllers, a service layer, DTOs, view decorators and a repository layer. She then shows how to implement this kind of structure and tie each of the pieces together with code examples for each piece.

tagged: tutorial mvc framework structure layer dto repository activerecord decorator service

Link: https://www.toptal.com/php/maintain-slim-php-mvc-frameworks-with-a-layered-structure

Master Zend Framework:
How To Use Forked Repositories In Composer
Dec 21, 2016 @ 12:40:09

The Master Zend Framework site has continued their series covering Composer and some more advanced concepts than just the usual introduction. In this new tutorial Matthew Setter shows you how to work with forked repositories.

Have you ever submitted a patch to a repository which your application relies on, but, because that patch is vital to the uptime of your application, you can’t wait for it to be reviewed and merged into the next release?

In times like these, it’s fair to want them to move faster than they normally would, so that you don’t have to wait for the normal review, merge, and release cycles. [...] But, you may urgently need the patch to be applied and released. So, what do you do? In times like these, you can use Composer’s ability to use custom repositories, specifically a fork which you create and patch.

If this sounds appealing to you — because perhaps you’re in this very situation right now — let’s now step through the process of modifying your composer.json configuration so that you can use one.

He walks through the Composer configuration you'll need to update to work with the forked repository as you'd expect. He also covers changes that would need to be made for working with private repositories and using local files instead of remote.

tagged: fork repository composer tutorial series

Link: http://www.masterzendframework.com/series/tooling/composer/forked-repositories/

Paul Jones:
Package Development Standards: "pds/skeleton" Now Open For Review!
Dec 16, 2016 @ 10:54:14

Paul Jones has a post to his site with a proposal for a standard structure for PHP packages to help provide consistency across the PHP package ecosystem. His proposal - the Package Development Standards initiative - defines the structure of the repository instead of conventions to be used in the package itself (like naming or object structure).

The new pds/skeleton (and the related research) for public review. If you are a package author, you are invited to post your comments and criticisms of the publication as issues on the relevant Github repository.

The pds/skeleton publication describes a set of standard top-level PHP package directories and files. If you are an author of more than three packages on Packagist, chances are you already follow the standard! That’s because PDS initiative researches the PHP package ecosystem to recognize commonly adopted development practices.

He's putting it out there for public review for now until he can get some feedback from the community on the structure and recommendations made. He also recommends going a head and adding "pds/skeleton" to your "require-dev" section to indicate your compliance to the suggestions he's presented.

tagged: package structure repository standard definition opinion composer

Link: http://paul-m-jones.com/archives/6457

Raphael Stolt:
Anatomy of a dope PHP package repository
Sep 22, 2016 @ 09:30:25

In this recent post to his site Raphael Stolt shares an example of what he thinks is a "dope" setup for a Composer package (a well-structured, consistent and fully populated package structure).

While contributing to Construct, maintained by Jonathan Torres, I gathered some insights and learnings on the characteristics of a dope PHP package repository. This post summarises and illustrates these, so that PHP package developers have a complementary guideline to improve existing or imminent package repositories. Jonathan Reinink did a good job in putting the PHP package checklist out there which provides an incomplete, but solid quality checklist for open-source PHP packages.

I'll distill the characteristics of a dope PHP package repository by looking at the repository artifacts Construct can generate for you when starting the development of a new PHP project or micro-package.

Included in his list of things every PHP package should include are things like:

  • the source (naturally), matching tests/specs and documentation
  • consistent naming
  • versioning information (via a CHANGELOG)
  • Travis-CI integration
  • A . gitattributes file for excluding certain files from export

He also makes a few more general suggestions like avoiding the posting of "badges" in the README and some reasons why you should care about the "dopeness" of your repository at all.

tagged: package wellstructured requirements opinion repository

Link: http://raphaelstolt.blogspot.com/2016/09/anatomy-of-dope-php-package-repository.html

Zend Framework Blog:
Announcement: ZF repository renamed!
May 05, 2016 @ 09:57:16

The Zend Framework blog has a post announcing the name change of the main Zend Framework repository on GitHub:

Per the GitHub documentation on renames, existing links will be automatically redirected, and will persist as long as we do not create a new repository with the name "zf2". Redirects occur for: issues, wikis, stars, followers and git operations.

The post also includes the instructions on how to update your current "remotes" in your git checkout (so you don't have to re-clone). It also mentions the change and how it relates to Composer - hint: nothing at all because of how Composer works.

tagged: zendframework2 repository rename zendframework announcement github

Link: http://framework.zend.com/blog/2016-05-03-zf-repo-rename.html

Zend Framework Blog:
Announcement: ZF repository rename 2016-05-03
Apr 28, 2016 @ 13:08:27

An announcement has been made on the Zend Framework blog today about a massive repository rename that will be happening May 3rd, 2016 to move away from the "zf2" naming.

In contrast to Zend Framework 2, which was a complete rewrite and break with the architecture of Zend Framework 1, the Zend Framework 3 initiative is more of an evolutionary change. [...] Another way of putting it: changes to the main repository are happening incrementally, and version 3 will just be a new major version update within the existing repository. However, such evolutionary change poses a slight logistical problem: the repository is currently named "zf2".

In order to make the change to Zend Framework 3 (and beyond) simpler, the repository will be renamed to "zendframework" instead. In the current configurations this namespace already exists and points to the correct locations so, ideally, no changes will need to be made on the Composer installations of current users - just updates to git remote entries to point to the new locations.

tagged: zendframework zendframework2 zendframework3 repository rename

Link: http://framework.zend.com/blog/2016-04-27-zf2-repo-rename.html

Matthew Weier O'Phinney:
Benefits of multiple repositories (Zend Framework)
Apr 26, 2016 @ 12:09:34

Matthew Weier O'Phinney, of Zend and the Zend Framework project, has put together a Storify stream of tweets he posted about some of the benefits of having multiple repositories in a project.

I've seen a number of critiques and write-ups recently about how monolithic repositories are intrinsically better for developing large projects than using a multi-repository approach. In the past year, we went the other direction, splitting our monolithic repository into individual component repositories, each with their own history, tests, and documentation. This is a summary of our experience.

He goes through a list of six different things they learned as a part of splitting up the (Zend) framework into multiple repositories instead of one monolithic one. He includes the contents of each Tweet and a paragraph or two giving it a bit more context and some examples of the changes that were involved. There's also a bit in there about changes they made to the documentation for the project as a result of these repository splits.

I'm quite happy with the switch from a monolithic repository to individual component repositories. I think our code quality is improving dramatically as a result, and I'm excited about the future of these various code bases.
tagged: multiple repository storify twitter zendframework learn process

Link: https://storify.com/mwop/zf-components

Leonid Mamchenkov:
Adventure in composer private repositories
Apr 22, 2016 @ 09:19:44

In this new post to his site Leonid Mamchenkov talks about some of his "adventure with Composer private repositories" in some of his deployment work with CakePHP 3 applications.

As good as the Packagist is, there is often a need for a repository or a package elsewhere. Whether it’s a commercial library, or sensitive corporate code, having an ability to store it outside of public eye and handle with the same ease and the same tool as the rest of the dependencies is a very welcome feature.

[...] We are setting up similar development and deployment process, but now for CakePHP-based projects. Things are much easier, since CakePHP 3 natively supports composer for the application itself and for its plugins. But we still have the need for private repositories here and there, so we follow the same setup as we did for WordPress.

Unfortunately he was getting a RuntimeException when he was trying to pull in a plugin through the same private repository workflow. Not only had he not seen the error before but the autoloader was configured as defined and other plugins were working with the same structure. As it turns out, it was the composer.json of the main application repository that was the problem. He includes the fix he made to the configuration on a sample CakePHP 3 project, showing how to switch it to a "vcs" type for more correct handling.

tagged: composer private repository issue runtime exception composerjson configuration

Link: http://mamchenkov.net/wordpress/2016/04/21/adventure-in-composer-private-repositories/

Zend Framework Blog:
Issues, Tags, and Closures (oh my)
Apr 14, 2016 @ 10:37:52

On the Zend Framework blog there's an update from Gary Hockin about some GitHub project-level changes that will be happening soon. He'll be doing some housekeeping on the current list of open issues in the main zf2 repository.

I want to make you aware of some upcoming changes to the issues that are currently logged in GitHub. We currently have 426 open issues that are logged against the (now) meta zf2 repository. The vast majority of these are now in the wrong place, as we've split our once monolithic single repository into the many single component repositories. These issues should be moved from the zf2 repository to the correct component that the issue relates to.

He's closed some issues in preparation and tagged others with a "To Be Closed" tag for later handling. By early May all issues tagged "To Be Closed" will be finished out and/or moved to the correct locations. This will leave the project with around 100 issues to manage and to move to the right locations.

tagged: zendframework2 github repository issues closing tagged

Link: http://framework.zend.com/blog/2016-04-11-issue-closures.html

The Repository Pattern in Laravel 5
Mar 15, 2016 @ 12:50:05

The TutsPlus.com site has posted a tutorial covering the use of the repository design pattern in Laravel, a popular PHP framework. While the article does introduce some of the basics of the design pattern, a bit more research may be in order if you're not familiar with its base concepts.

The repository pattern was introduced for the first time by Eric Evans in his Domain-Driven Design book. The repository is, in fact, the entry point for the application to access the domain layer.

To put it simply, the repository allows all your code to use objects without having to know how the objects are persisted. The repository contains all the knowledge of persistence, including mapping from tables to objects. This provides a more object-oriented view of the persistence layer and makes the mapping code more encapsulated.

In this article they replace the default storage/persistence method for database records away from the default Eloquent over to Doctrine, a widely used ORM tool. The start with a brief comparison between Eloquent and Doctrine before starting on on a simple "blog" application. They connect Doctrine to Laravel via an "entity manager" and make a basic Doctrine-based model for the Posts and a matching repository/controller implementation. All the code you'll need to implement it is included along with a simple view to take in the post content and display errors if there were any on the save.

tagged: repository designpattern laravel tutorial doctrine eloquent blog

Link: http://code.tutsplus.com/tutorials/the-repository-pattern-in-laravel-5--cms-25464