‪TYPO3CMS  9.5
VariableItem.php
Go to the documentation of this file.
1 <?php
2 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 
25  private ‪$variableKey;
26 
30  private ‪$value;
31 
36 
37  public static function ‪create(string $key, ‪$value): self
38  {
39  return new static(
40  ‪VariableValue::create(sprintf('[[%s]]', $key)),
42  );
43  }
44 
46  {
47  $this->variableKey = ‪$variableKey;
48  $this->value = ‪$value;
49  }
50 
51  public function ‪isArray(): bool
52  {
53  return is_array($this->value);
54  }
55 
56  public function ‪apply(‪Variables $variables): array
57  {
58  if (!$this->‪hasAllRequiredDefinedVariableNames($variables)) {
59  return [];
60  }
61  return [$this->‪key($variables) => ‪$this->value];
62  }
63 
64  public function ‪key(‪Variables $variables): ?string
65  {
66  if (!$this->‪hasAllRequiredDefinedVariableNames($variables)) {
67  return null;
68  }
69  return $this->variableKey->apply($variables);
70  }
71 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\create
‪static create(string $key, $value)
Definition: VariableItem.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\apply
‪apply(Variables $variables)
Definition: VariableItem.php:52
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\$requiredDefinedVariableNames
‪string[] $requiredDefinedVariableNames
Definition: VariableItem.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\$variableKey
‪VariableValue $variableKey
Definition: VariableItem.php:23
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables
Definition: Variables.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesTrait
Definition: VariablesTrait.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue\create
‪static create(string $value, Variables $defaultVariables=null)
Definition: VariableValue.php:37
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\__construct
‪__construct(VariableValue $variableKey, $value)
Definition: VariableItem.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\$value
‪array $value
Definition: VariableItem.php:27
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\key
‪key(Variables $variables)
Definition: VariableItem.php:60
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:3
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem
Definition: VariableItem.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\isArray
‪isArray()
Definition: VariableItem.php:47
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue
Definition: VariableValue.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesTrait\hasAllRequiredDefinedVariableNames
‪hasAllRequiredDefinedVariableNames(Variables $variables)
Definition: VariablesTrait.php:27