-
Notifications
You must be signed in to change notification settings - Fork 60
Fix compatibility with component-model 4.0 #72
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
base: master
Are you sure you want to change the base?
Changes from all commits
a2e403c
dd0f067
f97b315
47a7d85
cd47834
5f4fd4a
7c5a3df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,35 @@ | ||
| parameters: | ||
| ignoreErrors: | ||
| # https://github.com/phpstan/phpstan-nette/issues/141 | ||
| - | ||
| message: '#^Instanceof between Nette\\ComponentModel\\IComponent and Nette\\ComponentModel\\IComponent will always evaluate to true\.$#' | ||
| identifier: instanceof.alwaysTrue | ||
| # Only occurs with forms < 3.3.0 | ||
| reportUnmatched: false | ||
| count: 2 | ||
| path: src/Replicator/Container.php | ||
|
|
||
| - | ||
| message: '#^Parameter \#1 \$array of function array_filter expects array, Iterator\<int\|string, Nette\\ComponentModel\\IComponent\> given\.$#' | ||
| identifier: argument.type | ||
| # Only occurs with forms < 3.3.0 | ||
| reportUnmatched: false | ||
| count: 3 | ||
| path: src/Replicator/Container.php | ||
|
|
||
| - | ||
| message: '#^Parameter \#1 \$array of function array_filter expects array, Iterator\<int\|string, Nette\\ComponentModel\\IComponent\>\|list\<Nette\\ComponentModel\\IComponent\> given\.$#' | ||
| identifier: argument.type | ||
| # Only occurs with forms < 3.3.0 | ||
| reportUnmatched: false | ||
| count: 2 | ||
| path: src/Replicator/Container.php | ||
|
|
||
| - | ||
| # https://github.com/nette/forms/pull/354 | ||
| message: '#^Parameter \#2 \$callback of static method Nette\\Forms\\Container\:\:extensionMethod\(\) expects callable\(static\)\: mixed, Closure\(Nette\\Forms\\Container, string, callable, int\=, bool\=\)\: static given\.$#' | ||
| identifier: argument.type | ||
| # Only occurs with forms ≥ 3.3.0 | ||
| reportUnmatched: false | ||
| count: 1 | ||
| path: src/Replicator/Container.php |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -66,8 +66,8 @@ class Container extends Nette\Forms\Container | |||||
| */ | ||||||
| public function __construct(callable $factory, int $createDefault = 0, bool $forceDefault = FALSE) | ||||||
| { | ||||||
| $this->monitor(Nette\Application\UI\Presenter::class); | ||||||
| $this->monitor(Nette\Forms\Form::class); | ||||||
| $this->monitor(Nette\Forms\Form::class, $this->componentAttached(...)); | ||||||
| $this->monitor(Nette\Application\UI\Presenter::class, $this->componentAttached(...)); | ||||||
|
|
||||||
| try { | ||||||
| $this->factoryCallback = Closure::fromCallable($factory); | ||||||
|
|
@@ -92,10 +92,8 @@ public function setFactory(callable $factory): void | |||||
| /** | ||||||
| * Magical component factory | ||||||
| */ | ||||||
| protected function attached(Nette\ComponentModel\IComponent $obj): void | ||||||
| private function componentAttached(Nette\ComponentModel\IComponent $obj): void | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please retain the protected method. It has been subclass-visible since 2019 and is not marked
Suggested change
|
||||||
| { | ||||||
| parent::attached($obj); | ||||||
|
|
||||||
| if ( | ||||||
| !$obj instanceof Nette\Application\UI\Presenter | ||||||
| && | ||||||
|
|
@@ -143,14 +141,15 @@ protected function createComponent(string $name): ?Nette\ComponentModel\ICompone | |||||
|
|
||||||
| ($this->factoryCallback)($container); | ||||||
|
|
||||||
| return $this->created[$container->name] = $container; | ||||||
| return $this->created[$container->getName()] = $container; | ||||||
| } | ||||||
|
|
||||||
| private function getFirstControlName(): ?string | ||||||
| { | ||||||
| // TODO: The first instanceof check should be redundant but PHPStan infers getComponent() returns untyped array. | ||||||
| $controls = array_filter( | ||||||
| $this->getComponents(), | ||||||
| fn ($component): bool => $component instanceof Nette\Forms\Control, | ||||||
| fn ($component): bool => $component instanceof Nette\ComponentModel\IComponent && $component instanceof Nette\Forms\Control, | ||||||
| ); | ||||||
| $firstControl = reset($controls); | ||||||
|
|
||||||
|
|
@@ -274,8 +273,8 @@ private function getHttpData(): ?array | |||||
| */ | ||||||
| public function remove(Nette\ComponentModel\Container $container, bool $cleanUpGroups = FALSE): void | ||||||
| { | ||||||
| if ($container->parent !== $this) { | ||||||
| throw new Nette\InvalidArgumentException('Given component ' . $container->name . ' is not children of ' . $this->name . '.'); | ||||||
| if ($container->getParent() !== $this) { | ||||||
| throw new Nette\InvalidArgumentException('Given component ' . $container->getName() . ' is not children of ' . $this->getName() . '.'); | ||||||
| } | ||||||
|
|
||||||
| // to check if form was submitted by this one | ||||||
|
|
@@ -379,9 +378,11 @@ public function countFilledWithout(array $components = [], array $subComponents | |||||
| public function isAllFilled(array $exceptChildren = []): bool | ||||||
| { | ||||||
| $components = []; | ||||||
|
|
||||||
| // TODO: The first instanceof check should be redundant but PHPStan infers getComponent() returns untyped array. | ||||||
| $controls = array_filter( | ||||||
| $this->getComponents(), | ||||||
| fn ($component): bool => $component instanceof Nette\Forms\Control, | ||||||
| fn ($component): bool => $component instanceof Nette\ComponentModel\IComponent && $component instanceof Nette\Forms\Control, | ||||||
| ); | ||||||
| foreach ($controls as $control) { | ||||||
| if (($name = $control->getName()) !== null) { | ||||||
|
|
@@ -452,7 +453,7 @@ function (Nette\Forms\Controls\SubmitButton $_this, ?callable $callback = NULL) | |||||
| $_this->onClick[] = function (Nette\Forms\Controls\SubmitButton $button) use ($callback) { | ||||||
| /** @var self $replicator */ | ||||||
| $replicator = $button->lookup(static::class); | ||||||
| $container = $button->parent; | ||||||
| $container = $button->getParent(); | ||||||
| \assert($container instanceof Nette\ComponentModel\Container); | ||||||
| if (is_callable($callback)) { | ||||||
| $callback($replicator, $container); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the existing protected method as the explicit callback. This follows component-model 4’s required
monitor()API without dropping FormsReplicator’s subclass hook.