Skip to content

Commit

Permalink
Undo BC break for nette/component-model < 3.1.0
Browse files Browse the repository at this point in the history
Partly reverts the parent commit.
  • Loading branch information
jtojnar committed Mar 20, 2024
1 parent e1a246c commit 7d0aedd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"webchemistry/testing-helpers": "^4.0.0"
},
"conflict": {
"latte/latte": "<3.0.0",
"nette/component-model": "<3.1.0"
"latte/latte": "<3.0.0"
},
"autoload": {
"psr-4": {
Expand Down
30 changes: 23 additions & 7 deletions src/Multiplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ public function addCreateButton(?string $caption = null, int $copyCount = 1): Cr
*/
public function validate(?array $controls = null): void
{
/** @var Control[] $components */
/** @var iterable<Control> $components */
$components = $controls ?? $this->getComponents();
// Support both component-model ≥ 3.1 and < 3.1
$components = is_array($components) ? $components : iterator_to_array($components);

foreach ($components as $index => $control) {
foreach ($this->noValidate as $item) {
Expand Down Expand Up @@ -302,16 +304,21 @@ public function getControls(): Iterator
}

/**
* @return array<int|string,Container>
* @return Iterator<int|string,Container>
*/
public function getContainers(): iterable
public function getContainers(): Iterator
{
$this->createCopies();

/** @var iterable<int|string,Control> $components */
$components = $this->getComponents();
// Support both component-model ≥ 3.1 and < 3.1
$components = is_array($components) ? $components : iterator_to_array($components);

/** @var array<int|string,Container> $containers */
$containers = array_filter($this->getComponents(), fn ($component) => $component instanceof Container);
$containers = array_filter($components, fn ($component) => $component instanceof Container);

return $containers;
return new \ArrayIterator($containers);
}

/**
Expand Down Expand Up @@ -385,7 +392,12 @@ protected function loadHttpData(): void

protected function createNumber(): int
{
$count = count(array_filter($this->getComponents(), fn ($component) => $component instanceof Form));
/** @var iterable<int|string,Control> $components */
$components = $this->getComponents();
// Support both component-model ≥ 3.1 and < 3.1
$components = is_array($components) ? $components : iterator_to_array($components);

$count = count(array_filter($components, fn ($component) => $component instanceof Form));
while ($this->getComponent((string) $count, false)) {
$count++;
}
Expand Down Expand Up @@ -420,7 +432,11 @@ protected function createContainer(): Container
*/
protected function getFirstSubmit(): ?string
{
$submits = array_filter($this->getComponents(), fn ($component) => $component instanceof SubmitButton);
/** @var iterable<int|string,Control> $components */
$components = $this->getComponents();
// Support both component-model ≥ 3.1 and < 3.1
$components = is_array($components) ? $components : iterator_to_array($components);
$submits = array_filter($components, fn ($component) => $component instanceof SubmitButton);
if ($submits) {
return reset($submits)->getName();
}
Expand Down

0 comments on commit 7d0aedd

Please sign in to comment.