Skip to content

Component: Throw exception in case of signal method in Component or Presenter is private #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d922d2f
opened 3.1-dev
dg Jan 5, 2020
86f1b9a
requires PHP 7.2
dg Apr 20, 2020
f987965
removed some deprecated stuff
dg Jan 5, 2020
f3c261a
Presenter::getContext() triggers error message
dg Feb 11, 2020
51a31b5
Link: added isLinkCurrent() & getComponent() [Closes #229]
dg Jan 3, 2020
cb0c50b
Template divided into hierarchy Template > DefaultTemplate
dg Mar 4, 2020
7240ddf
Template, DefaultTemplate: magic access via __get/__set replaced with…
dg Mar 4, 2020
9914a49
DefaultTemplate: added default properites and @methods
dg Mar 4, 2020
c76c775
TemplateFactory: sets only properties that exist
dg Mar 4, 2020
07e59f7
TemplateFactory: requires ITemplate instead of Template
dg Mar 28, 2020
960ffa9
Control, Presenter::createTemplate() tries to create custom Template …
dg Jan 4, 2020
9e929df
Control, Presenter::createTemplate() added parameter $class for custo…
solcik Jan 9, 2020
56f3ece
Presenter::sendTemplate() added parameter $template
dg Jan 6, 2020
d3db2a4
UIMacros: overloaded macro {templatePrint}
dg Jan 8, 2020
379a067
interface Nette\Application\IRouter is alias for Nette\Routing\Router
dg Mar 10, 2020
8fb55b0
Route, SimpleRouter: flags is deprecated
dg Mar 10, 2020
0be7c64
RouteList: Countable and IteratorAggregate are deprecated
dg Mar 10, 2020
fac1172
Template: passes the template to the latte instead of just parameters.
dg Mar 31, 2020
1a873c6
UIMacros: modifiers are deprecated in {control}, {link} and {plink}
dg May 26, 2020
9d529b4
Presenter: life-time of flash message is always 30sec
dg Jun 9, 2020
ad470b6
Component: Throw exception in case of signal method in Component or P…
janbarasek Jun 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4']
php: ['7.2', '7.3', '7.4']

fail-fast: false

Expand Down
2 changes: 2 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@
exitPoint(\Nette\Application\UI\Presenter::sendResponse());
exitPoint(\Nette\Application\UI\Presenter::sendTemplate());
exitPoint(\Nette\Application\UI\Presenter::terminate());

override(\Nette\Application\UI\Control::createTemplate(0), map(['' => '@']));
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=7.2",
"nette/component-model": "^3.0",
"nette/http": "^3.0.2",
"nette/routing": "~3.0.0",
Expand All @@ -31,15 +31,15 @@
"nette/forms": "^3.0",
"nette/robot-loader": "^3.2",
"nette/security": "^3.0",
"latte/latte": "^2.6.2",
"latte/latte": "^2.7",
"tracy/tracy": "^2.6",
"mockery/mockery": "^1.0",
"phpstan/phpstan-nette": "^0.12"
},
"conflict": {
"nette/di": "<3.0-stable",
"nette/forms": "<3.0",
"latte/latte": "<2.6",
"latte/latte": "<2.7.1",
"tracy/tracy": "<2.5"
},
"autoload": {
Expand All @@ -52,7 +52,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
"dev-master": "3.1-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Application/MicroPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function run(Application\Request $request): Application\IResponse
public function createTemplate(string $class = null, callable $latteFactory = null): Application\UI\ITemplate
{
$latte = $latteFactory ? $latteFactory() : $this->getContext()->getByType(Nette\Bridges\ApplicationLatte\ILatteFactory::class)->create();
$template = $class ? new $class : new Nette\Bridges\ApplicationLatte\Template($latte);
$template = $class ? new $class : new Nette\Bridges\ApplicationLatte\DefaultTemplate($latte);

$template->setParameters($this->request->getParameters());
$template->presenter = $this;
Expand Down
3 changes: 1 addition & 2 deletions src/Application/Routers/CliRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
namespace Nette\Application\Routers;

use Nette;
use Nette\Application;


/**
* The unidirectional router for CLI. (experimental)
*/
final class CliRouter implements Application\IRouter
final class CliRouter implements Nette\Routing\Router
{
use Nette\SmartObject;

Expand Down
20 changes: 9 additions & 11 deletions src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* The bidirectional route is responsible for mapping
* HTTP request to an array for dispatch and vice-versa.
*/
class Route extends Nette\Routing\Route implements Nette\Application\IRouter
class Route extends Nette\Routing\Route implements Nette\Routing\Router
{
private const
PRESENTER_KEY = 'presenter',
Expand All @@ -40,9 +40,6 @@ class Route extends Nette\Routing\Route implements Nette\Application\IRouter
],
];

/** @deprecated */
public static $styles = [];

/** @var int */
private $flags;

Expand All @@ -69,12 +66,11 @@ public function __construct(string $mask, $metadata = [], int $flags = 0)
];
}

$this->defaultMeta = $this->defaultMeta + self::UI_META;
if (self::$styles) {
trigger_error('Route::$styles is deprecated.', E_USER_DEPRECATED);
array_replace_recursive($this->defaultMeta, self::$styles);
if ($flags) {
trigger_error(__METHOD__ . '() parameter $flags is deprecated, use RouteList::add(..., $flags) instead.', E_USER_DEPRECATED);
}

$this->defaultMeta = $this->defaultMeta + self::UI_META;
$this->flags = $flags;
parent::__construct($mask, $metadata);
}
Expand Down Expand Up @@ -149,11 +145,10 @@ public function getConstantParameters(): array
}


/**
* Returns flags.
*/
/** @deprecated */
public function getFlags(): int
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
return $this->flags;
}

Expand Down Expand Up @@ -210,3 +205,6 @@ public static function path2presenter(string $s): string
return $s;
}
}


interface_exists(Nette\Application\IRouter::class);
11 changes: 9 additions & 2 deletions src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* The router broker.
*/
class RouteList extends Nette\Routing\RouteList implements Nette\Application\IRouter, \ArrayAccess, \Countable, \IteratorAggregate
class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, \ArrayAccess, \Countable, \IteratorAggregate
{
private const PRESENTER_KEY = 'presenter';

Expand Down Expand Up @@ -93,8 +93,10 @@ public function getModule(): ?string
}


/** @deprecated */
public function count(): int
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
return count($this->getRouters());
}

Expand Down Expand Up @@ -132,7 +134,7 @@ public function offsetGet($index)
*/
public function offsetExists($index): bool
{
return is_int($index) && $index >= 0 && $index < $this->count();
return is_int($index) && $index >= 0 && $index < count($this->getRouters());
}


Expand All @@ -149,8 +151,13 @@ public function offsetUnset($index): void
}


/** @deprecated */
public function getIterator(): \ArrayIterator
{
trigger_error(__METHOD__ . '() is deprecated, use getRouters().', E_USER_DEPRECATED);
return new \ArrayIterator($this->getRouters());
}
}


interface_exists(Nette\Application\IRouter::class);
39 changes: 9 additions & 30 deletions src/Application/Routers/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
/**
* The bidirectional route for trivial routing via query parameters.
*/
final class SimpleRouter extends Nette\Routing\SimpleRouter implements Nette\Application\IRouter
final class SimpleRouter extends Nette\Routing\SimpleRouter implements Nette\Routing\Router
{
private const
PRESENTER_KEY = 'presenter',
MODULE_KEY = 'module';

/** @var string */
private $module = '';

/** @var int */
private $flags;

Expand All @@ -43,31 +40,16 @@ public function __construct($defaults = [], int $flags = 0)
}

if (isset($defaults[self::MODULE_KEY])) {
trigger_error(__METHOD__ . '() parameter module is deprecated, use RouteList::withModule() instead.', E_USER_DEPRECATED);
$this->module = $defaults[self::MODULE_KEY] . ':';
unset($defaults[self::MODULE_KEY]);
throw new Nette\DeprecatedException(__METHOD__ . '() parameter module is deprecated, use RouteList::withModule() instead.');
} elseif ($flags) {
trigger_error(__METHOD__ . '() parameter $flags is deprecated, use RouteList::add(..., $flags) instead.', E_USER_DEPRECATED);
}

$this->flags = $flags;
parent::__construct($defaults);
}


/**
* Maps HTTP request to an array.
*/
public function match(Nette\Http\IRequest $httpRequest): ?array
{
$params = parent::match($httpRequest);
$presenter = $params[self::PRESENTER_KEY] ?? null;
if (is_string($presenter)) {
$params[self::PRESENTER_KEY] = $this->module . $presenter;
}

return $params;
}


/**
* Constructs absolute URL from array.
*/
Expand All @@ -76,20 +58,17 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri
if ($this->flags & self::ONE_WAY) {
return null;
}

if (strncmp($params[self::PRESENTER_KEY], $this->module, strlen($this->module)) !== 0) {
return null;
}
$params[self::PRESENTER_KEY] = substr($params[self::PRESENTER_KEY], strlen($this->module));
return parent::constructUrl($params, $refUrl);
}


/**
* Returns flags.
*/
/** @deprecated */
public function getFlags(): int
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
return $this->flags;
}
}


interface_exists(Nette\Application\IRouter::class);
29 changes: 7 additions & 22 deletions src/Application/UI/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ protected function tryCall(string $method, array $params): bool
$rc = $this->getReflection();
if ($rc->hasMethod($method)) {
$rm = $rc->getMethod($method);
if ($rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic()) {
if ($rm->isPublic() === false) {
throw new Nette\InvalidStateException('Method ' . $rm->getName() . '() can not be called because it is private.');
}
if (!$rm->isAbstract() && !$rm->isStatic()) {
$this->checkRequirements($rm);
try {
$args = $rc->combineArgs($rm, $params);
Expand Down Expand Up @@ -199,14 +202,6 @@ final public function getParameterId(string $name): string
}


/** @deprecated */
final public function getParam($name = null, $default = null)
{
trigger_error(__METHOD__ . '() is deprecated; use getParameter() or getParameters() instead.', E_USER_DEPRECATED);
return func_num_args() ? $this->getParameter($name, $default) : $this->getParameters();
}


/********************* interface ISignalReceiver ****************d*g**/


Expand Down Expand Up @@ -287,21 +282,11 @@ public function isLinkCurrent(string $destination = null, $args = []): bool
* @param array|mixed $args
* @throws Nette\Application\AbortException
*/
public function redirect(/*int $code, string */$destination, $args = []): void
public function redirect($destination, $args = []): void
{
if (is_numeric($destination)) {
trigger_error(__METHOD__ . '() first parameter $code is deprecated; use redirectPermanent() for 301 redirect.', E_USER_DEPRECATED);
[$code, $destination, $args] = func_get_args() + [null, null, []];
if (func_num_args() > 3 || !is_array($args)) {
$args = array_slice(func_get_args(), 2);
}
} else {
$code = null;
$args = func_num_args() < 3 && is_array($args) ? $args : array_slice(func_get_args(), 1);
}

$args = func_num_args() < 3 && is_array($args) ? $args : array_slice(func_get_args(), 1);
$presenter = $this->getPresenter();
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'), $code);
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'));
}


Expand Down
27 changes: 24 additions & 3 deletions src/Application/UI/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Control is renderable Presenter component.
*
* @property-read ITemplate|Nette\Bridges\ApplicationLatte\Template|\stdClass $template
* @property-read ITemplate|Nette\Bridges\ApplicationLatte\DefaultTemplate|\stdClass $template
*/
abstract class Control extends Component implements IRenderable
{
Expand Down Expand Up @@ -51,10 +51,31 @@ final public function getTemplate(): ITemplate
}


protected function createTemplate(): ITemplate
/**
* @param string $class
*/
protected function createTemplate(/*string $class = null*/): ITemplate
{
$class = func_num_args() ? func_get_arg(0) : $this->formatTemplateClass(); // back compatibility
$templateFactory = $this->templateFactory ?: $this->getPresenter()->getTemplateFactory();
return $templateFactory->createTemplate($this);
return $templateFactory->createTemplate($this, $class);
}


public function formatTemplateClass(): ?string
{
$class = preg_replace('#Presenter$|Control$#', 'Template', static::class);
if ($class === static::class || !class_exists($class)) {
return null;
} elseif (!is_a($class, ITemplate::class, true)) {
trigger_error(sprintf(
'%s: class %s was found but does not implement the %s, so it will not be used for the template.',
static::class, $class, ITemplate::class
), E_USER_NOTICE);
return null;
} else {
return $class;
}
}


Expand Down
18 changes: 18 additions & 0 deletions src/Application/UI/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function __construct(Component $component, string $destination, array $pa
}


/**
* Returns link component.
*/
public function getComponent(): Component
{
return $this->component;
}


/**
* Returns link destination.
*/
Expand Down Expand Up @@ -80,6 +89,15 @@ public function getParameters(): array
}


/**
* Determines whether this links to the current page.
*/
public function isLinkCurrent(): bool
{
return $this->component->isLinkCurrent($this->destination, $this->params);
}


/**
* Converts link to URL.
*/
Expand Down
Loading