The Symfony Installer

Nice news! Symfony team has launched their own installer. The purpose of this installer is to start new projects based on the Symfony full-stack framework.

We can find how to install it and use it here.

As you can see it’s really easy to install and use. For instance, to create a new project (once installed) we can run:

1
user@unix:~$ symfony new my_project

Symfony keeps evolving :D.

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone

PHP Conference Argentina 2014

This conference rocks!. This last weekend I have attended the largest PHP conference for developers in Argentina. A huge amount of developers from all the world had the opportunity to listen excellent PHP’s guru’s.

Masters like Michael “Monty” Widenius (creator of MySQL), Brad Fitzpatrick (Creator of Memcached, Gearman and core developer of Go), Fabien Potencier (creator of Symfony PHP Framework) and Mitchel Hashimoto (creator of vagrant) between others.

Between the most interesting talks we can find:

Performance Testing Crash Course by Dustin Whittle.
Password storage (and attacking) in PHP by Anthony Ferrara.
API’s Pain Points by Phil Sturgeon.
OAuth2: The Swiss Framework by Brent Shaffer.

Also, Javier Eguiluz talked about Symfony 2 Best Practices and Mitchell Hashimoto about Consistent development environments with Vagrant.

And last but not least, on Sunday we shared an awesome barbecue in a beautiful ranch called the “Gaucho Day“.

Looking forward for the 2015 edition and thanks to the guys who did this possible.

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone

Supervisor: A Process Control System

For these days I had the possibility to work with a great tool in my job. This tool allows us to monitor and control a number of processes on Unix operating systems.

As their website says: “Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.“.

Supervisor is written in Python and based on a configuration file (supervisord.conf) the daemon (supervisord) keeps monitoring for defined processes are running, and if the process is killed by whatever cause the supervisord start it again.

A configuration file looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[supervisord]
logfile=/var/log/supervisord.log

[unix_http_server]
file=/tmp/supervisor.sock
username=supervisor
password=mysecret

[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface

[inet_http_server]
port=*:5858
username=supervisor
password=mysecret

// Programs
[program:email_sender]
command=/usr/bin/php email_sender.php --arg1=a --arg2=b
user=www-data
autorestart=true
stderr_logfile=/var/log/email_sender_%(process_num)1d.err.log
stdout_logfile=/var/log/email_sender_%(process_num)1d.out.log
numprocs=2
process_name=%(program_name)s_%(process_num)02d

And a web app shows us a status of processes:

supervisor-screenshot

For more information you can read the documentation.

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone

The Future of Web Development

Past, present and future of web development based on my own experience.

The web development work is something that I really love it and enjoy working on it, and as a full-stack web developer who is working on this from the last 8 years I want to share my experiences and thoughts about it.

I am mainly a PHP developer but I think these thoughts can apply to others backend languages like ASP or JAVA. When I started developing web apps with PHP it really was at your own way, writing spaghetti code and having PHP and HTML mixed, and honestly I think PHP was a little immature but for that time it just worked.

Fortunately, PHP has grown a lot as well as its community and in nowadays we have really great frameworks like Symfony, Zend, Laravel or much more, so if you are developing web applications my advise is please use a framework.

Javascript is conquering the world. Javascript exists from the almost the beginning of the Internet and it was and it is used for client-side functionalities, but in the last years is evolving so much until reached server-side development with nodejs. This made me think, why we need to have one server-side language and another client-side language? when we can have a developed application fully by the same language (in this case Javascript). Also, Javascript has evolved a lot in the client-side with great frameworks like BackboneJS, AngularJS or EmberJS, so if you are interesting on them, please take a look on them.

Web development and mobile development are siblings, when you are developing web apps you should think on make them mobile compatible. Nowadays, more than 25% of website visits are originated from mobile devices and it is expected to be the 50% in 2017. So, for that you need to think making your apps mobile friendly.

A great trend is which allow us to use a web app that acts like a desktop application updating only the needed views instead of reloading entire pages every time the user navigates between sections. Great frameworks to build websites like this are the already mentioned BackboneJS, AngularJs or EmberJS. Also, I would like to mention a promising full-stack Javascript framework like MEAN.

In conclusion I think the web development future is full-stack javascript and SPA applications, using nodejs in server-side development and one of the great JS frameworks mentioned above in the client-side development, or at least building these applications consuming APIs or web services built them with a mature PHP framework (Symfony in my preference :-)).

Please, keep learning, reading, hearing about web development, it is something amazing.

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone

Symfony 1.4 over PHP 5.5

As you might know Symfony 1.4.x has ended its LTS in last November 2012, at that time PHP 5.5 was not released yet. That 5.5 version came in June 2013 and if you want to upgrade to that version you need to know about Symfony 1.4.x is not 100% compatible with PHP 5.5.

If you upgrade to PHP 5.5 you will start seeing a couple of warnings in your Symfony 1.4 application:

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in lib/vendor/symfony/…

In this post I will show you a patch to fix these warnings and make Symfony works over PHP 5.5.

In lib/vendor/symfony/lib/command/sfCommandManager.class.php:

1
2
3
4
5
6
7
8
9
10
11
@@ -108,7 +108,9 @@ class sfCommandManager
     else if (!is_array($arguments))
     {
       // hack to split arguments with spaces : --test="with some spaces"
-      $arguments = preg_replace('/(\'|")(.+?)\\1/e', "str_replace(' ', '=PLACEHOLDER=', '\\2')", $arguments);
+      $arguments = preg_replace_callback('/(\'|")(.+?)\\1/', function($matches) {
+         return str_replace(' ', '=PLACEHOLDER=', $matches[2]);
+     }, $arguments);
       $arguments = preg_split('/\s+/', $arguments);
       $arguments = str_replace('=PLACEHOLDER=', ' ', $arguments);
     }

In lib/vendor/symfony/lib/form/addon/sfFormObject.class.php:

1
2
3
4
5
6
7
8
@@ -278,6 +278,6 @@ abstract class sfFormObject extends BaseForm

   protected function camelize($text)
   {
-    return preg_replace(array('#/(.?)#e', '/(^|_|-)+(.)/e'), array("'::'.strtoupper('\\1')", "strtoupper('\\2')"), $text);
+    return sfToolkit::camelize($text);
   }
 }

In lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormFilterDoctrine.class.php:

1
2
3
4
5
6
7
@@ -323,7 +323,7 @@ abstract class sfFormFilterDoctrine extends sfFormFilter

   protected function camelize($text)
   {
-    return sfToolkit::pregtr($text, array('#/(.?)#e' => "'::'.strtoupper('\\1')", '/(^|_|-)+(.)/e' => "strtoupper('\\2')"));
+    return sfToolkit::camelize($text);
   }

In lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/form/sfFormFilterPropel.class.php:

1
2
3
4
5
6
7
8
@@ -263,6 +263,6 @@ abstract class sfFormFilterPropel extends sfFormFilter

   protected function camelize($text)
   {
-    return sfToolkit::pregtr($text, array('#/(.?)#e' => "'::'.strtoupper('\\1')", '/(^|_|-)+(.)/e' => "strtoupper('\\2')"));
+       return sfToolkit::camelize($text);
   }
 }

In lib/vendor/symfony/lib/response/sfWebResponse.class.php:

1
2
3
4
5
6
7
@@ -406,7 +406,7 @@ class sfWebResponse extends sfResponse
    */
   protected function normalizeHeaderName($name)
   {
-    return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", strtr(ucfirst(strtolower($name)), '_', '-'));
+    return preg_replace_callback('/\-(.)/', function ($matches) { return '-'.strtoupper($matches[1]); }, strtr(ucfirst(strtolower($name)), '_', '-'));
   }

In lib/vendor/symfony/lib/util/sfInflector.class.php:

1
2
3
4
5
6
7
8
9
10
@@ -28,10 +28,7 @@ class sfInflector
   public static function camelize($lower_case_and_underscored_word)
   {
     $tmp = $lower_case_and_underscored_word;
-    $tmp = sfToolkit::pregtr($tmp, array('#/(.?)#e'    => "'::'.strtoupper('\\1')",
-                                         '/(^|_|-)+(.)/e' => "strtoupper('\\2')"));
-
-    return $tmp;
+    return sfToolkit::camelize($tmp);;
   }

EDIT: I’ve added a improved camelize function that the original.

In lib/vendor/symfony/lib/util/sfToolkit.class.php:

1
2
3
4
5
6
7
8
9
10
@@ -608,4 +608,15 @@ class sfToolkit

     return set_include_path(join(PATH_SEPARATOR, $paths));
   }
+
+   public static function camelize($text)
+   {
+       return strtr(ucwords(strtr($text, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => ''));
+   }
 }

This patch was tested in Symfony 1.4.20 and it works properly.

EDIT: Do NOT use Symfony 1.4.x for new projects. This patch works for existing legacy symfony1 applications, but Symfony2 is the way to go today.

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone

Unofficial Symfony 1.5

Since the official support for Symfony 1.x has been interrupted in November 2012, a community driven fork of symfony 1.4 has being developed to support DIC, form enhancements, latest Swiftmailer, better performance, composer compatible and PHP 5.5+ support.

This unofficial version can be found at https://github.com/LExpress/symfony1.

And you can read the README file there to know what has been added.

Keep on mind as they mention in the README file “Do not use it for new projects: this version is great to improve existing symfony1 applications, but Symfony2 is the way to go today“.

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone

symfony-all command line

If you are a symfony developer you already should know about the great commands you can use to ease your development. To learn more about those commands I would recommend you this chapter in the symfony’s documentation.

The most common commands are those to generate our model, forms and filter; so to do that you can to run each command individually.

To speed up this common use, I would share with you a really simply bash script to do all this in just one command:

1
2
3
4
5
#!/bin/bash
php /path/to/symfony doctrine:build-model
php /path/to/symfony doctrine:build-forms
php /path/to/symfony doctrine:build-filters
php /path/to/symfony cc

The above script will build our model, forms and filters, and it will clear the cache. Of course, you also could run the database related commands, but we have to be careful about changing database structures in existing projects.

I hope this script will be useful for you guys.

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone

CSS2LESS – PHP class

If you are a PHP developer who also works in frontend stuff you should learn about LESS (Leaner CSS) which is a CSS pre-processor and it allows you to make CSS more maintainable.

I’ve found a cool PHP class which can convert CSS into programmable CSS with LESS syntax. It can parse a given CSS style sheet and extract certain common property constant values to turn them into variables in the converted output using LESS.

Currently it turns the CSS properties into LESS variables: color, width, height, font-family and font-size.

You can find this class here.

I was playing with it and it works like a charm! 😀

share it...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Pin on PinterestDigg thisEmail this to someone