‪TYPO3CMS  10.4
VariableItem.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 {
23 
27  private ‪$variableKey;
28 
32  private ‪$value;
33 
38 
39  public static function ‪create(string $key, ‪$value): self
40  {
41  return new static(
42  ‪VariableValue::create(sprintf('[[%s]]', $key)),
44  );
45  }
46 
48  {
49  $this->variableKey = ‪$variableKey;
50  $this->value = ‪$value;
51  }
52 
53  public function ‪isArray(): bool
54  {
55  return is_array($this->value);
56  }
57 
58  public function ‪apply(‪Variables $variables): array
59  {
60  if (!$this->‪hasAllRequiredDefinedVariableNames($variables)) {
61  return [];
62  }
63  return [$this->‪key($variables) => ‪$this->value];
64  }
65 
66  public function ‪key(‪Variables $variables): ?string
67  {
68  if (!$this->‪hasAllRequiredDefinedVariableNames($variables)) {
69  return null;
70  }
71  return $this->variableKey->apply($variables);
72  }
73 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\create
‪static create(string $key, $value)
Definition: VariableItem.php:35
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\apply
‪apply(Variables $variables)
Definition: VariableItem.php:54
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\$requiredDefinedVariableNames
‪string[] $requiredDefinedVariableNames
Definition: VariableItem.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\$variableKey
‪VariableValue $variableKey
Definition: VariableItem.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables
Definition: Variables.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesTrait
Definition: VariablesTrait.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue\create
‪static create(string $value, Variables $defaultVariables=null)
Definition: VariableValue.php:39
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\__construct
‪__construct(VariableValue $variableKey, $value)
Definition: VariableItem.php:43
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\$value
‪array $value
Definition: VariableItem.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\key
‪key(Variables $variables)
Definition: VariableItem.php:62
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem
Definition: VariableItem.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\isArray
‪isArray()
Definition: VariableItem.php:49
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue
Definition: VariableValue.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesTrait\hasAllRequiredDefinedVariableNames
‪hasAllRequiredDefinedVariableNames(Variables $variables)
Definition: VariablesTrait.php:29