TYPO3 CMS  TYPO3_7-6
ApplicationContext.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
34 {
40  protected $contextString;
41 
47  protected $rootContextString;
48 
54  protected $parentContext;
55 
62  public function __construct($contextString)
63  {
64  if (strstr($contextString, '/') === false) {
65  $this->rootContextString = $contextString;
66  $this->parentContext = null;
67  } else {
68  $contextStringParts = explode('/', $contextString);
69  $this->rootContextString = $contextStringParts[0];
70  array_pop($contextStringParts);
71  $this->parentContext = new self(implode('/', $contextStringParts));
72  }
73 
74  if (!in_array($this->rootContextString, ['Development', 'Production', 'Testing'])) {
75  throw new \TYPO3\CMS\Core\Exception('The given context "' . $contextString . '" was not valid. Only allowed are Development, Production and Testing, including their sub-contexts', 1335436551);
76  }
77 
78  $this->contextString = $contextString;
79  }
80 
87  public function __toString()
88  {
89  return $this->contextString;
90  }
91 
98  public function isDevelopment()
99  {
100  return $this->rootContextString === 'Development';
101  }
102 
109  public function isProduction()
110  {
111  return $this->rootContextString === 'Production';
112  }
113 
120  public function isTesting()
121  {
122  return $this->rootContextString === 'Testing';
123  }
124 
131  public function getParent()
132  {
133  return $this->parentContext;
134  }
135 }