Move creation of Dice into Container class

This commit is contained in:
Art4 2025-01-08 22:35:27 +00:00
parent 610267a3ea
commit 37ffeb8121
7 changed files with 19 additions and 33 deletions

View file

@ -44,15 +44,12 @@ if (php_sapi_name() !== 'cli') {
exit(); exit();
} }
use Dice\Dice; chdir(dirname(__DIR__));
chdir(dirname(__FILE__, 2)); require dirname(__DIR__) . '/vendor/autoload.php';
require dirname(__FILE__, 2) . '/vendor/autoload.php'; $container = \Friendica\Core\Container::fromBasePath(dirname(__DIR__));
$dice = (new Dice())->addRules(require(dirname(__FILE__, 2) . '/static/dependencies.config.php')); $app = \Friendica\App::fromContainer($container);
$container = \Friendica\Core\Container::fromDice($dice);
$app = \Friendica\App::fromContainer($container);
$app->processEjabberd(); $app->processEjabberd();

View file

@ -13,13 +13,9 @@ if (php_sapi_name() !== 'cli') {
exit(); exit();
} }
use Dice\Dice;
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.config.php')); $container = \Friendica\Core\Container::fromBasePath(dirname(__DIR__));
$container = \Friendica\Core\Container::fromDice($dice);
$app = \Friendica\App::fromContainer($container); $app = \Friendica\App::fromContainer($container);

View file

@ -19,19 +19,15 @@ if (php_sapi_name() !== 'cli') {
exit(); exit();
} }
use Dice\Dice;
// Ensure that daemon.php is executed from the base path of the installation // Ensure that daemon.php is executed from the base path of the installation
chdir(dirname(__DIR__)); chdir(dirname(__DIR__));
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.config.php'));
$argv = $_SERVER['argv'] ?? []; $argv = $_SERVER['argv'] ?? [];
array_splice($argv, 1, 0, "daemon"); array_splice($argv, 1, 0, "daemon");
$container = \Friendica\Core\Container::fromDice($dice); $container = \Friendica\Core\Container::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container); $app = \Friendica\App::fromContainer($container);

View file

@ -9,8 +9,6 @@
* @deprecated 2025.02 use bin/console.php jetstream instead * @deprecated 2025.02 use bin/console.php jetstream instead
*/ */
use Dice\Dice;
if (php_sapi_name() !== 'cli') { if (php_sapi_name() !== 'cli') {
header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden');
exit(); exit();
@ -21,12 +19,10 @@ chdir(dirname(__DIR__));
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.config.php'));
$argv = $_SERVER['argv'] ?? []; $argv = $_SERVER['argv'] ?? [];
array_splice($argv, 1, 0, "jetstream"); array_splice($argv, 1, 0, "jetstream");
$container = \Friendica\Core\Container::fromDice($dice); $container = \Friendica\Core\Container::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container); $app = \Friendica\App::fromContainer($container);

View file

@ -16,19 +16,15 @@ if (php_sapi_name() !== 'cli') {
exit(); exit();
} }
use Dice\Dice;
// Ensure that worker.php is executed from the base path of the installation // Ensure that worker.php is executed from the base path of the installation
chdir(dirname(__DIR__)); chdir(dirname(__DIR__));
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.config.php'));
$argv = $_SERVER['argv'] ?? []; $argv = $_SERVER['argv'] ?? [];
array_splice($argv, 1, 0, "worker"); array_splice($argv, 1, 0, "worker");
$container = \Friendica\Core\Container::fromDice($dice); $container = \Friendica\Core\Container::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container); $app = \Friendica\App::fromContainer($container);

View file

@ -5,8 +5,6 @@
// //
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
use Dice\Dice;
$start_time = microtime(true); $start_time = microtime(true);
if (!file_exists(__DIR__ . '/vendor/autoload.php')) { if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
@ -17,9 +15,7 @@ require __DIR__ . '/vendor/autoload.php';
$request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals(); $request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
$dice = (new Dice())->addRules(require(__DIR__ . '/static/dependencies.config.php')); $container = \Friendica\Core\Container::fromBasePath(__DIR__);
$container = \Friendica\Core\Container::fromDice($dice);
$app = \Friendica\App::fromContainer($container); $app = \Friendica\App::fromContainer($container);
$app->processRequest($request, $start_time); $app->processRequest($request, $start_time);

View file

@ -21,9 +21,18 @@ use Psr\Log\LoggerInterface;
*/ */
class Container class Container
{ {
public static function fromBasePath(string $basePath): self
{
$path = $basePath . '/static/dependencies.config.php';
$dice = (new Dice())->addRules(require($path));
return static::fromDice($dice);
}
private Dice $container; private Dice $container;
protected function __construct(Dice $container) private function __construct(Dice $container)
{ {
$this->container = $container; $this->container = $container;
} }