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

Marc Morera:
Your Packages Dependencies
Dec 04, 2015 @ 10:36:58

In a recent post to his site Marc Morera discusses the topic of package dependencies in PHP applications. While a lot of the concepts and terms he use are more related to Symfony-based applications, the concepts are good and could apply anywhere.

I’m part of this group of people that consider themselves addicts to open source. [...] want to expose my personal experiences about what I learned over the time by leading an open source project, several small open source bundles and PHP libraries, and I want to do it by explaining how we should take care of our Symfony bundles or PHP component dependencies.

He starts by pointing out that he's talking about framework-agnostic packages and their dependencies here (but his own experience is, again, Symfony-centric). He talks about identifying true dependencies through both use statements and composer.json configurations. He points out that the tricky part comes when your dependencies have dependencies and conflicts that may come up because of these relationships. He also talks about another way to identify dependencies (through adapter use) and package versioning problems. He then gets into talking about Symfony bundle dependencies specifically and links to a tool that can help you map out your required packages. He ends the post with a look at development dependencies and the idea of "trust" in the open source software you use.

tagged: package dependencies version use composer adapter symfony bundle trust

Link: http://mmoreram.com/blog/2015/11/20/your-packages-dependencies/

Getting Started with Building APIs in Symfony2
Nov 09, 2015 @ 13:44:28

The IntelligentBee.com site has a "quickstart" kind of tutorial for those wanting to use Symfony 2 to build an API-based application. In this tutorial they walk you through a few step process to create the application and a few actions to get the basics working.

Hello all you Interwebs friends! While we’re passing through the shallow mists of time, REST is becoming more and more of a universal standard when building web applications. That said, here’s a very brief tutorial on how to get started with building APIs in Symfony2.

They make use of two other libraries, the FoSUserBundle, JMSSerializerBundle and Doctrine, to handle some of the low level user management and database functionality. They show you how to:

  • Generate a new bundle
  • Set up API versioning
  • Install the FoSUserBundle and JMSSerializerBundle
  • Configure the application's REST interface
  • Set up the routing to get things to the right place

Code is also included to show the creation of "get user" and "get users" actions along with a simple form and "add user" endpoints to allow new users to register. Wrapping the post up, he includes the code for the other pieces of the CRUD operations, the "edit user" and "delete user" methods.

tagged: api symfony2 tutorial introduction rest user management bundle versioning

Link: http://intelligentbee.com/blog/2015/11/03/getting-started-with-building-apis-in-symfony2/

Hart KT:
Custom Events in Symfony2 Bundle
Oct 12, 2015 @ 11:10:58

Hari KT has a quick tutorial posted to his site showing you how to use custom events in Symfony bundles from start to finish.

In this tutorial we will create a custom event for symfony2 bundle. Assuming you have downloaded the symfony-standard distribution to play.

He starts by creating a simple bundle (HktEventBundle) and building out the matching event class, extending the base Symfony EventDispatcherEvent. He then shows how to dispatch a simple event from a controller, triggering a html.event.page_viewed event when the request is made to this default controller. He matches this with a listener that subscribes to the event (including a handler method) and the changes you'll need to make to your configuration to wire them all together.

tagged: symfony2 bundle custom event simple tutorial introduction

Link: http://harikt.com/blog/2015/10/11/custom-events-in-symfony2-bundle/

SitePoint PHP Blog:
Can PuliPHP Re-Revolutionize PHP Package Development?
Oct 08, 2015 @ 11:17:56

In this recent post to the SitePoint PHP blog Nicola Pietroluongo looks at a newer tool in the PHP ecosystem that builds on to of the already widely popular Composer to expand packages outside of just the PHP code - Puli.

Puli is a new toolkit built on top of [Composer](https://getcomposer.org) that helps to manage and exchange resources like configuration files, images, CSS files, translation catalogs, and others. These are, you’ll agree, often difficult to maintain and share across projects.

The article starts with a brief overview of how it works and where it connects in with Composer, pulling in other dependencies as defined in a puli.json file. It then walks you through the creation of a simple package - installing the Puli CLI tool, building out the project file/folder structure and mapping resources/assets into the bundle. Finally they show how to install a demo package they've created, how the project maps in to the application and the pieces that make it up. The post ends with a look at the "resource discovery" feature Puli also includes making it easier to pull in configuration options without having to manually define them.

tagged: puli package development tutorial bundle asset dependency

Link: http://www.sitepoint.com/can-puliphp-re-revolutionize-php-package-development/

Sylius Blog:
Sending configurable e-mails in Symfony
Oct 05, 2015 @ 11:15:46

In a post to the Sylius blog Mateusz Zalewski shows you how to create configurable emails in your Symfony-based application with help from a custom bundle they've released to help make it a much simpler process.

Every developer, during their adventure with PHP programming has been struggling with sending emails in a web application. However using PHP send() function is often insufficient for common web applications, when you need templates, variables, configurations etc.Fortunately, Sylius provides SyliusMailerBundle and Mailer component, with some awesome features. [...] Of course, this bundle and component are fully decoupled and can be used in any Symfony application.

They walk you through the installation (via Composer) and configuration of the bundle, adding it's dependencies to the kernel of your application. He shows how to configure the container with connection information (like the name and from values) and update your database with the tool's migrations. From there he shows how to customize your emails, making use of the Twig template handling to define the body contents. The bundle also makes it possible to define custom email types with different settings for each. Finally they show how to send the emails, grabbing the sender information and sending the email, either more manually or via a custom defined email type.

tagged: symfony email configurable tutorial bundle customize template sender

Link: http://sylius.org/blog/sending-configurable-e-mails-in-symfony

KnP University:
Introducing Guard: Symfony Security with a Smile
Jul 14, 2015 @ 09:15:05

The KNP University site has a post that talks about a new library they've created (and matching tutorial series) about an easier method to handle authentication in your Symfony applications: Guard.

Symfony’s authorization system - the stuff related to voters and roles - is awesome. It’s simple, it kicks butt, and it’s one of my favorite things, just behind fresh-baked cookies.

But then there’s that other part: authentication. This is how you login: maybe with a form or via OAuth, like Facebook login. This part is probably the single worst part of Symfony. It’s over-engineered, hard to customize and no fun to work with. [...] This problem was screaming for a solution. If we could make Symfony’s authentication system simple and fun, the whole security system would go from a pain, to a powerful tool.

The library they've created, Guard centralizes the authentication handling into one place (via an interface) and makes the basics of authentication handling simpler. In their tutorial they walk you through the use of Guard as a part of a bundle complete with examples of login form and API token authentication handling. He ends the post with a quick comment about a "secret goal" he has to try to have Guard included in symfony itself.

tagged: guard symfony authentication library bundle tutorial simple

Link: http://knpuniversity.com/blog/guard-authentication

Symfony Finland Blog:
PHP and Symfony: Structure, Stability and Flexibility
Jul 03, 2015 @ 09:12:45

On the Symfony Finland blog they've posted a look at Symfony's past, present and future in terms of its structure and goals of stability and flexibility. This also includes some of the origins of PHP itself and how it evolved to the stage where creating framework made sense.

I like to think of modern PHP frameworks as glue to put together components to form something that is more than the sum of it's parts. [...] The Symfony Framework is a standard way (and framework code) to create applications using components. The application is always built with a specific structure, which allows code reuse of complete functionalities (Bundles in Symfony lingo) across projects. If you build using a collection of components, you'll need to invest time in learning how that software has decided to use the available components.

He talks more about the idea of components and how they make up a greater whole (like Symfony) and how they relate to the idea of "bundles". He then looks forward to the future of the framework, its long-term support and its work towards being fully PHP7 compatible.

The combination of the PHP language at 20 years and the Symfony framework at 10 years offers a stable platform with flexibility to adapt and grow in the future.
tagged: symfony framework past present future component bundle stability structure flexibility

Link: https://www.symfony.fi/entry/php-and-symfony-structure-stability-and-flexibility

Marc Morera:
Visithor, Testing Your Routes Without Pain
May 05, 2015 @ 09:25:55

In his latest post Marc Morera shares a new tool he's created to help with testing routes for specific HTTP code responses and other attributes of your "HTTP layer" - Visithor.

Many years ago I was thinking about a simple and fast tool to test specific routes, expecting specific HTTP codes and providing an easy environment of ensuring properly your HTTP layer. So... I present you Visithor, a PHP based library that provides you this functionality, with a simple configuration definition and a very easy way of installation.

He starts with a few quick commands to get the library installed (either globally or local to the project) and how to create the first configuration file. This file defines the tests to execute as a set of URLs with allowed HTTP response codes. He also shares a Symfony2 bundle that can be used to integrate it with your current application, allowing for more flexibility in route check configuration and environment settings. He also includes a quick example of integrating it with your Travis-CI build as a "script" command to be executed.

tagged: visithor library testing http response code symfony2 bundle integration

Link: http://mmoreram.com/blog/2015/05/04/visithor/

Programming Are Hard:
Structuring my applications, Cont'd
Mar 09, 2015 @ 12:03:16

The Programming Are Hard site continues its look at structuring Symfony-based applications in part two (it's just two parts) building on the structure and foundation laid out in part one.

It really irks me when I see some design/architecture decisions other developers have made but there's no technical explanation. What packages did they use? What challenges did they face? What trade-offs were made? I'll go over some more specifics in this post.

He recaps some of the things covered in the previous post first, ensuring everyone is on the same page. He then gets into the concept of "bundles" and how they encapsulate functionality. From there he talks about commands, controllers, dependency injection and lots of other topics, each with their own summary and a bit of code where needed for clarification.

tagged: structuring application symfony bundle command controller di form provider repository resource serialize

Link: http://programmingarehard.com/2015/03/05/structing-my-application-contd.html

SitePoint PHP Blog:
Grumpy Programmer’s Testing Bundle: Review
Feb 09, 2015 @ 13:18:22

The SitePoint PHP blog has posted a book review of a book bundle from the "Grumpy Programmer" (aka Chris Hartjes) with content about testing - how to test, what to test and creating testable applications.

After having gotten some constructive feedback regarding my testing practices on the basic TDD in your new PHP package tutorial, I decided to read Chris Hartjes “Grumpy Testing Bundle”, a set of two books consisting of The Grumpy Programmer’s Guide To Building Testable PHP Applications and The Grumpy Programmer’s PHPUnit Cookbook. It was my hope that those books will prevent me from using the shoddy practices I displayed in that original post and which originally prompted Matthew Weier O’Phinney’s critique. In this post, I’d like to share with you what I’ve learned, and how much this helped me, if at all.

He breaks down the bundle and talks about each of the two books separately, pointing out places he thought were most useful and others where he felt it needed updates/more clarification. He includes examples of some of the code shared in the books as illustrations and what kind of overall rating he gives it (in elePHPants naturally).

tagged: book review grumpyprogrammer chrishartjes review bundle

Link: http://www.sitepoint.com/grumpy-programmers-testing-bundle-review/