‪TYPO3CMS  ‪main
ApplicationContext.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 
39 {
45  protected ‪$contextString;
46 
52  protected ‪$rootContextString;
53 
59  protected ‪$parentContext;
60 
67  public function ‪__construct(‪$contextString)
68  {
69  if (!str_contains(‪$contextString, '/')) {
70  $this->rootContextString = ‪$contextString;
71  $this->parentContext = null;
72  } else {
73  $contextStringParts = explode('/', ‪$contextString);
74  $this->rootContextString = $contextStringParts[0];
75  array_pop($contextStringParts);
76  $this->parentContext = new self(implode('/', $contextStringParts));
77  }
78 
79  if (!in_array($this->rootContextString, ['Development', 'Production', 'Testing'], true)) {
80  throw new ‪Exception('The given context "' . ‪$contextString . '" was not valid. Only allowed are Development, Production and Testing, including their sub-contexts', 1335436551);
81  }
82 
83  $this->contextString = ‪$contextString;
84  }
85 
91  public function ‪__toString()
92  {
94  }
95 
101  public function ‪isDevelopment()
102  {
103  return $this->rootContextString === 'Development';
104  }
105 
111  public function ‪isProduction()
112  {
113  return $this->rootContextString === 'Production';
114  }
115 
121  public function ‪isTesting()
122  {
123  return $this->rootContextString === 'Testing';
124  }
125 
131  public function ‪getParent()
132  {
134  }
135 }
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:39
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Core\ApplicationContext\isProduction
‪bool isProduction()
Definition: ApplicationContext.php:108
‪TYPO3\CMS\Core\Core\ApplicationContext\getParent
‪TYPO3 CMS Core Core ApplicationContext null getParent()
Definition: ApplicationContext.php:128
‪TYPO3\CMS\Core\Core\ApplicationContext\$parentContext
‪TYPO3 CMS Core Core ApplicationContext null $parentContext
Definition: ApplicationContext.php:56
‪TYPO3\CMS\Core\Core\ApplicationContext\isTesting
‪bool isTesting()
Definition: ApplicationContext.php:118
‪TYPO3\CMS\Core\Core\ApplicationContext\$rootContextString
‪string $rootContextString
Definition: ApplicationContext.php:50
‪TYPO3\CMS\Core\Core\ApplicationContext\__toString
‪string __toString()
Definition: ApplicationContext.php:88
‪TYPO3\CMS\Core\Core\ApplicationContext\$contextString
‪string $contextString
Definition: ApplicationContext.php:44
‪TYPO3\CMS\Core\Error\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Core\ApplicationContext\isDevelopment
‪bool isDevelopment()
Definition: ApplicationContext.php:98
‪TYPO3\CMS\Core\Core
Definition: ApplicationContext.php:16
‪TYPO3\CMS\Core\Core\ApplicationContext\__construct
‪__construct($contextString)
Definition: ApplicationContext.php:64