performance improvements (#2329)

* remove work from constructor
* refactor twig extensions
* upgrade theme
* replace sub-request with direct template rendering
This commit is contained in:
Kevin Papst
2021-02-20 23:52:01 +01:00
committed by GitHub
parent 9eb25c412e
commit 607d09aefb
40 changed files with 992 additions and 1092 deletions

View File

@@ -0,0 +1,56 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Twig\Runtime;
use Psr\Container\ContainerInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
use Twig\Extension\RuntimeExtensionInterface;
final class EncoreExtension implements RuntimeExtensionInterface, ServiceSubscriberInterface
{
/**
* @var string
*/
private $publicDir;
/**
* @var ContainerInterface
*/
private $container;
public function __construct(ContainerInterface $container, string $projectDirectory)
{
$this->container = $container;
$this->publicDir = $projectDirectory . '/public';
}
public static function getSubscribedServices()
{
return [
EntrypointLookupInterface::class,
];
}
public function getEncoreEntryCssSource(string $packageName): string
{
$lookup = $this->container->get(EntrypointLookupInterface::class);
$files = $lookup->getCssFiles($packageName);
$source = '';
foreach ($files as $file) {
$source .= file_get_contents($this->publicDir . '/' . $file);
}
$lookup->reset();
return $source;
}
}