* @copyright Copyright (c) 2008, Christian Kerl * @license http://www.opensource.org/licenses/mit-license.php MIT License * @version SVN: $Id: $ */ /** * TODO: Enter description... * * @package sfRestServicePlugin * @subpackage config * @author Christian Kerl */ class sfRestRoutingConfigHandler extends sfYamlConfigHandler { private static $ACTION_MAP = array('index' => array('url' => '', 'method' => 'GET'), 'show' => array('url' => '/:id', 'method' => 'GET'), 'new' => array('url' => '/new', 'method' => 'GET'), 'create' => array('url' => '', 'method' => 'POST'), 'edit' => array('url' => '/:id/edit', 'method' => 'GET'), 'update' => array('url' => '/:id', 'method' => 'PUT'), 'delete' => array('url' => '/:id', 'method' => 'DELETE')); public function __construct() { } public function execute($configFiles) { $config = self::getConfiguration($configFiles); $data = array(); foreach($config as $controller => $options) { foreach(self::$ACTION_MAP as $name => $default) { $route_name = sprintf('%s_%s', $controller, $name); $url = $options['url'].$default['url']; $parameters = array('module' => $options['module'], 'action' => $name); $requirements = array('id' => '\d', sfConfig::get('sf_method_key') => $default['method']); $data[] = sprintf('$this->connect(\'%s\', \'%s\', %s, %s);', $route_name, $url, var_export($parameters, true), var_export($requirements, true)); } } return sprintf("