PHPBenelux Conference 2013

Anatomía del microframework Silex

Igor Wiedler  · 

Código de la presentación

Puedes acceder al código fuente utilizado en esta presentación en el siguiente enlace:

https://github.com/igorw/yolo

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

welcome to this talk on silex Anatomy for those of you who don't know me my name is Igor I'm one of the co-creators of silex and the main question that I would like to answer today is would you rather fight 1 elephant sized duck or 100 duck-sized elephants

so first of all I'd like to share my thoughts this all right I'd like to share my thoughts on what's alexs from kind of a more inside perspective so silex is a test suite for symphony and it's a test suite in two distinct ways so for one it

is an actual test suite because silex does have tests and it's testing the symphony components in a specific in a specific configuration kind of acting as an integration test it's also a moral test suite and what I mean by that is that well symphony

is kind of two things right so you have the symphony framework and the symphony components and the symphony framework is composed out of these components and the components have made certain promises which need to be enforced so for one there's the backwards

compatibility contract which means that in a new version of the symphony components you can't just break everything so you need to retain a certain level of backwards compatibility and well since since the symphony framework is the main client of those

components it could be or it could happen that certain changes are made specifically for the framework which break other users so by having a framework that uses the same components there is some way to ensure that if something breaks we will actually notice

it and we can kind of slap back to Symphony and tell them to stop doing that and stop breaking other things and as soon as more people start using these components which is happening like we have we have the level 4 framework and Drupal is using it PHP vb

is using certain components so it is rapidly expanding and it will become more and more important to to retain these compatibilities silex is also a Trojan horse for dependency injection so dependency injection it's it's really a quite a simple concept

and it's it's not been that well-known in the PHP community so it only really became popular during the last few years I would say and well it's kind of scary because you have all of these new concepts you have containers and what Silex does really

well is hide this well hide the concept of a DI container away from you while still giving you the possibility to use it if you want to and to customize bits so by by hiding the fact that there is a container there but still providing you the opportunity to

override services like that you can appeal to to people who don't necessarily want to learn all of that stuff and they can still use it without without knowing about it but as soon as they do hit certain limits and want to customize things then they can

start using it just fine and silex is also bloated so if we take a look at the application class which is the main class that you interact with when you use Silex and if I scroll down right to the bottom here it's about 500 lines of code in one single

class which is pretty massive if if you ask me and if we take a look at the class definition then you can see that there's an application class which extends pimple so pimple is the dependency injection container use place I legs which is the worst name

ever and it implements sorry yeah when you google don't thank Google for it and so it extends pimple it implements the HTTP Colonel interface so obviously there's quite a few responsibilities that are mixed up inside of this class and I would say there's

a there's a few main responsibilities so for one it's the root builder and this is to me this is the main responsibility of silex so when you call methods like get put post delete what you're doing is you're building roots or you're defining

or declaring roots so that that would be the main responsibility then you have pimples so it's also a container and you have the HTTP colonel interface and in addition to that you also have the run method so you have a kernel and a front controller also

in the same class and in addition to that certain utility functions as well so there's all kinds of stuff here and well show showing the the Silex codebase to explain the concepts it doesn't work so well because it's kind of hard to see the different

responsibilities and in what belongs where and which part does what so we're just going to close that now and let's talk about let's talk about monolithic frameworks and libraries for a second so I guess most of you have used monolithic frameworks

before where everything is kind of packed up into one huge package that contains everything that has an ORM has a routing library that has template tianjin and everything inside of it and it really sucks because you can't customize things you can't

make your own decisions and you forced well at least in most cases you're forced to use the things that are provided by this framework so I'm not really a fan of frameworks I really prefer libraries and to me silex is more of a library than a framework

because you are mostly in control of how you use it and it doesn't really make too many decisions for you and the decisions that it does make you're able to overwrite them if you want to so I think the the main difference between monolithic frameworks

and something like symphony is that symphony is decoupled symphony has components and this also applies his own framework more now than it was within framework one but the idea is the same so what do I mean by decoupled well these decouple components for one

they're independent so I can use one component without dragging in all of the framework or without dragging in 20 different other components so I can just use them stand alone and they aim to be a standalone as possible and the so the what's really

awesome about this is that you have interfaces between the components and that's how you communicate between them so by having these interfaces you're not bound to a specific implementation but you can replace it with something else if you want to

[ ... ]

Nota: se han omitido las otras 3.097 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.