Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -23,14 +23,13 @@ use App\Invoice\NumberGeneratorInterface;
|
||||
use App\Invoice\RendererInterface as InvoiceRendererInterface;
|
||||
use App\Ldap\FormLoginLdapFactory;
|
||||
use App\Plugin\PluginInterface;
|
||||
use App\Saml\Security\SamlFactory;
|
||||
use App\Plugin\PluginMetadata;
|
||||
use App\Timesheet\CalculatorInterface as TimesheetCalculator;
|
||||
use App\Timesheet\Rounding\RoundingInterface;
|
||||
use App\Timesheet\TrackingMode\TrackingModeInterface;
|
||||
use App\Validator\Constraints\ProjectConstraint;
|
||||
use App\Validator\Constraints\TimesheetConstraint;
|
||||
use App\Widget\WidgetInterface;
|
||||
use App\Widget\WidgetRendererInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
@@ -39,18 +38,17 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
use Symfony\Component\Routing\RouteCollectionBuilder;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
public const PLUGIN_DIRECTORY = '/var/plugins';
|
||||
public const CONFIG_EXTS = '.{php,xml,yaml,yml}';
|
||||
public const CONFIG_EXTS = '.{php,yaml}';
|
||||
|
||||
public const TAG_PLUGIN = 'kimai.plugin';
|
||||
public const TAG_WIDGET = 'widget';
|
||||
public const TAG_WIDGET_RENDERER = 'widget.renderer';
|
||||
public const TAG_EXPORT_RENDERER = 'export.renderer';
|
||||
public const TAG_EXPORT_REPOSITORY = 'export.repository';
|
||||
public const TAG_INVOICE_RENDERER = 'invoice.renderer';
|
||||
@@ -64,12 +62,12 @@ class Kernel extends BaseKernel
|
||||
public const TAG_TIMESHEET_ROUNDING_MODE = 'timesheet.rounding_mode';
|
||||
public const TAG_PROJECT_VALIDATOR = 'project.validator';
|
||||
|
||||
public function getCacheDir()
|
||||
public function getCacheDir(): string
|
||||
{
|
||||
return $this->getProjectDir() . '/var/cache/' . $this->environment;
|
||||
}
|
||||
|
||||
public function getLogDir()
|
||||
public function getLogDir(): string
|
||||
{
|
||||
return $this->getProjectDir() . '/var/log';
|
||||
}
|
||||
@@ -84,7 +82,6 @@ class Kernel extends BaseKernel
|
||||
$container->registerForAutoconfiguration(InvoiceCalculator::class)->addTag(self::TAG_INVOICE_CALCULATOR);
|
||||
$container->registerForAutoconfiguration(InvoiceItemRepositoryInterface::class)->addTag(self::TAG_INVOICE_REPOSITORY);
|
||||
$container->registerForAutoconfiguration(PluginInterface::class)->addTag(self::TAG_PLUGIN);
|
||||
$container->registerForAutoconfiguration(WidgetRendererInterface::class)->addTag(self::TAG_WIDGET_RENDERER);
|
||||
$container->registerForAutoconfiguration(WidgetInterface::class)->addTag(self::TAG_WIDGET);
|
||||
$container->registerForAutoconfiguration(TimesheetExportInterface::class)->addTag(self::TAG_TIMESHEET_EXPORTER);
|
||||
$container->registerForAutoconfiguration(TrackingModeInterface::class)->addTag(self::TAG_TIMESHEET_TRACKING_MODE);
|
||||
@@ -94,11 +91,10 @@ class Kernel extends BaseKernel
|
||||
|
||||
/** @var SecurityExtension $extension */
|
||||
$extension = $container->getExtension('security');
|
||||
$extension->addSecurityListenerFactory(new FormLoginLdapFactory());
|
||||
$extension->addSecurityListenerFactory(new SamlFactory());
|
||||
$extension->addAuthenticatorFactory(new FormLoginLdapFactory());
|
||||
}
|
||||
|
||||
public function registerBundles()
|
||||
public function registerBundles(): iterable
|
||||
{
|
||||
$contents = require $this->getProjectDir() . '/config/bundles.php';
|
||||
foreach ($contents as $class => $envs) {
|
||||
@@ -121,8 +117,8 @@ class Kernel extends BaseKernel
|
||||
}
|
||||
} else {
|
||||
// ... or we load them dynamically from the plugins directory
|
||||
foreach ($this->getBundleClasses() as $pluginClass) {
|
||||
yield new $pluginClass();
|
||||
foreach ($this->getBundleClasses() as $plugin) {
|
||||
yield $plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,8 +136,9 @@ class Kernel extends BaseKernel
|
||||
/** @var SplFileInfo $bundleDir */
|
||||
foreach ($finder->in($pluginsDir) as $bundleDir) {
|
||||
$bundleName = $bundleDir->getRelativePathname();
|
||||
$fullPath = $bundleDir->getRealPath();
|
||||
|
||||
if (file_exists($bundleDir->getRealPath() . '/.disabled')) {
|
||||
if (file_exists($fullPath . '/.disabled')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -150,7 +147,18 @@ class Kernel extends BaseKernel
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugins[] = $pluginClass;
|
||||
$plugin = new $pluginClass();
|
||||
if (!$plugin instanceof PluginInterface) {
|
||||
throw new \Exception(sprintf('Bundle "%s" does not implement %s, which is not supported since 2.0.', $bundleName, PluginInterface::class));
|
||||
}
|
||||
|
||||
$meta = PluginMetadata::loadFromComposer($fullPath);
|
||||
|
||||
if ($meta->getKimaiVersion() > Constants::VERSION_ID) {
|
||||
throw new \Exception(sprintf('Bundle "%s" requires minimum Kimai version %s, but yours is lower: %s (%s). Please update Kimai or use a lower Plugin version.', $bundleName, $meta->getKimaiVersion(), Constants::VERSION, Constants::VERSION_ID));
|
||||
}
|
||||
|
||||
$plugins[] = $plugin;
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
@@ -164,17 +172,12 @@ class Kernel extends BaseKernel
|
||||
$container->setParameter('container.dumper.inline_class_loader', true);
|
||||
$confDir = $this->getProjectDir() . '/config';
|
||||
|
||||
// if you want to prepend any config, you can do it here
|
||||
$loader->load($confDir . '/packages/local_before' . self::CONFIG_EXTS, 'glob');
|
||||
|
||||
// using this one instead of $loader->load($confDir . '/packages/*' . self::CONFIG_EXTS, 'glob');
|
||||
// to get rid of the local.yaml from the list, we load it afterwards explicit
|
||||
$finder = (new Finder())
|
||||
->files()
|
||||
->in([$confDir . '/packages/'])
|
||||
->name('*' . self::CONFIG_EXTS)
|
||||
->notName('local*' . self::CONFIG_EXTS)
|
||||
->depth('== 0')
|
||||
->sortByName()
|
||||
->followLinks()
|
||||
;
|
||||
@@ -184,12 +187,10 @@ class Kernel extends BaseKernel
|
||||
$loader->load($file->getPathname());
|
||||
}
|
||||
|
||||
if (is_dir($confDir . '/packages/' . $this->environment)) {
|
||||
$loader->load($confDir . '/packages/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
|
||||
if (is_file($confDir . '/packages/local.yaml')) {
|
||||
$loader->load($confDir . '/packages/local.yaml', 'glob');
|
||||
}
|
||||
$loader->load($confDir . '/packages/local' . self::CONFIG_EXTS, 'glob');
|
||||
$loader->load($confDir . '/services' . self::CONFIG_EXTS, 'glob');
|
||||
$loader->load($confDir . '/services-*' . self::CONFIG_EXTS, 'glob');
|
||||
$loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob');
|
||||
|
||||
$container->addCompilerPass(new TwigContextCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1000);
|
||||
@@ -198,29 +199,28 @@ class Kernel extends BaseKernel
|
||||
$container->addCompilerPass(new WidgetCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1000);
|
||||
}
|
||||
|
||||
protected function configureRoutes(RouteCollectionBuilder $routes)
|
||||
/** @phpstan-ignore-next-line */
|
||||
private function configureRoutes(RoutingConfigurator $routes): void
|
||||
{
|
||||
$confDir = $this->getProjectDir() . '/config';
|
||||
$configDir = $this->getConfigDir();
|
||||
|
||||
// load bundle specific route files
|
||||
if (is_dir($confDir . '/routes/')) {
|
||||
$routes->import($confDir . '/routes/*' . self::CONFIG_EXTS, '/', 'glob');
|
||||
}
|
||||
// load application specific route files
|
||||
$routes->import($configDir . '/routes/*.yaml');
|
||||
|
||||
// load environment specific route files
|
||||
if (is_dir($confDir . '/routes/' . $this->environment)) {
|
||||
$routes->import($confDir . '/routes/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
|
||||
// load environment specific route files if available
|
||||
if (is_dir($configDir . '/routes/' . $this->environment)) {
|
||||
$routes->import($configDir . '/routes/' . $this->environment . '/*.yaml');
|
||||
}
|
||||
|
||||
// load application routes
|
||||
$routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob');
|
||||
$routes->import($configDir . '/routes.yaml');
|
||||
|
||||
foreach ($this->bundles as $bundle) {
|
||||
if (strpos(\get_class($bundle), 'KimaiPlugin\\') !== false) {
|
||||
foreach ($this->getBundles() as $bundle) {
|
||||
if (str_contains(\get_class($bundle), 'KimaiPlugin\\')) {
|
||||
if (is_dir($bundle->getPath() . '/Resources/config/')) {
|
||||
$routes->import($bundle->getPath() . '/Resources/config/routes' . self::CONFIG_EXTS, '/', 'glob');
|
||||
$routes->import($bundle->getPath() . '/Resources/config/routes' . self::CONFIG_EXTS);
|
||||
} elseif (is_dir($bundle->getPath() . '/config/')) {
|
||||
$routes->import($bundle->getPath() . '/config/routes' . self::CONFIG_EXTS, '/', 'glob');
|
||||
$routes->import($bundle->getPath() . '/config/routes' . self::CONFIG_EXTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user