-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validation entities for keep standard convention.
- Loading branch information
1 parent
0c03f6c
commit 8cb3acf
Showing
5 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\StructuredApi\Entity; | ||
|
||
|
||
interface BulkAction | ||
{ | ||
/** | ||
* @return string[] (action => label) | ||
*/ | ||
public function getBulkActionsList(): array; | ||
|
||
/** | ||
* @param string $action | ||
* @param string[] $ids | ||
*/ | ||
public function postProcessBulkAction(string $action, array $ids): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\StructuredApi\Entity; | ||
|
||
|
||
final class ItemsList | ||
{ | ||
|
||
/** @var ItemsListItem[] */ | ||
private $items; | ||
|
||
|
||
/** | ||
* @param ItemsListItem[] $items | ||
*/ | ||
public function __construct(array $items = []) | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
|
||
/** | ||
* @param ItemsListItem[] $items | ||
* @return self | ||
*/ | ||
public static function from(array $items): self | ||
{ | ||
return new self($items); | ||
} | ||
|
||
|
||
/** | ||
* @return mixed[][] | ||
*/ | ||
public function getData(): array | ||
{ | ||
$return = []; | ||
foreach ($this->items as $item) { | ||
$return[] = array_merge($item->getData(), [ | ||
'id' => $item->getId(), | ||
]); | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
|
||
public function addItem(ItemsListItem $item): self | ||
{ | ||
$this->items[] = $item; | ||
|
||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return ItemsListItem[] | ||
*/ | ||
public function getItems(): array | ||
{ | ||
return $this->items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\StructuredApi\Entity; | ||
|
||
|
||
class ItemsListItem | ||
{ | ||
|
||
/** @var string */ | ||
private $id; | ||
|
||
/** @var mixed[] */ | ||
private $data; | ||
|
||
|
||
/** | ||
* @param string $id | ||
* @param mixed[] $data | ||
*/ | ||
public function __construct(string $id, array $data = []) | ||
{ | ||
$this->id = $id; | ||
$this->data = $data; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\StructuredApi\Entity; | ||
|
||
|
||
use Nette\Utils\Strings; | ||
|
||
final class StatusCount | ||
{ | ||
|
||
/** @var string */ | ||
private $key; | ||
|
||
/** @var string */ | ||
private $label; | ||
|
||
/** @var int */ | ||
private $count; | ||
|
||
|
||
/** | ||
* @param string $key | ||
* @param int $count | ||
* @param string $label | ||
*/ | ||
public function __construct(string $key, int $count, ?string $label = null) | ||
{ | ||
$this->key = $key; | ||
$this->count = $count; | ||
$this->label = $label ?? Strings::firstUpper(str_replace('-', ' ', $key)); | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKey(): string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return $this->label; | ||
} | ||
|
||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getCount(): int | ||
{ | ||
return $this->count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters