‪TYPO3CMS  9.5
VariablesContext.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 {
20  private ‪$variables;
21 
26 
27  public static function ‪create(‪Variables ‪$variables): self
28  {
29  return new static(‪$variables);
30  }
31 
32  private function ‪__construct(‪Variables ‪$variables)
33  {
34  $this->variables = ‪$variables;
35  }
36 
40  public function ‪getVariables(): ‪Variables
41  {
42  return ‪$this->variables;
43  }
44 
45  public function ‪matchesRequiredApplicables(‪Applicable ...$applicables): bool
46  {
47  if ($this->requiredApplicables === null || $this->requiredApplicables === []) {
48  return true;
49  }
50  $missingApplicables = array_udiff(
51  $this->requiredApplicables,
52  $applicables,
53  [$this, 'compareApplicables']
54  );
55  return count($missingApplicables) === 0;
56  }
57 
59  {
60  $target = clone $this;
61  $target->requiredApplicables = ‪$requiredApplicables;
62  return $target;
63  }
64 
65  public function ‪describe(): string
66  {
67  $items = [];
68  foreach ($this->variables->getArrayCopy() as $key => $value) {
69  $items[] = sprintf('$%s=%s', $key, $this->‪asHumanReadable($value));
70  }
71  return implode(', ', $items);
72  }
73 
74  private function ‪asHumanReadable($value)
75  {
76  if ($value === null) {
77  return '<null>';
78  }
79  if ($value === '') {
80  return '<empty>';
81  }
82  return $value;
83  }
84 
85  private function ‪compareApplicables(‪Applicable $a, ‪Applicable $b): int
86  {
87  if ($a === $b) {
88  return 0;
89  }
90  return 1;
91  }
92 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\getVariables
‪Variables getVariables()
Definition: VariablesContext.php:39
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\$variables
‪$variables
Definition: VariablesContext.php:20
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables
Definition: Variables.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\create
‪static create(Variables $variables)
Definition: VariablesContext.php:26
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext
Definition: VariablesContext.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\matchesRequiredApplicables
‪matchesRequiredApplicables(Applicable ... $applicables)
Definition: VariablesContext.php:44
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\$requiredApplicables
‪Applicable[] $requiredApplicables
Definition: VariablesContext.php:24
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Applicable
Definition: Applicable.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\describe
‪describe()
Definition: VariablesContext.php:64
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\asHumanReadable
‪asHumanReadable($value)
Definition: VariablesContext.php:73
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:3
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\__construct
‪__construct(Variables $variables)
Definition: VariablesContext.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\compareApplicables
‪compareApplicables(Applicable $a, Applicable $b)
Definition: VariablesContext.php:84
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\withRequiredApplicables
‪withRequiredApplicables(Applicable ... $requiredApplicables)
Definition: VariablesContext.php:57