Rapid Application Prototyping in PHP Using a Micro Framework (Silex) — Part1 Introduction May 22, 2014Posted by Tournas Dimitrios in Silex.
Tags: framework, Silex
add a comment
Setting up a Framework up to the point of a working web application isn’t difficult these days. We just have to open a terminal and take advantage of Composer’s functionality. Composer will handle the whole process of downloading the required package and its associated dependencies in just a couple minutes. Most popular Frameworks nowadays are distributed via packagist , a Composer package repository, which finds packages and lets Composer know where to get the code from. An important decision has to be made though, which framework should be chosen as a foundation for our web application ? Not a simple question indeed. An American pioneer of computer science (Kenneth Thompson) had proposed the “Unix philosophy” : >>> Building short, simple, clear, modular, and extendable code that can be easily maintained and repurposed by developers other than its creators <<< Many [PHP]frameworks follow the aforementioned philosophy very closely, their components are autonomous blocks of code which can be used by other frameworks as building blocks. A characteristic example is Symfony, its modules are used by many frameworks and libraries.
Silex is a PHP Micro-framework based on Symfony 2 components that has been built to focus on smaller web-applications. Silex handles basic tasks (ie routing , DI) without getting in our way, acting as a great base upon which we can architect the rest of our application. The “Application Class” (core component) of Silex is extending Pimple, it’s a [small] service container, more formally known as a Dependency Injection Container. If you are new to Pimple, reading up on it is going to be extremely important. Pimple’s documentation is pretty easily to follow. As many other dependency injection containers, Pimple is able to manage two different kind of data: services and parameters (key/value pairs). Developers familiar with Symfony’s Service_Container , Laravel’s IoC container or ZF2′ Service_Manager component will immediately recognize that some features which are inherent in those modules (and are required on large scale applications) are not available “out of the box” in Silex . This framework (Silex) is an excellent tool to build simple web applications, but also, it can be used for software prototyping and for building RESTfull API’s.
“Micro” does not mean that the whole web application has to fit into a single file, although it certainly can. Nor does it mean that Silex is lacking in functionality. The “micro” in micro-framework means Silex aims to keep the core simple but extensible. Silex won’t make many decisions for us, such as what database to use. Almost everything is configurable by the developer, so that Silex can be everything we need and nothing we don’t. Extending Silex’ functionality is simple as registering one of its build-in ServiceProviders, also, writing our own ServiceProviders (extensions) isn’t difficult to accomplish .