Changeset 13270
- Timestamp:
- 11/23/08 03:43:11 (1 year ago)
- Files:
-
- plugins/sfDoctrinePlugin/trunk/lib/record/sfDoctrineRecord.class.php (modified) (1 diff)
- plugins/sfDoctrinePlugin/trunk/lib/routing/sfDoctrineRoute.class.php (modified) (3 diffs)
- plugins/sfDoctrinePlugin/trunk/lib/task/sfDoctrineBuildFiltersTask.class.php (modified) (3 diffs)
- plugins/sfDoctrinePlugin/trunk/lib/task/sfDoctrineBuildFormsTask.class.php (modified) (6 diffs)
- plugins/sfDoctrinePlugin/trunk/lib/task/sfDoctrineGenerateAdminTask.class.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfDoctrinePlugin/trunk/lib/record/sfDoctrineRecord.class.php
r13217 r13270 111 111 112 112 /** 113 * Function required by symfony >= 1.2 admin generators114 *115 * @return array116 */117 public function toParams()118 {119 return $this->identifier();120 }121 122 /**123 113 * Function require by symfony >= 1.2 admin generators 124 114 * plugins/sfDoctrinePlugin/trunk/lib/routing/sfDoctrineRoute.class.php
r12670 r13270 23 23 class sfDoctrineRoute extends sfObjectRoute 24 24 { 25 protected 26 $query = null; 27 25 28 /** 26 29 * Constructor. … … 38 41 39 42 $this->options['object_model'] = $this->options['model']; 43 } 44 45 public function setListCriteria(Doctrine_Query $query) 46 { 47 if (!$this->isBound()) 48 { 49 throw new LogicException('The route is not bound.'); 50 } 51 52 $this->query = $query; 40 53 } 41 54 … … 75 88 return parent::getObjectsForParameters($parameters); 76 89 } 90 91 protected function doConvertObjectToArray($object) 92 { 93 if (isset($this->options['convert']) || method_exists($object, 'toParams')) 94 { 95 return parent::doConvertObjectToArray($object); 96 } 97 98 $className = $this->options['model']; 99 100 $parameters = array(); 101 102 foreach ($this->getRealVariables() as $variable) 103 { 104 $parameters[$variable] = $object->get($variable); 105 } 106 107 return $parameters; 108 } 77 109 } plugins/sfDoctrinePlugin/trunk/lib/task/sfDoctrineBuildFiltersTask.class.php
r12649 r13270 17 17 * @subpackage doctrine 18 18 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 19 * @version SVN: $Id: sfDoctrineBuildFiltersTask.class.php 1 1675 2008-09-19 15:21:38Z fabien $19 * @version SVN: $Id: sfDoctrineBuildFiltersTask.class.php 12537 2008-11-01 14:43:27Z fabien $ 20 20 */ 21 21 class sfDoctrineBuildFiltersTask extends sfDoctrineBaseTask … … 63 63 { 64 64 $this->logSection('doctrine', 'generating filter form classes'); 65 66 $databaseManager = new sfDatabaseManager($this->configuration); 65 67 66 $generatorManager = new sfGeneratorManager($this->configuration); 68 67 $generatorManager->generate('sfDoctrineFormFilterGenerator', array( … … 71 70 'filter_dir_name' => $options['filter-dir-name'], 72 71 )); 72 73 $properties = parse_ini_file(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'properties.ini', true); 74 75 $constants = array( 76 'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 77 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here' 78 ); 79 80 // customize php and yml files 81 $finder = sfFinder::type('file')->name('*.php'); 82 $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/filter/'), '##', '##', $constants); 73 83 } 74 84 } plugins/sfDoctrinePlugin/trunk/lib/task/sfDoctrineBuildFormsTask.class.php
r12649 r13270 3 3 /* 4 4 * This file is part of the symfony package. 5 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 6 * (c) Jonathan H. Wage <jonwage@gmail.com> 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 7 6 * 8 7 * For the full copyright and license information, please view the LICENSE … … 18 17 * @subpackage doctrine 19 18 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 20 * @author Jonathan H. Wage <jonwage@gmail.com> 21 * @version SVN: $Id: sfDoctrineBuildFormsTask.class.php 8512 2008-04-17 18:06:12Z fabien $ 19 * @version SVN: $Id: sfDoctrineBuildFormsTask.class.php 12537 2008-11-01 14:43:27Z fabien $ 22 20 */ 23 21 class sfDoctrineBuildFormsTask extends sfDoctrineBaseTask … … 35 33 )); 36 34 37 $this->aliases = array('doctrine-build-forms');38 35 $this->namespace = 'doctrine'; 39 36 $this->name = 'build-forms'; … … 45 42 [./symfony doctrine:build-forms|INFO] 46 43 47 The task read the schema information in [config/ doctrine/*.yml|COMMENT] from48 the project and all installed plugins.44 The task read the schema information in [config/*schema.xml|COMMENT] and/or 45 [config/*schema.yml|COMMENT] from the project and all installed plugins. 49 46 50 47 The task use the [doctrine|COMMENT] connection as defined in [config/databases.yml|COMMENT]. 51 48 You can use another connection by using the [--connection|COMMENT] option: 52 49 53 [./symfony doctrine:build-forms frontend--connection="name"|INFO]50 [./symfony doctrine:build-forms --connection="name"|INFO] 54 51 55 The model form classes files are created in [lib/form /doctrine|COMMENT].52 The model form classes files are created in [lib/form|COMMENT]. 56 53 57 This task never overrides custom classes in [lib/form /doctrine|COMMENT].58 It only replaces base classes generated in [lib/form/ doctrine/base|COMMENT].54 This task never overrides custom classes in [lib/form|COMMENT]. 55 It only replaces base classes generated in [lib/form/base|COMMENT]. 59 56 EOF; 60 57 } … … 67 64 $this->logSection('doctrine', 'generating form classes'); 68 65 69 $databaseManager = new sfDatabaseManager($this->configuration);70 71 66 $generatorManager = new sfGeneratorManager($this->configuration); 72 73 67 $generatorManager->generate('sfDoctrineFormGenerator', array( 74 68 'connection' => $options['connection'], … … 76 70 'form_dir_name' => $options['form-dir-name'], 77 71 )); 72 73 $properties = parse_ini_file(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'properties.ini', true); 74 75 $constants = array( 76 'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 77 'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here' 78 ); 79 80 // customize php and yml files 81 $finder = sfFinder::type('file')->name('*.php'); 82 $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/form/'), '##', '##', $constants); 78 83 } 79 84 } plugins/sfDoctrinePlugin/trunk/lib/task/sfDoctrineGenerateAdminTask.class.php
r12634 r13270 28 28 $this->addArguments(array( 29 29 new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), 30 new sfCommandArgument('route ', sfCommandArgument::REQUIRED, 'The route name'),30 new sfCommandArgument('route_or_model', sfCommandArgument::REQUIRED, 'The route name or the model class'), 31 31 )); 32 32 33 33 $this->addOptions(array( 34 new sfCommandOption('module', null, sfCommandOption::PARAMETER_REQUIRED, 'The module name', null), 34 35 new sfCommandOption('theme', null, sfCommandOption::PARAMETER_REQUIRED, 'The theme name', 'admin'), 35 36 new sfCommandOption('singular', null, sfCommandOption::PARAMETER_REQUIRED, 'The singular name', null), … … 45 46 The [doctrine:generate-admin|INFO] task generates a Doctrine admin module: 46 47 48 [./symfony doctrine:generate-admin frontend Article|INFO] 49 50 The task creates a module in the [%frontend%|COMMENT] application for the 51 [%Article%|COMMENT] model. 52 53 The task creates a route for you in the application [routing.yml|COMMENT]. 54 55 You can also generate a Doctrine admin module by passing a route name: 56 47 57 [./symfony doctrine:generate-admin frontend article|INFO] 48 58 … … 50 60 [%article%|COMMENT] route definition found in [routing.yml|COMMENT]. 51 61 52 For the filters to work properly, you need to add a collection route for it: 62 For the filters and batch actions to work properly, you need to add 63 collection routes for them: 53 64 54 article s:65 article: 55 66 class: sfDoctrineRouteCollection 56 67 options: 57 68 model: Article 58 module: article 59 collection_actions: { filter: post } 60 69 collection_actions: { filter: post, batch: post } 61 70 EOF; 62 71 } … … 68 77 { 69 78 // get configuration for the given route 70 $config = new sfRoutingConfigHandler(); 71 $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); 79 if (false !== ($route = $this->getRouteFromName($arguments['route_or_model']))) 80 { 81 $arguments['route'] = $route; 82 $arguments['route_name'] = $arguments['route_or_model']; 72 83 73 if (!isset($routes[$arguments['route']])) 74 { 75 throw new sfCommandException(sprintf('The route "%s" does not exist.', $arguments['route'])); 84 return $this->generateForRoute($arguments, $options); 76 85 } 77 86 78 $routeOptions = $routes[$arguments['route']]->getOptions(); 87 // is it a model class name 88 if (!class_exists($arguments['route_or_model'])) 89 { 90 throw new sfCommandException(sprintf('The route "%s" does not exist and there is no "%s" class.', $arguments['route_or_model'], $arguments['route_or_model'])); 91 } 79 92 80 if (!$routes[$arguments['route']] instanceof sfDoctrineRouteCollection) 93 $r = new ReflectionClass($arguments['route_or_model']); 94 if (!$r->isSubclassOf('Doctrine_Record')) 81 95 { 82 throw new sfCommandException(sprintf('The route "%s" is not a Doctrine collection route.', $arguments['route'])); 96 throw new sfCommandException(sprintf('"%s" is not a Doctrine class.', $arguments['route_or_model'])); 97 } 98 99 // create a route 100 $model = $arguments['route_or_model']; 101 $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model)); 102 103 $routing = sfConfig::get('sf_app_config_dir').'/routing.yml'; 104 $content = file_get_contents($routing); 105 $routesArray = sfYaml::load($content); 106 107 if (!isset($routesArray[$name])) 108 { 109 $module = $options['module'] ? $options['module'] : $name; 110 $content = sprintf(<<<EOF 111 %s: 112 class: sfDoctrineRouteCollection 113 options: 114 model: %s 115 module: %s 116 prefix_path: %s 117 with_wilcard_routes: true 118 119 120 EOF 121 , $name, $model, $module, $module).$content; 122 123 file_put_contents($routing, $content); 124 } 125 126 $arguments['route'] = $this->getRouteFromName($name); 127 $arguments['route_name'] = $name; 128 129 return $this->generateForRoute($arguments, $options); 130 } 131 132 protected function generateForRoute($arguments, $options) 133 { 134 $routeOptions = $arguments['route']->getOptions(); 135 136 if (!$arguments['route'] instanceof sfDoctrineRouteCollection) 137 { 138 throw new sfCommandException(sprintf('The route "%s" is not a Doctrine collection route.', $arguments['route_name'])); 83 139 } 84 140 … … 113 169 return $task->run(array($arguments['application'], $module, $model), $taskOptions); 114 170 } 171 172 protected function getRouteFromName($name) 173 { 174 $config = new sfRoutingConfigHandler(); 175 $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); 176 177 if (isset($routes[$name])) 178 { 179 return $routes[$name]; 180 } 181 182 return false; 183 } 115 184 }

