Skip to content

Commit a86f30a

Browse files
committed
Changed registration of event onClick in ApiListingControl
1 parent e8e7e40 commit a86f30a

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

UPGRADE.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,13 @@ new ApiListingControl($apiDecider)
7070
Some parameters were strictly typed:
7171
- second parameter in `JsonApiResponse::__construct` (`$payload` formerly known as `$data`) is now `array`
7272
- fifth parameter in `JsonApiResponse::__construct` (`$expiration`) is now `DateTimeInteface` or `null`
73-
- fourth parameter in `InputParam::__construc` (`$availableValues`) is now `array` or `null`
73+
- fourth parameter in `InputParam::__construct` (`$availableValues`) is now `array` or `null`
74+
75+
### Changed events
76+
Registration of event onClick in ApiListingControl.
77+
Use:
78+
```
79+
$apiListing->onClick[] = function ($method, $version, $package, $apiAction) {
80+
...
81+
};
82+
```

src/Component/ApiConsoleControl.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@
1010
use Tomaj\NetteApi\Authorization\ApiAuthorizationInterface;
1111
use Tomaj\NetteApi\Authorization\BearerTokenAuthorization;
1212
use Tomaj\NetteApi\Authorization\NoAuthorization;
13-
use Tomaj\NetteApi\EndpointIdentifier;
13+
use Tomaj\NetteApi\EndpointInterface;
1414
use Tomaj\NetteApi\Handlers\ApiHandlerInterface;
1515
use Tomaj\NetteApi\Misc\ConsoleRequest;
1616
use Tomaj\NetteApi\Params\InputParam;
1717

1818
class ApiConsoleControl extends Control
1919
{
20+
private $request;
21+
2022
private $endpoint;
2123

2224
private $handler;
2325

2426
private $authorization;
2527

26-
private $request;
27-
28-
public function __construct(IRequest $request, EndpointIdentifier $endpoint, ApiHandlerInterface $handler, ApiAuthorizationInterface $authorization)
28+
public function __construct(IRequest $request, EndpointInterface $endpoint, ApiHandlerInterface $handler, ApiAuthorizationInterface $authorization)
2929
{
30+
$this->request = $request;
3031
$this->endpoint = $endpoint;
3132
$this->handler = $handler;
3233
$this->authorization = $authorization;
33-
$this->request = $request;
3434
}
3535

3636
public function render(): void

src/Component/ApiListingControl.php

+3-15
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,20 @@
44

55
use Nette\Application\UI\Control;
66
use Tomaj\NetteApi\ApiDecider;
7-
use Closure;
8-
use Exception;
97
use Tomaj\NetteApi\Api;
108

119
class ApiListingControl extends Control
1210
{
1311
/** @var ApiDecider */
1412
private $apiDecider;
1513

16-
/** @var Closure|null */
17-
private $clickCallback;
14+
public $onClick = [];
1815

1916
public function __construct(ApiDecider $apiDecider)
2017
{
2118
$this->apiDecider = $apiDecider;
2219
}
2320

24-
public function onClick(Closure $callback): void
25-
{
26-
$this->clickCallback = $callback;
27-
}
28-
2921
public function render(): void
3022
{
3123
$apis = $this->apiDecider->getApis();
@@ -34,13 +26,9 @@ public function render(): void
3426
$this->getTemplate()->render();
3527
}
3628

37-
public function handleSelect(string $method, int $version, string $package, ?string $apiAction = null)
29+
public function handleSelect(string $method, int $version, string $package, ?string $apiAction = null): void
3830
{
39-
if (!$this->clickCallback) {
40-
throw new Exception('You have to set onClick callback to component!');
41-
}
42-
43-
$this->clickCallback->__invoke($method, $version, $package, $apiAction);
31+
$this->onClick($method, $version, $package, $apiAction);
4432
}
4533

4634
/**

0 commit comments

Comments
 (0)