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

Explicit seed/class suffix in property names #2145

Merged
merged 5 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 demos/form/html-layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Form\Layout::class,
[
'defaultInputTemplate' => __DIR__ . '/templates/input.html',
'defaultHint' => [Label::class, 'class' => ['pointing', 'below']],
'defaultHintSeed' => [Label::class, 'class' => ['pointing', 'below']],
],
],
]);
Expand Down
18 changes: 6 additions & 12 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,19 @@ parameters:
message: '~^Method Atk4\\Ui\\Form\\Layout\\Custom::addButton\(\) should return Atk4\\Ui\\Button but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form/Layout/Section.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\)\.$~'
-
path: 'src/Form/Layout/Section/Accordion.php'
message: '~^Return type \(Atk4\\Ui\\Form\\Layout\) of method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should be compatible with return type \(Atk4\\Ui\\AccordionSection\) of method Atk4\\Ui\\Accordion::addSection\(\)$~'
-
path: 'src/Form/Layout/Section/Accordion.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\\Accordion\)\.$~'
-
path: 'src/Form/Layout/Section/Columns.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Columns::addColumn\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\\Columns\)\.$~'
-
path: 'src/Form/Layout/Section/Tabs.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Tabs::addTab\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Tabs::addTab\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\\Tabs\)\.$~'
-
path: 'src/Grid.php'
message: '~^Property Atk4\\Ui\\Grid::\$menu \(array\|Atk4\\Ui\\Menu\|false\) does not accept Atk4\\Ui\\AbstractView\.$~'
Expand Down Expand Up @@ -377,15 +380,6 @@ parameters:

# TODO these rules are generated, this ignores should be fixed in the code
# for level = 5
-
path: 'src/Form/Layout/Section.php'
message: '~^Parameter #1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\AbstractView, array<int\|string, Atk4\\Ui\\Form\|class-string<Atk4\\Ui\\Form\\Layout>> given\.$~'
-
path: 'src/Form/Layout/Section/Accordion.php'
message: '~^Parameter #1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\AbstractView, array<int\|string, Atk4\\Ui\\Form\|class-string<Atk4\\Ui\\Form\\Layout>> given\.$~'
-
path: 'src/Form/Layout/Section/Tabs.php'
message: '~^Parameter #1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\AbstractView, array<int\|string, Atk4\\Ui\\Form\|class-string<Atk4\\Ui\\Form\\Layout>> given\.$~'
-
path: 'src/Grid.php'
message: '~^Parameter #1 \$view of method Atk4\\Ui\\Grid::addActionMenuItem\(\) expects Atk4\\Ui\\View\|string, Atk4\\Data\\Model\\UserAction given\.$~'
Expand Down
11 changes: 4 additions & 7 deletions src/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Card extends View
/** @var CardSection|null The main card section of this card */
public $section;

/** @var string The CardSection default class name. */
public $cardSection = CardSection::class;
/** @var array The CardSection default seed. */
public $cardSectionSeed = [CardSection::class];

/** @var View|null The extra content view container for the card. */
public $extraContainer;
Expand All @@ -70,9 +70,6 @@ class Card extends View
/** @var bool Use Field label with value data. */
public $useLabel = false;

/** @var string Default executor class. */
public $executor = UserAction\ModalExecutor::class;

#[\Override]
protected function init(): void
{
Expand Down Expand Up @@ -104,7 +101,7 @@ protected function init(): void
public function getSection()
{
if (!$this->section) {
$this->section = CardSection::addToWithCl($this, [$this->cardSection, 'card' => $this]);
$this->section = CardSection::addToWithCl($this, array_merge($this->cardSectionSeed, ['card' => $this]));
}

return $this->section;
Expand Down Expand Up @@ -193,7 +190,7 @@ public function setModel(Model $entity, array $fields = null): void
*/
public function addSection(string $title = null, Model $model = null, array $fields = null, bool $useTable = false, bool $useLabel = false)
{
$section = CardSection::addToWithCl($this, [$this->cardSection, 'card' => $this], ['Section']);
$section = CardSection::addToWithCl($this, array_merge($this->cardSectionSeed, ['card' => $this]), ['Section']);
if ($title) {
View::addTo($section, [$title, 'class.header' => true]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/CardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class CardDeck extends View

public $defaultTemplate = 'card-deck.html';

/** @var class-string<View> Card type inside this deck. */
public $card = Card::class;
/** @var array Seed of Card inside this deck. */
public $cardSeed = [Card::class];

/** @var bool Whether card should use table display or not. */
public $useTable = false;
Expand Down Expand Up @@ -146,7 +146,7 @@ public function setModel(Model $model, array $fields = null, array $extra = null
if ($count) {
foreach ($this->model as $m) {
/** @var Card */
$c = $this->cardHolder->add(Factory::factory([$this->card], ['useLabel' => $this->useLabel, 'useTable' => $this->useTable]));
$c = $this->cardHolder->add(Factory::factory($this->cardSeed, ['useLabel' => $this->useLabel, 'useTable' => $this->useTable]));
$c->setModel($m, $fields);
if ($extra) {
$c->addExtraFields($m, $extra, $this->extraGlue);
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Layout extends AbstractLayout
public $inputTemplate;

/** @var array Seed for creating input hint View used in this layout. */
public $defaultHint = [Label::class, 'class' => ['pointing']];
public $defaultHintSeed = [Label::class, 'class' => ['pointing']];

#[\Override]
protected function _addControl(Control $control, Field $field): Control
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function recursiveRender(): void
}

if ($element->hint && $template->hasTag('Hint')) {
$hint = Factory::factory($this->defaultHint);
$hint = Factory::factory($this->defaultHintSeed);
$hint->name = $element->name . '_hint';
if (is_object($element->hint) || is_array($element->hint)) {
$hint->add($element->hint);
Expand Down
9 changes: 6 additions & 3 deletions src/Form/Layout/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
class Section extends View
{
/** @var class-string<Form\Layout> */
public $formLayout = Form\Layout::class;
/** @var array */
public $formLayoutSeed = [Form\Layout::class];

public Form $form;

Expand All @@ -24,6 +24,9 @@ class Section extends View
*/
public function addSection()
{
return $this->add([$this->formLayout, 'form' => $this->form]);
$res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]);
$this->add($res);

return $res;
}
}
10 changes: 7 additions & 3 deletions src/Form/Layout/Section/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
use Atk4\Ui\AccordionSection;
use Atk4\Ui\Form;
use Atk4\Ui\Js\JsBlock;
use Atk4\Ui\View;

/**
* Represents form controls in accordion.
*/
class Accordion extends UiAccordion
{
/** @var class-string<Form\Layout> */
public $formLayout = Form\Layout::class;
/** @var array */
public $formLayoutSeed = [Form\Layout::class];

public Form $form;

Expand Down Expand Up @@ -49,7 +50,10 @@ public function addSection($title, \Closure $callback = null, $icon = 'dropdown'
{
$section = parent::addSection($title, $callback, $icon);

return $section->add([$this->formLayout, 'form' => $this->form]);
$res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]);
$section->add($res);

return $res;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/Form/Layout/Section/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Atk4\Ui\Columns as UiColumns;
use Atk4\Ui\Form;
use Atk4\Ui\View;

/**
* Represents form controls in columns.
*/
class Columns extends UiColumns
{
/** @var class-string<Form\Layout> */
public $formLayout = Form\Layout::class;
/** @var array */
public $formLayoutSeed = [Form\Layout::class];

public Form $form;

Expand All @@ -25,6 +26,9 @@ public function addColumn($defaults = [])
{
$column = parent::addColumn($defaults);

return $column->add([$this->formLayout, 'form' => $this->form]); // @phpstan-ignore-line
$res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]);
$column->add($res);

return $res;
}
}
10 changes: 7 additions & 3 deletions src/Form/Layout/Section/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Atk4\Ui\Form;
use Atk4\Ui\Tabs as UiTabs;
use Atk4\Ui\View;

/**
* Represents form controls in tabs.
*/
class Tabs extends UiTabs
{
/** @var class-string<Form\Layout> */
public $formLayout = Form\Layout::class;
/** @var array */
public $formLayoutSeed = [Form\Layout::class];

public Form $form;

Expand All @@ -25,6 +26,9 @@ public function addTab($name, \Closure $callback = null, array $settings = [])
{
$tab = parent::addTab($name, $callback, $settings);

return $tab->add([$this->formLayout, 'form' => $this->form]);
$res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]);
$tab->add($res);

return $res;
}
}
Loading