| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package ActiveSupport 13 * @subpackage Generators 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 */ 18 19 20 class ModelGenerator extends AkelosGenerator 21 { 22 var $command_values = array('class_name','(array)table_columns'); 23 24 function _preloadPaths() 25 { 26 $this->class_name = AkInflector::camelize($this->class_name); 27 $this->assignVarToTemplate('class_name', $this->class_name); 28 $this->table_columns = trim(join(' ', (array)@$this->table_columns)); 29 $this->assignVarToTemplate('table_columns', $this->table_columns); 30 $this->table_name = AkInflector::tableize($this->class_name); 31 $this->underscored_model_name = AkInflector::underscore($this->class_name); 32 $this->model_path = 'app'.DS.'models'.DS.$this->underscored_model_name.'.php'; 33 $this->installer_path = 'app'.DS.'installers'.DS.$this->underscored_model_name.'_installer.php'; 34 } 35 36 function hasCollisions() 37 { 38 $this->_preloadPaths(); 39 40 $this->collisions = array(); 41 42 if(AkInflector::is_plural($this->class_name)){ 43 $this->collisions[] = Ak::t('%class_name should be a singular noun',array('%class_name'=>$this->class_name)); 44 } 45 46 $files = array( 47 AkInflector::toModelFilename($this->class_name), 48 AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->underscored_model_name.'.php', 49 AK_TEST_DIR.DS.'fixtures'.DS.$this->model_path, 50 AK_TEST_DIR.DS.'fixtures'.DS.$this->installer_path 51 ); 52 53 foreach ($files as $file_name){ 54 if(file_exists($file_name)){ 55 $this->collisions[] = Ak::t('%file_name file already exists',array('%file_name'=>$file_name)); 56 } 57 } 58 return count($this->collisions) > 0; 59 } 60 61 function generate() 62 { 63 $this->_preloadPaths(); 64 65 $this->class_name = AkInflector::camelize($this->class_name); 66 67 $files = array( 68 'model'=>AkInflector::toModelFilename($this->class_name), 69 'unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->underscored_model_name.'.php', 70 'model_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->model_path, 71 'installer_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->installer_path 72 ); 73 74 foreach ($files as $template=>$file_path){ 75 $this->save($file_path, $this->render($template)); 76 } 77 78 $installer_path = AK_APP_DIR.DS.'installers'.DS.$this->underscored_model_name.'_installer.php'; 79 if(!file_exists($installer_path)){ 80 $this->save($installer_path, $this->render('installer')); 81 } 82 83 $unit_test_runner = AK_TEST_DIR.DS.'unit.php'; 84 if(!file_exists($unit_test_runner)){ 85 Ak::file_put_contents($unit_test_runner, file_get_contents(AK_FRAMEWORK_DIR.DS.'test'.DS.'app.php')); 86 } 87 } 88 89 function cast() 90 { 91 $this->_template_vars['class_name'] = AkInflector::camelize($this->class_name); 92 $this->_template_vars['table_columns'] = (array)@$this->table_columns; 93 } 94 95 } 96 97 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |