Symfony validators, a tool little used

Im talking on self experience, maybe im the only one that use this amazing tool so little. But i recently i propose my self to change that and integrate it on my forms.

There are a lot of build in validators but how we can combine them and end up with a powerful validation constraints is up to us.

One of them that kept my attention and is the reason of writing this post is the CallbackValidator.

The purpose of the Callback constraint is to create completely custom validation rules and to assign any validation errors to specific fields on your object. If you’re using validation with forms, this means that you can make these custom errors display next to a specific field, instead of simply at the top of your form.

My requirement at the time was to validate and restrict two date time fields of my form called startDate and endDate respectively. The endDate as suppose cant be set to a date before the startDate field., so enter CallbackValidator

->add('startDate', DateType::class, array(
    'widget' => 'single_text',
    'format' => 'yyyy/MM/dd',
    'constraints' => array(
        new NotBlank(),
        new DateTime(array(
            'format' => 'Y/m/d'
->add('endDate', DateType::class, array(
    'widget' => 'single_text',
    'format' => 'yyyy/MM/dd',
    'constraints' => array(
        new DateTime(array(
            'format' => 'Y/m/d'
        new Callback(array(
            'callback' => function (\DateTime $endDate, ExecutionContextInterface $context) {
                $startDate = $context->getRoot()->get('startYear')->getData();
                if ($startDate > $endDate) {
                    $context->buildViolation('End date cant be before start date.')

Just as easy as that my requirements where fulfilled.

So my advice is, and to my self; please use validators.


Nodetrine a database abstraction layer for NodeJS

As web developers we all worked with javascript at some point, and maybe not just throwing pure JS code, but using a frameworks like JQuery, AngularJS, ReactJS, or one of the many great frameworks available. Javascript background was on all of us by default.

After Google release the javascript engine, behind the chromium project; named V8 on 2008, the team on Joyet release the first version of NodeJS on 2009. It creates a great point on history for the javascript community, for the first time it has a runtime that execute pure javascript on server side. Now those who only works on “frontend”, and has limited knowledge of other server languages like PHP, Python and Java; can really begin to create full javascript  handled software solutions.

The NodeJS community

The community of NodeJS increase every year at a tremendous rate. Many new projects and frameworks, to easy the developers life on how to build agile and great software solutions; where born.

Projects like express and are the base of many, many projects. Some others aims to be a more complex web frameworks, like sails, totaljs and mean among others; providing a MVC approach and integrating some other tools like Template generation, Form generation, and ORMs

ORMs, Why?

Database access its one of the first tasks  we require to do on most projects, any dynamic application need to persist some data at some point.

Even when BigData and NoSQL databases change the perspective of storing data and build apps; relational databases, like MySQL, Postgres, SQLite and Oracle; are still commonly used.

ORMs provide an OO approach on how we talk to this database engines, and certainly allow us to interact with them in an easy way.

There are already great tools like waterline and sequelizejs already out there.

So why do we need a new one?

Design patterns

There are two common design patterns to implement ORMs solutions

The main difference between those two, and the one i want to bring out from my personal perspective; is the way it couples your code into its own code.

Active Record been the most simplest and easiest of both, requires you to extends its models; so your business code will be coupled to the ORM you choose to its end. In the other hand Data Mapper allows you keep business rules and database code separated, and from and architectural point of view; this is important if you want to keep your code clean, and you should, even when its learning curve can be more complex


There are great implementations of the Data Mapper pattern, two examples are SQLArchemy from the Python community and Doctrine from the PHP community.

Since i do a lot of programming with Symfony and Doctrine is the default ORM, i have more understanding on how it works and was implemented.

So i decide to create a clone of that great project and juggle a little with the names, that its how Nodetrine was born.


As its father Doctrine, Nodetrine will be the organization behind several projects starting from DBAL and followed by ORM


Database Abstraction Layer aims to create a common entry point for all relational databases implemented through the Driver interface, so it can be database engine agnostic and perform the common tasks for interaction with those engines in a seamlessly way.


The project DBAL project has been released to it first version 1.0.0 and can be installed with npm. You can find more info about it on its github page and on readthedocs.

On this first release you can find the base tools to query and manipulate data on the database. There are other tools that will be implemented on the upcoming releases.


I really hope this project can help build amazing apps, but i even desire more that we can create a community around it and collaborate to make it amazing, so feel free to file bugs, write docs, tests it, use it, and write code.

So till next time

Nodetrine its here!!!