I wrote an article on medium about SOLID principles:
- Single responsibility principle
- Open–closed principle
- Dependency inversion principle
Have a look and comment/clap there if you have any comments.
I wrote an article on medium about SOLID principles:
Have a look and comment/clap there if you have any comments.
With macOs, PHPStorm indexes all your project files and write cache files into files under
Thousands of files are stored there. If you want your Mac to use less your hard disk (to extend its life), and also be faster in general, you can create a RAM disk (a virtual disk that uses RAM instead of your disk), and symlink the cache directory there.
I’ve been using this for a while and it seems to work well. The only downside is losing the cache when you restart the IDE, but that takes only a few mins to recreate (and clean automatically), so I’m overall happy with this approach.
Add this script to your ~/.bash_profile
The bash command ramDiskCreate will now create a volume called RAMDiskwith a phpstorm-cache inside it. You need to call this script each time you restart and you need to launch PHPStorm (I don’t often restart, so I didn’t bother to make it automatically launched at start).
The thing left to do (only once) is symlinking the cache directory into the newly created directory (update and test with your path, don’t just copy and paste):
mv ~/Library/Caches/PhpStorm2017.3 /Volumes/RAMDisk/phpstorm-cache ln -s /Volumes/RAMDisk/phpstorm-cache ~/Library/Caches/PhpStorm2017.3
I’ve experienced lots of slowness using docker for Mac (xhyve), due to volume mounting.
I’ve used the rsync solution for docker-sync. Simple, but the downside is that newly created files in the container are not shared outside. That’s not generally a problem except when some code is generated from inside the container (e.g. Doctrine migrations). When needed, a normal mounting for those directories can still be used, or (more complicated), the file can be copied into the host with a docker cp command.
Other downsides are the slowness to rsync watch (a few seconds that can be annoying in some cases), that leads me to the next point:
PHPStorm file watcher
PHPStorm supports the execution of custom scripts on save (file watchers). The idea is having those file watchers to perform an immediate
docker cp inside the container with the modified file.
The screenshot should be clear enough. Replace docker bin with the real path of your docker executable (not the symlink), and <CONTAINER_NAME> with your docker container, and adjust
/app/ to have
docker cp copying files where your docker container expects.
Depending on your needs, you might want to adjust your shares, and decide whether
vendor directory needs to be watched or not.
Note: You can’t just use the file watcher, or you’ll have the rebuild (or manually copy all the files) any time you switch branch.
This year I decided to take a couple of days off work and attend the 2016’s Italian PHP conference.
I was curious to see what the Italians audience thought of talks from international speakers, where the business is normally different. In Italy, according to my freelance experience in 2002-2008 and confirmed by the conference’s attendees, there is a majority of very small businesses requiring small/medium CMSes, often serving tourism needs (e.g. booking platforms), with a small budget, sometimes requiring to maintain old platforms and obliging developers to share their time doing multiple roles: devops, backend and frontend, sometimes design too, SEO and marketing) and/or working for lots of clients with different (sometimes legacy) platforms.
What I observed is that the backend world is more or less the same as the previous years. Basics are still the same. I even re-heard some recommendations read in the old 1994’s OOP bible book .
But there were some interesting points and tools. I would group the talks this way:
In summary much more performances by just upgrading PHP to the version 7, a very few backwards incompatibilities, a few language improvements. Interesting to see some stats from the PHP’s creator himself: WordPress and composer seem to be hugely faster now, and use much less memory (I don’t remember the numbers for each but at least 2x). Tips about smem (a tool to better measure memory consumption excluding shared memory), settings tuning (realpath_cache_size, command_buffer_too_small, DocumentRoot in tmpfs), considerations about multiprocessors and NUMA.
I attended a talk from badoo – the widest dating/social network site, so quite a lot of servers – that switched to PHP 7 and implemented the needed upgrades to all the used extensions. A viable solution for a big company, whereas a small one would probably not afford that and would be obliged to wait for the stable repositories and extensions upgrades before switching. Pinba (MySQL storage engine to accumulate PHP profiling info sent over UDP, similarly to a local NewRelic setup) was used for some measuring. Runkit was used to modify constants, user-defined functions and classes in 60k tests, and – since it was not supported in PHP 7 – they ended up developing their own mock framework and distributing it for free on GitHub (well, thanks !).
A bit too “DevOps” for a PHP conference, but since it replicates the platform architecture locally, and simplifies the deployment, I guess it’s becoming a MUST. At MOJ, fortunately, we already use it, thanks to your dedicated DevOps team. Nothing new to learn for me, apart from the pipeline jenkins plugin suggested in this talk, that I might play with when I have time, instead of simply using job triggering.
That basically means storing DB changes and be able to query on those changes. I’ve already implemented something similar in the past using doctrine listeners, and IMO a great approach when the data to save is connected to entity operations. I didn’t like how the argument was covered but good to hear and become curious to learn more during the talk, ending up reading the Martin Fowler’s article about event sourcing, play with Prooph framework for it, along with doctrine and mongo adapters. The Command Query Responsibility Segregation (in short, different models for updating and displaying) pattern was also mentioned, but IMO not necessarily connected to event sourcing as I heard.
Doing something already existing, but in PHP
Interesting talk about the fann extension, for Artificial neural networks, and an application example of machine learning in this talk, where the “intelligence” was recognising PHP code from human language in code comments, by initially defining what a code normally contains (“$”, “->” and “;” symbols), then launching it on many inputs (=code comments), and using an iterative approach to improve the results.
Another talk about Raspberry PI and PHP libs (alternative here) to pilot it. Not something developers normally do for their clients, but good to hear something refreshing and different. Raspberry PI’s OS is a Debian distribution, so a web server with PHP could be installed on it, and pilot a huge variety of sensors. Good to know. I might use it to recognise pigeons on my balcony and pilot a plastic bullet BB Gun to shoot at them !
What I didn’t hear
No talks about unit testing, maybe because there is no much more to say ?
No talk about functional testing, one of the most underrated thing to discuss IMHO. The sSoftware has to respond to business’ needs, be reliable and bug-free. We should never forget and stop improving on this side. I hear developers talking and focusing too much on speed and performances, without even knowing the optimise-measure iterative process. Also I hear tools and framework adoptions based on personal preferences or by just trusting what’s new and sold “better” without objectively comparing the alternatives.
Among the many software principles to adopt, like KISS eYAGNI, another important one is DRY (Don’t repeat yourself), IMO connected to the Standing on the shoulder of giants principle. In other words: Great people already faced your problems, solved them elegantly and also published their solution. So why not using highly skilled people’s solutions instead of developing yours ?
Unless you do things for learning, it’s more efficient to re-use things and avoid reinventing the wheel. Is, therefore, important to learn how to contribute to export and distribute some code to the public. Below, a list of some libraries I’ve exported from some projects of mine because I thought I’d use them in the future, or somebody else would need them.
A few years ago I developed a component to convert GBP into EUR for a client who needed an auction website and price filtering in different currencies. No PHP library was available at the time (not sure there still is one), so I’ve developed this unit-tested parser able to read values from the European central bank feed. I’ve used it a couple of time since then, so it was a good idea exporting it. If I need to convert currencies, it’ll take minutes to add this to the project. Note: the library doesn’t download and cache the feed on purpose. I prefer to have repositories doing one thing only. Downloading and caching is a responsibility of the caller, and it could be doctrine caching and a simple PHP file_get_content or guzzle call, depending on what you already use in your project.
Mockery (PHP stubs framework for testing) allows to mock chains of called methods, but no arguments can be specified. If your arguments are strings or integers, you can use this simple extension and write the same assumptions in a simpler way.
I couldn’t find a simple twig extension to limit some text by the number of words (without truncating them), and – in case they are truncated – add a suffix like “continue …”. Also, there was nothing to remove accents (useful to Slugify), so I created this unit-tested one, where I’ll add more general purpose Twig filters in the future.
A simple extension of doctrine array collections that already work great, but a.t.m. misses functionalities like sorting, create a new one from a merge of multiple arrays/collections, get not empty values.
Very simple and worth exporting. It’s unit tested, so I next time I need to work with a ArrayCollection, I’ll add this repo to the composer file and save time. Besides, any improvements will get saved into the repository itself, and not into a private project that might be abandoned, and therefore not lost.
Simple WordPress Woocommerce plugin to order woocommerce layered navs filters by order descending. Took minutes to implement.
Google Tasks web client, displaying all the lists on one page, functionalities to drag and drop tasks from one list to another. Written with AngularJs and Silex. I’ve abandoned this project due to some priorities, but some parts of it could be useful for similar projects. Sorry, no demo available
There are free language dictionaries on the web, but no open source library to parse them.
I’ve created one, that can be used for auto text spinning or suggesting synonyms.
The web application I’m working on (PHP 5.3, zf2, Doctrine2, on MySQL/Apache) has recently raised interest from the clients and it now needs to be installed on their premises, often a Windows server( arghhh!). That meant we had to make the application compatible with both MySQL and SQL-Server.
Here I summarize the changes and the solutions we adopted.
When developing and adjusting the CSS, a methodology is using firebug to directly edit the styles and then re-apply the change on the real file with the editor.
In other cases, it’s more practical to change the CSS directly, but reloading the full page is a bit time consuming.
Here is a trick to reload only the CSS. There are browser extensions for it, but at the time of writing, none of existing ones works as expected, at least on chrome.
From your browser toolbar: right click and select the option to add a new URL (“Add Page” on Chrome)
name: “Reload CSS”
url: the following script
Or just drag this into the toolbar Reload CSS