Adding DependencyFactory
This commit is contained in:
parent
0a318925a4
commit
cdcf1667d7
|
@ -32,10 +32,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\App;
|
|
||||||
use Friendica\Core\Config\Cache;
|
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Util\BasePath;
|
|
||||||
use Friendica\Util\ExAuth;
|
use Friendica\Util\ExAuth;
|
||||||
|
|
||||||
if (sizeof($_SERVER["argv"]) == 0) {
|
if (sizeof($_SERVER["argv"]) == 0) {
|
||||||
|
@ -54,17 +51,7 @@ chdir($directory);
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
|
$a = Factory\DependencyFactory::setUp('auth_ejabbered', dirname(__DIR__));
|
||||||
$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);
|
|
||||||
|
|
||||||
if ($a->getMode()->isNormal()) {
|
if ($a->getMode()->isNormal()) {
|
||||||
$oAuth = new ExAuth();
|
$oAuth = new ExAuth();
|
||||||
|
|
|
@ -3,21 +3,9 @@
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Util\BasePath;
|
|
||||||
|
|
||||||
$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
|
$a = Factory\DependencyFactory::setUp('console', dirname(__DIR__));
|
||||||
$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);
|
|
||||||
\Friendica\BaseObject::setApp($a);
|
\Friendica\BaseObject::setApp($a);
|
||||||
|
|
||||||
(new Friendica\Core\Console($argv))->execute();
|
(new Friendica\Core\Console($argv))->execute();
|
||||||
|
|
|
@ -7,13 +7,11 @@
|
||||||
* This script was taken from http://php.net/manual/en/function.pcntl-fork.php
|
* 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;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Util\BasePath;
|
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
$shortopts = 'f';
|
$shortopts = 'f';
|
||||||
|
@ -34,17 +32,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
|
$a = Factory\DependencyFactory::setUp('daemon', dirname(__DIR__));
|
||||||
$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);
|
|
||||||
|
|
||||||
if ($a->getMode()->isInstall()) {
|
if ($a->getMode()->isInstall()) {
|
||||||
die("Friendica isn't properly installed yet.\n");
|
die("Friendica isn't properly installed yet.\n");
|
||||||
|
@ -114,7 +102,7 @@ if ($mode == "stop") {
|
||||||
|
|
||||||
unlink($pidfile);
|
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);
|
Config::set('system', 'worker_daemon_mode', false);
|
||||||
die("Worker daemon process $pid was killed.\n");
|
die("Worker daemon process $pid was killed.\n");
|
||||||
|
@ -124,7 +112,7 @@ if (!empty($pid) && posix_kill($pid, 0)) {
|
||||||
die("Daemon process $pid is already running.\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) {
|
if (!$foreground) {
|
||||||
echo "Starting worker daemon.\n";
|
echo "Starting worker daemon.\n";
|
||||||
|
@ -172,7 +160,7 @@ $last_cron = 0;
|
||||||
// Now running as a daemon.
|
// Now running as a daemon.
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!$do_cron && ($last_cron + $wait_interval) < time()) {
|
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;
|
$do_cron = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +174,7 @@ while (true) {
|
||||||
$last_cron = time();
|
$last_cron = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger->info("Sleeping", ["pid" => $pid]);
|
Logger::info("Sleeping", ["pid" => $pid]);
|
||||||
$start = time();
|
$start = time();
|
||||||
do {
|
do {
|
||||||
$seconds = (time() - $start);
|
$seconds = (time() - $start);
|
||||||
|
@ -203,10 +191,10 @@ while (true) {
|
||||||
|
|
||||||
if ($timeout) {
|
if ($timeout) {
|
||||||
$do_cron = true;
|
$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 {
|
} else {
|
||||||
$do_cron = false;
|
$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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,9 @@
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\Config\Cache;
|
|
||||||
use Friendica\Core\Update;
|
use Friendica\Core\Update;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Util\BasePath;
|
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
$shortopts = 'sn';
|
$shortopts = 'sn';
|
||||||
|
@ -32,17 +30,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
$basedir = BasePath::create(dirname(__DIR__), $_SERVER);
|
$a = Factory\DependencyFactory::setUp('worker', dirname(__DIR__));
|
||||||
$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);
|
|
||||||
|
|
||||||
// Check the database structure and possibly fixes it
|
// Check the database structure and possibly fixes it
|
||||||
Update::check($a->getBasePath(), true);
|
Update::check($a->getBasePath(), true);
|
||||||
|
|
15
index.php
15
index.php
|
@ -4,10 +4,7 @@
|
||||||
* Friendica
|
* Friendica
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\App;
|
|
||||||
use Friendica\Core\Config\Cache;
|
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Util\BasePath;
|
|
||||||
|
|
||||||
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
|
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.');
|
die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.');
|
||||||
|
@ -15,18 +12,8 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
|
||||||
|
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
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
|
// We assume that the index.php is called by a frontend process
|
||||||
// The value is set to "true" by default in App
|
// 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();
|
$a->runFrontend();
|
||||||
|
|
36
src/Factory/DependencyFactory.php
Normal file
36
src/Factory/DependencyFactory.php
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue