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

Gonzalo Ayuso:
Silex is dead (… or not)
Jul 10, 2017 @ 11:24:58

In a new post to his site Gonzalo Ayuso talks about the Silex project (a Symfony-based microframework) and how it just might be dead.

The last week was deSymfony conference in Castellón (Spain). IMHO deSymfony is the best conference I’ve ever attended. [...] This year I cannot join to the conference. It was a pity. A lot of good friends there. So I only can follow the buzz in Twitter, read the published slides (thanks Raul) and wait for the talk videos in youtube.

In my Twitter timeline especially two tweets get my attention. One tweet was from Julieta Cuadrado and another one from Asier Marqués. [...] Tweets are in Spanish but the translation is clear: Javier Eguiluz (Symfony Core Team member and co-organizer of the conference) said in his talk: “Silex is dead”.

He goes on to talk about how, despite the overly dramatic title, the Silex project isn't really "dead" but does have an uncertain future. He talks some about the next version of Symfony - Symfony 4 - and how, because if the changes since v3, it could essentially replace most of what Silex offers. Unfortunately, this also leads to another problem - Symfony 4 isn't ready and if Silex will be deprecated which should he choose for new projects? After some investigation, he decided that Lumen, a Laravel-based microframework, was just right for his needs.

tagged: silex microframework symfony framework project dead symfony4

Link: https://gonzalo123.com/2017/07/10/silex-is-dead-or-not/

Gonzalo Ayuso:
Playing with Docker, Silex, Python, Node and WebSockets
Jan 03, 2017 @ 09:47:19

Gonzalo Ayuso has a new post to his site sharing some of the results of his work combining Docker, Silex, Python, Node and WebSockets, discovering how to create a complete platform with these tools.

I’m learning Docker. In this post I want to share a little experiment that I have done. I know the code looks like over-engineering but it’s just an excuse to build something with docker and containers. Let me explain it a little bit.

The idea is build a Time clock in the browser. [...] Yes I know. We can do it only with js, css and html but we want to hack a little bit more. The idea is to create: a Silex/PHP frontend, a WebSocket server with socket.io/node [and a] Python script to obtain the current time.

He then starts in on the code, first creating the WebSocket server in Node then the Python script that makes an internal request to get the time and return it. Then the Silex route is created to serve up the template for the page and the code it uses to connect back to the websocket. The post ends with the Docker configuration he used to create the Docker environment all of this lives in.

tagged: docker silex python node websockets tutorial environment

Link: https://gonzalo123.com/2017/01/02/playing-with-docker-silex-python-node-and-websockets/

CloudWays Blog:
Getting Started With Silex Micro-Framework On Cloud Hosting
Sep 19, 2016 @ 11:54:34

On the CloudWays blog they've posted a tutorial that introduces you to the Silex framework, a product from SensioLabs of Symfony fame and using it on a cloud hosting platform (their own).

Extensibility is one of the main aims of web app development projects. However, there are times when you need to get things up and running as soon as possible and with minimum time dedicated to coding. This is where micro-framework s really outshine the competition. There is a long list of these frameworks including Silex, Slim, Lumen, etc. These are ideal for developing small-scale applications with clean code and user defined directory structures.

In this tutorial I am going to explain how to install Silex, its operation, directory structure, Routings and HTTP Requests. Silex is a micro-framework written in Symfony and inspired by Sinatra, a DSL for quickly creating web applications in Ruby with minimal effort.

They start by helping you get the CloudWays instance up and running with their "PHPStack" setup. Once created they show how to get to a command prompt, make the public HTML directory and use Composer to install Silex and Twig (for templating). The tutorial then briefly covers the directory structure for the site and the code to create the Silex application instance. They define some of the basic routing (to work with book data) and show the handling for sending feedback submitted via a simple page. The remainder of the tutorial shows the use of different features of Silex including: providers, middleware, before/after handlers and defining controllers as classes.

tagged: silex introduction tutorial microframework symfony

Link: https://www.cloudways.com/blog/install-silex-on-cloud/

Gonzalo Ayuso:
Sharing authentication between socket.io and a PHP frontend
May 16, 2016 @ 10:56:30

In a post to his site Gonzalo Ayuso shows you how to combine authentication between Socket.io and a PHP frontend running a simple Silex-based application.

Normally, when I work with websockets, my stack is a socket.io server and a Silex frontend. Protect a PHP frontend with one kind of authentication of another is pretty straightforward. But if we want to use websockets, we need to set up another server and if we protect our frontend we need to protect our websocket server too.

If our frontend is node too (express for example), sharing authentication is more easy but at this time we we want to use two different servers (a node server and a PHP server). I’ve written about it too but today we`ll see another solution.

He sets up a simple Silex application with three routes - the root (/), a login route and a "private" one requiring a user to be logged in. This last route makes the connection to the websocket server in the template. This connection sends the current session ID to the backend where it's verified with a simple Socket.io middleware. Sometimes the session ID cookie will be set as HttpOnly so he provides an alternative for that: a new endpoint just for getting the current session ID for the websocket request.

tagged: socketio websocket server frontend sharing authentication session silex tutorial

Link: https://gonzalo123.com/2016/05/16/sharing-authentication-between-socket-io-and-a-php-frontend/

Symfony Finland:
Learn Symfony and modern PHP with Bolt 3.0 - a Silex powered CMS
May 11, 2016 @ 09:36:53

On the Symfony Finland site there's a new article posted about the recently released v3.0 of the Bolt CMS and details about this Silex-powered, modern PHP-based system.

On Tuesday 10th of May the development team released a new major version of Bolt CMS. The Open Source content management system is a lightweight and easy to use tool for managing websites and blogs. In addition it's perfect for learning modern PHP development practises.

The third major version of Bolt continues on the path, being an evolution rather than a revolution. The CMS is built on the Silex microframework based on the Symfony PHP components.

The article talks about the "solid foundation" of Silex and good project management skills of the team behind it. They then get into the installation of the tool and some of the libraries that it uses to get the job done (including Twig and YAML handling). They also list some of the things that are new in the v3.0 of the CMS including:

  • A new extensible Storage layer
  • Backend UI refresh
  • Improved tests / code coverage
  • New documentation
  • Web asset queues, and easier to keep files out of webroot

There's also mention of some of the things that were removed and didn't make the cut to be included in the release. The post ends with links to other resources where you can find out about Bolt, get its source and a few other articles about people putting it to use.

tagged: bold cms silex symfony modern release v3 overview installation

Link: https://www.symfony.fi/entry/learn-symfony-and-modern-php-with-bolt-3-0-a-silex-powered-cms

Gonzalo Ayuso:
POST Request logger using websockets
Nov 17, 2015 @ 10:25:32

In this post to his site Gonzalo Ayuso shows you how to create a logger for your POST requests and their information with a bit of helpful code and Websockets.

Last days I’ve been working with background geolocation with an ionic application. There’s a cool plugin to do that. [...] Basically this plugin performs a POST request to the server with the GPS data. [...] I can develop a simple Silex application with a POST route and log the request in a file or flush those request to the console. This’d have been easy but as far as I’m a big fan of WebSockets (yes I must admit that I want to use WebSockets everywhere :) I had one idea in my mind.

He shows the creation of a simple Silex-based application with just two endpoints (channel that handles both GET and POST) that uses the Guzzle HTTP library to listen on the Websockets port for incoming connections. He then shows how to add the code necessary on the frontend (using express) to send the POST data automatically to the waiting Silex application. He's provided the full working code for the example on his GitHub account as well so you can see it fully fleshed out.

tagged: websockets post log silex tutorial example gps plugin automatic debug

Link: http://gonzalo123.com/2015/11/16/post-request-logger-using-websockets/

SitePoint PHP Blog:
How Laravel Facades Work and How to Use Them Elsewhere
Nov 05, 2015 @ 11:55:49

The SitePoint PHP blog has a new tutorial posted showing you how Laravel Facades work and how they ("Facades") can be used in other framework types.

The Facade pattern is a software design pattern which is often used in object oriented programming. A facade is, in fact, a class wrapping a complex library to provide a simpler and more readable interface to it. The Facade pattern can also be used to provide a unified and well-designed API to a group of complex and poorly designed APIs. The Laravel framework has a feature similar to this pattern, also termed Facades. In this tutorial we will learn how to bring Laravel’s "Facades" to other frameworks.

He starts off by looking at how the Laravel framework has implemented facades through out the entire framework. He includes examples of using these facades (like the App to make a new object instance) and how the base Facade class is structured to make it work. He covers some of the basic features of the classes that extend this base and how they're aliased in the Laravel code/configuration. He then gets into using this same sort of "facade" approach to other frameworks, specifically in an app based on the Silex microframework. He lists some of the requirements and shows how to pull in the base Facade class to extend. He also integrates the aliasing code and configuration to make it simpler to use the short names rather than full namespaced versions of the classes.

tagged: laravel facade introduction tutorial silex approach naming

Link: http://www.sitepoint.com/how-laravel-facades-work-and-how-to-use-them-elsewhere/

SitePoint PHP Blog:
Popular Users per Language and Region with Silex and Github
Jun 18, 2015 @ 11:53:49

The SitePoint PHP blog has a new tutorial posted showing you how to use the data the GitHub API provides to find popular users, per language, in an area. His sample example is a simple Silex framework based application and uses the KNPLabs GitHub library to interface with the API.

The data you can get through the GitHub API V3 is mostly what you can see on the GitHub web interface, except you can use the data in your application to come to interesting conclusions. That is what we are going to do in this article. [...] Now, what if there was a web service in which we could specify a location and a language (e.g. PHP) and get a sorted list of contributors to open-source? [...] In our web service, we will have one endpoint (i.e. action, URL) that shows the most popular ten creators. The most popular creators are the people in a location who have the largest number of stargazers. For this, we will retrieve each person’s repositories and add up the number of times each one has been starred.

He steps you through getting a Homestead Improved VM up and running (via Vagrant) and a basic Silex application up and running inside. He then pulls in the KNPLabs GitHub library via Composer and sets up a new client in the default route (and grabs the public user data for a user). He then shows how to change it up and use the Search API and some special queries to locate users by a given location. He adds another class, a "StarGazerCalculator", that's given the users returned, filters out the forks in the list and calculates the total "stargazer" count for the user. He does the same with the "top creators" list and sets it up as a service provider, fetches the data and returns the results as a JSON document.

tagged: popular user language region github api silex tutorial

Link: http://www.sitepoint.com/popular-users-per-language-region-silex-github/

SitePoint PHP Blog:
Record Retrieval and Pagination in Bolt CMS
Jun 02, 2015 @ 12:29:59

The SitePoint PHP blog has a new tutorial posted showing you how to set up pagination in the results provided by the Bolt CMS that includes handling to grab content from the database and display the results.

Bolt is a lightweight CMS built on Silex with Symfony components that’s fast, easy, and fun to develop with. My recent affinity for Bolt has turned it into my CMS of choice as I make a conscious effort to choose wisely and step away from bloated frameworks. Previously, I gave a very detailed insight into what it’s like developing with Bolt. Today, we’re going to break down a very popular task into steps in order to accomplish it with ease.

He starts with an installation of the Homestead Improved virtual machine and checks out a new copy of Bolt. He sets up a basic Bootstrap-based theme, including header and footer partial views. He then shows how to create "contenttypes" and fetch the current content records. He updates the Twig template to show the results and integrates the simple pagination. He then creates the single page version to view the content and "previous" and "next" links to accompany it.

tagged: bolt cms tutorial pagination content type management silex

Link: http://www.sitepoint.com/record-retrieval-pagination-bolt-cms/

SitePoint PHP Blog:
Pagination with jQuery, AJAX and PHP
May 28, 2015 @ 09:46:57

The SitePoint PHP blog has a new tutorial posted showing you how to set up pagination with jQuery and PHP using a simple Silex-based application.

n this article, we’re going to explain how easy it is to paginate your data set using PHP and AJAX via jQuery. We’re also going to use the Silex framework for simplicity.

The data he's going to paginate through is a list of "people" data with ID, name and age values. He starts by helping you get Silex installed and a new project created. With that in place, he shows how to inject the database connection (PDO) into the application and set up the simple route to output the "people" data back to the waiting Javascript. The route includes a page number value that's used in the LIMIT statement to segment the results into pages. He also includes another route that returns a total count of people records so the pagination knows when to end. With the backend in place, he then moves to the frontend, showing the complete code to get the page records and populate them into the page (via a list).

tagged: pagination tutorial ajax jquery silex people data

Link: http://www.sitepoint.com/pagination-jquery-ajax-php/