Skip to content

Commit

Permalink
PresenterComponentReflection β‡’ ComponentReflection
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 25, 2016
1 parent fb12d8d commit d814c54
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 27 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"nette/latte": "<2.4"
},
"autoload": {
"classmap": ["src/"]
"classmap": ["src/"],
"files": ["src/compatibility.php"]
},
"minimum-stability": "dev",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion src/Application/MicroPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function run(Application\Request $request)
$params['presenter'] = $this;
$callback = $params['callback'];
$reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback));
$params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params);
$params = Application\UI\ComponentReflection::combineArgs($reflection, $params);

if ($this->context) {
foreach ($reflection->getParameters() as $param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @property-read string $fileName
* @internal
*/
class PresenterComponentReflection extends \ReflectionClass
class ComponentReflection extends \ReflectionClass
{
use Nette\SmartObject;

Expand Down
4 changes: 2 additions & 2 deletions src/Application/UI/MethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MethodReflection extends \ReflectionMethod
*/
public function hasAnnotation($name)
{
return (bool) PresenterComponentReflection::parseAnnotation($this, $name);
return (bool) ComponentReflection::parseAnnotation($this, $name);
}


Expand All @@ -36,7 +36,7 @@ public function hasAnnotation($name)
*/
public function getAnnotation($name)
{
$res = PresenterComponentReflection::parseAnnotation($this, $name);
$res = ComponentReflection::parseAnnotation($this, $name);
return $res ? end($res) : NULL;
}

Expand Down
14 changes: 7 additions & 7 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected function shutdown($response)
*/
public function checkRequirements($element)
{
$user = (array) PresenterComponentReflection::parseAnnotation($element, 'User');
$user = (array) ComponentReflection::parseAnnotation($element, 'User');
if (in_array('loggedIn', $user, TRUE) && !$this->getUser()->isLoggedIn()) {
throw new Application\ForbiddenRequestException;
}
Expand Down Expand Up @@ -855,7 +855,7 @@ protected function createRequest($component, $destination, array $args, $mode)

// PROCESS SIGNAL ARGUMENTS
if (isset($signal)) { // $component must be IStatePersistent
$reflection = new PresenterComponentReflection(get_class($component));
$reflection = new ComponentReflection(get_class($component));
if ($signal === 'this') { // means "no signal"
$signal = '';
if (array_key_exists(0, $args)) {
Expand Down Expand Up @@ -894,7 +894,7 @@ protected function createRequest($component, $destination, array $args, $mode)

$current = ($action === '*' || strcasecmp($action, $this->action) === 0) && $presenterClass === get_class($this);

$reflection = new PresenterComponentReflection($presenterClass);
$reflection = new ComponentReflection($presenterClass);

// counterpart of run() & tryCall()
$method = $presenterClass::formatActionMethod($action);
Expand Down Expand Up @@ -1005,7 +1005,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
$i = 0;
$rm = new \ReflectionMethod($class, $method);
foreach ($rm->getParameters() as $param) {
list($type, $isClass) = PresenterComponentReflection::getParameterType($param);
list($type, $isClass) = ComponentReflection::getParameterType($param);
$name = $param->getName();

if (array_key_exists($i, $args)) {
Expand All @@ -1027,7 +1027,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
throw new InvalidLinkException("Missing parameter \$$name required by $class::{$rm->getName()}()");
}

if (!PresenterComponentReflection::convertType($args[$name], $type, $isClass)) {
if (!ComponentReflection::convertType($args[$name], $type, $isClass)) {
throw new InvalidLinkException(sprintf(
'Argument $%s passed to %s() must be %s, %s given.',
$name,
Expand Down Expand Up @@ -1119,7 +1119,7 @@ public function restoreRequest($key)
*/
public static function getPersistentComponents()
{
return (array) PresenterComponentReflection::parseAnnotation(new \ReflectionClass(get_called_class()), 'persistent');
return (array) ComponentReflection::parseAnnotation(new \ReflectionClass(get_called_class()), 'persistent');
}


Expand All @@ -1139,7 +1139,7 @@ protected function getGlobalState($forClass = NULL)
$state[$prefix . $key] = $val;
}
}
$this->saveState($state, $forClass ? new PresenterComponentReflection($forClass) : NULL);
$this->saveState($state, $forClass ? new ComponentReflection($forClass) : NULL);

if ($sinces === NULL) {
$sinces = [];
Expand Down
10 changes: 5 additions & 5 deletions src/Application/UI/PresenterComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public function checkRequirements($element)

/**
* Access to reflection.
* @return PresenterComponentReflection
* @return ComponentReflection
*/
public static function getReflection()
{
return new PresenterComponentReflection(get_called_class());
return new ComponentReflection(get_called_class());
}


Expand Down Expand Up @@ -151,7 +151,7 @@ public function loadState(array $params)
/**
* Saves state informations for next request.
* @param array
* @param PresenterComponentReflection (internal, used by Presenter)
* @param ComponentReflection (internal, used by Presenter)
* @return void
*/
public function saveState(array & $params, $reflection = NULL)
Expand All @@ -173,7 +173,7 @@ public function saveState(array & $params, $reflection = NULL)
}

$type = gettype($meta['def']);
if (!PresenterComponentReflection::convertType($params[$name], $type)) {
if (!ComponentReflection::convertType($params[$name], $type)) {
throw new InvalidLinkException(sprintf(
"Value passed to persistent parameter '%s' in %s must be %s, %s given.",
$name,
Expand Down Expand Up @@ -247,7 +247,7 @@ public static function getPersistentParams()
$rc = new \ReflectionClass(get_called_class());
$params = [];
foreach ($rc->getProperties(\ReflectionProperty::IS_PUBLIC) as $rp) {
if (!$rp->isStatic() && PresenterComponentReflection::parseAnnotation($rp, 'persistent')) {
if (!$rp->isStatic() && ComponentReflection::parseAnnotation($rp, 'persistent')) {
$params[] = $rp->getName();
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/compatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

class_alias('Nette\Application\UI\ComponentReflection', 'Nette\Application\UI\PresenterComponentReflection');
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

/**
* Test: PresenterComponentReflection::combineArgs()
* Test: ComponentReflection::combineArgs()
* @phpVersion 7
*/

use Nette\Application\UI\PresenterComponentReflection as Reflection;
use Nette\Application\UI\ComponentReflection as Reflection;
use Nette\Application\BadRequestException;
use Tester\Assert;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* Test: PresenterComponentReflection::combineArgs()
* Test: ComponentReflection::combineArgs()
*/

use Nette\Application\UI\PresenterComponentReflection as Reflection;
use Nette\Application\UI\ComponentReflection as Reflection;
use Nette\Application\BadRequestException;
use Tester\Assert;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* Test: PresenterComponentReflection::convertType()
* Test: ComponentReflection::convertType()
*/

use Nette\Application\UI\PresenterComponentReflection;
use Nette\Application\UI\ComponentReflection;
use Tester\Assert;


Expand All @@ -23,10 +23,10 @@ function testIt($type, $val, $res = NULL)
{
$isClass = class_exists($type);
if (func_num_args() === 3) {
Assert::true(PresenterComponentReflection::convertType($val, $type, $isClass));
Assert::true(ComponentReflection::convertType($val, $type, $isClass));
} else {
$res = $val;
Assert::false(PresenterComponentReflection::convertType($val, $type, $isClass));
Assert::false(ComponentReflection::convertType($val, $type, $isClass));
}
Assert::same($res, $val);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* Test: PresenterComponentReflection annotation parser.
* Test: ComponentReflection annotation parser.
*/

use Nette\Application\UI\PresenterComponentReflection as Reflection;
use Nette\Application\UI\ComponentReflection as Reflection;
use Tester\Assert;


Expand Down

0 comments on commit d814c54

Please sign in to comment.