PHP UK Conference 2013

Refactorización de aplicaciones con los componentes Symfony

Michael Peacock  · 

Presentación

HTML (pincha para descargar)

Vídeo

Transcripción

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

hi thank over thank you very much everybody for coming on to this talk I'm going to be talking about how you can use Symphony components to refactor your existing application particularly if it's a some legacy code or something that you just like to

to modernize and improve a little bit about me I'm the head developer for a company called ground six we're a technology investment firm based in the northeast of England so people come to us with tech based business ideas we build them into a product

and we build them into a business i'm also a technical author written a couple of books about different content management systems and PHP applications and occasion area to speak at events and conferences such as this so the components the symphony framework

is built using a series of stand-alone reusable components they've been released independently so that you don't need to use them as part of the framework you can use them in your own application be at legacy be something brand new and it ranges from

things such as browser emulation CSS selecting finding files rooting within your application security translations forms a whole host of things that are available out there you can find all the information about them on the air the symphony component website

it's all the documentation for each of them as well as download and installation instructions so why might you want to use components as opposed to just using a simply framework or rebuilding it in something else or refactoring using some other traditional

methods well the first one is that the components they solve common problems that already exist why reinvent the wheel why build a translation tool when there's already one out there why build the router when there's already one out there there's

things that exist that do this really well you can focus on building the product using the business logic that it needs not worry about the actual fundamentals of how the application and the underlying aspects work they're very well documented or the source

code is available it's very easy to raise issues get them fixed the installation usage and extending instructions are excellent so if you decide that you want to change how it works for your particular use case it's very easy to do that as well they're

often built in a way that allows you to interchange different aspects of them so for example with the routing component you can use a mol file to pulling the roots you can use annotations you can use of the types of file to use PHP code or you could write

your own extension if you want to they're very well interchangeable they're relatively standalone I said relatively because some of them do have some dependencies on theater so if you want to use the routing component with llamo you need the other

components as well but apart from that they are relatively standalone and work well independently and I think they're ideal for refactoring as I say they allow you to focus on building your application building the product getting business in rather than

thinking I've got to build all these things that I need to have a solid stable platform so if you've got something that's legacy needs to be refracted or put onto something that's more stable instead of going right let's scrap this and

go and use WordPress or magento or the symphony framework let's do a bit at a time let's introduce a ruder let's introduce this let's introduce that which is a very nice aspect so you want to install any of the components at the knight in shining

armor for this is composer or anybody that's not using composer really suggest that you do download it over another command in command line that will download the composer dependency management system create a composer that Jason filing the project this

is just a Jason file that says what dependencies your project has your for example would be Symphony forward slash and then the project name of the components that you want to use so it could be routing translation you just say that you want the current development

version now allow you to pull that in and you run composer and you've got all the components that you've asked for so if you want a routing component start it to you your RAM composite of JSON file you want other components you have them as well it's

very straightforward I'm also going to talk a little bit about some of their friends so there's Swift Mahler twig pimple they made biol up the team behind the symphony components and the symphony framework but they're not not part of the component

sweet and there's also a third-party caching library I'm going to talk about when we talk about template twig it's a little bit about what's in store today going to talk about how you can autoload your classes using the symphony component class

loader so you drive to worry about how to pull in your PS r0 compatible code are you root requests using the symphony bruder I can listen for events within your application so a new users being created you better content has been posted you can use the event

dispatcher to listen for those events and react and do something with a party on all files so that we can easily use configuration within our code and also how we can deal with HTTP requests using the HTTP foundation component will also look at injecting dependencies

instead of having dependencies gathered in some legacy code base we can make use of something like pimple to inject them and finally we'll look at some templating with twig as well so we can turn a legacy templating solution instantly nice and user-friendly

developer friendly at least around eight months ago or so a project landed on my desk there was an existing web application with reasonable amount of user generated content reasonable amount of members reasonable amount of traffic you know nothing fantastic

but still very good numbers and we had a problem it was very slow to develop on this there was an existing team in place and they were trying to add new features and because of how old the codebase was it was just passed from developer to develop it to developer

nothing was consistent there's lots of very old techniques you could see when a new design pattern or technique could become popular what became the previous developers flavor of the month they saw it went wild with it and then I got forgotten about so

there's no consistency no standards and everything seemed to be about how the code worked together and nothing was about how the code was doing what the business needed so we have us we had two choices really we could either scrap what we had and rebuild

it using something like WordPress symphony framework joomla into the content system or Drupal or something like that the risks that we thought associated for that were obviously got all that business logic in our code that we couldn't guarantee we'd

remember it all might not get all of it and no idea how that would be possible to to guarantee that every last bit of that would be kept so easy to say right well we'll use this module to the other authentication and it misses that crucial edge case or

that use case that you need so we thought this quite a lot of risk associated with that as well you've also got all your existing content your users your members you've got to do some port database migration that becomes particularly hard when using

something off the shelf because you don't know exactly what your resolving database is going to look like until you've decided on all the modules you've got to use and built any custom modules so we went down the option of let's refactor what's

there the business logic that we've got in the application is good it's just hidden away we need to get rid of the application specific stuff get everything there that focuses on what the product does that's what we decided to do so we had a very

messy structure there was some objects there's some procedural code monolithic codes it was just included in ran blindly it wasn't very nice so you needed to look at standardizing that using something like the PSR Oh standard so we're going to

make use of the class loader for that Global's Singleton's crazy guard like objects all over the place so we needed to manage that that's why pimple comes in routing logic was all over the place come into an index file lots of if-else conditions

delegate to another file with a failed conditions several files down the chain you've got your actual code is just what you want so we needed the ruler to fix that with a lot of duplicated logic all over the place so if a user create an account that get

an email with the user credits of content that get an email for that email code was just a function call somewhere else so if we wanted to add it to something you'd have to go find new bit where you want to send an email and put that function call in if

you needed to remove it you have to go and find bits of code remove it not very extendable but not terrible at the same time event dispatcher let's just listen for those event separately we also had a lot of PHP and HTML mixed together he look at a template

file and it was just horrendous the designer on the project it was very difficult to actually do any design work that wasn't just CSS or images because the HTML files were so interlaced with PHP and business logic it just didn't make any sense we also

a lot of spaghetti formed logic so when it form was submitted validation was very messy very sporadic and very duplicated so we looked at some validation libraries though some of the improvements we introduced such as mailer component Swift mela at translation

and validation so how do we solve messy and procedural code using the lights of a class loader well to refactor the code to a more suitable standard such as PSR oh we needed to have a solid foundation in place that we could then make use of that component

with so we have to lay the foundations first stage was our controllers the only controllers we had which were objects who want to dealt with form submissions everything else was just a PHP file was included and ran blindly didn't make very much sense and

it was very difficult for us to to work with so we changed everything so that was object-based made it much more more suitable we restructured it using the PS ro standard so we introduced namespaces restructure debt to a better in directory hierarchy using

[ ... ]

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