12 * obtain it through the world-wide-web, please send an email |
12 * obtain it through the world-wide-web, please send an email |
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Reflection |
16 * @package Zend_Reflection |
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @version $Id: Method.php 20096 2010-01-06 02:05:09Z bkarwin $ |
19 * @version $Id: Method.php 24870 2012-06-02 02:15:12Z adamlundrigan $ |
20 */ |
20 */ |
21 |
21 |
22 /** |
22 /** |
23 * @see Zend_Reflection_Class |
23 * @see Zend_Reflection_Class |
24 */ |
24 */ |
35 require_once 'Zend/Reflection/Parameter.php'; |
35 require_once 'Zend/Reflection/Parameter.php'; |
36 |
36 |
37 /** |
37 /** |
38 * @category Zend |
38 * @category Zend |
39 * @package Zend_Reflection |
39 * @package Zend_Reflection |
40 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
40 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
41 * @license http://framework.zend.com/license/new-bsd New BSD License |
41 * @license http://framework.zend.com/license/new-bsd New BSD License |
42 */ |
42 */ |
43 class Zend_Reflection_Method extends ReflectionMethod |
43 class Zend_Reflection_Method extends ReflectionMethod |
44 { |
44 { |
45 /** |
45 /** |
143 */ |
143 */ |
144 public function getBody() |
144 public function getBody() |
145 { |
145 { |
146 $lines = array_slice( |
146 $lines = array_slice( |
147 file($this->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES), |
147 file($this->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES), |
148 $this->getStartLine(), |
148 $this->getStartLine()-1, |
149 ($this->getEndLine() - $this->getStartLine()), |
149 ($this->getEndLine() - $this->getStartLine()) + 1, |
150 true |
150 true |
151 ); |
151 ); |
152 |
152 |
153 $firstLine = array_shift($lines); |
153 // Strip off lines until we come to a closing bracket |
|
154 do { |
|
155 if (count($lines) == 0) break; |
|
156 $firstLine = array_shift($lines); |
|
157 } while (strpos($firstLine, ')') === false); |
154 |
158 |
155 if (trim($firstLine) !== '{') { |
159 // If the opening brace isn't on the same line as method |
156 array_unshift($lines, $firstLine); |
160 // signature, then we should pop off more lines until we find it |
|
161 if (strpos($firstLine,'{') === false) { |
|
162 do { |
|
163 if (count($lines) == 0) break; |
|
164 $firstLine = array_shift($lines); |
|
165 } while (strpos($firstLine, '{') === false); |
|
166 } |
|
167 |
|
168 // If there are more characters on the line after the opening brace, |
|
169 // push them back onto the lines stack as they are part of the body |
|
170 $restOfFirstLine = trim(substr($firstLine, strpos($firstLine, '{')+1)); |
|
171 if (!empty($restOfFirstLine)) { |
|
172 array_unshift($lines, $restOfFirstLine); |
157 } |
173 } |
158 |
174 |
159 $lastLine = array_pop($lines); |
175 $lastLine = array_pop($lines); |
160 |
176 |
161 if (trim($lastLine) !== '}') { |
177 // If there are more characters on the line before the closing brace, |
162 array_push($lines, $lastLine); |
178 // push them back onto the lines stack as they are part of the body |
|
179 $restOfLastLine = trim(substr($lastLine, 0, strrpos($lastLine, '}')-1)); |
|
180 if (!empty($restOfLastLine)) { |
|
181 array_push($lines, $restOfLastLine); |
163 } |
182 } |
164 |
183 |
165 // just in case we had code on the bracket lines |
184 // just in case we had code on the bracket lines |
166 return rtrim(ltrim(implode("\n", $lines), '{'), '}'); |
185 return implode("\n", $lines); |
167 } |
186 } |
168 } |
187 } |