So I’ve been attempting to improve my coding workflow over the last few months and a couple of the tools I’ve been looking at to help me do that are Visual Studio (my new favourite IDE, if you didn’t know) and Symfony. Well, more of the former and less of the latter. After dabbling with Symfony for a bit I kind of tailed off as I didn’t really have any projects to apply it to…
…BUT NOT ANY MORE! (Too dramatic? I think that might have been too dramatic…)
The other week I built a very quick PHP application that ran from the command line – nothing too special, just something to compare two csv files against a given column and split out any rows with values that didn’t appear in both files. But it’s something that could have a wide reaching use in the library, so it either needs to be able to run as a desktop application or a web application. I’ve started building the latter as a wrapper around the core functions I coded for the CLI version.
To make life a little easier I first did some investigation into how I can use my current toolkit to help me. Firstly I wanted to be able to quickly roll Bootstrap templates – that was fairly easy, installing the Bootstrap 4 CDN Snippet plugin into VSCode. I decided to add a couple of others while I was there, installing PHP Intellisense and Path Intellisense, as I noticed the stock IDE didn’t really do anything special there – autocompleting functions and paths FTW!
So I could now start writing a web frontend for this little application, but I wanted to take this further and make my code easier to follow – I didn’t want to create a bunch of additional flat PHP inside what was really quite a clean little tool. So I thought about the templating I’d looked at in Symfony and whether I could port that across. I totally could!
Symfony components can be installed in any project from the command line through Composer by simply navigating to your project and typing:
composer require symfony/name_of_component
That’ll set up all the requirements – you do still have to include the Symfony “autoload.php” file in your project, but you can get stuck in retrofitting existing applications with the Symfony MVC framework. Very cool! Now I’m working with Symfony templates and forms within my project, making sure that I separate “doing” code from “output” code and allowing me to easily keep the CLI version of this application running alongside the more user friendly web frontend! A great way to add and test new functionality once the application has been deployed for wider use.
If you want to find out more about including Symfony Components in your existing projects, you should check out the Symfony Documentation.