Moved common bootstrapping code to run.php script

This commit is contained in:
Alejandro Celaya 2019-12-27 14:02:43 +01:00
parent 3fdba53995
commit 25243a10ec
5 changed files with 30 additions and 20 deletions

View File

@ -1,10 +1,7 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Application as CliApp;
/** @var ContainerInterface $container */
$container = include __DIR__ . '/../config/container.php';
$container->get(CliApp::class)->run();
$run = require __DIR__ . '/../config/run.php';
$run(true);

View File

@ -10,10 +10,15 @@ chdir(dirname(__DIR__));
require 'vendor/autoload.php';
// This class alias tricks the ConfigAbstractFactory to return Lock\Factory instances even with a different service name
if (! class_exists('Shlinkio\Shlink\LocalLockFactory')) {
class_alias(Lock\LockFactory::class, 'Shlinkio\Shlink\LocalLockFactory');
}
// Build container
return (function () {
$config = require __DIR__ . '/config.php';
$container = new ServiceManager($config['dependencies']);
$container->setService('config', $config);
return $container;
})();

15
config/run.php Normal file
View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Application as CliApp;
use Zend\Expressive\Application;
return function (bool $isCli = false): void {
/** @var ContainerInterface $container */
$container = include __DIR__ . '/container.php';
$app = $container->get($isCli ? CliApp::class : Application::class);
$app->run();
};

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core;
use GuzzleHttp\ClientInterface;
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;

View File

@ -2,11 +2,5 @@
declare(strict_types=1);
use Psr\Container\ContainerInterface;
use Zend\Expressive\Application;
(function () {
/** @var ContainerInterface $container */
$container = include __DIR__ . '/../config/container.php';
$container->get(Application::class)->run();
})();
$run = require __DIR__ . '/../config/run.php';
$run();