*
*/
-use Friendica\Factory;
use Friendica\Util\ExAuth;
if (sizeof($_SERVER["argv"]) == 0) {
$dice = new \Dice\Dice();
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
-$a = Factory\DependencyFactory::setUp('auth_ejabbered', $dice);
+$appMode = $dice->create(\Friendica\App\Mode::class);
-if ($a->getMode()->isNormal()) {
+if ($appMode->isNormal()) {
$oAuth = new ExAuth();
$oAuth->readStdin();
}
require dirname(__DIR__) . '/vendor/autoload.php';
-use Friendica\Factory;
-
$dice = new \Dice\Dice();
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
-$a = Factory\DependencyFactory::setUp('console', $dice);
-\Friendica\BaseObject::setApp($a);
+\Friendica\BaseObject::setDependencyInjection($dice);
(new Friendica\Core\Console($argv))->execute();
use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
-use Friendica\Factory;
// Get options
$shortopts = 'f';
$dice = new \Dice\Dice();
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
-$a = Factory\DependencyFactory::setUp('daemon', $dice);
+\Friendica\BaseObject::setDependencyInjection($dice);
+$a = \Friendica\BaseObject::getApp();
if ($a->getMode()->isInstall()) {
die("Friendica isn't properly installed yet.\n");
file_put_contents($pidfile, $pid);
// We lose the database connection upon forking
- $a->getDatabase()->reconnect();
+ DBA::reconnect();
}
Config::set('system', 'worker_daemon_mode', true);
use Friendica\Core\Config;
use Friendica\Core\Update;
use Friendica\Core\Worker;
-use Friendica\Factory;
// Get options
$shortopts = 'sn';
$dice = new \Dice\Dice();
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
-$a = Factory\DependencyFactory::setUp('worker', $dice);
+\Friendica\BaseObject::setDependencyInjection($dice);
+$a = \Friendica\BaseObject::getApp();
// Check the database structure and possibly fixes it
Update::check($a->getBasePath(), true, $a->getMode());
* Friendica
*/
-use Friendica\Factory;
-
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.');
}
$dice = new \Dice\Dice();
$dice = $dice->addRules(include __DIR__ . '/static/dependencies.config.php');
-$a = Factory\DependencyFactory::setUp('index', $dice, false);
+\Friendica\BaseObject::setDependencyInjection($dice);
+
+$a = \Friendica\BaseObject::getApp();
$a->runFrontend();
theme_post($a);
}
} else {
- $a->getDatabase()->update('user', ['theme' => $theme], ['uid' => local_user()]);
+ DBA::update('user', ['theme' => $theme], ['uid' => local_user()]);
}
} else {
notice(L10n::t('The theme you chose isn\'t available.'));
return $this->mode;
}
- /**
- * Returns the router of the Application
- *
- * @return App\Router
- */
- public function getRouter()
- {
- return $this->router;
- }
-
- /**
- * @return Database
- */
- public function getDatabase()
- {
- return $this->database;
- }
-
- /**
- * @return L10n
- */
- public function getL10n()
- {
- return $this->l10n;
- }
-
/**
* Register a stylesheet file path to be included in the <head> tag of every page.
* Inclusion is done in App->initHead().
* @param LoggerInterface $logger The current app logger
* @param Profiler $profiler The profiler of this application
* @param L10n $l10n The translator instance
- * @param bool $isBackend Whether it is used for backend or frontend (Default true=backend)
*
* @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, $isBackend = true)
+ public function __construct(Database $database, Configuration $config, App\Mode $mode, App\Router $router, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n)
{
- BaseObject::setApp($this);
-
$this->database = $database;
$this->config = $config;
$this->mode = $mode;
$this->module = 'home';
}
- $this->isBackend = $isBackend || $this->checkBackend($this->module);
+ $this->isBackend = $this->isBackend || $this->checkBackend($this->module);
// Detect mobile devices
$mobile_detect = new MobileDetect();
*/
public function reload()
{
+ $this->isBackend = basename($_SERVER['PHP_SELF'], '.php') !== 'index';
+
$this->getMode()->determine($this->getBasePath());
if ($this->getMode()->has(App\Mode::DBAVAILABLE)) {
require_once __DIR__ . '/../boot.php';
+use Dice\Dice;
use Friendica\Network\HTTPException\InternalServerErrorException;
/**
* Basic object
*
* Contains what is useful to any object
+ *
+ * Act's like a global registry for classes
*/
class BaseObject
{
/**
- * @var App
+ * @var Dice The Dependency Injection library
*/
- private static $app = null;
+ private static $dice;
+
+ /**
+ * Set's the dependency injection library for a global usage
+ *
+ * @param Dice $dice The dependency injection library
+ */
+ public static function setDependencyInjection(Dice $dice)
+ {
+ self::$dice = $dice;
+ }
/**
* Get the app
* Same as get_app from boot.php
*
* @return App
- * @throws \Exception
*/
public static function getApp()
{
- if (empty(self::$app)) {
- throw new InternalServerErrorException('App isn\'t initialized.');
- }
-
- return self::$app;
+ return self::$dice->create(App::class);
}
/**
- * Set the app
+ * Returns the initialized class based on it's name
*
- * @param App $app App
+ * @param string $name The name of the class
*
- * @return void
+ * @return object The initialized name
+ *
+ * @throws InternalServerErrorException
*/
- public static function setApp(App $app)
+ public static function getClass(string $name)
{
- self::$app = $app;
+ if (class_exists($name) || interface_exists($name )) {
+ return self::$dice->create($name);
+ } else {
+ throw new InternalServerErrorException('Class \'' . $name . '\' isn\'t valid.');
+ }
}
}
*/
namespace Friendica\Core;
+use Friendica\BaseObject;
+use Friendica\Core\Config\Configuration;
+
/**
* @brief Arbitrary system configuration storage
*
* If we ever would decide to return exactly the variable type as entered,
* we will have fun with the additional features. :-)
*/
-class Config
+class Config extends BaseObject
{
- /**
- * @var Config\Configuration
- */
- private static $config;
-
- /**
- * Initialize the config
- *
- * @param Config\Configuration $config
- */
- public static function init(Config\Configuration $config)
- {
- self::$config = $config;
- }
-
/**
* @brief Loads all configuration values of family into a cached storage.
*
*/
public static function load($cat = "config")
{
- self::$config->load($cat);
+ self::getClass(Configuration::class)->load($cat);
}
/**
*/
public static function get($cat, $key, $default_value = null, $refresh = false)
{
- return self::$config->get($cat, $key, $default_value, $refresh);
+ return self::getClass(Configuration::class)->get($cat, $key, $default_value, $refresh);
}
/**
*/
public static function set($cat, $key, $value)
{
- return self::$config->set($cat, $key, $value);
+ return self::getClass(Configuration::class)->set($cat, $key, $value);
}
/**
*/
public static function delete($cat, $key)
{
- return self::$config->delete($cat, $key);
+ return self::getClass(Configuration::class)->delete($cat, $key);
}
}
use DOMDocument;
use Exception;
use Friendica\Core\Config\Cache\ConfigCache;
-use Friendica\Database\Database;
+use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\Object\Image;
-use Friendica\Util\Logger\VoidLogger;
use Friendica\Util\Network;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
*/
public function checkDB(ConfigCache $configCache, Profiler $profiler)
{
- $database = new Database($configCache, $profiler, new VoidLogger());
+ DBA::reconnect();
- if ($database->connected()) {
+ if (DBA::connected()) {
if (DBStructure::existsTable('user')) {
$this->addCheck(L10n::t('Database already in use.'), false, true, '');
*/
namespace Friendica\Core;
+use Friendica\BaseObject;
use Friendica\Core\L10n\L10n as L10nClass;
/**
* Provide Language, Translation, and Localization functions to the application
* Localization can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N").
*/
-class L10n
+class L10n extends BaseObject
{
- /**
- * @var L10nClass
- */
- private static $l10n;
-
- /**
- * Initializes the L10n static wrapper with the instance
- *
- * @param L10nClass $l10n The l10n class
- */
- public static function init(L10nClass $l10n)
- {
- self::$l10n = $l10n;
- }
-
/**
* Returns the current language code
*
*/
public static function getCurrentLang()
{
- return self::$l10n->getCurrentLang();
+ return self::getClass(L10nClass::class)->getCurrentLang();
}
/**
*/
public static function pushLang($lang)
{
- self::$l10n->pushLang($lang);
+ self::getClass(L10nClass::class)->pushLang($lang);
}
/**
*/
public static function popLang()
{
- self::$l10n->popLang();
+ self::getClass(L10nClass::class)->popLang();
}
/**
*/
public static function t($s, ...$vars)
{
- return self::$l10n->t($s, ...$vars);
+ return self::getClass(L10nClass::class)->t($s, ...$vars);
}
/**
*/
public static function tt(string $singular, string $plural, int $count)
{
- return self::$l10n->tt($singular, $plural, $count);
+ return self::getClass(L10nClass::class)->tt($singular, $plural, $count);
}
/**
*/
public static function getAvailableLanguages()
{
- return self::$l10n::getAvailableLanguages();
+ return L10nClass::getAvailableLanguages();
}
/**
*/
public static function getDay($s)
{
- return self::$l10n->getDay($s);
+ return self::getClass(L10nClass::class)->getDay($s);
}
/**
*/
public static function getDayShort($s)
{
- return self::$l10n->getDayShort($s);
+ return self::getClass(L10nClass::class)->getDayShort($s);
}
}
$this->logger = $logger;
$this->loadTranslationTable(L10n::detectLanguage($config->get('system', 'language', 'en')));
-
- \Friendica\Core\L10n::init($this);
}
/**
*/
namespace Friendica\Core;
+use Friendica\BaseObject;
+use Friendica\Util\Logger\WorkerLogger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
/**
* @brief Logger functions
*/
-class Logger
+class Logger extends BaseObject
{
/**
* @see Logger::error()
*/
const ALL = LogLevel::DEBUG;
+ /**
+ * @var LoggerInterface The default Logger type
+ */
+ const TYPE_LOGGER = LoggerInterface::class;
+ /**
+ * @var WorkerLogger A specific worker logger type, which can be anabled
+ */
+ const TYPE_WORKER = WorkerLogger::class;
+ /**
+ * @var LoggerInterface The current logger type
+ */
+ private static $type = self::TYPE_LOGGER;
+
/**
* @var array the legacy loglevels
* @deprecated 2019.03 use PSR-3 loglevels
];
/**
- * @var LoggerInterface A PSR-3 compliant logger instance
- */
- private static $logger;
-
- /**
- * @var LoggerInterface A PSR-3 compliant logger instance for developing only
- */
- private static $devLogger;
-
- /**
- * Sets the default logging handler for Friendica.
+ * Enable additional logging for worker usage
+ *
+ * @param string $functionName The worker function, which got called
*
- * @param LoggerInterface $logger The Logger instance of this Application
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function init(LoggerInterface $logger)
+ public static function enableWorker(string $functionName)
{
- self::$logger = $logger;
+ self::$type = self::TYPE_WORKER;
+ self::getClass(self::$type)->setFunctionName($functionName);
}
/**
- * Sets the default dev-logging handler for Friendica.
- *
- * @param LoggerInterface $logger The Logger instance of this Application
+ * Disable additional logging for worker usage
*/
- public static function setDevLogger(LoggerInterface $logger)
+ public static function disableWorker()
{
- self::$devLogger = $logger;
+ self::$type = self::TYPE_LOGGER;
}
/**
*/
public static function emergency($message, $context = [])
{
- self::$logger->emergency($message, $context);
+ self::getClass(self::$type)->emergency($message, $context);
}
/**
*/
public static function alert($message, $context = [])
{
- self::$logger->alert($message, $context);
+ self::getClass(self::$type)->alert($message, $context);
}
/**
*/
public static function critical($message, $context = [])
{
- self::$logger->critical($message, $context);
+ self::getClass(self::$type)->critical($message, $context);
}
/**
*/
public static function error($message, $context = [])
{
- self::$logger->error($message, $context);
+ self::getClass(self::$type)->error($message, $context);
}
/**
*/
public static function warning($message, $context = [])
{
- self::$logger->warning($message, $context);
+ self::getClass(self::$type)->warning($message, $context);
}
/**
*/
public static function notice($message, $context = [])
{
- self::$logger->notice($message, $context);
+ self::getClass(self::$type)->notice($message, $context);
}
/**
*/
public static function info($message, $context = [])
{
- self::$logger->info($message, $context);
+ self::getClass(self::$type)->info($message, $context);
}
/**
*/
public static function debug($message, $context = [])
{
- self::$logger->debug($message, $context);
+ self::getClass(self::$type)->debug($message, $context);
}
/**
*/
public static function log($msg, $level = LogLevel::INFO)
{
- self::$logger->log($level, $msg);
+ self::getClass(self::$type)->log($level, $msg);
}
/**
*/
public static function devLog($msg, $level = LogLevel::DEBUG)
{
- if (!isset(self::$devLogger)) {
- return;
- }
-
- self::$devLogger->log($level, $msg);
+ self::getClass('$devLogger')->log($level, $msg);
}
}
*/
namespace Friendica\Core;
+use Friendica\BaseObject;
+use Friendica\Core\Config\PConfiguration;
+
/**
* @brief Management of user configuration storage
* Note:
* The PConfig::get() functions return boolean false for keys that are unset,
* and this could lead to subtle bugs.
*/
-class PConfig
+class PConfig extends BaseObject
{
- /**
- * @var Config\PConfiguration
- */
- private static $config;
-
- /**
- * Initialize the config with only the cache
- *
- * @param Config\PConfiguration $config The configuration cache
- */
- public static function init(Config\PConfiguration $config)
- {
- self::$config = $config;
- }
-
/**
* @brief Loads all configuration values of a user's config family into a cached storage.
*
*/
public static function load(int $uid, string $cat)
{
- self::$config->load($uid, $cat);
+ self::getClass(PConfiguration::class)->load($uid, $cat);
}
/**
*/
public static function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false)
{
- return self::$config->get($uid, $cat, $key, $default_value, $refresh);
+ return self::getClass(PConfiguration::class)->get($uid, $cat, $key, $default_value, $refresh);
}
/**
*/
public static function set(int $uid, string $cat, string $key, $value)
{
- return self::$config->set($uid, $cat, $key, $value);
+ return self::getClass(PConfiguration::class)->set($uid, $cat, $key, $value);
}
/**
*/
public static function delete(int $uid, string $cat, string $key)
{
- return self::$config->delete($uid, $cat, $key);
+ return self::getClass(PConfiguration::class)->delete($uid, $cat, $key);
}
}
use Friendica\Database\DBA;
use Friendica\Model\Process;
use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Logger\WorkerLogger;
use Friendica\Util\Network;
/**
$argc = count($argv);
- $logger = $a->getLogger();
- $workerLogger = new WorkerLogger($logger, $funcname);
+ Logger::enableWorker($funcname);
- $workerLogger ->info("Process start.", ['priority' => $queue["priority"], 'id' => $queue["id"]]);
+ Logger::info("Process start.", ['priority' => $queue["priority"], 'id' => $queue["id"]]);
$stamp = (float)microtime(true);
unset($_SESSION);
// Set the workerLogger as new default logger
- Logger::init($workerLogger);
if ($method_call) {
call_user_func_array(sprintf('Friendica\Worker\%s::execute', $funcname), $argv);
} else {
$funcname($argv, $argc);
}
- Logger::init($logger);
+
+ Logger::disableWorker();
unset($a->queue);
$rest = round(max(0, $up_duration - (self::$db_duration + self::$lock_duration)), 2);
$exec = round($duration, 2);
- $logger->info('Performance:', ['state' => self::$state, 'count' => $dbcount, 'stat' => $dbstat, 'write' => $dbwrite, 'lock' => $dblock, 'total' => $dbtotal, 'rest' => $rest, 'exec' => $exec]);
+ Logger::info('Performance:', ['state' => self::$state, 'count' => $dbcount, 'stat' => $dbstat, 'write' => $dbwrite, 'lock' => $dblock, 'total' => $dbtotal, 'rest' => $rest, 'exec' => $exec]);
self::$up_start = microtime(true);
self::$db_duration = 0;
self::$lock_duration = 0;
if ($duration > 3600) {
- $logger->info('Longer than 1 hour.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
+ Logger::info('Longer than 1 hour.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
} elseif ($duration > 600) {
- $logger->info('Longer than 10 minutes.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
+ Logger::info('Longer than 10 minutes.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
} elseif ($duration > 300) {
- $logger->info('Longer than 5 minutes.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
+ Logger::info('Longer than 5 minutes.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
} elseif ($duration > 120) {
- $logger->info('Longer than 2 minutes.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
+ Logger::info('Longer than 2 minutes.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration/60, 3)]);
}
- $workerLogger->info('Process done.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration, 3)]);
+ Logger::info('Process done.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration, 3)]);
$a->getProfiler()->saveLog($a->getLogger(), "ID " . $queue["id"] . ": " . $funcname);
$cooldown = Config::get("system", "worker_cooldown", 0);
if ($cooldown > 0) {
- $logger->info('Cooldown.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'cooldown' => $cooldown]);
+ Logger::info('Cooldown.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'cooldown' => $cooldown]);
sleep($cooldown);
}
}
namespace Friendica\Database;
+use Friendica\BaseObject;
use mysqli;
use mysqli_result;
use mysqli_stmt;
*
* This class is for the low level database stuff that does driver specific things.
*/
-class DBA
+class DBA extends BaseObject
{
/**
* Lowest possible date value
*/
const NULL_DATETIME = '0001-01-01 00:00:00';
- /**
- * @var Database
- */
- private static $database;
-
- public static function init(Database $database)
- {
- self::$database = $database;
- }
-
public static function connect()
{
- return self::$database->connect();
+ return self::getClass(Database::class)->connect();
}
/**
*/
public static function disconnect()
{
- self::$database->disconnect();
+ self::getClass(Database::class)->disconnect();
}
/**
*/
public static function reconnect()
{
- return self::$database->reconnect();
+ return self::getClass(Database::class)->reconnect();
}
/**
*/
public static function getConnection()
{
- return self::$database->getConnection();
+ return self::getClass(Database::class)->getConnection();
}
/**
*/
public static function serverInfo()
{
- return self::$database->serverInfo();
+ return self::getClass(Database::class)->serverInfo();
}
/**
*/
public static function databaseName()
{
- return self::$database->databaseName();
+ return self::getClass(Database::class)->databaseName();
}
public static function escape($str)
{
- return self::$database->escape($str);
+ return self::getClass(Database::class)->escape($str);
}
public static function connected()
{
- return self::$database->connected();
+ return self::getClass(Database::class)->connected();
}
/**
*/
public static function anyValueFallback($sql)
{
- return self::$database->anyValueFallback($sql);
+ return self::getClass(Database::class)->anyValueFallback($sql);
}
/**
{
$params = self::getParam(func_get_args());
- return self::$database->p($sql, $params);
+ return self::getClass(Database::class)->p($sql, $params);
}
/**
$params = self::getParam(func_get_args());
- return self::$database->e($sql, $params);
+ return self::getClass(Database::class)->e($sql, $params);
}
/**
*/
public static function exists($table, $condition)
{
- return self::$database->exists($table, $condition);
+ return self::getClass(Database::class)->exists($table, $condition);
}
/**
{
$params = self::getParam(func_get_args());
- return self::$database->fetchFirst($sql, $params);
+ return self::getClass(Database::class)->fetchFirst($sql, $params);
}
/**
*/
public static function affectedRows()
{
- return self::$database->affectedRows();
+ return self::getClass(Database::class)->affectedRows();
}
/**
*/
public static function columnCount($stmt)
{
- return self::$database->columnCount($stmt);
+ return self::getClass(Database::class)->columnCount($stmt);
}
/**
* @brief Returns the number of rows of a statement
*/
public static function numRows($stmt)
{
- return self::$database->numRows($stmt);
+ return self::getClass(Database::class)->numRows($stmt);
}
/**
*/
public static function fetch($stmt)
{
- return self::$database->fetch($stmt);
+ return self::getClass(Database::class)->fetch($stmt);
}
/**
*/
public static function insert($table, $param, $on_duplicate_update = false)
{
- return self::$database->insert($table, $param, $on_duplicate_update);
+ return self::getClass(Database::class)->insert($table, $param, $on_duplicate_update);
}
/**
*/
public static function lastInsertId()
{
- return self::$database->lastInsertId();
+ return self::getClass(Database::class)->lastInsertId();
}
/**
*/
public static function lock($table)
{
- return self::$database->lock($table);
+ return self::getClass(Database::class)->lock($table);
}
/**
*/
public static function unlock()
{
- return self::$database->unlock();
+ return self::getClass(Database::class)->unlock();
}
/**
*/
public static function transaction()
{
- return self::$database->transaction();
+ return self::getClass(Database::class)->transaction();
}
/**
*/
public static function commit()
{
- return self::$database->commit();
+ return self::getClass(Database::class)->commit();
}
/**
*/
public static function rollback()
{
- return self::$database->rollback();
+ return self::getClass(Database::class)->rollback();
}
/**
*/
public static function delete($table, array $conditions, array $options = [])
{
- return self::$database->delete($table, $conditions, $options);
+ return self::getClass(Database::class)->delete($table, $conditions, $options);
}
/**
*/
public static function update($table, $fields, $condition, $old_fields = [])
{
- return self::$database->update($table, $fields, $condition, $old_fields);
+ return self::getClass(Database::class)->update($table, $fields, $condition, $old_fields);
}
/**
*/
public static function selectFirst($table, array $fields = [], array $condition = [], $params = [])
{
- return self::$database->selectFirst($table, $fields, $condition, $params);
+ return self::getClass(Database::class)->selectFirst($table, $fields, $condition, $params);
}
/**
*/
public static function select($table, array $fields = [], array $condition = [], array $params = [])
{
- return self::$database->select($table, $fields, $condition, $params);
+ return self::getClass(Database::class)->select($table, $fields, $condition, $params);
}
/**
*/
public static function count($table, array $condition = [])
{
- return self::$database->count($table, $condition);
+ return self::getClass(Database::class)->count($table, $condition);
}
/**
*/
public static function toArray($stmt, $do_close = true)
{
- return self::$database->toArray($stmt, $do_close);
+ return self::getClass(Database::class)->toArray($stmt, $do_close);
}
/**
*/
public static function errorNo()
{
- return self::$database->errorNo();
+ return self::getClass(Database::class)->errorNo();
}
/**
*/
public static function errorMessage()
{
- return self::$database->errorMessage();
+ return self::getClass(Database::class)->errorMessage();
}
/**
*/
public static function close($stmt)
{
- return self::$database->close($stmt);
+ return self::getClass(Database::class)->close($stmt);
}
/**
*/
public static function processlist()
{
- return self::$database->processlist();
+ return self::getClass(Database::class)->processlist();
}
/**
*/
public static function isResult($array)
{
- return self::$database->isResult($array);
+ return self::getClass(Database::class)->isResult($array);
}
/**
*/
public static function escapeArray(&$arr, $add_quotation = false)
{
- return self::$database->escapeArray($arr, $add_quotation);
+ return self::getClass(Database::class)->escapeArray($arr, $add_quotation);
}
}
$this->readServerVariables($server);
$this->connect();
- DBA::init($this);
-
if ($this->isConnected()) {
// Loads DB_UPDATE_VERSION constant
DBStructure::definition($configCache->get('system', 'basepath'), false);
namespace Friendica\Factory;
-use Friendica\Core;
use Friendica\Core\Config;
use Friendica\Core\Config\Cache;
use Friendica\Model\Config\Config as ConfigModel;
}
- // Set the config in the static container for legacy usage
- Core\Config::init($configuration);
-
return $configuration;
}
$configuration = new Config\JitPConfiguration($pConfigCache, $configModel);
}
- // Set the config in the static container for legacy usage
- Core\PConfig::init($configuration);
-
return $configuration;
}
}
+++ /dev/null
-<?php
-
-namespace Friendica\Factory;
-
-use Dice\Dice;
-use Friendica\App;
-use Friendica\Core\Config\PConfiguration;
-use Psr\Log\LoggerInterface;
-
-class DependencyFactory
-{
- /**
- * Setting all default-dependencies of a friendica execution
- *
- * @param string $channel The channel of this execution
- * @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, Dice $dice, $isBackend = true)
- {
- $pConfig = $dice->create(PConfiguration::class);
- $logger = $dice->create(LoggerInterface::class, [$channel]);
- $devLogger = $dice->create('$devLogger', [$channel]);
-
- return $dice->create(App::class, [$isBackend]);
- }
-}
*/
class LoggerFactory
{
+ const DEV_CHANNEL = 'dev';
+
/**
* A list of classes, which shouldn't get logged
*
'Friendica\\Util\\Logger',
];
+ /**
+ * Retrieve the channel based on the __FILE__
+ *
+ * @return string
+ */
+ private function findChannel()
+ {
+ return basename($_SERVER['PHP_SELF'], '.php');
+ }
+
/**
* Creates a new PSR-3 compliant logger instances
*
- * @param string $channel The channel of the logger instance
* @param Configuration $config The config
* @param Profiler $profiler The profiler of the app
*
* @throws \Exception
* @throws InternalServerErrorException
*/
- public function create($channel, Database $database, Configuration $config, Profiler $profiler)
+ public function create(Database $database, Configuration $config, Profiler $profiler)
{
if (empty($config->get('system', 'debugging', false))) {
$logger = new VoidLogger();
$database->setLogger($logger);
- Logger::init($logger);
return $logger;
}
$loggerTimeZone = new \DateTimeZone('UTC');
Monolog\Logger::setTimezone($loggerTimeZone);
- $logger = new Monolog\Logger($channel);
+ $logger = new Monolog\Logger($this->findChannel());
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
break;
case 'syslog':
- $logger = new SyslogLogger($channel, $introspection, $loglevel);
+ $logger = new SyslogLogger($this->findChannel(), $introspection, $loglevel);
break;
case 'stream':
$stream = $config->get('system', 'logfile');
// just add a stream in case it's either writable or not file
if (!is_file($stream) || is_writable($stream)) {
- $logger = new StreamLogger($channel, $stream, $introspection, $loglevel);
+ $logger = new StreamLogger($this->findChannel(), $stream, $introspection, $loglevel);
} else {
$logger = new VoidLogger();
}
}
$database->setLogger($logger);
- Logger::init($logger);
-
return $logger;
}
*
* It should never get filled during normal usage of Friendica
*
- * @param string $channel The channel of the logger instance
* @param Configuration $config The config
* @param Profiler $profiler The profiler of the app
*
* @throws InternalServerErrorException
* @throws \Exception
*/
- public static function createDev($channel, Configuration $config, Profiler $profiler)
+ public static function createDev(Configuration $config, Profiler $profiler)
{
$debugging = $config->get('system', 'debugging');
$stream = $config->get('system', 'dlogfile');
if ((!isset($developerIp) || !$debugging) &&
(!is_file($stream) || is_writable($stream))) {
$logger = new VoidLogger();
- Logger::setDevLogger($logger);
return $logger;
}
$loggerTimeZone = new \DateTimeZone('UTC');
Monolog\Logger::setTimezone($loggerTimeZone);
- $logger = new Monolog\Logger($channel);
+ $logger = new Monolog\Logger(self::DEV_CHANNEL);
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
break;
case 'syslog':
- $logger = new SyslogLogger($channel, $introspection, LogLevel::DEBUG);
+ $logger = new SyslogLogger(self::DEV_CHANNEL, $introspection, LogLevel::DEBUG);
break;
case 'stream':
default:
- $logger = new StreamLogger($channel, $stream, $introspection, LogLevel::DEBUG);
+ $logger = new StreamLogger(self::DEV_CHANNEL, $stream, $introspection, LogLevel::DEBUG);
break;
}
$logger = new ProfilerLogger($logger, $profiler);
}
- Logger::setDevLogger($logger);
-
return $logger;
}
* @param string $functionName The current function name of the worker
* @param int $idLength The length of the generated worker ID
*/
- public function __construct(LoggerInterface $logger, $functionName, $idLength = 7)
+ public function __construct(LoggerInterface $logger, $functionName = '', $idLength = 7)
{
$this->logger = $logger;
$this->functionName = $functionName;
$this->workerId = Strings::getRandomHex($idLength);
}
+ /**
+ * Sets the function name for additional logging
+ *
+ * @param string $functionName
+ */
+ public function setFunctionName(string $functionName)
+ {
+ $this->functionName = $functionName;
+ }
+
/**
* Adds the worker context for each log entry
*