| [ 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 ServiceGenerator extends AkelosGenerator 20 { 21 var $command_values = array('api_name'); 22 23 var $api_methods; 24 var $api_method_doc; 25 26 function _preloadPaths() 27 { 28 $this->api_name = AkInflector::camelize($this->api_name); 29 $this->api_class_name = $this->api_name.'Api'; 30 31 $this->assignVarToTemplate('api_class_name', $this->api_class_name); 32 33 $this->service_class_name = $this->api_name.'Service'; 34 $this->assignVarToTemplate('service_class_name', $this->service_class_name); 35 36 $this->api_path = AK_APIS_DIR.DS.AkInflector::underscore($this->api_class_name).'.php'; 37 38 $this->underscored_service_name = AkInflector::underscore($this->api_name); 39 $this->service_path = AK_MODELS_DIR.DS.$this->underscored_service_name.'_service.php'; 40 } 41 42 function hasCollisions() 43 { 44 $this->_preloadPaths(); 45 46 $this->collisions = array(); 47 48 $files = array( 49 $this->service_path 50 ); 51 foreach ($files as $file_name){ 52 if(file_exists($file_name)){ 53 $this->collisions[] = Ak::t('%file_name file already exists',array('%file_name'=>$file_name)); 54 } 55 } 56 return count($this->collisions) > 0; 57 } 58 59 function _loadServiceStructureFromApi() 60 { 61 require_once (AK_LIB_DIR.DS.'AkActionWebService'.DS.'AkActionWebServiceApi.php'); 62 require_once($this->api_path); 63 $Api =& new $this->api_class_name; 64 $api_methods =& $Api->getApiMethods(); 65 $methods = array_keys($api_methods); 66 foreach ($methods as $method_name){ 67 $this->api_methods[$method_name] = $this->_getFunctionParamsAsText($api_methods[$method_name]); 68 $this->_addDocBlock($api_methods[$method_name]); 69 } 70 71 $this->assignVarToTemplate('api_methods', $this->api_methods); 72 $this->assignVarToTemplate('api_method_doc', $this->api_method_doc); 73 } 74 75 function _getFunctionParamsAsText($ApiMethod) 76 { 77 $params = array(); 78 foreach ($ApiMethod->expects as $k=>$param){ 79 $params[] = "\$param_".($k+1)."_as_".$param; 80 } 81 return join(", ", $params); 82 } 83 84 function _addDocBlock($ApiMethod) 85 { 86 $this->api_method_doc[$ApiMethod->name] = !empty($ApiMethod->documentation)? "\n\t* ".$ApiMethod->documentation."\n\t*" : ''; 87 foreach (array('expects', 'returns') as $expects_or_returns){ 88 if(!empty($ApiMethod->{$expects_or_returns})){ 89 //$this->api_method_doc[$ApiMethod->name] .= "\n\t* ".ucfirst($expects_or_returns).":"; 90 foreach ($ApiMethod->{$expects_or_returns} as $k=>$type){ 91 $this->api_method_doc[$ApiMethod->name] .= "\n\t* ".( 92 $expects_or_returns == 'expects' ? 93 '@param param'.($k+1) : '@return ' 94 )." $type"; 95 if(!empty($ApiMethod->{$expects_or_returns.'_documentation'}[$k])){ 96 $this->api_method_doc[$ApiMethod->name] .= ' '.$ApiMethod->{$expects_or_returns.'_documentation'}[$k]; 97 } 98 } 99 $this->api_method_doc[$ApiMethod->name] .= "\n\t* "; 100 } 101 } 102 } 103 104 105 function generate() 106 { 107 $this->_preloadPaths(); 108 109 $this->_loadServiceStructureFromApi(); 110 111 $files = array( 112 'service'=> $this->service_path 113 ); 114 115 foreach ($files as $template=>$file_path){ 116 $this->save($file_path, $this->render($template)); 117 } 118 } 119 120 } 121 122 ?>
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 |