Author: stefbach
Date: 2010-03-09 02:45:50 +0100 (Tue, 09 Mar 2010)
New Revision: 28423

Added:
   
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfValueObjectTemplate.php
   
plugins/sfAmfPlugin/lib/task/generator/doctrine/sfAmfPluginDoctrineValueObjectGenerator.php
   
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelValueObjectGenerator.php
   plugins/sfAmfPlugin/lib/task/sfAmfPluginBuildValueObjectTask.class.php
Modified:
   plugins/sfAmfPlugin/
   
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfServiceTemplate.php
   
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelServiceGenerator.class.php
   plugins/sfAmfPlugin/lib/task/generator/sfAmfPluginGenerator.class.php
Log:
Some refactoring 
+ Renamed function in sfAmfPluginPropelGenerator
+ Added ValueObject generator based on schema
+ Added Doctrine Value Object generator stub



Property changes on: plugins/sfAmfPlugin
___________________________________________________________________
Modified: svk:merge
   - 7ce51a29-67ea-4596-9a32-2e0fcaf8b5e0:/local/symfony/sfAmfPlugin:30
   + 7ce51a29-67ea-4596-9a32-2e0fcaf8b5e0:/local/symfony/sfAmfPlugin:35

Modified: 
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfServiceTemplate.php
===================================================================
--- 
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfServiceTemplate.php
     2010-03-09 00:36:30 UTC (rev 28422)
+++ 
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfServiceTemplate.php
     2010-03-09 01:45:50 UTC (rev 28423)
@@ -6,7 +6,7 @@
  * @package    ##PACKAGE_NAME##
  * @author     ##AUTHOR_NAME##
  */
-class <?php echo $this->table->getClassname() ?>Service extends sfAmfService
+class <?php echo $this->table->getClassname() ?>Service extends <?php echo 
(is_null($this->serviceParent) ? 'sfAmfService' : $this->serviceParent); ?> 
 {
 
 }

Added: 
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfValueObjectTemplate.php
===================================================================
--- 
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfValueObjectTemplate.php
                         (rev 0)
+++ 
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfValueObjectTemplate.php
 2010-03-09 01:45:50 UTC (rev 28423)
@@ -0,0 +1,19 @@
+[?php
+
+/**
+ * <?php echo $this->table->getClassname() ?> value object.
+ *
+ * @package    ##PACKAGE_NAME##
+ * @author     ##AUTHOR_NAME##
+ */
+class <?php echo $this->table->getClassname() ?>ValueObject
+{
+<?php
+$columns = $this->table->getColumns();
+
+foreach ($columns as $column)
+{
+echo '  public $' . lcfirst($column->getPhpName()). ";\n";
+}
+?>
+}


Property changes on: 
plugins/sfAmfPlugin/data/generator/sfAmfPropelService/default/template/sfAmfValueObjectTemplate.php
___________________________________________________________________
Added: svn:mime-type
   + text/x-php
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: 
plugins/sfAmfPlugin/lib/task/generator/doctrine/sfAmfPluginDoctrineValueObjectGenerator.php
===================================================================
--- 
plugins/sfAmfPlugin/lib/task/generator/doctrine/sfAmfPluginDoctrineValueObjectGenerator.php
                         (rev 0)
+++ 
plugins/sfAmfPlugin/lib/task/generator/doctrine/sfAmfPluginDoctrineValueObjectGenerator.php
 2010-03-09 01:45:50 UTC (rev 28423)
@@ -0,0 +1,32 @@
+<?php
+/**
+ * This file is part of the sfAmfPlugin package.
+ * (c) 2008, 2009 Timo Haberkern <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Generator-Class for the generation of AMF-ValueObject class based on 
Doctrine 
+ *
+ * @author Stephane Bachelier (http://blog.0x89b.org)
+ * @copyright Stephane Bachelier
+ * @license MIT
+ * @version SVN: $Id $
+ */
+
+class sfAmfPluginDoctrineValueObjectGenerator extends 
sfAmfPluginDoctrineGenerator
+{
+  public function initialize(sfGeneratorManager $generatorManager)
+  {
+    parent::initialize($generatorManager);
+  }
+
+  public function generateAll()
+  {
+    // TODO
+    throw new sfCommandException("Doctrine generator must be implemented.");
+  }
+
+}


Property changes on: 
plugins/sfAmfPlugin/lib/task/generator/doctrine/sfAmfPluginDoctrineValueObjectGenerator.php
___________________________________________________________________
Added: svn:mime-type
   + text/x-php
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Modified: 
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelServiceGenerator.class.php
===================================================================
--- 
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelServiceGenerator.class.php
   2010-03-09 00:36:30 UTC (rev 28422)
+++ 
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelServiceGenerator.class.php
   2010-03-09 01:45:50 UTC (rev 28423)
@@ -31,8 +31,7 @@
       $this->table = $table;
       $tableClassname = $table->getClassname();
 
-      $serviceName = $tableClassname . 'Service';
-      $serviceFile = $this->getServiceFileName($serviceName);
+      $serviceFile = $this->getAbsoluteFileName($table->getClassname() . 
'Service');
 
       if (file_exists($serviceFile))
       {
@@ -42,10 +41,9 @@
         ));
       }
       
-      file_put_contents($serviceFile, 
+      $this->writeFile($serviceFile, 
         $this->evalTemplate('sfAmfServiceTemplate.php'));
 
-      $this->replaceTokens($serviceFile);
     }
   }
 

Added: 
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelValueObjectGenerator.php
===================================================================
--- 
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelValueObjectGenerator.php
                             (rev 0)
+++ 
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelValueObjectGenerator.php
     2010-03-09 01:45:50 UTC (rev 28423)
@@ -0,0 +1,51 @@
+<?php
+/**
+ * This file is part of the sfAmfPlugin package.
+ * (c) 2008, 2009 Timo Haberkern <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Generator-Class for the generation of AMF-ValueObject class based on Propel 
+ *
+ * @author Stephane Bachelier (http://blog.0x89b.org)
+ * @copyright Stephane Bachelier
+ * @license MIT
+ * @version SVN: $Id $
+ */
+
+class sfAmfPluginPropelValueObjectGenerator extends sfAmfPluginPropelGenerator
+{
+  public function initialize(sfGeneratorManager $generatorManager)
+  {
+    parent::initialize($generatorManager);
+  }
+
+  protected function generateAll()
+  {
+    // generate files for each table
+    foreach ($this->dbMap->getTables() as $tableName => $table)
+    {
+      $this->table = $table;
+      $tableClassname = $table->getClassname();
+
+      $serviceFile = $this->getAbsoluteFileName($table->getClassname(), 
'ValueObject');
+
+      if (file_exists($serviceFile))
+      {
+        throw new sfCommandException(
+          sprintf("ValueObjects already exist in %s directory. You must remove 
them manually",
+          $this->getServiceDirname()
+        ));
+      }
+      
+      file_put_contents($serviceFile, 
+        $this->evalTemplate('sfAmfValueObjectTemplate.php'));
+
+      $this->replaceTokens($serviceFile);
+    }
+  }
+
+}


Property changes on: 
plugins/sfAmfPlugin/lib/task/generator/propel/sfAmfPluginPropelValueObjectGenerator.php
___________________________________________________________________
Added: svn:mime-type
   + text/x-php
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Modified: plugins/sfAmfPlugin/lib/task/generator/sfAmfPluginGenerator.class.php
===================================================================
--- plugins/sfAmfPlugin/lib/task/generator/sfAmfPluginGenerator.class.php       
2010-03-09 00:36:30 UTC (rev 28422)
+++ plugins/sfAmfPlugin/lib/task/generator/sfAmfPluginGenerator.class.php       
2010-03-09 01:45:50 UTC (rev 28423)
@@ -21,6 +21,7 @@
   protected $package = null;
   protected $serviceDirname = null;
   protected $connection = null;
+  protected $serviceParent = null;
 
   /**
    *
@@ -104,19 +105,19 @@
   /**
    *
    */
-  protected function getServiceDirectory()
+  protected function getServiceDirectory($package = null)
   {
     return sfConfig::get('sf_lib_dir') . '/' . 
                     $this->getServiceDirname() . '/' . 
-                    $this->getPackage(true) . '/';
+                    (is_null($package) ? $this->getPackage(true) : $package). 
'/';
   }
 
   /**
    *
    */ 
-  protected function getServiceFileName($serviceName)
+  protected function getAbsoluteFileName($name, $package = null)
   {
-    return $this->getServiceDirectory() . $serviceName . 'Service.class.php';
+    return $this->getServiceDirectory($package) . $name . '.class.php';
   }
 
   /**
@@ -129,4 +130,18 @@
       mkdir($this->getServiceDirectory(), 0777, true); 
     }
   }
+
+  protected function writeFile($file, $template)
+  {
+    if (!file_exists($file))
+    {
+      if (!is_dir($directory = dirname($file)))
+      {
+        mkdir($directory, 0777, true);
+      }
+    }
+
+    file_put_contents($file, $template);
+    $this->replaceTokens($file);
+  }
 }

Added: plugins/sfAmfPlugin/lib/task/sfAmfPluginBuildValueObjectTask.class.php
===================================================================
--- plugins/sfAmfPlugin/lib/task/sfAmfPluginBuildValueObjectTask.class.php      
                        (rev 0)
+++ plugins/sfAmfPlugin/lib/task/sfAmfPluginBuildValueObjectTask.class.php      
2010-03-09 01:45:50 UTC (rev 28423)
@@ -0,0 +1,80 @@
+<?php
+/**
+ * This file is part of the sfAmfPlugin package.
+ * (c) 2008, 2009 Timo Haberkern <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Task-Class for symfony command-line task for the generation of AMF-Service
+ * class from database
+ *
+ * @author Stephane Bachelier (http://blog.0x89b.org)
+ * @copyright Stephane Bachelier
+ * @license MIT
+ * @version SVN: $Id $
+ */
+
+class sfAmfPluginBuildValueObjectTask extends sfBaseTask 
+{
+  /**
+   * @see sfTask
+   */
+  protected function configure()
+  {
+    $this->addOptions(array(
+      new sfCommandOption('connection', '-c', 
sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 
sfConfig::get('sf_orm')),
+      new sfCommandOption('package', '-p', 
sfCommandOption::PARAMETER_REQUIRED, 'Package name (i.e. 
org.symfony.valueobjects)'),
+      new sfCommandOption('service_dir', '-s', 
sfCommandOption::PARAMETER_REQUIRED, 'The service dir name', 'services'),
+    ));
+
+    $this->namespace        = 'amf';
+    $this->name             = 'build-valueobjects';
+    $this->briefDescription = 'Generate value objects based on schema';
+    $this->detailedDescription = <<<EOF
+The amf:build-valueobjects task generates a value object class for each table 
in database 
+
+Call it with:
+
+  [php symfony amf:build-valueobjects|INFO]
+EOF;
+  }
+
+  /**
+   * @see sfTask
+   */
+  protected function execute($arguments = array(), $options = array()) 
+  {
+    $this->logSection($this->namespace, 'generating valueobject classes');
+
+    $generatorManager = new sfGeneratorManager($this->configuration);
+    $generatorManager->generate($this->generatorClass($options['connection']), 
array(
+      'connection'        => $options['connection'],
+      'service_dir'       => $options['service_dir'],
+      'package'           => $options['package'],
+    ));
+
+  }
+
+  /**
+   *
+   */ 
+  private function generatorClass($connection)
+  {
+    switch($connection)
+    {
+      case 'propel':
+        return 'sfAmfPluginPropelValueObjectGenerator';
+
+      case 'doctrine':
+        return 'sfAmfPluginDoctrineValueObjectGenerator';
+
+      default:
+        throw new sfCommandException("Connection is not supported. (Only 
propel or doctrine)");  
+    }
+  }
+    
+}
+    


Property changes on: 
plugins/sfAmfPlugin/lib/task/sfAmfPluginBuildValueObjectTask.class.php
___________________________________________________________________
Added: svn:mime-type
   + text/x-php
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

-- 
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