diff --git a/composer.json b/composer.json index 118f1b2..4283173 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,11 @@ ], "require" : { "php": ">= 7.1.0", - "nette/http": "^2.4", - "nette/forms": "^2.4", - "nette/utils": "^2.4", - "latte/latte": "^2.4", - "nette/application": "^2.4" + "nette/http": "^3.0", + "nette/forms": "^3.0", + "nette/utils": "^3.0", + "latte/latte": "^2.5", + "nette/application": "^3.0" }, "require-dev": { "jakub-onderka/php-parallel-lint": "^1.0", diff --git a/src/TwiGrid/Components/Action.php b/src/TwiGrid/Components/Action.php index 5bc2c25..ea7dbc9 100644 --- a/src/TwiGrid/Components/Action.php +++ b/src/TwiGrid/Components/Action.php @@ -12,8 +12,6 @@ namespace TwiGrid\Components; -use Nette\Utils\Callback as NCallback; - class Action extends Component { @@ -30,8 +28,6 @@ class Action extends Component public function __construct(string $label, callable $callback) { - parent::__construct(); - $this->label = $label; $this->callback = $callback; } @@ -78,7 +74,7 @@ public function hasConfirmation(): bool */ public function invoke($record) { - return NCallback::invoke($this->callback, $record); + return call_user_func($this->callback, $record); } } diff --git a/src/TwiGrid/Components/Column.php b/src/TwiGrid/Components/Column.php index eca44ce..203522b 100644 --- a/src/TwiGrid/Components/Column.php +++ b/src/TwiGrid/Components/Column.php @@ -38,8 +38,6 @@ class Column extends Component public function __construct(string $label) { - parent::__construct(); - $this->label = $label; } diff --git a/src/TwiGrid/Components/Translator.php b/src/TwiGrid/Components/Translator.php index 8152966..f4102d6 100644 --- a/src/TwiGrid/Components/Translator.php +++ b/src/TwiGrid/Components/Translator.php @@ -47,12 +47,7 @@ public function addDictionary(array $dictionary): self } - /** - * @param string $message - * @param int $count - * @return string - */ - public function translate($message, $count = null): string + public function translate($message, ...$parameters): string { if (isset($this->dictionary[$message])) { $s = $this->dictionary[$message]; @@ -61,7 +56,7 @@ public function translate($message, $count = null): string $s = $message; } - return sprintf($s, $count); + return sprintf($s, ...$parameters); } } diff --git a/src/TwiGrid/DataGrid.php b/src/TwiGrid/DataGrid.php index b84409a..9198a2c 100644 --- a/src/TwiGrid/DataGrid.php +++ b/src/TwiGrid/DataGrid.php @@ -16,7 +16,6 @@ use TwiGrid\Components\Column; use TwiGrid\Components\RowAction; use Nette\ComponentModel\IContainer; -use Nette\Utils\Callback as NCallback; use Nette\Bridges\ApplicationLatte\Template; use Nette\Application\UI\Control as NControl; use Nette\Application\UI\Presenter as NPresenter; @@ -150,12 +149,11 @@ class DataGrid extends NControl // === LIFE CYCLE ====================================================== - /** @param NPresenter $presenter */ - protected function attached($presenter): void + public function __construct() { - if ($presenter instanceof NPresenter) { + $this->monitor(NPresenter::class, function (NPresenter $presenter) { $this->build(); - parent::attached($presenter); + $this->session = $presenter->getSession(sprintf('%s-%s', __CLASS__, $this->getName())); if (!isset($presenter->payload->twiGrid)) { @@ -165,7 +163,7 @@ protected function attached($presenter): void } $this->payload = $presenter->payload->twiGrid; - } + }); } @@ -553,7 +551,7 @@ public function getData() $args[] = ($this->page - 1) * $this->itemsPerPage; } - $this->data = NCallback::invokeArgs($this->dataLoader, $args); + $this->data = call_user_func_array($this->dataLoader, $args); } return $this->data; @@ -678,7 +676,7 @@ public function getItemCount(): ?int throw new \LogicException('Data loader not set.'); } - $data = NCallback::invoke($this->dataLoader, $this->filters, [], null, 0); + $data = call_user_func($this->dataLoader, $this->filters, [], null, 0); if ($data instanceof NSelection) { $count = $data->count('*'); @@ -688,7 +686,7 @@ public function getItemCount(): ?int } } else { - $count = NCallback::invoke($this->itemCounter, $this->filters); + $count = call_user_func($this->itemCounter, $this->filters); } $this->itemCount = max(0, (int) $count); @@ -875,7 +873,7 @@ public function processForm(\Nette\Forms\Form $form): void throw new \LogicException('Inline edit callback not set.'); } - NCallback::invoke($this->ieProcessCallback, $this->getRecordHandler()->findIn($this->iePrimary, $this->getData()), $values); + call_user_func($this->ieProcessCallback, $this->getRecordHandler()->findIn($this->iePrimary, $this->getData()), $values); } $this->deactivateInlineEditing(); @@ -937,7 +935,7 @@ public function render(): void $template->form = $form = $this['form']; if ($this->presenter->isAjax()) { - $this->payload->id = $this->getSnippetId(); + $this->payload->id = $this->getSnippetId((string) $this->getName()); $this->payload->url = $this->link('this'); $this->payload->refreshing = $this->refreshing; $this->payload->refreshSignal = $this->link('refresh!'); diff --git a/src/TwiGrid/Form.php b/src/TwiGrid/Form.php index b8a5809..0654875 100644 --- a/src/TwiGrid/Form.php +++ b/src/TwiGrid/Form.php @@ -12,7 +12,6 @@ namespace TwiGrid; -use Nette\Forms\Container; use Nette\Forms\Controls\Button; use Nette\Forms\Controls\Checkbox; use Nette\Forms\Controls\SubmitButton; @@ -134,7 +133,7 @@ public function addInlineEditControls($data, callable $containerSetupCb, ?string if ($this->lazyCreateContainer('inline', 'buttons', $buttons)) { foreach ($data as $record) { if ($this->recordHandler->is($record, $iePrimary)) { - /** @var Container $inline */ + /** @var NContainer $inline */ $inline = $this['inline']; $containerSetupCb($inline->addContainer('values'), $record); @@ -196,7 +195,7 @@ protected function lazyCreateContainer(string $parent, string $name, NContainer } if (!isset($this[$parent][$name])) { - /** @var Container $parentContainer */ + /** @var NContainer $parentContainer */ $parentContainer = $this[$parent]; $parentContainer->addContainer($name); diff --git a/tests/Utils/GridPresenter.php b/tests/Utils/GridPresenter.php index a7c5fec..8256306 100644 --- a/tests/Utils/GridPresenter.php +++ b/tests/Utils/GridPresenter.php @@ -23,8 +23,11 @@ public function __construct(DataGrid $grid) { parent::__construct(); + $this->setParent(null, 'grid'); + $this->changeAction(self::DEFAULT_ACTION); + $httpResponse = new Response; - $httpRequest = new Request(new UrlScript('http://kesspess.cz/twigrid/')); + $httpRequest = new Request(new UrlScript('https://kesspess.cz/twigrid/')); $this->injectPrimary( null, @@ -36,7 +39,7 @@ public function __construct(DataGrid $grid) null, new TemplateFactory(new class implements ILatteFactory { - public function create() + public function create(): Engine { return new Engine; }