source: pro-bachkim-filespace/sourcecode/api.violet.vn/www/plugins/sfPropel13Plugin/data/tasks/sfPakePropel13CrudGenerator.php @ 72

Last change on this file since 72 was 19, checked in by dungnv, 11 years ago
File size: 4.4 KB
Line 
1<?php
2/*
3 * This file is part of the sfPropel13Plugin package.
4 * (c) 2007 Joshua May <notjosh@gmail.com>
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 */
9
10/**
11 * @package    symfony.plugins
12 * @subpackage sfPropel13Plugin
13 * @author     Joshua May <notjosh@gmail.com>
14 * @version    SVN: $Id$
15 */
16
17pake_desc('initialize a new propel CRUD module');
18pake_task('propel-13-init-crud', 'app_exists');
19
20pake_desc('generate a new propel CRUD module');
21pake_task('propel-13-generate-crud', 'app_exists');
22
23function run_propel_13_init_crud($task, $args)
24{
25//  run_propel_init_crud($task, $args);
26
27
28
29
30  if (count($args) < 2)
31  {
32    throw new Exception('You must provide your module name.');
33  }
34
35  if (count($args) < 3)
36  {
37    throw new Exception('You must provide your model class name.');
38  }
39
40  $app         = $args[0];
41  $module      = $args[1];
42  $model_class = $args[2];
43
44  try
45  {
46    $author_name = $task->get_property('author', 'symfony');
47  }
48  catch (pakeException $e)
49  {
50    $author_name = 'Your name here';
51  }
52
53  $constants = array(
54    'PROJECT_NAME' => $task->get_property('name', 'symfony'),
55    'APP_NAME'     => $app,
56    'MODULE_NAME'  => $module,
57    'MODEL_CLASS'  => $model_class,
58    'AUTHOR_NAME'  => $author_name,
59  );
60
61  $sf_root_dir = sfConfig::get('sf_root_dir');
62  $moduleDir   = $sf_root_dir.'/'.sfConfig::get('sf_apps_dir_name').'/'.$app.'/'.sfConfig::get('sf_app_module_dir_name').'/'.$module;
63
64  // create basic application structure
65  $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
66 
67  $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . '/generator/sfPropelCrud/default/skeleton';
68  $dir = realpath($dir);
69 
70  pake_mirror($finder, $dir, $moduleDir);
71
72  // create basic test
73  pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/module/test/actionsTest.php', $sf_root_dir.'/test/functional/'.$app.'/'.$module.'ActionsTest.php');
74
75  // customize test file
76  pake_replace_tokens($module.'ActionsTest.php', $sf_root_dir.'/test/functional/'.$app, '##', '##', $constants);
77
78  // customize php and yml files
79  $finder = pakeFinder::type('file')->name('*.php', '*.yml');
80  pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
81}
82
83function run_propel_13_generate_crud($task, $args)
84{
85  _init_db_path();
86
87  if (count($args) < 2)
88  {
89    throw new Exception('You must provide your module name.');
90  }
91
92  if (count($args) < 3)
93  {
94    throw new Exception('You must provide your model class name.');
95  }
96
97  $theme = isset($args[3]) ? $args[3] : 'default';
98
99  $app         = $args[0];
100  $module      = $args[1];
101  $model_class = $args[2];
102
103  $sf_root_dir = sfConfig::get('sf_root_dir');
104
105  // generate module
106  $tmp_dir = $sf_root_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.md5(uniqid(rand(), true));
107  sfConfig::set('sf_module_cache_dir', $tmp_dir);
108  $generator_manager = new sfGeneratorManager();
109  $generator_manager->initialize();
110  $generator_manager->generate('sfPropel13CrudGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme));
111
112  $moduleDir = $sf_root_dir.'/'.sfConfig::get('sf_apps_dir_name').'/'.$app.'/'.sfConfig::get('sf_app_module_dir_name').'/'.$module;
113
114  // copy our generated module
115  $finder = pakeFinder::type('any');
116  pake_mirror($finder, $tmp_dir.'/auto'.ucfirst($module), $moduleDir);
117
118  // change module name
119  pake_replace_tokens($moduleDir.'/actions/actions.class.php', getcwd(), '', '', array('auto'.ucfirst($module) => $module));
120
121  try
122  {
123    $author_name = $task->get_property('author', 'symfony');
124  }
125  catch (pakeException $e)
126  {
127    $author_name = 'Your name here';
128  }
129
130  $constants = array(
131    'PROJECT_NAME' => $task->get_property('name', 'symfony'),
132    'APP_NAME'     => $app,
133    'MODULE_NAME'  => $module,
134    'MODEL_CLASS'  => $model_class,
135    'AUTHOR_NAME'  => $author_name,
136  );
137
138  // customize php and yml files
139  $finder = pakeFinder::type('file')->name('*.php', '*.yml');
140  pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
141
142  // create basic test
143  pake_copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/module/test/actionsTest.php', $sf_root_dir.'/test/functional/'.$app.'/'.$module.'ActionsTest.php');
144
145  // customize test file
146  pake_replace_tokens($module.'ActionsTest.php', $sf_root_dir.'/test/functional/'.$app, '##', '##', $constants);
147
148  // delete temp files
149  $finder = pakeFinder::type('any');
150  pake_remove($finder, $tmp_dir);
151}
Note: See TracBrowser for help on using the repository browser.