2018-11-12 03:08:33 +01:00
|
|
|
<?php
|
|
|
|
|
2020-06-17 15:27:20 +02:00
|
|
|
use Psr\Container\ContainerInterface;
|
2018-11-12 03:08:33 +01:00
|
|
|
|
|
|
|
// DIC configuration
|
|
|
|
|
|
|
|
// l10n
|
2018-11-16 05:59:00 +01:00
|
|
|
$container['l10n'] = function (ContainerInterface $c): Gettext\TranslatorInterface {
|
|
|
|
$translator = new Gettext\Translator();
|
|
|
|
return $translator;
|
2018-11-12 03:08:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// simple cache
|
|
|
|
$container['simplecache'] = function (ContainerInterface $c): Sarahman\SimpleCache\FileSystemCache {
|
|
|
|
$settings = $c->get('settings')['simplecache'];
|
|
|
|
return new Sarahman\SimpleCache\FileSystemCache($settings['directory']);
|
|
|
|
};
|
|
|
|
|
|
|
|
// zend escaper
|
|
|
|
$container['escaper'] = function (ContainerInterface $c): Zend\Escaper\Escaper {
|
|
|
|
$settings = $c->get('settings')['escaper'];
|
|
|
|
return new Zend\Escaper\Escaper($settings['encoding']);
|
|
|
|
};
|
|
|
|
|
|
|
|
// view renderer
|
|
|
|
$container['renderer'] = function (ContainerInterface $c): Friendica\Directory\Views\PhpRenderer {
|
|
|
|
$settings = $c->get('settings')['renderer'];
|
2020-06-13 19:20:49 +02:00
|
|
|
return new Friendica\Directory\Views\PhpRenderer(
|
|
|
|
$c->get('escaper'),
|
|
|
|
$c->get('l10n'),
|
|
|
|
$c->get('router'),
|
|
|
|
$settings['template_path']
|
|
|
|
);
|
2018-11-12 03:08:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// monolog
|
|
|
|
$container['logger'] = function (ContainerInterface $c): Monolog\Logger {
|
|
|
|
$settings = $c->get('settings')['logger'];
|
|
|
|
$logger = new Monolog\Logger($settings['name']);
|
|
|
|
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
|
|
|
|
|
|
|
|
switch ($settings['formatter']) {
|
|
|
|
case 'console':
|
|
|
|
$formatter = new Monolog\Formatter\LineFormatter("[%level_name%] %message% %context%\n");
|
|
|
|
break;
|
|
|
|
case 'logfile':
|
|
|
|
default:
|
|
|
|
$formatter = new Monolog\Formatter\LineFormatter("%datetime% - %level_name% %extra%: %message% %context%\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$handler = new Monolog\Handler\StreamHandler($settings['path'], $settings['level']);
|
|
|
|
$handler->setFormatter($formatter);
|
|
|
|
$logger->pushHandler($handler);
|
|
|
|
return $logger;
|
|
|
|
};
|
|
|
|
|
|
|
|
// PDO wrapper
|
|
|
|
$container['atlas'] = function (ContainerInterface $c): Atlas\Pdo\Connection {
|
|
|
|
$args = $c->get('settings')['database'];
|
|
|
|
|
|
|
|
$dsn = "{$args['driver']}:dbname={$args['database']};host={$args['hostname']}";
|
|
|
|
|
|
|
|
$atlasConnection = Atlas\Pdo\Connection::new($dsn, $args['username'], $args['password']);
|
|
|
|
|
|
|
|
return $atlasConnection;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Database migration manager
|
|
|
|
$container['migration'] = function (ContainerInterface $c): ByJG\DbMigration\Migration {
|
|
|
|
$args = $c->get('settings')['database'];
|
|
|
|
|
|
|
|
$connectionUri = new ByJG\Util\Uri("{$args['driver']}://{$args['username']}:{$args['password']}@{$args['hostname']}/{$args['database']}");
|
|
|
|
|
|
|
|
$migration = new ByJG\DbMigration\Migration($connectionUri, __DIR__ . '/sql');
|
|
|
|
|
|
|
|
$migration->addCallbackProgress(function (string $action, int $currentVersion) use ($c): void {
|
|
|
|
switch($action) {
|
|
|
|
case 'reset': $c->get('logger')->notice('Resetting database schema'); break;
|
|
|
|
case 'migrate': $c->get('logger')->notice('Migrating database schema to version ' . $currentVersion); break;
|
|
|
|
default:
|
|
|
|
$c->get('logger')->notice('Migration action: ' . $action . ' Current Version: ' . $currentVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$migration->registerDatabase('mysql', ByJG\DbMigration\Database\MySqlDatabase::class);
|
|
|
|
|
|
|
|
return $migration;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Internal Dependency Injection
|
|
|
|
|
2020-10-26 01:19:41 +01:00
|
|
|
$container[\Friendica\Directory\Models\Profile::class] = function (ContainerInterface $c): Friendica\Directory\Models\Profile {
|
2018-11-12 03:08:33 +01:00
|
|
|
return new Friendica\Directory\Models\Profile($c->get('atlas'));
|
|
|
|
};
|
|
|
|
|
2020-10-26 01:19:41 +01:00
|
|
|
$container[\Friendica\Directory\Models\ProfilePollQueue::class] = function (ContainerInterface $c): Friendica\Directory\Models\ProfilePollQueue {
|
2018-11-12 03:08:33 +01:00
|
|
|
return new Friendica\Directory\Models\ProfilePollQueue($c->get('atlas'));
|
|
|
|
};
|
|
|
|
|
2020-10-26 01:19:41 +01:00
|
|
|
$container[\Friendica\Directory\Models\Server::class] = function (ContainerInterface $c): Friendica\Directory\Models\Server {
|
2018-11-12 03:08:33 +01:00
|
|
|
return new Friendica\Directory\Models\Server($c->get('atlas'));
|
|
|
|
};
|
|
|
|
|
2020-10-26 01:19:41 +01:00
|
|
|
$container[\Friendica\Directory\Pollers\Directory::class] = function (ContainerInterface $c): Friendica\Directory\Pollers\Directory {
|
2018-11-12 03:08:33 +01:00
|
|
|
$settings = $c->get('settings')['poller'];
|
|
|
|
return new Friendica\Directory\Pollers\Directory(
|
|
|
|
$c->get('atlas'),
|
2020-10-26 01:19:41 +01:00
|
|
|
$c->get(\Friendica\Directory\Models\ProfilePollQueue::class),
|
2018-11-12 03:08:33 +01:00
|
|
|
$c->get('logger'),
|
|
|
|
$settings ?: []
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-26 01:19:41 +01:00
|
|
|
$container[\Friendica\Directory\Pollers\Profile::class] = function (ContainerInterface $c): Friendica\Directory\Pollers\Profile {
|
2018-11-12 03:08:33 +01:00
|
|
|
$settings = $c->get('settings')['poller'];
|
|
|
|
return new Friendica\Directory\Pollers\Profile(
|
|
|
|
$c->get('atlas'),
|
2020-10-26 01:19:41 +01:00
|
|
|
$c->get(\Friendica\Directory\Models\Server::class),
|
|
|
|
$c->get(\Friendica\Directory\Models\Profile::class),
|
2018-11-12 03:08:33 +01:00
|
|
|
$c->get('logger'),
|
|
|
|
$settings ?: []
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-26 01:19:41 +01:00
|
|
|
$container[\Friendica\Directory\Pollers\Server::class] = function (ContainerInterface $c): Friendica\Directory\Pollers\Server {
|
2018-11-12 03:08:33 +01:00
|
|
|
$settings = $c->get('settings')['poller'];
|
|
|
|
return new Friendica\Directory\Pollers\Server(
|
|
|
|
$c->get('atlas'),
|
2020-10-26 01:19:41 +01:00
|
|
|
$c->get(\Friendica\Directory\Models\ProfilePollQueue::class),
|
|
|
|
$c->get(\Friendica\Directory\Models\Server::class),
|
2018-11-12 03:08:33 +01:00
|
|
|
$c->get('simplecache'),
|
|
|
|
$c->get('logger'),
|
|
|
|
$settings ?: []
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-26 01:19:41 +01:00
|
|
|
$container[\Friendica\Directory\Views\Widget\AccountTypeTabs::class] = function (ContainerInterface $c): Friendica\Directory\Views\Widget\AccountTypeTabs {
|
2018-11-12 03:08:33 +01:00
|
|
|
return new Friendica\Directory\Views\Widget\AccountTypeTabs(
|
|
|
|
$c->get('atlas'),
|
|
|
|
$c->get('renderer'),
|
|
|
|
$c->get('router')
|
|
|
|
);
|
|
|
|
};
|