*
*/
-use Friendica\App;
-use Friendica\Core\Config\Cache;
use Friendica\Factory;
-use Friendica\Util\BasePath;
use Friendica\Util\ExAuth;
if (sizeof($_SERVER["argv"]) == 0) {
require dirname(__DIR__) . '/vendor/autoload.php';
-$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
-$configLoader = new Cache\ConfigCacheLoader($basedir);
-$configCache = Factory\ConfigFactory::createCache($configLoader);
-Factory\DBFactory::init($configCache, $_SERVER);
-$config = Factory\ConfigFactory::createConfig($configCache);
-// needed to call PConfig::init()
-Factory\ConfigFactory::createPConfig($configCache);
-$logger = Factory\LoggerFactory::create('auth_ejabberd', $config);
-$profiler = Factory\ProfilerFactory::create($logger, $config);
-
-$a = new App($config, $logger, $profiler);
+$a = Factory\DependencyFactory::setUp('auth_ejabbered', dirname(__DIR__));
if ($a->getMode()->isNormal()) {
$oAuth = new ExAuth();
require dirname(__DIR__) . '/vendor/autoload.php';
-use Friendica\Core\Config\Cache;
use Friendica\Factory;
-use Friendica\Util\BasePath;
-$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
-$configLoader = new Cache\ConfigCacheLoader($basedir);
-$configCache = Factory\ConfigFactory::createCache($configLoader);
-Factory\DBFactory::init($configCache, $_SERVER);
-$config = Factory\ConfigFactory::createConfig($configCache);
-// needed to call PConfig::init()
-Factory\ConfigFactory::createPConfig($configCache);
-$logger = Factory\LoggerFactory::create('console', $config);
-$profiler = Factory\ProfilerFactory::create($logger, $config);
-
-$a = new Friendica\App($config, $logger, $profiler);
+$a = Factory\DependencyFactory::setUp('console', dirname(__DIR__));
\Friendica\BaseObject::setApp($a);
(new Friendica\Core\Console($argv))->execute();
* This script was taken from http://php.net/manual/en/function.pcntl-fork.php
*/
-use Friendica\App;
use Friendica\Core\Config;
-use Friendica\Core\Config\Cache;
+use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Factory;
-use Friendica\Util\BasePath;
// Get options
$shortopts = 'f';
require dirname(__DIR__) . '/vendor/autoload.php';
-$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
-$configLoader = new Cache\ConfigCacheLoader($basedir);
-$configCache = Factory\ConfigFactory::createCache($configLoader);
-Factory\DBFactory::init($configCache, $_SERVER);
-$config = Factory\ConfigFactory::createConfig($configCache);
-// needed to call PConfig::init()
-Factory\ConfigFactory::createPConfig($configCache);
-$logger = Factory\LoggerFactory::create('daemon', $config);
-$profiler = Factory\ProfilerFactory::create($logger, $config);
-
-$a = new App($config, $logger, $profiler);
+$a = Factory\DependencyFactory::setUp('daemon', dirname(__DIR__));
if ($a->getMode()->isInstall()) {
die("Friendica isn't properly installed yet.\n");
unlink($pidfile);
- $logger->notice("Worker daemon process was killed", ["pid" => $pid]);
+ Logger::notice("Worker daemon process was killed", ["pid" => $pid]);
Config::set('system', 'worker_daemon_mode', false);
die("Worker daemon process $pid was killed.\n");
die("Daemon process $pid is already running.\n");
}
-$logger->notice('Starting worker daemon.', ["pid" => $pid]);
+Logger::notice('Starting worker daemon.', ["pid" => $pid]);
if (!$foreground) {
echo "Starting worker daemon.\n";
// Now running as a daemon.
while (true) {
if (!$do_cron && ($last_cron + $wait_interval) < time()) {
- $logger->info('Forcing cron worker call.', ["pid" => $pid]);
+ Logger::info('Forcing cron worker call.', ["pid" => $pid]);
$do_cron = true;
}
$last_cron = time();
}
- $logger->info("Sleeping", ["pid" => $pid]);
+ Logger::info("Sleeping", ["pid" => $pid]);
$start = time();
do {
$seconds = (time() - $start);
if ($timeout) {
$do_cron = true;
- $logger->info("Woke up after $wait_interval seconds.", ["pid" => $pid, 'sleep' => $wait_interval]);
+ Logger::info("Woke up after $wait_interval seconds.", ["pid" => $pid, 'sleep' => $wait_interval]);
} else {
$do_cron = false;
- $logger->info("Worker jobs are calling to be forked.", ["pid" => $pid]);
+ Logger::info("Worker jobs are calling to be forked.", ["pid" => $pid]);
}
}
use Friendica\App;
use Friendica\Core\Config;
-use Friendica\Core\Config\Cache;
use Friendica\Core\Update;
use Friendica\Core\Worker;
use Friendica\Factory;
-use Friendica\Util\BasePath;
// Get options
$shortopts = 'sn';
require dirname(__DIR__) . '/vendor/autoload.php';
-$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
-$configLoader = new Cache\ConfigCacheLoader($basedir);
-$configCache = Factory\ConfigFactory::createCache($configLoader);
-Factory\DBFactory::init($configCache, $_SERVER);
-$config = Factory\ConfigFactory::createConfig($configCache);
-// needed to call PConfig::init()
-Factory\ConfigFactory::createPConfig($configCache);
-$logger = Factory\LoggerFactory::create('worker', $config);
-$profiler = Factory\ProfilerFactory::create($logger, $config);
-
-$a = new App($config, $logger, $profiler);
+$a = Factory\DependencyFactory::setUp('worker', dirname(__DIR__));
// Check the database structure and possibly fixes it
Update::check($a->getBasePath(), true);
* Friendica
*/
-use Friendica\App;
-use Friendica\Core\Config\Cache;
use Friendica\Factory;
-use Friendica\Util\BasePath;
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.');
require __DIR__ . '/vendor/autoload.php';
-$basedir = BasePath::create(__DIR__, $_SERVER);
-$configLoader = new Cache\ConfigCacheLoader($basedir);
-$configCache = Factory\ConfigFactory::createCache($configLoader);
-Factory\DBFactory::init($configCache, $_SERVER);
-$config = Factory\ConfigFactory::createConfig($configCache);
-// needed to call PConfig::init()
-Factory\ConfigFactory::createPConfig($configCache);
-$logger = Factory\LoggerFactory::create('index', $config);
-$profiler = Factory\ProfilerFactory::create($logger, $config);
-
// We assume that the index.php is called by a frontend process
// The value is set to "true" by default in App
-$a = new App($config, $logger, $profiler, false);
+$a = Factory\DependencyFactory::setUp('index', __DIR__, true);
$a->runFrontend();
--- /dev/null
+<?php
+
+namespace Friendica\Factory;
+
+use Friendica\App;
+use Friendica\Core\Config\Cache;
+use Friendica\Factory;
+use Friendica\Util\BasePath;
+
+class DependencyFactory
+{
+ /**
+ * Setting all default-dependencies of a friendica execution
+ *
+ * @param string $channel The channel of this execution
+ * @param string $directory The base directory
+ * @param bool $isBackend True, if it's a backend execution, otherwise false (Default true)
+ *
+ * @return App The application
+ *
+ * @throws \Exception
+ */
+ public static function setUp($channel, $directory, $isBackend = true)
+ {
+ $basedir = BasePath::create($directory, $_SERVER);
+ $configLoader = new Cache\ConfigCacheLoader($basedir);
+ $configCache = Factory\ConfigFactory::createCache($configLoader);
+ Factory\DBFactory::init($configCache, $_SERVER);
+ $config = Factory\ConfigFactory::createConfig($configCache);
+ // needed to call PConfig::init()
+ Factory\ConfigFactory::createPConfig($configCache);
+ Factory\LoggerFactory::create($channel, $config);
+
+ return new App($config, $isBackend);
+ }
+}