Skip to content
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

Latte bridge: add block rendering support #326

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7eae7a7
tests: simplified tests
dg Apr 6, 2024
a795f73
Control::flashMessage() enhanced type hint
dg Mar 18, 2024
e742568
Revert "ApplicationExtension: $catchExceptions can be '4xx' in additi…
dg Mar 27, 2024
6833458
Latte: |modifyDate moved to UIExtension
dg Apr 6, 2024
436fd04
Latte: removed error message for missing |translate
dg Apr 6, 2024
0c58435
Latte: CacheExtension & FormExtension are added before user extension…
dg Apr 6, 2024
f6d36ec
Latte: UIExtension is added before user extensions if $control is pas…
dg Oct 11, 2023
863eb7d
opened 4.0-dev
dg Dec 14, 2023
e785bc9
removed support for Latte 2
dg Apr 6, 2024
9fc5371
removed compatibility for old class names
dg Oct 15, 2021
a49deb7
added type hints (BC break)
dg Feb 8, 2024
7787aff
RouteList: array access is deprecated
dg Oct 15, 2021
8a01270
Revert "UI\PresenterComponent: removed references created by loadStat…
dg Oct 24, 2022
9f9e96a
Component: only UI components can be added to presenter/component (BC…
dg Sep 12, 2021
d0b663e
deprecated magic properties except for $template & $payload (BC break)
dg Sep 24, 2021
6638156
Component::link() & etc uses variadic parameter
dg Oct 19, 2021
050427f
Component::getParameter() $default is deprecated
dg Jun 21, 2022
0ee3273
Presenter: removed constructor (BC break!)
dg Dec 11, 2023
f2026a8
@annotations are deprecated (BC break)
dg Apr 6, 2024
7b63393
LatteFactory: $control is passed to create() (BC break)
dg Apr 6, 2024
2dddce7
uses nette/routing 4.0
dg Jan 21, 2024
488ccc6
LatteExtension: added option 'variables'
dg Jan 9, 2023
e0ef23e
Latte bridge: add block rendering support
Apr 7, 2024
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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"nette/forms": "^3.2",
"nette/robot-loader": "^4.0",
"nette/security": "^3.2",
"latte/latte": "^2.10.2 || ^3.0.12",
"latte/latte": "^3.0.12",
"tracy/tracy": "^2.9",
"mockery/mockery": "^1.6",
"phpstan/phpstan-nette": "^1.0",
Expand All @@ -42,7 +42,7 @@
"nette/di": "<3.2",
"nette/forms": "<3.2",
"nette/schema": "<1.3",
"latte/latte": "<2.7.1 || >=3.0.0 <3.0.12 || >=3.1",
"latte/latte": "<3.0.12",
"tracy/tracy": "<2.9"
},
"autoload": {
Expand All @@ -55,7 +55,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "4.0-dev"
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Nette Application MVC
=====================

[![Downloads this Month](https://img.shields.io/packagist/dm/nette/application.svg)](https://packagist.org/packages/nette/application)
[![Tests](https://github.com/nette/application/actions/workflows/tests.yml/badge.svg?branch=v3.2)](https://github.com/nette/application/actions)
[![Tests](https://github.com/nette/application/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/nette/application/actions)
[![Latest Stable Version](https://poser.pugx.org/nette/application/v/stable)](https://github.com/nette/application/releases)
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/application/blob/master/license.md)

Expand Down
10 changes: 5 additions & 5 deletions src/Application/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
/**
* Presenter request.
*
* @property string $presenterName
* @property array $parameters
* @property array $post
* @property array $files
* @property string|null $method
* @property-deprecated string $presenterName
* @property-deprecated array $parameters
* @property-deprecated array $post
* @property-deprecated array $files
* @property-deprecated string|null $method
*/
final class Request
{
Expand Down
3 changes: 0 additions & 3 deletions src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,3 @@ public static function path2presenter(string $s): string
return $s;
}
}


interface_exists(Nette\Application\IRouter::class);
17 changes: 12 additions & 5 deletions src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function addRoute(
#[Language('TEXT')]
string $mask,
array|string|\Closure $metadata = [],
int|bool $oneWay = 0,
bool $oneWay = false,
): static
{
$this->add(new Route($mask, $metadata), (int) $oneWay);
$this->add(new Route($mask, $metadata), $oneWay);
return $this;
}

Expand All @@ -95,6 +95,13 @@ public function getModule(): ?string
*/
public function offsetSet($index, $router): void
{
if ($router instanceof Route) {
trigger_error('Usage `$router[] = new Route(...)` is deprecated, use `$router->addRoute(...)`.', E_USER_DEPRECATED);
} else {
$class = getclass($router);
trigger_error("Usage `\$router[] = new $class` is deprecated, use `\$router->add(new $class)`.", E_USER_DEPRECATED);
}

if ($index === null) {
$this->add($router);
} else {
Expand All @@ -109,6 +116,7 @@ public function offsetSet($index, $router): void
*/
public function offsetGet($index): Nette\Routing\Router
{
trigger_error('Usage `$route = $router[...]` is deprecated, use `$router->getRouters()`.', E_USER_DEPRECATED);
if (!$this->offsetExists($index)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
}
Expand All @@ -122,6 +130,7 @@ public function offsetGet($index): Nette\Routing\Router
*/
public function offsetExists($index): bool
{
trigger_error('Usage `isset($router[...])` is deprecated.', E_USER_DEPRECATED);
return is_int($index) && $index >= 0 && $index < count($this->getRouters());
}

Expand All @@ -132,13 +141,11 @@ public function offsetExists($index): bool
*/
public function offsetUnset($index): void
{
trigger_error('Usage `unset($router[$index])` is deprecated, use `$router->modify($index, null)`.', E_USER_DEPRECATED);
if (!$this->offsetExists($index)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
}

$this->modify($index, null);
}
}


interface_exists(Nette\Application\IRouter::class);
3 changes: 0 additions & 3 deletions src/Application/Routers/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,3 @@ public function __construct(array|string $defaults = [])
parent::__construct($defaults);
}
}


interface_exists(Nette\Application\IRouter::class);
78 changes: 39 additions & 39 deletions src/Application/UI/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* other child components, and interact with user. Components have properties
* for storing their status, and responds to user command.
*
* @property-read Presenter $presenter
* @property-read bool $linkCurrent
* @property-deprecated Presenter $presenter
* @property-deprecated bool $linkCurrent
*/
abstract class Component extends Nette\ComponentModel\Container implements SignalReceiver, StatePersistent, \ArrayAccess
{
Expand Down Expand Up @@ -71,15 +71,17 @@ public function getUniqueId(): string
}


protected function createComponent(string $name): ?Nette\ComponentModel\IComponent
public function addComponent(
Nette\ComponentModel\IComponent $component,
?string $name,
?string $insertBefore = null,
): static
{
$res = parent::createComponent($name);
if ($res && !$res instanceof SignalReceiver && !$res instanceof StatePersistent) {
$type = $res::class;
trigger_error("It seems that component '$name' of type $type is not intended to be used in the Presenter.");
if (!$component instanceof SignalReceiver && !$component instanceof StatePersistent) {
throw new Nette\InvalidStateException("Component '$name' of type " . get_debug_type($component) . ' is not intended to be used in the Presenter.');
}

return $res;
return parent::addComponent($component, $name, $insertBefore = null);
}


Expand Down Expand Up @@ -165,9 +167,9 @@ public function loadState(array $params): void
));
}

$this->$name = $params[$name];
$this->$name = &$params[$name];
} else {
$params[$name] = $this->$name ?? null;
$params[$name] = &$this->$name;
}
}

Expand All @@ -190,6 +192,7 @@ public function saveState(array &$params): void
final public function getParameter(string $name): mixed
{
if (func_num_args() > 1) {
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
$default = func_get_arg(1);
}
return $this->params[$name] ?? $default ?? null;
Expand All @@ -201,7 +204,7 @@ final public function getParameter(string $name): mixed
*/
final public function getParameters(): array
{
return $this->params;
return array_map(fn($item) => $item, $this->params);
}


Expand Down Expand Up @@ -246,15 +249,15 @@ public static function formatSignalMethod(string $signal): string
/**
* Generates URL to presenter, action or signal.
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
* @param array|mixed $args
* @param mixed ...$args
* @throws InvalidLinkException
*/
public function link(string $destination, $args = []): string
public function link(string $destination, ...$args): string
{
try {
$args = func_num_args() < 3 && is_array($args)
? $args
: array_slice(func_get_args(), 1);
$args = count($args) === 1 && is_array($args[0] ?? null)
? $args[0]
: $args;
return $this->getPresenter()->createRequest($this, $destination, $args, 'link');

} catch (InvalidLinkException $e) {
Expand All @@ -266,29 +269,29 @@ public function link(string $destination, $args = []): string
/**
* Returns destination as Link object.
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
* @param array|mixed $args
* @param mixed ...$args
*/
public function lazyLink(string $destination, $args = []): Link
public function lazyLink(string $destination, ...$args): Link
{
$args = func_num_args() < 3 && is_array($args)
? $args
: array_slice(func_get_args(), 1);
$args = count($args) === 1 && is_array($args[0] ?? null)
? $args[0]
: $args;
return new Link($this, $destination, $args);
}


/**
* Determines whether it links to the current page.
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
* @param array|mixed $args
* @param mixed ...$args
* @throws InvalidLinkException
*/
public function isLinkCurrent(?string $destination = null, $args = []): bool
public function isLinkCurrent(?string $destination = null, ...$args): bool
{
if ($destination !== null) {
$args = func_num_args() < 3 && is_array($args)
? $args
: array_slice(func_get_args(), 1);
$args = count($args) === 1 && is_array($args[0] ?? null)
? $args[0]
: $args;
$this->getPresenter()->createRequest($this, $destination, $args, 'test');
}

Expand All @@ -299,15 +302,15 @@ public function isLinkCurrent(?string $destination = null, $args = []): bool
/**
* Redirect to another presenter, action or signal.
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
* @param array|mixed $args
* @param mixed ...$args
* @return never
* @throws Nette\Application\AbortException
*/
public function redirect(string $destination, $args = []): void
public function redirect(string $destination, ...$args): void
{
$args = func_num_args() < 3 && is_array($args)
? $args
: array_slice(func_get_args(), 1);
$args = count($args) === 1 && is_array($args[0] ?? null)
? $args[0]
: $args;
$presenter = $this->getPresenter();
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'));
}
Expand All @@ -316,15 +319,15 @@ public function redirect(string $destination, $args = []): void
/**
* Permanently redirects to presenter, action or signal.
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
* @param array|mixed $args
* @param mixed ...$args
* @return never
* @throws Nette\Application\AbortException
*/
public function redirectPermanent(string $destination, $args = []): void
public function redirectPermanent(string $destination, ...$args): void
{
$args = func_num_args() < 3 && is_array($args)
? $args
: array_slice(func_get_args(), 1);
$args = count($args) === 1 && is_array($args[0] ?? null)
? $args[0]
: $args;
$presenter = $this->getPresenter();
$presenter->redirectUrl(
$presenter->createRequest($this, $destination, $args, 'redirect'),
Expand All @@ -342,6 +345,3 @@ public function error(string $message = '', int $httpCode = Nette\Http\IResponse
throw new Nette\Application\BadRequestException($message, $httpCode);
}
}


class_exists(PresenterComponent::class);
20 changes: 13 additions & 7 deletions src/Application/UI/ComponentReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

/**
* Helpers for Presenter & Component.
* @property-read string $name
* @property-read string $fileName
* @property-deprecated string $name
* @property-deprecated string $fileName
* @internal
*/
final class ComponentReflection extends \ReflectionClass
Expand All @@ -26,7 +26,7 @@ final class ComponentReflection extends \ReflectionClass


/**
* Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter] or annotation @persistent.
* Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter].
*/
public function getParameters(): array
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public function getParameters(): array


/**
* Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent.
* Returns array of persistent properties. They are public and have attribute #[Persistent].
*/
public function getPersistentParams(): array
{
Expand Down Expand Up @@ -251,6 +251,7 @@ private static function castScalar(mixed &$val, string $type): bool

/**
* Returns an annotation value.
* @deprecated
*/
public static function parseAnnotation(\Reflector $ref, string $name): ?array
{
Expand All @@ -268,6 +269,12 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?array
}
}

$attr = match ($name) {
'persistent' => '#[Nette\Application\Attributes\Persistent]',
'deprecated' => '#[Nette\Application\Attributes\Deprecated]',
'crossOrigin' => '#[Nette\Application\Attributes\Request(sameOrigin: false)]',
};
trigger_error("Annotation @$name is deprecated, use $attr (used in " . Nette\Utils\Reflection::toString($ref) . ')', E_USER_DEPRECATED);
return $res;
}

Expand All @@ -286,6 +293,7 @@ public static function getType(\ReflectionParameter|\ReflectionProperty $item):

/**
* Has class specified annotation?
* @deprecated
*/
public function hasAnnotation(string $name): bool
{
Expand All @@ -295,6 +303,7 @@ public function hasAnnotation(string $name): bool

/**
* Returns an annotation value.
* @deprecated
*/
public function getAnnotation(string $name): mixed
{
Expand Down Expand Up @@ -341,6 +350,3 @@ public static function getClassesAndTraits(string $class): array
return $res;
}
}


class_exists(PresenterComponentReflection::class);
2 changes: 1 addition & 1 deletion src/Application/UI/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function templatePrepareFilters(Template $template): void
/**
* Saves the message to template, that can be displayed after redirect.
*/
public function flashMessage(string|\stdClass|Nette\HtmlStringable $message, string $type = 'info'): \stdClass
public function flashMessage(string|\stdClass|\Stringable $message, string $type = 'info'): \stdClass
{
$id = $this->getParameterId('flash');
$flash = $message instanceof \stdClass ? $message : (object) [
Expand Down
Loading