Author: KRavEN
Date: 2010-05-13 21:37:11 +0200 (Thu, 13 May 2010)
New Revision: 29445

Modified:
   plugins/ExtjsGeneratorPlugin/trunk/lib/task/ExtjsGenerateAdminTask.class.php
Log:
Updated generate-admin task with new route collection class.

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/lib/task/ExtjsGenerateAdminTask.class.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/lib/task/ExtjsGenerateAdminTask.class.php    
    2010-05-13 19:26:46 UTC (rev 29444)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/lib/task/ExtjsGenerateAdminTask.class.php    
    2010-05-13 19:37:11 UTC (rev 29445)
@@ -61,6 +61,77 @@
 EOF;
   }
 
+  /**
+   * @see sfTask
+   */
+  protected function execute($arguments = array(), $options = array())
+  {
+    // get configuration for the given route
+    if (false !== ($route = 
$this->getRouteFromName($arguments['route_or_model'])))
+    {
+      $arguments['route'] = $route;
+      $arguments['route_name'] = $arguments['route_or_model'];
+
+      return $this->generateForRoute($arguments, $options);
+    }
+
+    // is it a model class name
+    if (!class_exists($arguments['route_or_model']))
+    {
+      throw new sfCommandException(sprintf('The route "%s" does not exist and 
there is no "%s" class.', $arguments['route_or_model'], 
$arguments['route_or_model']));
+    }
+
+    $r = new ReflectionClass($arguments['route_or_model']);
+    if (!$r->isSubclassOf('BaseObject'))
+    {
+      throw new sfCommandException(sprintf('"%s" is not a Propel class.', 
$arguments['route_or_model']));
+    }
+
+    // create a route
+    $model = $arguments['route_or_model'];
+    $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', 
'/([a-z\d])([A-Z])/'), '\\1_\\2', $model));
+
+    if (isset($options['module']))
+    {
+      $route = $this->getRouteFromName($name);
+      if ($route && !$this->checkRoute($route, $model, $options['module']))
+      {
+        $name .= '_'.$options['module'];
+      }
+    }
+
+    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml';
+    $content = file_get_contents($routing);
+    $routesArray = sfYaml::load($content);
+
+    if (!isset($routesArray[$name]))
+    {
+      $primaryKey = $this->getPrimaryKey($model);
+      $module = $options['module'] ? $options['module'] : $name;
+      $content = sprintf(<<<EOF
+%s:
+  class: ExtjsPropel15RouteCollection
+  options:
+    model:                %s
+    module:               %s
+    prefix_path:          /%s
+    column:               %s
+    with_wildcard_routes: true
+
+
+EOF
+      , $name, $model, $module, isset($options['plural']) ? $options['plural'] 
: $module, $primaryKey).$content;
+
+      $this->logSection('file+', $routing);
+      file_put_contents($routing, $content);
+    }
+
+    $arguments['route'] = $this->getRouteFromName($name);
+    $arguments['route_name'] = $name;
+
+    return $this->generateForRoute($arguments, $options);
+  }
+  
   protected function generateForRoute($arguments, $options)
   {
     $routeOptions = $arguments['route']->getOptions();
@@ -91,4 +162,24 @@
       'actions-base-class'    => $options['actions-base-class'],
     ));
   }
+  
+  /**
+   * Checks whether a route references a model and module.
+   *
+   * @param mixed  $route  A route collection
+   * @param string $model  A model name
+   * @param string $module A module name
+   *
+   * @return boolean
+   */
+  protected function checkRoute($route, $model, $module)
+  {
+    if ($route instanceof ExtjsPropel15RouteCollection)
+    {
+      $options = $route->getOptions();
+      return $model == $options['model'] && $module == $options['module'];
+    }
+
+    return false;
+  }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to