[FEATURE] Introduce methods to detect TYPO3_MODE properly
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Sun, 17 Mar 2013 21:31:08 +0000 (22:31 +0100)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Mon, 18 Mar 2013 08:19:40 +0000 (09:19 +0100)
Currently a lot of conditions exist that directly
check for TYPO3_MODE to be "FE" or "BE". When it
comes to unit test this is pretty bad as constants
cannot be mocked at all.

Therefore this patch introduces two methods in the
ExtensionService to detect if the plugin is running
in frontend or backend mode.

Releases: 6.1
Resolves: #46391
Change-Id: I7367cda467ac2a421e0f8d6d25dd2209f939b99b
Reviewed-on: https://review.typo3.org/18995
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Mattias Nilsson
Tested-by: Mattias Nilsson
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
typo3/sysext/extbase/Classes/Service/EnvironmentService.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Service/ExtensionService.php

diff --git a/typo3/sysext/extbase/Classes/Service/EnvironmentService.php b/typo3/sysext/extbase/Classes/Service/EnvironmentService.php
new file mode 100644 (file)
index 0000000..ff98854
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+namespace TYPO3\CMS\Extbase\Service;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Service for determining environment params
+ */
+class EnvironmentService {
+
+       /**
+        * Detects if TYPO3_MODE is defined and its value is "FE"
+        *
+        * @return boolean
+        */
+       public function isInFrontendMode() {
+               return (defined('TYPO3_MODE') && TYPO3_MODE === 'FE') ?: FALSE;
+       }
+
+       /**
+        * Detects if TYPO3_MODE is defined and its value is "BE"
+        *
+        * @return boolean
+        */
+       public function isInBackendMode() {
+               return (defined('TYPO3_MODE') && TYPO3_MODE === 'BE') ?: FALSE;
+       }
+}
+
+?>
\ No newline at end of file
index deb84a0..e47d41c 100644 (file)
@@ -28,7 +28,7 @@ namespace TYPO3\CMS\Extbase\Service;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 /**
- * Utilities to process FlexForms
+ * Service for determining basic extension params
  */
 class ExtensionService implements \TYPO3\CMS\Core\SingletonInterface {