Arrgh.
This commit is contained in:
parent
de3da89d9c
commit
d1e18f9c0f
3 changed files with 59 additions and 7 deletions
45
src/App.php
45
src/App.php
|
|
@ -46,6 +46,7 @@ use Monolog\Logger;
|
||||||
use Monolog\Processor\PsrLogMessageProcessor;
|
use Monolog\Processor\PsrLogMessageProcessor;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use SebastianBergmann\Timer\Timer;
|
||||||
use Slim;
|
use Slim;
|
||||||
use Slim\Factory\AppFactory;
|
use Slim\Factory\AppFactory;
|
||||||
use Slim\Factory\ServerRequestCreatorFactory;
|
use Slim\Factory\ServerRequestCreatorFactory;
|
||||||
|
|
@ -81,11 +82,21 @@ class App
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
self::$timer = new Timer();
|
||||||
|
self::$timer->start();
|
||||||
|
|
||||||
// Configure Dependency Injector
|
// Configure Dependency Injector
|
||||||
$container = $this->setupContainer();
|
$container = $this->setupContainer();
|
||||||
|
App::Timing();
|
||||||
|
|
||||||
$this->logger = $container->get(Logger::class);
|
$this->logger = $container->get(Logger::class);
|
||||||
|
App::Timing();
|
||||||
|
|
||||||
$this->debugBar = $container->get(DebugBar::class);
|
$this->debugBar = $container->get(DebugBar::class);
|
||||||
|
App::Timing();
|
||||||
|
|
||||||
AppFactory::setContainer($container);
|
AppFactory::setContainer($container);
|
||||||
|
App::Timing();
|
||||||
|
|
||||||
// If we're not on the CLI and Sessions ARE enabled...
|
// If we're not on the CLI and Sessions ARE enabled...
|
||||||
if ('cli' !== php_sapi_name() && $this->isSessionsEnabled) {
|
if ('cli' !== php_sapi_name() && $this->isSessionsEnabled) {
|
||||||
|
|
@ -100,8 +111,10 @@ class App
|
||||||
// Configure Slim
|
// Configure Slim
|
||||||
$this->app = AppFactory::create();
|
$this->app = AppFactory::create();
|
||||||
$this->app->add(Slim\Views\TwigMiddleware::createFromContainer($this->app));
|
$this->app->add(Slim\Views\TwigMiddleware::createFromContainer($this->app));
|
||||||
|
App::Timing();
|
||||||
|
|
||||||
$this->setupMiddlewares($container);
|
$this->setupMiddlewares($container);
|
||||||
|
App::Timing();
|
||||||
|
|
||||||
$this->app->add($container->get(JsonValidationMiddleware::class));
|
$this->app->add($container->get(JsonValidationMiddleware::class));
|
||||||
$this->app->addBodyParsingMiddleware();
|
$this->app->addBodyParsingMiddleware();
|
||||||
|
|
@ -122,6 +135,7 @@ class App
|
||||||
$this->debugBar['time']->stopMeasure('interrogateTranslations');
|
$this->debugBar['time']->stopMeasure('interrogateTranslations');
|
||||||
|
|
||||||
$this->app->add(new ServerTimingMiddleware());
|
$this->app->add(new ServerTimingMiddleware());
|
||||||
|
App::Timing();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCachePath(): string
|
public function getCachePath(): string
|
||||||
|
|
@ -170,19 +184,21 @@ class App
|
||||||
|
|
||||||
public function setupContainer(): Container
|
public function setupContainer(): Container
|
||||||
{
|
{
|
||||||
|
App::Timing();
|
||||||
$app = $this;
|
$app = $this;
|
||||||
$container =
|
$container =
|
||||||
(new ContainerBuilder())
|
(new ContainerBuilder())
|
||||||
->useAutowiring(true)
|
->useAutowiring(true)
|
||||||
->useAttributes(true)
|
->useAttributes(true)
|
||||||
;
|
;
|
||||||
|
App::Timing();
|
||||||
// if ((new Filesystem())->exists($this->getCachePath())) {
|
// if ((new Filesystem())->exists($this->getCachePath())) {
|
||||||
// $container->enableCompilation($this->getCachePath());
|
// $container->enableCompilation($this->getCachePath());
|
||||||
// $container->writeProxiesToFile(true, "{$this->getCachePath()}/injection-proxies");
|
// $container->writeProxiesToFile(true, "{$this->getCachePath()}/injection-proxies");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$container = $container->build();
|
$container = $container->build();
|
||||||
|
App::Timing();
|
||||||
$container->set(Slim\Views\Twig::class, function (
|
$container->set(Slim\Views\Twig::class, function (
|
||||||
EnvironmentService $environmentService,
|
EnvironmentService $environmentService,
|
||||||
SessionService $sessionService,
|
SessionService $sessionService,
|
||||||
|
|
@ -276,7 +292,7 @@ class App
|
||||||
|
|
||||||
return $translator;
|
return $translator;
|
||||||
});
|
});
|
||||||
|
App::Timing();
|
||||||
$container->set(ConfigurationService::class, function (EnvironmentService $environmentService) use ($app) {
|
$container->set(ConfigurationService::class, function (EnvironmentService $environmentService) use ($app) {
|
||||||
return new ConfigurationService(
|
return new ConfigurationService(
|
||||||
$app,
|
$app,
|
||||||
|
|
@ -321,7 +337,7 @@ class App
|
||||||
|
|
||||||
return $this->cachePoolChain;
|
return $this->cachePoolChain;
|
||||||
});
|
});
|
||||||
|
App::Timing();
|
||||||
$container->set('MonologFormatter', function (EnvironmentService $environmentService) {
|
$container->set('MonologFormatter', function (EnvironmentService $environmentService) {
|
||||||
return new LineFormatter(
|
return new LineFormatter(
|
||||||
// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%"
|
// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%"
|
||||||
|
|
@ -378,7 +394,7 @@ class App
|
||||||
$databases
|
$databases
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
App::Timing();
|
||||||
$container->set(TrailingSlash::class, fn () => (new TrailingSlash())->redirect());
|
$container->set(TrailingSlash::class, fn () => (new TrailingSlash())->redirect());
|
||||||
|
|
||||||
$container->set(DebugBar::class, function (Logger $logger) {
|
$container->set(DebugBar::class, function (Logger $logger) {
|
||||||
|
|
@ -407,6 +423,7 @@ class App
|
||||||
} else {
|
} else {
|
||||||
date_default_timezone_set(self::DEFAULT_TIMEZONE);
|
date_default_timezone_set(self::DEFAULT_TIMEZONE);
|
||||||
}
|
}
|
||||||
|
App::Timing();
|
||||||
|
|
||||||
$this->router = $container->get(Router::class);
|
$this->router = $container->get(Router::class);
|
||||||
|
|
||||||
|
|
@ -483,9 +500,12 @@ class App
|
||||||
|
|
||||||
public function runHttp(): void
|
public function runHttp(): void
|
||||||
{
|
{
|
||||||
|
$timer = new Timer();
|
||||||
|
$timer->start();
|
||||||
$serverRequestCreator = ServerRequestCreatorFactory::create();
|
$serverRequestCreator = ServerRequestCreatorFactory::create();
|
||||||
$request = $serverRequestCreator->createServerRequestFromGlobals();
|
$request = $serverRequestCreator->createServerRequestFromGlobals();
|
||||||
|
$duration = $timer->stop();
|
||||||
|
\Kint::dump($duration->asSeconds());
|
||||||
$this->loadAllRoutes($request);
|
$this->loadAllRoutes($request);
|
||||||
|
|
||||||
$this->debugBar['time']->startMeasure('runHTTP', 'HTTP runtime');
|
$this->debugBar['time']->startMeasure('runHTTP', 'HTTP runtime');
|
||||||
|
|
@ -605,6 +625,7 @@ class App
|
||||||
],
|
],
|
||||||
$appClass->getNamespaceName()
|
$appClass->getNamespaceName()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$this->router->cache();
|
$this->router->cache();
|
||||||
|
|
||||||
|
|
@ -615,4 +636,18 @@ class App
|
||||||
{
|
{
|
||||||
return $this->app->getContainer();
|
return $this->app->getContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static Timer $timer;
|
||||||
|
static public function Timing(){
|
||||||
|
$duration = self::$timer->stop();
|
||||||
|
# Get caller
|
||||||
|
$caller = debug_backtrace()[1];
|
||||||
|
if($duration->asSeconds() >= 1) {
|
||||||
|
$timingMessage = sprintf("%f seconds: %s::%s (%s:%d)", $duration->asSeconds(), $caller['class'], $caller['function'], $caller['file'], $caller['line']);
|
||||||
|
\Kint::dump($timingMessage);
|
||||||
|
self::DI(Logger::class)->debug($timingMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$timer->start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use SebastianBergmann\Timer\Timer;
|
||||||
use Slim\App;
|
use Slim\App;
|
||||||
|
|
||||||
class Router
|
class Router
|
||||||
|
|
@ -38,10 +39,25 @@ class Router
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$timer = new Timer();
|
||||||
|
$timer->start();
|
||||||
$dirIterator = new \RecursiveDirectoryIterator($controllerPath);
|
$dirIterator = new \RecursiveDirectoryIterator($controllerPath);
|
||||||
$iteratorIterator = new \RecursiveIteratorIterator($dirIterator);
|
$duration = $timer->stop();
|
||||||
$phpFiles = new \RegexIterator($iteratorIterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH);
|
\Kint::dump($duration->asSeconds());
|
||||||
|
|
||||||
|
$timer = new Timer();
|
||||||
|
$timer->start();
|
||||||
|
$iteratorIterator = new \RecursiveIteratorIterator($dirIterator);
|
||||||
|
$duration = $timer->stop();
|
||||||
|
\Kint::dump($duration->asSeconds());
|
||||||
|
|
||||||
|
$timer = new Timer();
|
||||||
|
$timer->start();
|
||||||
|
$phpFiles = new \RegexIterator($iteratorIterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH);
|
||||||
|
$duration = $timer->stop();
|
||||||
|
\Kint::dump($duration->asSeconds());
|
||||||
|
|
||||||
|
\Kint::dump($phpFiles);exit;
|
||||||
foreach ($phpFiles as $controllerFile) {
|
foreach ($phpFiles as $controllerFile) {
|
||||||
$fileClassName = ltrim(str_replace([$controllerPath, '/', '.php'], ['', '\\', ''], $controllerFile[0]), '\\');
|
$fileClassName = ltrim(str_replace([$controllerPath, '/', '.php'], ['', '\\', ''], $controllerFile[0]), '\\');
|
||||||
$expectedClasses = [
|
$expectedClasses = [
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace Benzine\Services;
|
||||||
|
|
||||||
use Benzine\App;
|
use Benzine\App;
|
||||||
use Benzine\Exceptions\BenzineConfigurationException;
|
use Benzine\Exceptions\BenzineConfigurationException;
|
||||||
|
use SebastianBergmann\Timer\Timer;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue