| [ 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 class ControllerGenerator extends AkelosGenerator 20 { 21 var $command_values = array('class_name','(array)actions'); 22 var $scaffold = false; 23 24 25 function _preloadPaths() 26 { 27 if(!empty($this->class_name_arg)){ 28 $this->class_name = $this->class_name_arg; 29 } 30 31 $this->class_name = $this->controller_name = $this->class_name_arg = str_replace('::', '/', AkInflector::camelize(preg_replace('/_?controller$/i','',$this->class_name))); 32 33 $this->module_path = ''; 34 35 // Controller inside module 36 if(strstr($this->class_name_arg,'/')){ 37 $module_parts = substr($this->class_name, 0, strrpos($this->class_name_arg, '/')); 38 $this->module_path = join(DS, array_map(array('AkInflector','underscore'), strstr($module_parts, '/') ? explode('/', $module_parts) : array($module_parts))).DS; 39 40 $this->controller_name = substr($this->class_name_arg, strrpos($this->class_name_arg, '/') + 1); 41 $this->underscored_controller_name = $this->module_path.AkInflector::underscore($this->controller_name); 42 $this->controller_path = 'controllers'.DS.$this->underscored_controller_name.'_controller.php'; 43 44 $this->class_name = str_replace('/', '_', $this->class_name_arg); 45 }else{ 46 $this->underscored_controller_name = AkInflector::underscore($this->class_name); 47 $this->controller_path = 'controllers'.DS.$this->underscored_controller_name.'_controller.php'; 48 } 49 50 $this->assignVarToTemplate('class_name', $this->class_name); 51 52 } 53 54 function hasCollisions() 55 { 56 $this->collisions = array(); 57 $this->_preloadPaths(); 58 $this->actions = empty($this->actions) ? array() : (array)$this->actions; 59 60 $files = array( 61 AK_APP_DIR.DS.$this->controller_path, 62 AK_TEST_DIR.DS.'functional'.DS.'app'.DS.$this->controller_path, 63 AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.$this->controller_path, 64 AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'helpers'.DS.$this->underscored_controller_name."_helper.php", 65 AK_HELPERS_DIR.DS.$this->underscored_controller_name."_helper.php" 66 ); 67 68 foreach ($this->actions as $action){ 69 $files[] = AK_VIEWS_DIR.DS.$this->module_path.AkInflector::underscore($this->controller_name).DS.$action.'.tpl'; 70 } 71 72 foreach ($files as $file_name){ 73 if(file_exists($file_name)){ 74 $this->collisions[] = Ak::t('%file_name file already exists',array('%file_name'=>$file_name)); 75 } 76 } 77 return count($this->collisions) > 0; 78 } 79 80 function generate() 81 { 82 $this->_preloadPaths(); 83 84 $this->save(AK_APP_DIR.DS.$this->controller_path, $this->render('controller')); 85 $this->save(AK_HELPERS_DIR.DS.$this->underscored_controller_name."_helper.php", $this->render('helper')); 86 $this->save(AK_TEST_DIR.DS.'functional'.DS.$this->controller_path, $this->render('functional_test')); 87 $this->save(AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.$this->controller_path, $this->render('fixture')); 88 $this->save(AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'helpers'.DS.$this->underscored_controller_name."_helper.php", $this->render('helper_fixture')); 89 90 @Ak::make_dir(AK_VIEWS_DIR.DS.$this->module_path.AkInflector::underscore($this->controller_name)); 91 92 foreach ($this->actions as $action){ 93 //$this->action = $action; 94 $this->assignVarToTemplate('action',$action); 95 $this->assignVarToTemplate('path','AK_VIEWS_DIR.DS.\''.$this->module_path.AkInflector::underscore($this->controller_name).'/'.$action.'.tpl\''); 96 $this->save(AK_VIEWS_DIR.DS.$this->module_path.AkInflector::underscore($this->controller_name).DS.$action.'.tpl', $this->render('view')); 97 } 98 } 99 } 100 101 ?>
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 |