use DOMXPath;
use Exception;
use Friendica\App\Arguments;
-use Friendica\App\Module;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\Configuration;
use Friendica\Core\Config\PConfiguration;
*/
private $baseURL;
- /**
- * @var bool true, if the call is from an backend node (f.e. worker)
- */
- private $isBackend;
-
/**
* @var string The name of the current theme
*/
*/
private $args;
- /**
- * @var App\Module
- */
- private $moduleClass;
-
/**
* Returns the current config cache of this node
*
*
* @throws Exception if the Basepath is not usable
*/
- public function __construct(Database $database, Configuration $config, App\Mode $mode, App\Router $router, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, Module $module)
+ public function __construct(Database $database, Configuration $config, App\Mode $mode, App\Router $router, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args)
{
$this->database = $database;
$this->config = $config;
$this->logger = $logger;
$this->l10n = $l10n;
$this->args = $args;
- $this->isBackend = $this->checkBackend($module);
$this->profiler->reset();
$this->getBaseURL();
}
- /**
- * Checks if the site is called via a backend process
- *
- * @param Module $module The pre-loaded module (just name, not class!)
-
- * @return bool True, if the call is a backend call
- */
- private function checkBackend(Module $module)
- {
- return basename(($_SERVER['PHP_SELF'] ?? ''), '.php') !== 'index' ||
- $module->isBackend();
- }
-
/**
* Returns true, if the call is from a backend node (f.e. from a worker)
*
* @return bool Is it a known backend?
+ *
+ * @deprecated 2019.09 - use App\Mode->isBackend() instead
+ * @see App\Mode::isBackend()
*/
public function isBackend()
{
- return $this->isBackend;
+ return $this->mode->isBackend();
}
/**
const MAINTENANCEDISABLED = 8;
/***
- * @var int the mode of this Application
+ * @var int The mode of this Application
*
*/
private $mode;
- public function __construct(int $mode = 0)
+ /**
+ * @var bool True, if the call is a backend call
+ */
+ private $isBackend;
+
+ public function __construct(int $mode = 0, bool $isBackend = false)
{
- $this->mode = $mode;
+ $this->mode = $mode;
+ $this->isBackend = $isBackend;
}
/**
$mode |= Mode::MAINTENANCEDISABLED;
- return new Mode($mode);
+ return new Mode($mode, $this->isBackend);
+ }
+
+ /**
+ * Checks if the site is called via a backend process
+ *
+ * @param Module $module The pre-loaded module (just name, not class!)
+ * @param array $server The $_SERVER variable
+ *
+ * @return Mode returns the determined mode
+ */
+ public function determineBackend(Module $module, array $server)
+ {
+ $isBackend = basename(($server['PHP_SELF'] ?? ''), '.php') !== 'index' ||
+ $module->isBackend();
+
+ return new Mode($this->mode, $isBackend);
}
/**
$this->has(Mode::DBCONFIGAVAILABLE) &&
$this->has(Mode::MAINTENANCEDISABLED);
}
+
+ /**
+ * Returns true, if the call is from a backend node (f.e. from a worker)
+ *
+ * @return bool Is it a backend call
+ */
+ public function isBackend()
+ {
+ return $this->isBackend;
+ }
}
],
App\Mode::class => [
'call' => [
+ ['determineBackend', [$_SERVER], Dice::CHAIN_CALL],
['determine', [], Dice::CHAIN_CALL],
],
],
namespace Friendica\Test\src\App;
use Friendica\App\Mode;
+use Friendica\App\Module;
use Friendica\Core\Config;
use Friendica\Database\Database;
use Friendica\Test\MockedTest;
$this->assertNotSame($modeNew, $mode);
}
+
+ /**
+ * Test if not called by index is backend
+ */
+ public function testIsBackendNotIndex()
+ {
+ $server = ['PHP_SELF' => '/daemon.php'];
+ $module = new Module();
+
+ $mode = (new Mode())->determineBackend($module, $server);
+
+ $this->assertTrue($mode->isBackend());
+ }
+
+ /**
+ * Test is called by index but module is backend
+ */
+ public function testIsBackendButIndex()
+ {
+ $server = ['PHP_SELF' => '/index.php'];
+ $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, true);
+
+ $mode = (new Mode())->determineBackend($module, $server);
+
+ $this->assertTrue($mode->isBackend());
+ }
+
+ /**
+ * Test is called by index and module is not backend
+ */
+ public function testIsNotBackend()
+ {
+ $server = ['PHP_SELF' => '/index.php'];
+ $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, false);
+
+ $mode = (new Mode())->determineBackend($module, $server);
+
+ $this->assertFalse($mode->isBackend());
+ }
}