Skip to content

Commit 7ee1327

Browse files
committed
Merge pull request #91 from dg/reflection
Removing nette/reflection [WIP]
2 parents a4fc407 + 2bfb38b commit 7ee1327

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

src/Application/MicroPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function run(Application\Request $request)
7878

7979
if ($this->context) {
8080
foreach ($reflection->getParameters() as $param) {
81-
if ($param->getClassName()) {
81+
if ($param->getClass()) {
8282
unset($params[$param->getPosition()]);
8383
}
8484
}

src/Application/UI/Presenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function run(Application\Request $request)
176176
}
177177

178178
$this->initGlobalParameters();
179-
$this->checkRequirements($this->getReflection());
179+
$this->checkRequirements(new \ReflectionClass($this));
180180
$this->startup();
181181
if (!$this->startupCheck) {
182182
$class = $this->getReflection()->getMethod('startup')->getDeclaringClass()->getName();

src/Application/UI/PresenterComponentReflection.php

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99

1010
use Nette;
1111
use Nette\Application\BadRequestException;
12+
use Nette\Reflection\ClassType;
13+
use Nette\Reflection\Method;
1214

1315

1416
/**
1517
* Helpers for Presenter & PresenterComponent.
18+
* @property-read string $name
19+
* @property-read string $fileName
1620
* @internal
1721
*/
18-
class PresenterComponentReflection extends Nette\Reflection\ClassType
22+
class PresenterComponentReflection extends \ReflectionClass
1923
{
24+
use Nette\SmartObject;
25+
2026
/** @var array getPersistentParams cache */
2127
private static $ppCache = [];
2228

@@ -229,4 +235,76 @@ public static function getParameterType(\ReflectionParameter $param)
229235
}
230236
}
231237

238+
239+
/********************* compatiblity with Nette\Reflection ****************d*g**/
240+
241+
242+
public function getMethod($name)
243+
{
244+
return new MethodCompatibility($this->getName(), $name);
245+
}
246+
247+
248+
public function getMethods($filter = -1)
249+
{
250+
foreach ($res = parent::getMethods($filter) as $key => $val) {
251+
$res[$key] = new MethodCompatibility($this->getName(), $val->getName());
252+
}
253+
return $res;
254+
}
255+
256+
257+
public function __toString()
258+
{
259+
trigger_error(__METHOD__ . ' is deprecated.', E_USER_DEPRECATED);
260+
return $this->getName();
261+
}
262+
263+
264+
public function __get($name)
265+
{
266+
trigger_error("getReflection()->$name is deprecated.", E_USER_DEPRECATED);
267+
return (new ClassType($this->getName()))->$name;
268+
}
269+
270+
271+
public function __call($name, $args)
272+
{
273+
if (method_exists(ClassType::class, $name)) {
274+
trigger_error("getReflection()->$name() is deprecated, use Nette\\Reflection\\ClassType::from(\$presenter)->$name()", E_USER_DEPRECATED);
275+
return call_user_func_array([new ClassType($this->getName()), $name], $args);
276+
}
277+
Nette\Utils\ObjectMixin::strictCall(get_class($this), $name);
278+
}
279+
280+
}
281+
282+
283+
/**
284+
* @internal
285+
*/
286+
class MethodCompatibility extends \ReflectionMethod
287+
{
288+
use Nette\SmartObject;
289+
290+
public function __toString()
291+
{
292+
trigger_error(__METHOD__ . ' is deprecated.', E_USER_DEPRECATED);
293+
return parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
294+
}
295+
296+
297+
public function __get($name)
298+
{
299+
trigger_error("getMethod('{$this->getName()}')->$name is deprecated.", E_USER_DEPRECATED);
300+
return (new Method(parent::getDeclaringClass()->getName(), $this->getName()))->$name;
301+
}
302+
303+
304+
public function __call($name, $args)
305+
{
306+
trigger_error("getMethod('{$this->getName()}')->$name() is deprecated, use Nette\\Reflection\\Method::from(\$presenter, '{$this->getName()}')->$name()", E_USER_DEPRECATED);
307+
return call_user_func_array([new Method(parent::getDeclaringClass()->getName(), $this->getName()), $name], $args);
308+
}
309+
232310
}

0 commit comments

Comments
 (0)