dimanche 15 novembre 2009

appart story

Posted by Picasa

Le fabuleux appart de kiby....

mercredi 14 octobre 2009

Build php5.3 from source

sudo apt-get install libtidy-dev curl libcurl4-openssl-dev libcurl3 libcurl3-gnutls zlib1g zlib1g-dev libxslt1-dev libzip-dev libzip1 libxml2 libsnmp-base libsnmp15 libxml2-dev libsnmp-dev libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev zlib1g zlib1g-dev libfreetype6 libfreetype6-dev libbz2-dev libmcrypt-dev libmcrypt4 apache2-prefork-dev apache2-dev

Get snapshots de php5.3.x from http://php.net

http://fr.php.net/get/php-5.3.0.tar.gz/from/this/mirror


...for example


tar -zxf php-5.3.0.tar.gz


cd php-5.3.0

make distclean



./configure --with-apxs2=/usr/bin/apxs2 -prefix=/opt/php --with-mysql=/usr --with-mysqli=/usr/bin/mysql_config --with-tidy=/usr --with-curl=/usr/bin --with-curlwrappers --with-openssl-dir=/usr --with-zlib-dir=/usr --enable-mbstring --with-pdo-mysql=/usr --with-xsl=/usr --with-ldap --with-xmlrpc --with-iconv-dir=/usr --with-snmp=/usr --enable-exif --enable-calendar --with-bz2=/usr --with-mcrypt=/usr --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr --enable-mbstring --enable-zip --with-pear --with-config-file-path=/etc/php5 --with-config-file-scan-dir=/etc/php5/conf.d



make

sudo make install


then,

install your php extensions ( apc, mcrypt, pdo, ... )

If unavailable, try:


sudo pecl install pdo


If you have to change your php.ini path, you can use Apache conf Directive :


PHPIniDir /etc/php5/apache2


but with the 'with-config-file-path=/etc/php5' configure option, it will search for /etc/php5/php.ini, so you only have to make a symbolic link between /etc/php5/php.ini /etc/php5/apache2/php.ini

mercredi 16 septembre 2009

Security aware routing in symfony

Hi all,

Bernhard Schussek introduced a very good idea of security aware routing:

use sfRouting to verify owner rights...


Here is my implementation :


// in lib/routing/securePropelRoute.class.php

/**
* secureObjectRoute represents a route that is bound to PHP object(s) which are owned by sfUser.
*
* An object route can represent a single object or a list of objects.
*
* @package symfony
* @subpackage routing
* @author Fabien Potencier
* @version SVN: $Id: sfObjectRoute.class.php 15850 2009-02-27 16:48:19Z fabien $
*/
class securePropelRoute extends sfPropelRoute
{
/**
* Constructor.
*
* @param string $pattern The pattern to match
* @param array $defaults An array of default parameter values
* @param array $requirements An array of requirements for parameters (regexes)
* @param array $options An array of options
*
* @see sfRoute
*/
public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array())
{
parent::__construct($pattern, $defaults, $requirements, $options);
}

public function getObjectAuthorizedFor(sfUser $user) {
parent::getObject();
if(!$this->verifyAccess($user)) {
throw new sfError404Exception(sprintf('Unable to find the %s object for sfUser %s with the following parameters "%s").', $this->options['model'], $user, str_replace("\n", '', var_export($this->filterParameters($this->parameters), true))));
}
return $this->object;
}

public function verifyAccess(sfUser $user) {
return true;
}
}




// in lib/routing/securePropelRouteCollection.class.php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* securePropelRouteCollection represents a collection of routes bound to Propel objects.
*
* @package symfony
* @subpackage routing
* @author Fabien Potencier
* @version SVN: $Id: sfPropelRouteCollection.class.php 12755 2008-11-08 09:48:03Z fabien $
*/
class securePropelRouteCollection extends sfObjectRouteCollection
{
protected
$routeClass = 'securePropelRoute';
}



An exemple of routing definition in /config/routing.yml :



test:
class: securePropelRouteCollection
options:
model: Test
module: test
prefix_path: test
column: id
with_wildcard_routes: true



Voilà !

The only thing you have to do is to customize the securePropelRoute::verifiyAccess method
to fit your needs, by surcharging it with a secureTestRoute class for example...

Let's see an example for the test route:


// in lib/routing/secureTestRoute.class.php

class secureTestRoute extends securePropelRoute
{
public function verifyAccess(sfUser $user) {
return $this->getObject()->getOwnerId() == $user->getId();
}
}




Then, you have to call


$this->getRoute()->getObjectAuthorizedFor($this->getUser())


in your actions.

But we've forgotten sfObjectRoute::getObjects() .... for the next time :)

mercredi 17 juin 2009

Idea: Propel CompositeElement

As ext-js do with Ext.CompositeElementLite,
It maybe would be a good idea to modify multiple objects as if they were one !

I have to work on that...

Propel Collection Object

AS you can see here, BaseObjects collection could be a very usefull functionnality for Propel ( or others ).

Propel dev's are apparently discussing on that, but it will not be implemented before 2.0.

Thats sounds good, so when 2.0 will be out ?!

magic method call for Propel Peer class

It's just an idea, I didn't tested already !!

Not my fault, PHP 5.3 isn't in ubuntu default repositories... ;)




public function __call($name, $args) {
return self::handleCall($name, $args);
}

// As of PHP 5.3
public static function __callStatic($name, $args) {
return self::handleCall($name, $args);
}

private static function handleCall($name, $args) {
if(strstr('doSelectOrderedBy', $name) !== false) {
return self::handleDoSelectOrderedBy($name, $args);
}
throw new Exception('Invalid call : the method ['.$name.'] is not defined in class ['.get_class($this).'].');

}

/**
* Called by magic method __callStatic for adding Ascending or Descending order to Criteria;
*
* Catch method names with pattern : doSelectOderedBy*Asc OR doSelectOderedBy*Desc
* where * is the PHPName of a column.
*
* @param $name The name of method called
*
* @see self::doSelect
* @see Criteria::addAscendingOrderByColumn
* @see Criteria::addDescendingOrderByColumn
*
* @TODO use preg_match ?
* @TODO handle Join with pattern doSelect(Join*)OrderedBy(*)([Asc|Desc])
*
* @return array
*/
private static function handleDoSelectOrderedBy($name, $args) {
$cols = self::fieldKeys;
if(array_key_exists($name, $cols[BasePeer::TYPE_PHPNAME])) {
$c = new Criteria;
$col = substr($name, 17);
$order = substr($col, -4, 4);
$method = sprintf('add%sOrderByColumn', 0 === strpos(strtoupper($order), 'DESC') ? 'Descending' : 'Ascending');
$criteria->$method(call_user_func(array(self, 'translateFieldName'), $col, BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME));
return self::doSelect($c);
}
}