Changeset 18361
- Timestamp:
- 05/17/09 02:49:34 (4 years ago)
- Files:
-
- plugins/sfExtjs3Plugin/trunk/lib/model (added)
- plugins/sfExtjs3Plugin/trunk/lib/model/sfExtjs3Function.class.php (moved) (moved from plugins/sfExtjs3Plugin/trunk/lib/helper/sfExtjs3Function.php) (5 diffs, 1 prop)
- plugins/sfExtjs3Plugin/trunk/lib/model/sfExtjs3Json.class.php (added)
- plugins/sfExtjs3Plugin/trunk/lib/model/sfExtjs3Object.class.php (moved) (moved from plugins/sfExtjs3Plugin/trunk/lib/helper/sfExtjs3Object.class.php) (11 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfExtjs3Plugin/trunk/lib/model/sfExtjs3Function.class.php
- Property svn:mergeinfo set
r18315 r18361 2 2 /** 3 3 * sfExtjs3Function 4 * 4 * 5 5 * Instances of this class can render themself as JavaScript functions 6 6 * … … 11 11 $arguments, 12 12 $content; 13 13 14 14 /** 15 15 * Creates a new JsObject 16 16 * 17 * @param array $arguments 18 * @param string $content17 * @param array $arguments the arguments that this functions should accept 18 * @param mixed $content anything that can be rendered as a string (arrays will be imploded) 19 19 */ 20 20 public function __construct($arguments, $content) … … 24 24 throw new Exception('arguments should be an array'); 25 25 } 26 26 27 27 $this->arguments = $arguments; 28 28 $this->content = $content; 29 29 } 30 30 31 31 /** 32 32 * Renders this function as a js-text … … 36 36 public function render() 37 37 { 38 $content = $this->content; 39 40 // convert array to string by imploding it 41 if (is_array($content)) 42 { 43 $content = implode("\n", $content); 44 } 45 38 46 $js = 'function('; 39 40 47 $js .= implode(', ', $this->arguments); 41 42 48 $js .= ') {'; 43 44 $js .= $this->content; 45 49 if ($content) 50 { 51 $js .= "\n"; 52 } 53 $js .= $content; 54 if ($content) 55 { 56 $js .= "\n"; 57 } 46 58 $js .= '}'; 47 59 48 60 return $js; 49 61 } 50 62 51 63 /** 52 64 * @see render() … … 56 68 return $this->render(); 57 69 } 58 70 59 71 } 60 72 plugins/sfExtjs3Plugin/trunk/lib/model/sfExtjs3Object.class.php
- Property svn:mergeinfo set
r18315 r18361 2 2 /** 3 3 * sfExtjs3Object 4 * 4 * 5 5 * Instances of this class can render themself as JavaScript (definitions and instances) 6 6 * … … 9 9 { 10 10 const FUNCTION_SEPARATOR = ' : '; 11 11 12 12 protected 13 13 $objectName, 14 14 $baseObject, 15 15 $functions = array(); 16 16 17 17 /** 18 18 * Creates a new JsObject 19 19 * 20 * @param string $ namethe name of the new class to be created (can be preceded with dotted namespace21 * @param string $base the base object which this new class should extend22 * @param array $functions an associative array of function-names and the sfExtjs3Function itself 20 * @param string $objectName the name of the new class to be created (can be preceded with dotted namespace 21 * @param string $baseObject the base object which this new class should extend 22 * @param array $functions an associative array of function-names and the sfExtjs3Function itself 23 23 */ 24 24 public function __construct($objectName, $baseObject, $functions = array()) … … 26 26 $this->objectName = trim($objectName); 27 27 $this->baseObject = trim($baseObject); 28 28 29 29 if (!is_array($functions)) 30 30 { … … 33 33 foreach ($functions as $functionName => $function) 34 34 { 35 $this->addFunction($functionName, $function); 35 $this->addFunction($functionName, $function); 36 36 } 37 37 } 38 38 39 39 public function getFunctions() 40 40 { 41 41 return $this->functions; 42 42 } 43 43 44 44 /** 45 45 * Adds a function to the extjs-object … … 54 54 throw new Exception('The function "'.$functionName.'" is already defined for object "'.$this->objectName.'".'); 55 55 } 56 56 57 57 $this->functions[$functionName] = $function; 58 58 } 59 59 60 60 /** 61 61 * returns the name of this object … … 66 66 return $this->objectName; 67 67 } 68 68 69 69 /** 70 70 * renders the construction for a new instance for this object … … 76 76 { 77 77 $args = implode(', ', func_get_args()); 78 78 79 79 $js = 'new '.$this->getName().'('; 80 80 $js .= $args; 81 81 $js .= ')'; 82 82 83 83 return $js; 84 84 } 85 85 86 86 /** 87 87 * Renders the calling of a function for this object … … 97 97 throw new Exception('arguments should be an array'); 98 98 } 99 99 100 100 $js = $this->getName().'.'.$functionName.'('; 101 102 101 $js .= implode(', ', $arguments); 103 104 $js .= ');'; 105 102 $js .= ')'; 103 106 104 return $js; 107 105 } 108 106 109 107 /** 110 108 * text representation of all functions defined for this object … … 115 113 { 116 114 $js = '{'; 117 115 118 116 $functions = $this->getFunctions(); 119 117 if (count($functions)) 120 118 { 121 $firstFunctionName = current(array_keys($functions)); 122 $firstFunction = array_shift($functions); 123 124 $js .= $firstFunctionName.self::FUNCTION_SEPARATOR.$firstFunction; 125 126 foreach ($functions as $functionName => $function) 119 list($firstFunctionName, $firstFunction) = each($functions); 120 121 $js .= "\n".$firstFunctionName.self::FUNCTION_SEPARATOR.$firstFunction; 122 123 while (list($functionName, $function) = each($functions)) 127 124 { 128 $js .= ', '.$functionName.self::FUNCTION_SEPARATOR.$function;125 $js .= ",\n".$functionName.self::FUNCTION_SEPARATOR.$function; 129 126 } 130 131 $js .= ' ';127 128 $js .= "\n"; 132 129 } 133 130 134 131 $js .= '}'; 135 132 136 133 return $js; 137 134 } 138 135 139 136 /** 140 137 * renders the object definition … … 145 142 { 146 143 $js = $this->getName(); 147 144 148 145 $js .= ' = Ext.extend('.$this->baseObject.', '; 149 146 150 147 $js .= $this->renderFunctionDefinitions(); 151 148 152 149 $js .= ');'; 153 150 154 151 return $js; 155 152 } 156 153 157 154 /** 158 155 * @see renderDefinition() … … 162 159 return $this->renderDefinition(); 163 160 } 164 161 165 162 } 166 163