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

Securing client-side public API access with OAuth 2 and Symfony
Jul 18, 2016 @ 12:30:26

On the Codevate.com blog there's a tutorial posted by Chris Lush showing you how to secure your client-side public API with OAuth 2 (based on the Symfony platform).

Say you’ll be developing a web application for a customer to create and manage restaurant bookings, exposing restaurant information (name, opening times, menu contents etc.) and booking creation as RESTful API endpoints, which are consumed by secure admin backend. You’ll need to authorise access to the API, but there is no end-user involved since the web app is its own resource owner, so the previous flow doesn’t apply.

[...] However, you also need to develop a booking widget that will be embedded in a company or restaurant’s website for visitors to use. In this case, the client-side is no longer trusted enough to share the OAuth client secret that’s required to authenticate with your API. [...] We encountered a similar use-case for a client project recently, and this blog post details the steps taken to address it.

He then shows how to integrate the FOSOAuthServerBundle bundle into your current Symfony-based application and the updates you'll need to make to your security.yml file. He includes the code needed to create a "client" and associating it with a company already in the customer list. Next is the creation of access tokens and linking them to the restaurants in their system (a unique identifier to use externally for the restaurant rather than an ID). He shows an example of handling the token requests and the code/config changes needed to set it up. Finally he talks about scoping API requests down to certain functionality and an example cURL call to the API to show the results of it all combined.

tagged: clientside api access security oauth2 symfony tutorial bundle

Link: https://www.codevate.com/blog/12-securing-client-side-public-api-access-with-oauth-2-and-symfony

Stefan Koopmanschap:
Command or Controller
Jun 20, 2016 @ 12:04:18

In a post to his site Stefan Koopmanschap takes a look at the technical term "command" and tries to clear up some of the confusion around its use and how it differs from the idea of a "controller".

A couple of weeks ago while walking towards lunch with Jelrik we were having a bit of a discussion about the use of the term Command. Not long before that, Jelrik had asked a question about naming of Commands in our Slack channel, which led to some confusion.

He starts off by defining what a command is and why it's called a "command" instead of a controller (hint: it "just works" with the Symfony Console). He then gives an example of a command in a Symfony bundle structure and how a CLI "controller" can extend the Command and automatically be integrated into the command structure.

tagged: command controller clarification example difference symfony bundle

Link: http://leftontheweb.com/blog/2016/06/18/Command-or-Controller/

Symfony Finland:
GraphQL with PHP and the Symfony Framework
May 16, 2016 @ 12:19:09

The Symfony Finland site has a recent post giving an overview of GraphQL and Symfony, combing the GraphQL query language (RESTish handling) from Facebook with your application.

The origins of GraphQL stem from the needs that Facebook's mobile applications had (and continue to have). They needed a data-fetching API that was flexible enough to describe all the different kinds of data that the social network had available. [...] Back in September 2015 GraphQL was already powering Billions of API calls a day at Facebook. [...] The core idea of GraphQL is to send a simple string to the server. This string is then interpreted by the server and it sends back a JSON payload that responds to follows the structure of the query itself.

The post includes an example of what the request and response from a GraphQL query might look like for a social network's data. They also link to several PHP libraries that have come up around the functionality making it easier to integrate. There's also links to some Symfony bundles that provide functionality to make your own GraphQL servers.

tagged: graphql symfony bundle introduction facebook rest query json library

Link: https://www.symfony.fi/entry/graphql-with-php-and-the-symfony-framework

Loïc Faugeron:
The Ultimate Developer Guide to Symfony - Skeleton
Mar 17, 2016 @ 10:24:39

Loïc Faugeron has posted another in his series of "Ultimate Developer Guides" for a component of the Symfony framework. In the latest part of the series, he looks at the Skeleton component.

In this guide we've explored the main standalone libraries (also known as "Components") provided by Symfony to help us build applications: HTTP Kernel and HTTP Foundation, Event Dispatcher, Routing and YAML, Dependency Injection and Console. We've also seen how HttpKernel enabled reusable code with Bundles.

In this article, we're going to have a closer look at how to organise our applications directory tree.

He shows how to create a new project with the "empty edition", a skeleton for creating a basic Symfony framework with some of the basic boilerplate already in place. He shows the resulting directory tree and creates a new AppBundle for his new development. Initially he put the bundle under the main directory so he then shows how to decouple this and move bundles and libraries out into a src/ directory outside of the main application directory in the skeleton.

tagged: symfony ultimate developer guide tutorial skeleton edition empty bundle library decouple

Link: https://gnugat.github.io/2016/03/16/ultimate-symfony-skeleton.html

Loïc Faugeron:
The Ultimate Developer Guide to Symfony - Bundle
Mar 09, 2016 @ 10:53:40

Loïc Faugeron is back again with another of his "Ultimate Developer Guide" tutorials in his series. In his latest he looks at the Bundle component and the functionality it introduces as it relates to some of the components already discussed (like HttpKernel).

In this guide we've explored the main standalone libraries (also known as "Components") provided by Symfony to help us build applications: HTTP Kernel and HTTP Foundation, Event Dispatcher, Routing and YAML, Dependency Injection and Console. In this article, we're going to have a closer look at how HttpKernel enables reusable code.

He starts by comparing the HttpKernel and Kernel components, laying them out so that their use makes sense later. From there he then gets into the actual Bundle component. He introduces the component, provides a code example showing its interface and talks about situations where bundles could be useful. To help make it a bit more "real world" he then shows how to create a "NanoFrameworkBundle" complete with Extension, Compiler, configuration and bundle definition examples.

tagged: ultimate developer guide symfony component bundle tutorial

Link: https://gnugat.github.io/2016/03/09/ultimate-symfony-bundle.html

Marc Morera:
You Probably Need Bundle Dependencies
Feb 10, 2016 @ 09:04:18

In this post to his site Marc Morera responds to some comments from another post about bundles dependencies in Symfony-based applications.

This post tries to answer the Magnus Nordlander’s blog post, and to explain why the Symfony Bundle Dependencies is not just a personal project to fulfill my bundles dependencies, but a practice we should implement in all our Symfony bundles as well.

Believe me, I had a big post to explain why people really need this bundle, but I think that you don’t need these words, but a simple and real example.

He points out a more "real world" example of why this kind of dependency system can be useful in Symfony development. He points out a common service (security.encoder_factory) that's used widely across many bundles, but also defined as a dependency in each. If the bundle dependency structure/tool was in wide use, this dependency would be define elsewhere and not as a part of the bundle itself.

tagged: bundle dependencies symfony security factory example

Link: http://mmoreram.com/blog/2016/02/09/you-probably-need-bundle-dependencies/

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/