Changeset 383
- Timestamp:
- 10/05/07 16:42:09 (1 year ago)
- Files:
-
- trunk/config/locales/en.php (modified) (1 diff)
- trunk/config/locales/es.php (modified) (1 diff)
- trunk/lib/Ak.php (modified) (1 diff)
- trunk/lib/AkActionController.php (modified) (4 diffs)
- trunk/lib/AkRequest.php (modified) (6 diffs)
- trunk/lib/utils/generators/controller/controller_generator.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/locales/en.php
r281 r383 148 148 $dictionary['Could not find the file /app/controllers/<i>%controller_file_name</i> for the controller %controller_class_name'] = 'Could not find the file /app/controllers/<i>%controller_file_name</i> for the controller %controller_class_name'; 149 149 150 $dictionary['No controller was specified.'] = 'No controller was specified.'; 151 152 // 2007-10-05 23:28:22 153 154 155 $dictionary['Please add force=true to the argument list in order to overwrite existing files.'] = 'Please add force=true to the argument list in order to overwrite existing files.'; 156 157 150 158 ?> trunk/config/locales/es.php
r281 r383 142 142 $dictionary['Could not find the file /app/controllers/<i>%controller_file_name</i> for the controller %controller_class_name'] = 'No se ha encontrado el fichero /app/controllers/<i>%controller_file_name</i> del controlador %controller_class_name'; 143 143 144 $dictionary['No controller was specified.'] = 'No se ha especificado ningĂșn controlador.'; 145 146 // 2007-10-05 23:28:22 147 148 149 $dictionary['Please add force=true to the argument list in order to overwrite existing files.'] = 'Please add force=true to the argument list in order to overwrite existing files.'; 150 151 144 152 ?> trunk/lib/Ak.php
r380 r383 1777 1777 $rules = array( 1778 1778 'paranoid' => '/([^A-Z^a-z^0-9^_^-^ ]+)/', 1779 'high' => '/([^A-Z^a-z^0-9^_^-^ ^\/^\\\^:]+)/', 1779 1780 'normal' => '/([^A-Z^a-z^0-9^_^-^ ^\.^\/^\\\]+)/' 1780 1781 ); trunk/lib/AkActionController.php
r359 r383 123 123 var $web_service_api; 124 124 var $web_service_apis = array(); 125 126 var $module_name; 125 127 126 128 /** … … 208 210 require_once(AK_LIB_DIR.DS.'AkActionView.php'); 209 211 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkPhpTemplateHandler.php'); 210 $this->Template =& new AkActionView( AK_APP_DIR.DS.'views'.DS.$this->Request->getController(),212 $this->Template =& new AkActionView($this->_getTemplateBasePath(), 211 213 $this->Request->getParameters(),$this->Request->getController()); 212 214 … … 760 762 { 761 763 $defaults = $this->defaultUrlOptions($options); 764 if(!empty($this->module_name)){ 765 $defaults['module'] = $this->getModuleName(); 766 } 767 if(!empty($options['controller']) && strstr($options['controller'], '/')){ 768 $defaults['module'] = substr($options['controller'], 0, strrpos($options['controller'], '/')); 769 $options['controller'] = substr($options['controller'], strrpos($options['controller'], '/') + 1); 770 } 762 771 $options = !empty($defaults) ? array_merge($defaults, $options) : $options; 763 772 $options['controller'] = empty($options['controller']) ? AkInflector::underscore($this->getControllerName()) : $options['controller']; … … 765 774 } 766 775 767 function &getControllerName()776 function getControllerName() 768 777 { 769 778 770 779 if(!isset($this->controller_name)){ 771 780 $current_class_name = get_class($this); 781 772 782 $included_controllers = $this->_getIncludedControllerNames(); 773 783 $lowercase_included_controllers = array_filter($included_controllers, 'strtolower'); 774 $key = array_search(strtolower($current_class_name), $lowercase_included_controllers,true);775 $found_controller = substr($included_controllers[$key], 0,-10);784 $key = array_search(strtolower($current_class_name), $lowercase_included_controllers, true); 785 $found_controller = substr($included_controllers[$key], 0, -10); 776 786 $this->controller_name = $found_controller; 787 $this->_removeModuleNameFromControllerName(); 777 788 } 778 789 779 790 return $this->controller_name; 780 791 } 781 782 /** 783 * @todo Refactorize transversing dir instead of looking for loaded files (if faster) 792 793 function getModuleName() 794 { 795 return $this->module_name; 796 } 797 798 /** 799 * Removes the modules name from the controller if exists. 800 * 801 * Additionally it sets the default url_options for this controller and the module name scope. 784 802 */ 803 function _removeModuleNameFromControllerName() 804 { 805 if(strstr($this->controller_name, '::')){ 806 $module_parts = substr($this->controller_name, 0, strrpos($this->controller_name, '::')); 807 $this->module_name = join('/', array_map(array('AkInflector','underscore'), strstr($module_parts, '::') ? explode('::', $module_parts) : array($module_parts))); 808 $this->controller_name = substr($this->controller_name, strrpos($this->controller_name, '::')+2); 809 } 810 } 811 812 function _getTemplateBasePath() 813 { 814 return AK_APP_DIR.DS.'views'.DS.(empty($this->_module_path)?'':$this->_module_path).$this->Request->getController(); 815 } 816 785 817 function _getIncludedControllerNames() 786 818 { trunk/lib/AkRequest.php
r364 r383 207 207 if($found = $Router->toParams($ak_request)){ 208 208 if(!isset($found['controller'])){ 209 trigger_error(Ak::t('No controller was specified.'), E_USER_WARNING);209 trigger_error(Ak::t('No controller was specified.'), E_USER_WARNING); 210 210 } 211 211 if(!isset($found['action'])){ 212 trigger_error(Ak::t('No action was specified.'), E_USER_WARNING);212 trigger_error(Ak::t('No action was specified.'), E_USER_WARNING); 213 213 } 214 214 … … 223 223 } 224 224 } 225 225 if(isset($found['module'])){ 226 if($this->_addParam('module',$found['module'])){ 227 $this->module = $this->_request['module'] = $found['module']; 228 } 229 } 230 226 231 foreach ($found as $k=>$v){ 227 232 if($this->_addParam($k,$v)){ … … 241 246 { 242 247 return $this->_validateTechName($action_name); 248 } 249 250 function isValidModuleName($module_name) 251 { 252 return preg_match('/^[A-Za-z]{1,}[A-Za-z0-9_\/]*$/', $module_name); 243 253 } 244 254 … … 658 668 { 659 669 if($variable[0] != '_'){ 660 if(($variable == 'action' && !$this->isValidActionName($value)) || ( $variable == 'controller' && !$this->isValidControllerName($value))){ 670 if( ( $variable == 'action' && !$this->isValidActionName($value)) || 671 ( $variable == 'controller' && !$this->isValidControllerName($value)) || 672 ( $variable == 'module' && !$this->isValidModuleName($value)) 673 ){ 661 674 return false; 662 675 } … … 729 742 730 743 $params = $this->getParams(); 744 745 $module_path = $module_class_peffix = ''; 746 if(!empty($params['module'])){ 747 $module_path = trim(str_replace(array('/','\\'), DS, Ak::sanitize_include($params['module'], 'high')), DS).DS; 748 $module_class_peffix = str_replace(' ','_',AkInflector::titleize(str_replace(DS,' ', trim($module_path, DS)))).'_'; 749 } 750 731 751 $controller_file_name = AkInflector::underscore($params['controller']).'_controller.php'; 732 $controller_class_name = AkInflector::camelize($params['controller']).'Controller';733 $controller_path = AK_CONTROLLERS_DIR.DS.$ controller_file_name;752 $controller_class_name = $module_class_peffix.AkInflector::camelize($params['controller']).'Controller'; 753 $controller_path = AK_CONTROLLERS_DIR.DS.$module_path.$controller_file_name; 734 754 include_once(AK_APP_DIR.DS.'application_controller.php'); 735 755 if(@!include_once($controller_path)){ … … 744 764 } 745 765 $Controller =& new $controller_class_name(array('controller'=>true)); 766 $Controller->_module_path = $module_path; 746 767 isset($_SESSION) ? $Controller->session =& $_SESSION : null; 747 768 return $Controller; trunk/lib/utils/generators/controller/controller_generator.php
r305 r383 25 25 function _preloadPaths() 26 26 { 27 $this->class_name = AkInflector::camelize(preg_replace('/_?controller$/i','',$this->class_name)); 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 28 50 $this->assignVarToTemplate('class_name', $this->class_name); 29 $this->underscored_controller_name = AkInflector::underscore($this->class_name); 30 $this->controller_path = 'controllers'.DS.$this->underscored_controller_name.'_controller.php'; 51 31 52 } 32 53 33 54 function hasCollisions() 34 55 { … … 36 57 $this->_preloadPaths(); 37 58 $this->actions = empty($this->actions) ? array() : (array)$this->actions; 38 59 39 60 $files = array( 40 61 AK_APP_DIR.DS.$this->controller_path, … … 46 67 47 68 foreach ($this->actions as $action){ 48 $files[] = AK_VIEWS_DIR.DS. AkInflector::underscore($this->class_name).DS.$action.'.tpl';69 $files[] = AK_VIEWS_DIR.DS.$this->module_path.AkInflector::underscore($this->controller_name).DS.$action.'.tpl'; 49 70 } 50 71 51 72 foreach ($files as $file_name){ 52 73 if(file_exists($file_name)){ … … 60 81 { 61 82 $this->_preloadPaths(); 62 83 63 84 $this->save(AK_APP_DIR.DS.$this->controller_path, $this->render('controller')); 64 85 $this->save(AK_HELPERS_DIR.DS.$this->underscored_controller_name."_helper.php", $this->render('helper')); … … 66 87 $this->save(AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.$this->controller_path, $this->render('fixture')); 67 88 $this->save(AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'helpers'.DS.$this->underscored_controller_name."_helper.php", $this->render('helper_fixture')); 68 69 @Ak::make_dir(AK_VIEWS_DIR.DS. AkInflector::underscore($this->class_name));70 89 90 @Ak::make_dir(AK_VIEWS_DIR.DS.$this->module_path.AkInflector::underscore($this->controller_name)); 91 71 92 foreach ($this->actions as $action){ 72 93 //$this->action = $action; 73 94 $this->assignVarToTemplate('action',$action); 74 $this->assignVarToTemplate('path','AK_VIEWS_DIR.DS.\''. AkInflector::underscore($this->class_name).'/'.$action.'.tpl\'');75 $this->save(AK_VIEWS_DIR.DS. AkInflector::underscore($this->class_name).DS.$action.'.tpl', $this->render('view'));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')); 76 97 } 77 98 }
