Plugins support (#592)

This commit is contained in:
Kevin Papst
2019-02-24 15:54:38 +01:00
committed by GitHub
parent 36a158a805
commit 03aa4c9ddc
11 changed files with 220 additions and 35 deletions

View File

@@ -23,6 +23,8 @@ use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
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;
@@ -64,6 +66,30 @@ class Kernel extends BaseKernel
yield new $class();
}
}
$pluginsDir = $this->getProjectDir() . '/var/plugins';
if (!file_exists($pluginsDir)) {
return;
}
$finder = new Finder();
$finder->ignoreUnreadableDirs()->directories()->name('*Bundle');
/** @var SplFileInfo $bundleDir */
foreach ($finder->in($pluginsDir) as $bundleDir) {
$bundleName = $bundleDir->getRelativePathname();
$bundleFilename = $bundleDir->getRealPath() . '/' . $bundleName . '.php';
if (!file_exists($bundleFilename)) {
continue;
}
$pluginClass = 'KimaiPlugin\\' . $bundleName . '\\' . $bundleName;
if (!class_exists($pluginClass)) {
continue;
}
yield new $pluginClass;
}
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
@@ -106,6 +132,10 @@ class Kernel extends BaseKernel
// load application routes
$routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob');
// load plugin routes
$pluginsDir = $this->getProjectDir() . '/var/plugins';
$routes->import($pluginsDir . '/*Bundle/Resources/config/routes'. self::CONFIG_EXTS, '/', 'glob');
}
protected function configureFosUserRoutes(RouteCollectionBuilder $routes)