Skip to content

Commit

Permalink
updated for Nette 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
uestla committed Oct 11, 2019
1 parent b3ea598 commit 97f4193
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 35 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions src/TwiGrid/Components/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

namespace TwiGrid\Components;

use Nette\Utils\Callback as NCallback;


class Action extends Component
{
Expand All @@ -30,8 +28,6 @@ class Action extends Component

public function __construct(string $label, callable $callback)
{
parent::__construct();

$this->label = $label;
$this->callback = $callback;
}
Expand Down Expand Up @@ -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);
}

}
2 changes: 0 additions & 2 deletions src/TwiGrid/Components/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class Column extends Component

public function __construct(string $label)
{
parent::__construct();

$this->label = $label;
}

Expand Down
9 changes: 2 additions & 7 deletions src/TwiGrid/Components/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -61,7 +56,7 @@ public function translate($message, $count = null): string
$s = $message;
}

return sprintf($s, $count);
return sprintf($s, ...$parameters);
}

}
20 changes: 9 additions & 11 deletions src/TwiGrid/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -165,7 +163,7 @@ protected function attached($presenter): void
}

$this->payload = $presenter->payload->twiGrid;
}
});
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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('*');
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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!');
Expand Down
5 changes: 2 additions & 3 deletions src/TwiGrid/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions tests/Utils/GridPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit 97f4193

Please sign in to comment.