first commit
This commit is contained in:
37
bundles/KupShop/ComponentsBundle/Attributes/Blocek.php
Normal file
37
bundles/KupShop/ComponentsBundle/Attributes/Blocek.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KupShop\ComponentsBundle\Attributes;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class Blocek
|
||||
{
|
||||
public function __construct(
|
||||
protected bool $lazy = false,
|
||||
protected ?string $title = null,
|
||||
protected ?string $descr = null,
|
||||
protected ?string $icon = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function isLazy(): bool
|
||||
{
|
||||
return $this->lazy;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getDescr(): ?string
|
||||
{
|
||||
return $this->descr;
|
||||
}
|
||||
|
||||
public function getIcon(): ?string
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KupShop\ComponentsBundle\Attributes;
|
||||
|
||||
use KupShop\ContentBundle\Util\BlocekTypes;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||
class BlocekAttribute
|
||||
{
|
||||
/**
|
||||
* @param mixed|null $default Default value inserted into the parameter setting
|
||||
* @param string|null $title Name used in the Blocek
|
||||
* @param BlocekTypes|null $type Overrides the default type that is taken from the parameter type
|
||||
* @param array|string|null $options Value used in SELECT type
|
||||
*/
|
||||
public function __construct(
|
||||
protected mixed $default = null,
|
||||
protected ?string $title = null,
|
||||
protected ?BlocekTypes $type = null,
|
||||
protected array|string|null $options = null,
|
||||
protected ?string $autocompleteType = null,
|
||||
protected ?bool $autocompleteMulti = null,
|
||||
protected ?string $autocompletePreload = null,
|
||||
protected ?bool $autocompleteInvert = null,
|
||||
protected ?bool $autocompleteSortable = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getDefault(): ?bool
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getType(): ?BlocekTypes
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getOptions(): ?array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
54
bundles/KupShop/ComponentsBundle/Attributes/Component.php
Normal file
54
bundles/KupShop/ComponentsBundle/Attributes/Component.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KupShop\ComponentsBundle\Attributes;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class Component
|
||||
{
|
||||
public function __construct(
|
||||
protected int $latestVersion = 1,
|
||||
/** @var Version[] */
|
||||
protected array $versions = [],
|
||||
protected string $entrypoint = 'app',
|
||||
) {
|
||||
end($versions)->setIsLatest();
|
||||
}
|
||||
|
||||
public function getVersions(): \Generator
|
||||
{
|
||||
$latestVersions = ['template' => 1, 'js' => 1, 'css' => 1];
|
||||
|
||||
yield 1 => $latestVersions;
|
||||
|
||||
foreach ($this->versions as $version) {
|
||||
if ($version->isNewTemplate()) {
|
||||
$latestVersions['template'] = $version->getVersionFrom();
|
||||
}
|
||||
|
||||
if ($version->isNewJs()) {
|
||||
$latestVersions['js'] = $version->getVersionFrom();
|
||||
} elseif ($version->isNewJs() === null) {
|
||||
$latestVersions['js'] = 0;
|
||||
}
|
||||
|
||||
if ($version->isNewCss()) {
|
||||
$latestVersions['css'] = $version->getVersionFrom();
|
||||
} elseif ($version->isNewCss() === null) {
|
||||
$latestVersions['css'] = 0;
|
||||
}
|
||||
|
||||
yield $version->getVersionFrom() => $latestVersions;
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfig(): array
|
||||
{
|
||||
return [
|
||||
'versions' => iterator_to_array($this->getVersions()),
|
||||
'latestVersion' => $this->latestVersion,
|
||||
'entrypoint' => $this->entrypoint,
|
||||
];
|
||||
}
|
||||
}
|
||||
23
bundles/KupShop/ComponentsBundle/Attributes/Entrypoint.php
Normal file
23
bundles/KupShop/ComponentsBundle/Attributes/Entrypoint.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KupShop\ComponentsBundle\Attributes;
|
||||
|
||||
/**
|
||||
* Always registers a component to components.yaml to with specified entrypoint.
|
||||
*
|
||||
* @depracated Je to mega hnusnej super hack, používat fakt je v krajní nouzi kdy potřebuju zaregistrovat komponentu kterou budu používat někde ve starejch šablonách.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class Entrypoint
|
||||
{
|
||||
public function __construct(protected string $entrypoint)
|
||||
{
|
||||
}
|
||||
|
||||
public function getEntrypoint(): string
|
||||
{
|
||||
return $this->entrypoint;
|
||||
}
|
||||
}
|
||||
49
bundles/KupShop/ComponentsBundle/Attributes/Version.php
Normal file
49
bundles/KupShop/ComponentsBundle/Attributes/Version.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KupShop\ComponentsBundle\Attributes;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class Version
|
||||
{
|
||||
protected bool $isLatest = false;
|
||||
|
||||
public function __construct(
|
||||
protected int $versionFrom,
|
||||
protected bool $newTemplate = false,
|
||||
protected ?bool $newJs = false,
|
||||
protected ?bool $newCss = false,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getVersionFrom(): int
|
||||
{
|
||||
return $this->versionFrom;
|
||||
}
|
||||
|
||||
public function setIsLatest()
|
||||
{
|
||||
$this->isLatest = true;
|
||||
}
|
||||
|
||||
public function getIsLatest(): bool
|
||||
{
|
||||
return $this->isLatest;
|
||||
}
|
||||
|
||||
public function isNewTemplate(): bool
|
||||
{
|
||||
return $this->newTemplate;
|
||||
}
|
||||
|
||||
public function isNewJs(): ?bool
|
||||
{
|
||||
return $this->newJs;
|
||||
}
|
||||
|
||||
public function isNewCss(): ?bool
|
||||
{
|
||||
return $this->newCss;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user