TYPO3 CMS  TYPO3_8-7
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 
18 
36 {
42  protected $contextString;
43 
49  protected $rootContextString;
50 
56  protected $parentContext;
57 
64  public function __construct($contextString)
65  {
66  if (strpos($contextString, '/') === false) {
67  $this->rootContextString = $contextString;
68  $this->parentContext = null;
69  } else {
70  $contextStringParts = explode('/', $contextString);
71  $this->rootContextString = $contextStringParts[0];
72  array_pop($contextStringParts);
73  $this->parentContext = new self(implode('/', $contextStringParts));
74  }
75 
76  if (!in_array($this->rootContextString, ['Development', 'Production', 'Testing'], true)) {
77  throw new Exception('The given context "' . $contextString . '" was not valid. Only allowed are Development, Production and Testing, including their sub-contexts', 1335436551);
78  }
79 
80  $this->contextString = $contextString;
81  }
82 
89  public function __toString()
90  {
91  return $this->contextString;
92  }
93 
100  public function isDevelopment()
101  {
102  return $this->rootContextString === 'Development';
103  }
104 
111  public function isProduction()
112  {
113  return $this->rootContextString === 'Production';
114  }
115 
122  public function isTesting()
123  {
124  return $this->rootContextString === 'Testing';
125  }
126 
133  public function getParent()
134  {
135  return $this->parentContext;
136  }
137 }