New Year 2016, from PHP to new technologies, retrospective and tell it how it is

Hi, it has been a while since i have not blogged. I still continue to do PHP, however no longer consider it for new projects. I have been somewhat more involved with new technologies and languages. From reactive Java, node, to go. From webpack, semanticui to terraform, docker, microservices and deployment pipeline. I have unsubscribed myself from most PHP repositories I follow, the fact is that they are not relevant as they used to be. Regarding Symfony I think no matter 2 or 3 it is somewhat stuck and with a good reason, it is a platform and that is it. Is still good, but no longer good for most new things. I disagree with trying to innovate some old ball in the wrong way.

That said, this past year was good. I got a new addition to my family, a cute baby girl. In the future I would seek to write blog posts whenever I can on go and on the things I consider interesting.

Regarding development in PHP and architecture in general, I discovered the lie of several approaches, like Event Sourcing. It is not a total lie because it works, but you seldom will run your events ever in the lifetime of your system for most cases. So we just finished removing it from one of my favorite projects. The same goes for OO, that madness we still use it but we are careful to go dumb crazy to abstract more than what the business requires. Both of these lies were noticeable if we would have paid attention to our gut feelings. I believe experience and taste ultimately helps you stir as a developer among right and wrong approaches. What works for others don’t necessarily is right or work for your case.

Some people move faster than others, I am learning this and I am liking to have good friends around that go fast so I am starting to go fast and paying attention to the important parts. Everything else is not worth the time. Keep it simple is still the best principle ever.

Ok, with this I am just making a quick update and setting a better direction. I am still writing PHP, but less of course so don’t panic 🙂

your friend @cordoval

Mac Cursor Best Configuration

This is actually a note to myself when configuring cursor behavior on mac. Credits to @hafci.

defaults write -g ApplePressAndHoldEnabled -bool false

If you have the dock on autohide and want it to open directly with no delay:

defaults write autohide-delay -float 0

Set a blazingly fast keyboard repeat rate:

defaults write NSGlobalDomain KeyRepeat -int 0

Set a shorter Delay until key repeat:

defaults write NSGlobalDomain InitialKeyRepeat -int 12


EDIT: This works with old macs, but for new Yosemite just go to system keyboard and max the first two sliders. That works better!

Telling Symfony to Use Cached Validation From Doctrine Cache Bundle Provider

Right now Symfony on 2.7-2.8 and probably until before 3.0 will still support apc type validation caching. This will be dropped soon, at least the class support. You could still use apc past that point however you would have to wrap your ApcCache class into a DoctrineCache. The DoctrineCache is a means to adapt any Cache service implementing Doctrine\Common\Cache\Cache interface into a Symfony caching service for validation.

How this looks in code follows:

-        cache: apc
+        cache: vendor.validation_cache.doctrine 
+        vendor_filesystem_validation_cache:
+            file_system:
+                extension: cache
+                directory: %kernel.root_dir%/cache/doctrine
+    vendor.validation_cache.doctrine:
+        class: Symfony\Component\Validator\Mapping\Cache\DoctrineCache
+        arguments:
+            - @doctrine_cache.providers.vendor_filesystem_validation_cache

ArrayCache and FilesystemCache are implementations of doctrine caches, but in order to tube them in to make them available to symfony we have to use this DoctrineCache wrapper.

One extra trick to test services is to include config_prod.yml in config_dev.yml imports and comment the first lines of config_prod.yml importing config.yml since it is already imported in config_dev.yml. Then you can exercise your container:debug –show-private command without problems to test and ensure things are working correctly.


Doctrine File System Caching with Doctrine Cache Bundle

Some people had experience some difficulty configuring a filesystem cache type. Symfony by default comes with some caching because of the doctrine bundle, however if one wants to extend to more types one has to install the Doctrine Cache Bundle which brings more provides into place. Now if you want to still instruct doctrine to cache metadata, the results and the query caching with these service providers then this is the way:

            type: service
            id: doctrine_cache.providers.vendor_filesystem_metadata_cache
            type: service
            id: doctrine_cache.providers.vendor_filesystem_result_cache
            type: service
            id: doctrine_cache.providers.vendor_filesystem_query_cache

                extension: cache
                directory: %kernel.root_dir%/cache/doctrine
                extension: cache
                directory: %kernel.root_dir%/cache/doctrine
                extension: cache
                directory: %kernel.root_dir%/cache/doctrine

I hope this resolves it for you when you need it.

Docker Symfony Development Box with Data Containers

Data containers are containers where you define a path or folder to be mounted onto other containers. The data here can be read only or writeable. This means that for when you need a swap or temp storage for your projects you can use these containers since any other containers that are perhaps mounted on your host will not be writeable.

So we start by defining the cache and logs container as follows:

// cache_container
FROM busybox
RUN mkdir -p /var/cache/repay/dev
VOLUME /var/cache/repay
ENTRYPOINT chmod -R 777 /var/cache/repay; /usr/bin/tail -f /dev/null


// logs_container
FROM busybox
RUN mkdir -p /var/log/repay/
VOLUME /var/log/repay
ENTRYPOINT chmod -R 777 /var/log/repay; /usr/bin/tail -f /dev/null

Here is how you piece everything together. You build those containers, notice that they have entry points so that after running that command gets invoked setting the right permissions for those folders when they get ran.

After the symfony box gets build you can run the whole thing and attach/mount the data containers to your main host shared container where the code is:

!#/usr/bin/env bash
# troubleshoot
# docker exec -i -t repay bash
# kill all previous containers
docker rm -f $(docker ps -a -q)
docker build --rm -t "cache_container:v1" docker/cache_container
docker build --rm -t "logs_container:v1" docker/logs_container
docker run -d --name repay_cache_container cache_container:v1
docker run -d --name repay_logs_container logs_container:v1
# build symfony project box
docker build -rm -t repay .
# run symfony container
docker run \
    -v $PWD:/srv \
    -e DB_NAME=repay \
    -e INIT=bin/reload \
    --volumes-from repay_cache_container:rw \
    --volumes-from repay_logs_container:rw \
    --name repay_development_webserver \
    -itP repay
This can work thanks to adding in the kernel a couple of methods:
<pre lang="php">
     * {@inheritdoc}
    public function getCacheDir()
        return '/var/cache/repay/'.$this->environment;
     * {@inheritdoc}
    public function getLogDir()
        return '/var/log/repay';

I grabbed the top Dockerfile from an adaptation of ubermuda repo for symfony docker:

FROM debian:jessie
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y
RUN apt-get install -y nginx php5-fpm php5-mysqlnd php5-cli mysql-server supervisor
RUN sed -e 's/;daemonize = yes/daemonize = no/' -i /etc/php5/fpm/php-fpm.conf
RUN sed -e 's/;listen\.owner/listen.owner/' -i /etc/php5/fpm/pool.d/www.conf
RUN sed -e 's/;listen\.group/' -i /etc/php5/fpm/pool.d/www.conf
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
ADD vhost.conf /etc/nginx/sites-available/default
ADD supervisor.conf /etc/supervisor/conf.d/supervisor.conf
RUN chmod 777 /
VOLUME ["/srv"]
CMD ["/usr/bin/supervisord"]

Now you can enjoy!