123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace OCA\Files_External\Lib;
- trait FrontendDefinitionTrait {
-
- private string $text = '';
-
- private array $parameters = [];
-
- private array $customJs = [];
- public function getText(): string {
- return $this->text;
- }
- public function setText(string $text): self {
- $this->text = $text;
- return $this;
- }
- public static function lexicalCompare(IFrontendDefinition $a, IFrontendDefinition $b): int {
- return strcmp($a->getText(), $b->getText());
- }
-
- public function getParameters(): array {
- return $this->parameters;
- }
-
- public function addParameters(array $parameters): self {
- foreach ($parameters as $parameter) {
- $this->addParameter($parameter);
- }
- return $this;
- }
- public function addParameter(DefinitionParameter $parameter): self {
- $this->parameters[$parameter->getName()] = $parameter;
- return $this;
- }
-
- public function getCustomJs(): array {
- return $this->customJs;
- }
-
- public function addCustomJs(string $custom): self {
- $this->customJs[] = $custom;
- return $this;
- }
-
- public function jsonSerializeDefinition(): array {
- $configuration = [];
- foreach ($this->getParameters() as $parameter) {
- $configuration[$parameter->getName()] = $parameter;
- }
- $data = [
- 'name' => $this->getText(),
- 'configuration' => $configuration,
- 'custom' => $this->getCustomJs(),
- ];
- return $data;
- }
-
- public function validateStorageDefinition(StorageConfig $storage): bool {
- foreach ($this->getParameters() as $name => $parameter) {
- $value = $storage->getBackendOption($name);
- if (!is_null($value) || !$parameter->isOptional()) {
- if (!$parameter->validateValue($value)) {
- return false;
- }
- $storage->setBackendOption($name, $value);
- }
- }
- return true;
- }
- }
|