Posts Tagged ‘symfony’

Conflict error on PECL YAML

Monday, December 10th, 2012 | Programming, Tech

If you are trying to install PECL YAML on Mac OS X Lion, you may find you get a conflict with an error message similar to the following.

WARNING: pecl.php.net/yaml: conflicting files found:
yaml/LICENSE (pear.symfony-project.com/yaml)

This error is documented on GitHub and as it is not critical, can be overcome by turning off errors.

pecl install --ignore-errors yaml

On running that command, it should no longer stop at that point.

PHP complains date.timezone is not set

Wednesday, November 28th, 2012 | Programming, Tech

Sometimes, PHP will kick up a fuss complaining about date.timezone not being set. We found this on the Symfony framework and were able to replicate it on standalone scripts.

[Exception]
DateTime::__construct(): It is not safe to rely on the system's timezone settings.
You are required to use the date.timezone setting or the date_default_timezone_set()
function. In case you used any of those methods and you are still getting this
warning, you most likely misspelled the timezone identifier.
We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead

Normally, you would fix this by editing your php.ini file and adding a declaration there.

date.timezone = "Europe/Berlin"

But we had already done this and it still wasn’t working! After some further investigation, it seemed that PHP simply couldn’t access the value.

echo(ini_get("date.timezone"));

This doesn’t make any sense, and we never got to the bottom of what was going on, but there are two ways around the problem. Firstly, you could modify your PHP script so that it makes a call to set the system timezone.

date_default_timezone_set("Europe/Berlin");

However, this involves having to modify your code, which is bad as you don’t want to have to set the timezone manually, especially in a piece of code which could be deployed to servers in different timezones.

A better approach is to set it in the vhosts directive in Apache.

php_value "date.timezone" "Europe/Berlin"

This isn’t the cleanest solution but allowed us to solve an otherwise unexplainable error.

Silex

Saturday, June 9th, 2012 | Limited, Programming

Silex is a PHP microframework based on Symfony2 components.

With the shift in recent years to leveraging more JavaScript and front-end code in fat clients, a lot of server-side processing has been reduced to simple data relay and APIs. As a result, there have been a number of microframeworks arisen, which allow you to serve out content in a really simple and easy way.

One of the most popular is Sinatra, a micro-framework for Ruby, which is what we built Village Chief on. Indeed, Silex is inspired by Sinatra, but is PHP-based and uses some of the great components that can be found in the Symfony2 framework.

As you would expect from a microframework, it’s really easy to get started.

<?php
require_once __DIR__.'/../vendor/autoload.php';

$app = new Silex\Application();

$app->get('/hello/{name}', function ($name) use ($app) {
    return 'Hello '.$app->escape($name);
});

$app->run();

It relies heavily on Composer, a PHP dependency manager. This is a bit of a pain if you’re not already using Composer as it means you have to have yet another piece of software on your computer, but unfortunately, you’re somewhat railroaded into it as there is virtually no documentation on how to install things like Twig without it. Luckily, once you have it, it does make things easy and pain-free, so it’s probably worth going through the initial setup.

Once you’re up and running, it’s a snap to add content. We recently re-launched Maze Finance and the entire process of getting Silex up and running and migrating our existing website into it took less than two hours!