From c03534a9b069c6eaeab3533476c63b43ebf876be Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 16:22:35 +0200 Subject: [PATCH 01/99] fixes #493 --- composer.json | 1 + phpunit.xml.dist | 4 +- .../Twig/DataCollector/Resources/css/twig.css | 10 +- .../Twig/DataCollector/TwigDataCollector.php | 8 +- ...wigBridgeDataCollectorsServiceProvider.php | 8 +- .../DataCollector/TwigDataCollectorTest.php | 4 +- ...ridgeDataCollectorsServiceProviderTest.php | 12 +- .../{WebProfiler => Profiler}/AssetAware.php | 2 +- .../DataCollector.php | 2 +- .../{WebProfiler => Profiler}/PanelAware.php | 2 +- .../WebProfiler.php => Profiler/Profiler.php} | 14 +- .../TooltipAware.php | 2 +- .../DataCollectors/FilesLoadedCollector.php | 8 +- .../NarrowsparkDataCollector.php | 4 +- .../Resources/css/request-response.css | 14 +- .../ViserioHttpDataCollector.php | 8 +- .../Component/Foundation/Http/Kernel.php | 8 +- ...FoundationDataCollectorServiceProvider.php | 10 +- .../NarrowsparkDataCollectorTest.php | 2 +- .../Foundation/Tests/Http/KernelTest.php | 8 +- ...dationDataCollectorServiceProviderTest.php | 12 +- .../Log/DataCollectors/LogParser.php | 2 + .../Log/DataCollectors/LogsDataCollector.php | 4 +- .../LogsDataCollectorServiceProvider.php | 10 +- .../LogsDataCollectorServiceProviderTest.php | 10 +- .../.github/PULL_REQUEST_TEMPLATE.md | 0 .../AssetsRenderer.php | 34 +- .../Controllers/AssetController.php | 20 +- .../Controllers/OpenHandlerController.php | 16 +- .../DataCollectors/AbstractDataCollector.php | 18 +- .../AjaxRequestsDataCollector.php | 10 +- .../Bridge/Cache/Psr6CacheDataCollector.php | 12 +- .../Cache/TraceableCacheItemDecorater.php | 2 +- .../Bridge/PDO/PDODataCollector.php | 8 +- .../Bridge/PDO/TraceablePDODecorater.php | 4 +- .../PDO/TraceablePDOStatementDecorater.php | 2 +- .../Bridge/PDO/TracedStatement.php | 2 +- .../Bridge/SwiftMailDataCollector.php | 6 +- .../DataCollectors/MemoryDataCollector.php | 4 +- .../DataCollectors/MessagesDataCollector.php | 2 +- .../DataCollectors/PhpInfoDataCollector.php | 2 +- .../DataCollectors/TimeDataCollector.php | 2 +- .../{WebProfiler => Profiler}/LICENSE | 0 .../Middleware/ProfilerMiddleware.php | 40 ++ .../{WebProfiler => Profiler}/Profile.php | 14 +- .../WebProfiler.php => Profiler/Profiler.php} | 40 +- .../ProfilerPDOBridgeServiceProvider.php} | 18 +- ...rofilerPsr6CacheBridgeServiceProvider.php} | 16 +- .../Providers/ProfilerServiceProvider.php} | 48 +- ...filerSwiftMailerBridgeServiceProvider.php} | 14 +- .../Proxies/WebProfiler.php | 4 +- .../{WebProfiler => Profiler}/README.md | 2 +- .../Resources/css/ajax-requests.css | 24 +- .../Profiler/Resources/css/profiler-grid.css | 54 +++ .../Profiler/Resources/css/profiler.css | 424 ++++++++++++++++++ .../Resources/icons/LICENSE | 0 .../Resources/icons/ic_clear_white_24px.svg | 0 .../icons/ic_insert_drive_file_white_24px.svg | 0 .../ic_keyboard_arrow_down_white_24px.svg | 0 .../icons/ic_keyboard_arrow_up_white_24px.svg | 0 .../Resources/icons/ic_layers_white_24px.svg | 0 .../icons/ic_mail_outline_white_24px.svg | 0 .../Resources/icons/ic_memory_white_24px.svg | 0 .../Resources/icons/ic_message_white_24px.svg | 0 .../icons/ic_narrowspark_white_24px.svg | 0 .../Resources/icons/ic_repeat_white_24px.svg | 0 .../icons/ic_schedule_white_24px.svg | 0 .../Resources/icons/ic_storage_white_24px.svg | 0 .../Profiler/Resources/js/ajaxHandler.js | 13 + .../Resources/js/profiler.js} | 68 +-- .../Resources/js/zepto.min.js | 0 .../Resources/views/profiler.html.php} | 40 +- .../TemplateManager.php | 18 +- .../Tests/AssetsRendererTest.php | 32 +- .../Cache/Psr6CacheDataCollectorTest.php | 10 +- .../Cache/TraceableCacheItemDecoraterTest.php | 4 +- .../Bridge/SwiftMailDataCollectorTest.php | 4 +- .../DataCollectors/DataCollectorTest.php | 12 +- .../MemoryDataCollectorTest.php | 6 +- .../MessagesDataCollectorTest.php | 4 +- .../PhpInfoDataCollectorTest.php | 4 +- .../DataCollectors/TimeDataCollectorTest.php | 4 +- .../Tests/Fixture/FixtureDataCollector.php | 4 +- .../Fixture/Icons/ic_clear_white_24px.svg | 0 .../Tests/Fixture/ProfilerTester.php} | 6 +- .../Tests/Fixture/View/array_table.html | 0 .../Tests/Fixture/View/default_table.html | 0 .../Tests/Fixture/View/profile.html | 14 +- .../View/profilewithajaxcollector.html.php | 8 +- .../View/profilewithcollector.html.php | 8 +- .../View/profilewithpanelcollector.html.php | 8 +- .../Middleware/ProfilerMiddlewareTest.php} | 18 +- .../Tests/ProfileTest.php | 6 +- .../Tests/ProfilerTest.php} | 32 +- .../ProfilerPDOBridgeServiceProviderTest.php} | 20 +- ...lerPsr6CacheBridgeServiceProviderTest.php} | 20 +- .../ProfilerServiceProviderTest.php} | 28 +- ...rSwiftMailerBridgeServiceProviderTest.php} | 18 +- .../Tests/Stub/database.sqlite | Bin .../Tests/TemplateManagerTest.php | 22 +- .../Tests/Util/HtmlDumperOutputTest.php | 4 +- .../Util/HtmlDumperOutput.php | 2 +- .../{WebProfiler => Profiler}/composer.json | 11 +- .../phpunit.xml.dist | 2 +- .../DataCollectors/RoutingDataCollector.php | 4 +- .../RoutingDataCollectorServiceProvider.php | 10 +- ...outingDataCollectorServiceProviderTest.php | 12 +- .../ViserioTranslationDataCollector.php | 6 +- ...ranslationDataCollectorServiceProvider.php | 10 +- .../ViserioTranslationDataCollectorTest.php | 10 +- ...lationDataCollectorServiceProviderTest.php | 10 +- .../Component/View/Engines/MarkdownEngine.php | 1 - .../Middleware/WebProfilerMiddleware.php | 40 -- .../Resources/css/webprofiler-grid.css | 54 --- .../WebProfiler/Resources/css/webprofiler.css | 424 ------------------ .../WebProfiler/Resources/js/ajaxHandler.js | 13 - src/Viserio/helpers.php | 3 +- 117 files changed, 1030 insertions(+), 1028 deletions(-) rename src/Viserio/Component/Contracts/{WebProfiler => Profiler}/AssetAware.php (84%) rename src/Viserio/Component/Contracts/{WebProfiler => Profiler}/DataCollector.php (95%) rename src/Viserio/Component/Contracts/{WebProfiler => Profiler}/PanelAware.php (80%) rename src/Viserio/Component/Contracts/{WebProfiler/WebProfiler.php => Profiler/Profiler.php} (85%) rename src/Viserio/Component/Contracts/{WebProfiler => Profiler}/TooltipAware.php (80%) rename src/Viserio/Component/{WebProfiler => Profiler}/.github/PULL_REQUEST_TEMPLATE.md (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/AssetsRenderer.php (88%) rename src/Viserio/Component/{WebProfiler => Profiler}/Controllers/AssetController.php (82%) rename src/Viserio/Component/{WebProfiler => Profiler}/Controllers/OpenHandlerController.php (80%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/AbstractDataCollector.php (94%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/AjaxRequestsDataCollector.php (81%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php (93%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php (98%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/Bridge/PDO/PDODataCollector.php (70%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/Bridge/PDO/TraceablePDODecorater.php (96%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/Bridge/PDO/TraceablePDOStatementDecorater.php (62%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/Bridge/PDO/TracedStatement.php (98%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/Bridge/SwiftMailDataCollector.php (90%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/MemoryDataCollector.php (92%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/MessagesDataCollector.php (97%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/PhpInfoDataCollector.php (97%) rename src/Viserio/Component/{WebProfiler => Profiler}/DataCollectors/TimeDataCollector.php (99%) rename src/Viserio/Component/{WebProfiler => Profiler}/LICENSE (100%) create mode 100644 src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php rename src/Viserio/Component/{WebProfiler => Profiler}/Profile.php (91%) rename src/Viserio/Component/{WebProfiler/WebProfiler.php => Profiler/Profiler.php} (88%) rename src/Viserio/Component/{WebProfiler/Providers/WebProfilerPDOBridgeServiceProvider.php => Profiler/Providers/ProfilerPDOBridgeServiceProvider.php} (66%) rename src/Viserio/Component/{WebProfiler/Providers/WebProfilerPsr6CacheBridgeServiceProvider.php => Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php} (64%) rename src/Viserio/Component/{WebProfiler/Providers/WebProfilerServiceProvider.php => Profiler/Providers/ProfilerServiceProvider.php} (77%) rename src/Viserio/Component/{WebProfiler/Providers/WebProfilerSwiftMailerBridgeServiceProvider.php => Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php} (56%) rename src/Viserio/Component/{WebProfiler => Profiler}/Proxies/WebProfiler.php (73%) rename src/Viserio/Component/{WebProfiler => Profiler}/README.md (98%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/css/ajax-requests.css (53%) create mode 100644 src/Viserio/Component/Profiler/Resources/css/profiler-grid.css create mode 100644 src/Viserio/Component/Profiler/Resources/css/profiler.css rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/LICENSE (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_clear_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_insert_drive_file_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_keyboard_arrow_down_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_keyboard_arrow_up_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_layers_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_mail_outline_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_memory_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_message_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_narrowspark_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_repeat_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_schedule_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/icons/ic_storage_white_24px.svg (100%) create mode 100644 src/Viserio/Component/Profiler/Resources/js/ajaxHandler.js rename src/Viserio/Component/{WebProfiler/Resources/js/webprofiler.js => Profiler/Resources/js/profiler.js} (69%) rename src/Viserio/Component/{WebProfiler => Profiler}/Resources/js/zepto.min.js (100%) rename src/Viserio/Component/{WebProfiler/Resources/views/webprofiler.html.php => Profiler/Resources/views/profiler.html.php} (54%) rename src/Viserio/Component/{WebProfiler => Profiler}/TemplateManager.php (86%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/AssetsRendererTest.php (75%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php (51%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php (97%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php (89%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/DataCollectorTest.php (74%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/MemoryDataCollectorTest.php (73%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/MessagesDataCollectorTest.php (91%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/PhpInfoDataCollectorTest.php (90%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/DataCollectors/TimeDataCollectorTest.php (95%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/FixtureDataCollector.php (93%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/Icons/ic_clear_white_24px.svg (100%) rename src/Viserio/Component/{WebProfiler/Tests/Fixture/WebProfilerTester.php => Profiler/Tests/Fixture/ProfilerTester.php} (62%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/View/array_table.html (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/View/default_table.html (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/View/profile.html (87%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/View/profilewithajaxcollector.html.php (95%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/View/profilewithcollector.html.php (94%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Fixture/View/profilewithpanelcollector.html.php (95%) rename src/Viserio/Component/{WebProfiler/Tests/Middleware/WebProfilerMiddlewareTest.php => Profiler/Tests/Middleware/ProfilerMiddlewareTest.php} (71%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/ProfileTest.php (93%) rename src/Viserio/Component/{WebProfiler/Tests/WebProfilerTest.php => Profiler/Tests/ProfilerTest.php} (83%) rename src/Viserio/Component/{WebProfiler/Tests/Providers/WebProfilerPDOBridgeServiceProviderTest.php => Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php} (60%) rename src/Viserio/Component/{WebProfiler/Tests/Providers/WebProfilerPsr6CacheBridgeServiceProviderTest.php => Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php} (61%) rename src/Viserio/Component/{WebProfiler/Tests/Providers/WebProfilerServiceProviderTest.php => Profiler/Tests/Providers/ProfilerServiceProviderTest.php} (64%) rename src/Viserio/Component/{WebProfiler/Tests/Providers/WebProfilerSwiftMailerBridgeServiceProviderTest.php => Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php} (62%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Stub/database.sqlite (100%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/TemplateManagerTest.php (83%) rename src/Viserio/Component/{WebProfiler => Profiler}/Tests/Util/HtmlDumperOutputTest.php (87%) rename src/Viserio/Component/{WebProfiler => Profiler}/Util/HtmlDumperOutput.php (95%) rename src/Viserio/Component/{WebProfiler => Profiler}/composer.json (89%) rename src/Viserio/Component/{WebProfiler => Profiler}/phpunit.xml.dist (94%) delete mode 100644 src/Viserio/Component/WebProfiler/Middleware/WebProfilerMiddleware.php delete mode 100644 src/Viserio/Component/WebProfiler/Resources/css/webprofiler-grid.css delete mode 100644 src/Viserio/Component/WebProfiler/Resources/css/webprofiler.css delete mode 100644 src/Viserio/Component/WebProfiler/Resources/js/ajaxHandler.js diff --git a/composer.json b/composer.json index e4a9a38ed..9fe3a4175 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,7 @@ "symfony/polyfill-mbstring" : "^1.0", "symfony/polyfill-intl-icu" : "^1.0", "symfony/process" : "^3.2", + "symfony/stopwatch" : "^3.2", "symfony/var-dumper" : "^3.2", "swiftmailer/swiftmailer" : "^5.4", "vlucas/phpdotenv" : "^2.3" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e0be0683c..5ff5a6cd8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -124,8 +124,8 @@ ./src/Viserio/Component/View/Tests - - ./src/Viserio/Component/WebProfiler/Tests + + ./src/Viserio/Component/Profiler/Tests diff --git a/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css b/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css index 530331f37..30f38d074 100644 --- a/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css +++ b/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css @@ -1,20 +1,20 @@ -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph { +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph { margin-top: 25px; } -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre { +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre { font-size: 14px; color: #2B2A28; padding: 10px; background-color: #fff; } -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-success { +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-success { color: #4F805D; } -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-warning { +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-warning { background-color: #A46A1F; color: #FFF; padding: 0px 5px; } -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-error { +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-error { color: #B0413E; } diff --git a/src/Viserio/Bridge/Twig/DataCollector/TwigDataCollector.php b/src/Viserio/Bridge/Twig/DataCollector/TwigDataCollector.php index 1b9f5af28..5ae31939a 100644 --- a/src/Viserio/Bridge/Twig/DataCollector/TwigDataCollector.php +++ b/src/Viserio/Bridge/Twig/DataCollector/TwigDataCollector.php @@ -8,10 +8,10 @@ use Twig_Markup; use Twig_Profiler_Dumper_Html; use Twig_Profiler_Profile; -use Viserio\Component\Contracts\WebProfiler\AssetAware as AssetAwareContract; -use Viserio\Component\Contracts\WebProfiler\PanelAware as PanelAwareContract; -use Viserio\Component\Contracts\WebProfiler\TooltipAware as TooltipAwareContract; -use Viserio\Component\WebProfiler\DataCollectors\AbstractDataCollector; +use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract; +use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; +use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; +use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; class TwigDataCollector extends AbstractDataCollector implements PanelAwareContract, diff --git a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php index 0db8f1007..fb4b99209 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php @@ -10,7 +10,7 @@ use Viserio\Bridge\Twig\DataCollector\TwigDataCollector; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\OptionsResolver\RequiresMandatoryOptions as RequiresMandatoryOptionsContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\OptionsResolver\OptionsResolver; class TwigBridgeDataCollectorsServiceProvider implements @@ -33,7 +33,7 @@ public function getServices() return [ Twig_Profiler_Profile::class => [self::class, 'createTwigProfilerProfile'], TwigEnvironment::class => [self::class, 'createTwigEnvironment'], - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -42,7 +42,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'Profiler']; } /** @@ -57,7 +57,7 @@ public function getMandatoryOptions(): iterable ]; } - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ProfilerContract { self::resolveOptions($container); diff --git a/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php b/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php index d213bf690..03f8c6e18 100644 --- a/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php +++ b/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php @@ -36,7 +36,7 @@ public function testGetTooltip() $this->mock(ResponseInterface::class) ); - static::assertSame('
Template calls1
Block calls0
Macro calls0
', $collect->getTooltip()); + static::assertSame('
Template calls1
Block calls0
Macro calls0
', $collect->getTooltip()); } public function testGetPanel() @@ -56,7 +56,7 @@ public function testGetPanel() $this->mock(ResponseInterface::class) ); - $expect = preg_replace('/(\r\n|\n\r|\r)/', "\n", '

Twig Metrics

  • ' . $this->formatDuration($collect->getTime()) . 'Render time
  • 1Template calls
  • 0Block calls
  • 0Macro calls

Rendered Templates

Template NameRender Count
test.twig1

Rendering Call Graph

' . $collect->getHtmlCallGraph() . '
Extension
Twig_Extension_Core
Twig_Extension_Escaper
Twig_Extension_Optimizer
Twig_Extension_Profiler
'); + $expect = preg_replace('/(\r\n|\n\r|\r)/', "\n", '

Twig Metrics

  • ' . $this->formatDuration($collect->getTime()) . 'Render time
  • 1Template calls
  • 0Block calls
  • 0Macro calls

Rendered Templates

Template NameRender Count
test.twig1

Rendering Call Graph

' . $collect->getHtmlCallGraph() . '
Extension
Twig_Extension_Core
Twig_Extension_Escaper
Twig_Extension_Optimizer
Twig_Extension_Profiler
'); static::assertSame($this->removeTabId($expect), $this->removeTabId(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collect->getPanel()))); } diff --git a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php index 788730eda..74a1a8fcc 100644 --- a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php +++ b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php @@ -9,12 +9,12 @@ use Viserio\Bridge\Twig\Providers\TwigBridgeDataCollectorsServiceProvider; use Viserio\Bridge\Twig\Providers\TwigBridgeServiceProvider; use Viserio\Component\Container\Container; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Filesystem\Providers\FilesServiceProvider; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; use Viserio\Component\View\Providers\ViewServiceProvider; -use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; /** * @runTestsInSeparateProcesses @@ -29,13 +29,13 @@ public function testGetServices() $container->register(new FilesServiceProvider()); $container->register(new ViewServiceProvider()); $container->register(new HttpFactoryServiceProvider()); - $container->register(new WebProfilerServiceProvider()); + $container->register(new ProfilerServiceProvider()); $container->register(new TwigBridgeServiceProvider()); $container->register(new TwigBridgeDataCollectorsServiceProvider()); $container->instance('config', [ 'viserio' => [ - 'webprofiler' => [ + 'Profiler' => [ 'enable' => true, 'collector' => [ 'twig' => true, @@ -61,9 +61,9 @@ public function testGetServices() ], ]); - $profiler = $container->get(WebProfilerContract::class); + $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(WebProfilerContract::class, $profiler); + static::assertInstanceOf(ProfilerContract::class, $profiler); static::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); static::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); diff --git a/src/Viserio/Component/Contracts/WebProfiler/AssetAware.php b/src/Viserio/Component/Contracts/Profiler/AssetAware.php similarity index 84% rename from src/Viserio/Component/Contracts/WebProfiler/AssetAware.php rename to src/Viserio/Component/Contracts/Profiler/AssetAware.php index 8c47ba788..399950774 100644 --- a/src/Viserio/Component/Contracts/WebProfiler/AssetAware.php +++ b/src/Viserio/Component/Contracts/Profiler/AssetAware.php @@ -1,6 +1,6 @@ sendRequestThroughRouter($serverRequest); - if ($this->app->has(WebProfilerContract::class)) { - // Modify the response to add the webprofiler - $response = $this->app->get(WebProfilerContract::class)->modifyResponse( + if ($this->app->has(ProfilerContract::class)) { + // Modify the response to add the Profiler + $response = $this->app->get(ProfilerContract::class)->modifyResponse( $serverRequest, $response ); diff --git a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php index 5171b13b5..f8661a75e 100644 --- a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php @@ -9,7 +9,7 @@ use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\OptionsResolver\RequiresMandatoryOptions as RequiresMandatoryOptionsContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Foundation\DataCollectors\FilesLoadedCollector; use Viserio\Component\Foundation\DataCollectors\NarrowsparkDataCollector; use Viserio\Component\Foundation\DataCollectors\ViserioHttpDataCollector; @@ -34,7 +34,7 @@ class FoundationDataCollectorServiceProvider implements public function getServices() { return [ - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -43,7 +43,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'profiler']; } /** @@ -76,9 +76,9 @@ public function getDefaultOptions(): iterable * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { self::resolveOptions($container); diff --git a/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php b/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php index d9312569c..d44f06204 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php @@ -40,6 +40,6 @@ public function testGetTooltip() $opcache = (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) ? 'status-green' : 'status-red'; $version = Application::VERSION; - static::assertSame('
Profiler token
Application name
Environmentdevelop
Debugdisabled
PHP version' . phpversion() . '
Architecture' . PHP_INT_SIZE * 8 . '
Timezone' . date_default_timezone_get() . '
PHP ExtensionsXdebugOPcache
PHP SAPIcli
', $collect->getTooltip()); + static::assertSame('
Profiler token
Application name
Environmentdevelop
Debugdisabled
PHP version' . phpversion() . '
Architecture' . PHP_INT_SIZE * 8 . '
Timezone' . date_default_timezone_get() . '
PHP ExtensionsXdebugOPcache
PHP SAPIcli
', $collect->getTooltip()); } } diff --git a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php index b7b47530d..b6e08f04f 100644 --- a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php +++ b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php @@ -11,7 +11,7 @@ use Viserio\Component\Contracts\Exception\Handler as HandlerContract; use Viserio\Component\Contracts\Foundation\Application as ApplicationContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as Profilertract; use Viserio\Component\Foundation\Bootstrap\HandleExceptions; use Viserio\Component\Foundation\Bootstrap\LoadConfiguration; use Viserio\Component\Foundation\Bootstrap\LoadEnvironmentVariables; @@ -128,7 +128,7 @@ public function testHandle() $events->shouldReceive('trigger') ->twice(); - $profiler = $this->mock(WebProfilerContract::class); + $profiler = $this->mock(Profilertract::class); $profiler->shouldReceive('modifyResponse') ->once() ->with($serverRequest, $response) @@ -169,11 +169,11 @@ public function testHandle() ->andReturn($config); $app->shouldReceive('has') ->once() - ->with(WebProfilerContract::class) + ->with(Profilertract::class) ->andReturn(true); $app->shouldReceive('get') ->once() - ->with(WebProfilerContract::class) + ->with(Profilertract::class) ->andReturn($profiler); $app->shouldReceive('instance') ->once() diff --git a/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php b/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php index e9f75c036..a057cbad3 100644 --- a/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php @@ -9,11 +9,11 @@ use Viserio\Component\Contracts\Config\Repository as RepositoryContract; use Viserio\Component\Contracts\Routing\Route as RouteContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Foundation\Providers\FoundationDataCollectorServiceProvider; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; -use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; class FoundationDataCollectorServiceProviderTest extends MockeryTestCase { @@ -37,11 +37,11 @@ public function testGetServices() $container->register(new OptionsResolverServiceProvider()); $container->register(new HttpFactoryServiceProvider()); $container->register(new ConfigServiceProvider()); - $container->register(new WebProfilerServiceProvider()); + $container->register(new ProfilerServiceProvider()); $container->register(new FoundationDataCollectorServiceProvider()); $container->get(RepositoryContract::class)->set('viserio', [ - 'webprofiler' => [ + 'profiler' => [ 'enable' => true, 'collector' => [ 'narrowspark' => true, @@ -52,9 +52,9 @@ public function testGetServices() ]); $container->get(RepositoryContract::class)->set('path.base', '/'); - $profiler = $container->get(WebProfilerContract::class); + $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(WebProfilerContract::class, $profiler); + static::assertInstanceOf(ProfilerContract::class, $profiler); static::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); static::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); diff --git a/src/Viserio/Component/Log/DataCollectors/LogParser.php b/src/Viserio/Component/Log/DataCollectors/LogParser.php index b51c1bc10..36d2c8fa6 100644 --- a/src/Viserio/Component/Log/DataCollectors/LogParser.php +++ b/src/Viserio/Component/Log/DataCollectors/LogParser.php @@ -10,6 +10,8 @@ class LogParser /** * The max size of a log file. + * + * @var int */ public const MAX_FILE_SIZE = 52428800; diff --git a/src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php b/src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php index 29ccf380c..c0ce2c10d 100644 --- a/src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php +++ b/src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php @@ -2,8 +2,8 @@ declare(strict_types=1); namespace Viserio\Component\Log\DataCollectors; -use Viserio\Component\Contracts\WebProfiler\PanelAware as PanelAwareContract; -use Viserio\Component\WebProfiler\DataCollectors\MessagesDataCollector; +use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; +use Viserio\Component\Profiler\DataCollectors\MessagesDataCollector; class LogsDataCollector extends MessagesDataCollector implements PanelAwareContract { diff --git a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php index 24afb8476..023390bf7 100644 --- a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php @@ -7,7 +7,7 @@ use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\OptionsResolver\RequiresMandatoryOptions as RequiresMandatoryOptionsContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Log\DataCollectors\LogParser; use Viserio\Component\Log\DataCollectors\LogsDataCollector; use Viserio\Component\OptionsResolver\OptionsResolver; @@ -32,7 +32,7 @@ public function getServices() { return [ LogParser::class => [self::class, 'createLogParser'], - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -41,7 +41,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'Profiler']; } /** @@ -80,9 +80,9 @@ public static function createLogParser(): LogParser * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { self::resolveOptions($container); diff --git a/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php b/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php index 3a5ed2b30..48e19ed42 100644 --- a/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php @@ -5,12 +5,12 @@ use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Container\Container; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\Log\DataCollectors\LogParser; use Viserio\Component\Log\Providers\LogsDataCollectorServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; -use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; class LogsDataCollectorServiceProviderTest extends MockeryTestCase { @@ -20,12 +20,12 @@ public function testProvider() $container->register(new OptionsResolverServiceProvider()); $container->instance(ServerRequestInterface::class, $this->getRequest()); $container->register(new HttpFactoryServiceProvider()); - $container->register(new WebProfilerServiceProvider()); + $container->register(new ProfilerServiceProvider()); $container->register(new LogsDataCollectorServiceProvider()); $container->instance('config', [ 'viserio' => [ - 'webprofiler' => [ + 'Profiler' => [ 'enable' => true, 'logs_storages' => [__DIR__], 'collector' => [ @@ -36,7 +36,7 @@ public function testProvider() ]); self::assertInstanceOf(LogParser::class, $container->get(LogParser::class)); - self::assertInstanceOf(WebProfilerContract::class, $container->get(WebProfilerContract::class)); + self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); } private function getRequest() diff --git a/src/Viserio/Component/WebProfiler/.github/PULL_REQUEST_TEMPLATE.md b/src/Viserio/Component/Profiler/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from src/Viserio/Component/WebProfiler/.github/PULL_REQUEST_TEMPLATE.md rename to src/Viserio/Component/Profiler/.github/PULL_REQUEST_TEMPLATE.md diff --git a/src/Viserio/Component/WebProfiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php similarity index 88% rename from src/Viserio/Component/WebProfiler/AssetsRenderer.php rename to src/Viserio/Component/Profiler/AssetsRenderer.php index 716314e54..c2f260c9a 100644 --- a/src/Viserio/Component/WebProfiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -1,10 +1,10 @@ webprofiler = $webprofiler; + $this->Profiler = $Profiler; return $this; } @@ -159,11 +159,11 @@ public function getIgnoredCollectors(): array */ public function render(): string { - if (($urlGenerator = $this->webprofiler->getUrlGenerator()) !== null) { - $cssRoute = $urlGenerator->generate('webprofiler.assets.css', [ + if (($urlGenerator = $this->Profiler->getUrlGenerator()) !== null) { + $cssRoute = $urlGenerator->generate('Profiler.assets.css', [ 'v' => $this->getModifiedTime('css'), ]); - $jsRoute = $urlGenerator->generate('webprofiler.assets.js', [ + $jsRoute = $urlGenerator->generate('Profiler.assets.js', [ 'v' => $this->getModifiedTime('js'), ]); @@ -231,7 +231,7 @@ function ($js) { $additionalAssets = []; // finds assets provided by collectors - foreach ($this->webprofiler->getCollectors() as $collector) { + foreach ($this->Profiler->getCollectors() as $collector) { if ($collector instanceof AssetAwareContract && ! in_array($collector->getName(), $this->ignoredCollectors) ) { diff --git a/src/Viserio/Component/WebProfiler/Controllers/AssetController.php b/src/Viserio/Component/Profiler/Controllers/AssetController.php similarity index 82% rename from src/Viserio/Component/WebProfiler/Controllers/AssetController.php rename to src/Viserio/Component/Profiler/Controllers/AssetController.php index 6d5ff2ac0..619d2d3bc 100644 --- a/src/Viserio/Component/WebProfiler/Controllers/AssetController.php +++ b/src/Viserio/Component/Profiler/Controllers/AssetController.php @@ -1,13 +1,13 @@ responseFactory = $responseFactory; $this->streamFactory = $streamFactory; - $this->webprofiler = $webprofiler; + $this->Profiler = $Profiler; if ($session = $serverRequest->getAttribute('session')) { $session->reflash(); @@ -62,7 +62,7 @@ public function __construct( */ public function js(): ResponseInterface { - $renderer = $this->webprofiler->getAssetsRenderer(); + $renderer = $this->profiler->getAssetsRenderer(); $stream = $this->streamFactory->createStream( $renderer->dumpAssetsToString('js') @@ -81,7 +81,7 @@ public function js(): ResponseInterface */ public function css(): ResponseInterface { - $renderer = $this->webprofiler->getAssetsRenderer(); + $renderer = $this->profiler->getAssetsRenderer(); $stream = $this->streamFactory->createStream( $renderer->dumpAssetsToString('css') diff --git a/src/Viserio/Component/WebProfiler/Controllers/OpenHandlerController.php b/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php similarity index 80% rename from src/Viserio/Component/WebProfiler/Controllers/OpenHandlerController.php rename to src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php index f03b5472a..2d9c7cb74 100644 --- a/src/Viserio/Component/WebProfiler/Controllers/OpenHandlerController.php +++ b/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php @@ -1,12 +1,12 @@ responseFactory = $responseFactory; $this->streamFactory = $streamFactory; - $this->webprofiler = $webprofiler; + $this->Profiler = $ProfilerContract } /** diff --git a/src/Viserio/Component/WebProfiler/DataCollectors/AbstractDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php similarity index 94% rename from src/Viserio/Component/WebProfiler/DataCollectors/AbstractDataCollector.php rename to src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php index b377dcf48..920af7955 100644 --- a/src/Viserio/Component/WebProfiler/DataCollectors/AbstractDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php @@ -1,6 +1,6 @@ '; + $tooltip = '
'; foreach ($data as $strong => $infos) { - $tooltip .= '
'; + $tooltip .= '
'; if (is_array($infos)) { $tooltip .= '' . $strong . ''; @@ -205,15 +205,15 @@ protected function createTabs(array $data): string $grid = ' col span_' . floor(12 / $counted); } - $html = '
'; + $html = '
'; foreach ($data as $key => $value) { $id = uniqid($key . '-'); - $html .= '
'; + $html .= '
'; $html .= ''; $html .= ''; - $html .= '
'; + $html .= '
'; $html .= $value['content']; $html .= '
'; } diff --git a/src/Viserio/Component/WebProfiler/DataCollectors/AjaxRequestsDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/AjaxRequestsDataCollector.php similarity index 81% rename from src/Viserio/Component/WebProfiler/DataCollectors/AjaxRequestsDataCollector.php rename to src/Viserio/Component/Profiler/DataCollectors/AjaxRequestsDataCollector.php index b5c900922..7335a9d37 100644 --- a/src/Viserio/Component/WebProfiler/DataCollectors/AjaxRequestsDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/AjaxRequestsDataCollector.php @@ -1,11 +1,11 @@ createTooltipGroup([ '0 AJAX requests' => '', - ' + '
@@ -49,7 +49,7 @@ public function getTooltip(): string - +
MethodProfile
', ]); } diff --git a/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php similarity index 93% rename from src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php rename to src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php index 6d63b3536..0de9d7a29 100644 --- a/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php @@ -1,13 +1,13 @@ profiler = $profiler; + } + + /** + * {@inheritdoc} + */ + public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface + { + $response = $delegate->process($request); + + // Modify the response to add the Profiler + return $this->profiler->modifyResponse($request, $response); + } +} diff --git a/src/Viserio/Component/WebProfiler/Profile.php b/src/Viserio/Component/Profiler/Profile.php similarity index 91% rename from src/Viserio/Component/WebProfiler/Profile.php rename to src/Viserio/Component/Profiler/Profile.php index 8d16a2ee0..cb6cfe8e4 100644 --- a/src/Viserio/Component/WebProfiler/Profile.php +++ b/src/Viserio/Component/Profiler/Profile.php @@ -1,9 +1,9 @@ assetsRenderer = $assetsRenderer->setWebProfiler($this); + $this->assetsRenderer = $assetsRenderer->setProfiler($this); } /** @@ -99,7 +99,7 @@ public function enable(): void /** * {@inheritdoc} */ - public function setUrlGenerator(UrlGeneratorContract $urlGenerator): WebProfilerContract + public function setUrlGenerator(UrlGeneratorContract $urlGenerator): ProfilerContract { $this->urlGenerator = $urlGenerator; @@ -115,13 +115,13 @@ public function getUrlGenerator(): ?UrlGeneratorContract } /** - * Set the webprofiler template path. + * Set the Profiler template path. * * @param string $path * * @return $this */ - public function setTemplate(string $path): WebProfilerContract + public function setTemplate(string $path): ProfilerContract { $this->template = $path; @@ -129,7 +129,7 @@ public function setTemplate(string $path): WebProfilerContract } /** - * Get the webprofiler template path. + * Get the Profiler template path. * * @return string */ @@ -141,7 +141,7 @@ public function getTemplate(): string /** * {@inheritdoc} */ - public function addCollector(DataCollectorContract $collector, int $priority = 100): WebProfilerContract + public function addCollector(DataCollectorContract $collector, int $priority = 100): ProfilerContract { if (isset($this->collectors[$collector->getName()])) { throw new RuntimeException(sprintf('[%s] is already a registered collector.', $collector->getName())); @@ -196,19 +196,19 @@ public function modifyResponse( } } catch (Throwable $exception) { if ($this->logger !== null) { - $this->logger->error('WebProfiler exception: ' . $exception->getMessage()); + $this->logger->error('Profiler exception: ' . $exception->getMessage()); } else { throw $exception; } } - return $this->injectWebProfiler($response, $token); + return $this->injectProfiler($response, $token); } /** * Returns a AssetsRenderer for this instance. * - * @return \Viserio\Component\WebProfiler\AssetsRenderer + * @return \Viserio\Component\Profiler\AssetsRenderer */ public function getAssetsRenderer(): AssetsRenderer { @@ -223,9 +223,9 @@ public function getAssetsRenderer(): AssetsRenderer * * @return \Psr\Http\Message\ResponseInterface * - * @link https://github.com/symfony/WebProfilerBundle/blob/master/EventListener/WebDebugToolbarListener.php + * @link https://github.com/symfony/ProfilerBundle/blob/master/EventListener/WebDebugToolbarListener.php */ - protected function injectWebProfiler(ResponseInterface $response, string $token): ResponseInterface + protected function injectProfiler(ResponseInterface $response, string $token): ResponseInterface { $content = (string) $response->getBody(); $renderedContent = $this->createTemplate($token); diff --git a/src/Viserio/Component/WebProfiler/Providers/WebProfilerPDOBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php similarity index 66% rename from src/Viserio/Component/WebProfiler/Providers/WebProfilerPDOBridgeServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php index d896c0525..698a8cb79 100644 --- a/src/Viserio/Component/WebProfiler/Providers/WebProfilerPDOBridgeServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php @@ -1,15 +1,15 @@ function (ContainerInterface $container) { return $container->get(PDO::class); }, - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -31,7 +31,7 @@ public function getServices() * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\WebProfiler\DataCollectors\Bridge\PDO\TraceablePDODecorater + * @return null|\Viserio\Component\Profiler\DataCollectors\Bridge\PDO\TraceablePDODecorater */ public static function createTraceablePDODecorater(ContainerInterface $container, ?callable $getPrevious = null): ?TraceablePDODecorater { @@ -50,9 +50,9 @@ public static function createTraceablePDODecorater(ContainerInterface $container * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { $profiler = $getPrevious(); diff --git a/src/Viserio/Component/WebProfiler/Providers/WebProfilerPsr6CacheBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php similarity index 64% rename from src/Viserio/Component/WebProfiler/Providers/WebProfilerPsr6CacheBridgeServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php index 04c1eeafe..6e4628f80 100644 --- a/src/Viserio/Component/WebProfiler/Providers/WebProfilerPsr6CacheBridgeServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php @@ -1,15 +1,15 @@ [self::class, 'createCacheItemPoolDecorater'], - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -33,9 +33,9 @@ public static function createCacheItemPoolDecorater(ContainerInterface $containe * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { $profiler = $getPrevious(); diff --git a/src/Viserio/Component/WebProfiler/Providers/WebProfilerServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php similarity index 77% rename from src/Viserio/Component/WebProfiler/Providers/WebProfilerServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php index 3b96fb1bb..570758a06 100644 --- a/src/Viserio/Component/WebProfiler/Providers/WebProfilerServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php @@ -1,6 +1,6 @@ [self::class, 'registerWebProfilerAssetsControllers'], + RouterContract::class => [self::class, 'registerProfilerAssetsControllers'], AssetsRenderer::class => [self::class, 'createAssetsRenderer'], - WebProfilerContract::class => [self::class, 'createWebProfiler'], - WebProfiler::class => function (ContainerInterface $container) { - return $container->get(WebProfilerContract::class); + ProfilerContract::class => [self::class, 'createProfiler'], + Profiler::class => function (ContainerInterface $container) { + return $container->get(ProfilerContract::class); }, ]; } @@ -55,7 +55,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'profiler']; } /** @@ -86,11 +86,11 @@ public function getDefaultOptions(): iterable ]; } - public static function createWebProfiler(ContainerInterface $container): WebProfilerContract + public static function createProfiler(ContainerInterface $container): ProfilerContract { self::resolveOptions($container); - $profiler = new WebProfiler($container->get(AssetsRenderer::class)); + $profiler = new Profiler($container->get(AssetsRenderer::class)); if (self::$options['enable']) { $profiler->enable(); @@ -130,23 +130,23 @@ public static function createAssetsRenderer(ContainerInterface $container): Asse ); } - public static function registerWebProfilerAssetsControllers(ContainerInterface $container): RouterContract + public static function registerProfilerAssetsControllers(ContainerInterface $container): RouterContract { $router = $container->get(RouterContract::class); $router->group( [ - 'namespace' => 'Viserio\Component\WebProfiler\Controllers', - 'prefix' => 'webprofiler', + 'namespace' => 'Viserio\Component\Profiler\Controllers', + 'prefix' => 'Profiler', ], function ($router) { $router->get('assets/stylesheets', [ 'uses' => 'AssetController@css', - 'as' => 'webprofiler.assets.css', + 'as' => 'Profiler.assets.css', ]); $router->get('assets/javascript', [ 'uses' => 'AssetController@js', - 'as' => 'webprofiler.assets.js', + 'as' => 'Profiler.assets.js', ]); } ); @@ -154,7 +154,7 @@ function ($router) { return $router; } - protected static function registerCollectors(ContainerInterface $container, WebProfiler $profiler) + protected static function registerCollectors(ContainerInterface $container, Profiler $profiler) { self::resolveOptions($container); @@ -177,7 +177,7 @@ protected static function registerCollectors(ContainerInterface $container, WebP } } - private static function registerCollectorsFromConfig(ContainerInterface $container, WebProfiler $profiler) + private static function registerCollectorsFromConfig(ContainerInterface $container, Profiler $profiler) { if (($collectors = self::$options['collectors']) !== null) { foreach ($collectors as $collector) { diff --git a/src/Viserio/Component/WebProfiler/Providers/WebProfilerSwiftMailerBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php similarity index 56% rename from src/Viserio/Component/WebProfiler/Providers/WebProfilerSwiftMailerBridgeServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php index 1c21f9d6b..66a078369 100644 --- a/src/Viserio/Component/WebProfiler/Providers/WebProfilerSwiftMailerBridgeServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php @@ -1,14 +1,14 @@ [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -26,9 +26,9 @@ public function getServices() * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { $profiler = $getPrevious(); diff --git a/src/Viserio/Component/WebProfiler/Proxies/WebProfiler.php b/src/Viserio/Component/Profiler/Proxies/WebProfiler.php similarity index 73% rename from src/Viserio/Component/WebProfiler/Proxies/WebProfiler.php rename to src/Viserio/Component/Profiler/Proxies/WebProfiler.php index 099099bd3..ddd7b07be 100644 --- a/src/Viserio/Component/WebProfiler/Proxies/WebProfiler.php +++ b/src/Viserio/Component/Profiler/Proxies/WebProfiler.php @@ -1,10 +1,10 @@ -
- +
+ -
+
-
- +
+ $menu): @@ -22,27 +22,27 @@ $tooltip = true; } - $data = isset($panels[$name]) ? 'data-panel-target-id="webprofiler-panel-' . TemplateManager::escape($name) . '"' : ''; - $hasPanels = isset($panels[$name]) ? ' webprofiler-menu-has-panel' : ''; - $hasTooltip = $tooltip ? ' webprofiler-menu-has-tooltip' : ''; + $data = isset($panels[$name]) ? 'data-panel-target-id="profiler-panel-' . TemplateManager::escape($name) . '"' : ''; + $hasPanels = isset($panels[$name]) ? ' profiler-menu-has-panel' : ''; + $hasTooltip = $tooltip ? ' profiler-menu-has-tooltip' : ''; $cssClasses = isset($menu['menu']['class']) ? ' ' . $menu['menu']['class'] : ''; ?> -
class="webprofiler-menu webprofiler-menu- webprofiler-menu-position-"> -
+
class="profiler-menu profiler-menu- profiler-menu-position-"> +
- + - + - +
-
+
@@ -51,17 +51,17 @@
-
-
- +
+ $panel): ?> -
+
diff --git a/src/Viserio/Component/WebProfiler/TemplateManager.php b/src/Viserio/Component/Profiler/TemplateManager.php similarity index 86% rename from src/Viserio/Component/WebProfiler/TemplateManager.php rename to src/Viserio/Component/Profiler/TemplateManager.php index 92bbb2828..e9295e300 100644 --- a/src/Viserio/Component/WebProfiler/TemplateManager.php +++ b/src/Viserio/Component/Profiler/TemplateManager.php @@ -1,10 +1,10 @@ getPanel(); // @codeCoverageIgnoreStart - if (mb_strpos($panel, '
') !== false) { - $class = ' webprofiler-body-has-table'; + $class = ' profiler-body-has-table'; } // @codeCoverageIgnoreEnd diff --git a/src/Viserio/Component/WebProfiler/Tests/AssetsRendererTest.php b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php similarity index 75% rename from src/Viserio/Component/WebProfiler/Tests/AssetsRendererTest.php rename to src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php index e7ae580ab..9d30e3323 100644 --- a/src/Viserio/Component/WebProfiler/Tests/AssetsRendererTest.php +++ b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php @@ -1,13 +1,13 @@ mock(WebProfilerContract::class); + $profiler = $this->mock(ProfilerContract::class); $profiler->shouldReceive('getCollectors') ->twice() ->andReturn([]); $assets = new AssetsRenderer(false, __DIR__); - $assets->setWebProfiler($profiler); + $assets->setProfiler($profiler); $cssAssets = [ - __DIR__ . '/css/webprofiler.css', - __DIR__ . '/css/webprofiler-grid.css', + __DIR__ . '/css/profiler.css', + __DIR__ . '/css/profiler-grid.css', ]; $jsAssets = [ __DIR__ . '/js/zepto.min.js', - __DIR__ . '/js/webprofiler.js', + __DIR__ . '/js/Profiler.js', ]; static::assertSame($cssAssets, $assets->getAssets('css')); @@ -55,20 +55,20 @@ public function testGetAssets() public function testGetAssetsFromCollectors() { - $profiler = $this->mock(WebProfilerContract::class); + $profiler = $this->mock(ProfilerContract::class); $profiler->shouldReceive('getCollectors') ->once() ->andReturn([new AjaxRequestsDataCollector()]); $assets = new AssetsRenderer(true, __DIR__); - $assets->setWebProfiler($profiler); + $assets->setProfiler($profiler); $cssAssets = [ - __DIR__ . '/css/webprofiler.css', - __DIR__ . '/css/webprofiler-grid.css', + __DIR__ . '/css/profiler.css', + __DIR__ . '/css/profiler-grid.css', str_replace('Tests', 'DataCollectors', __DIR__) . '/../Resources/css/ajax-requests.css', ]; $jsAssets = [ - __DIR__ . '/js/webprofiler.js', + __DIR__ . '/js/Profiler.js', str_replace('Tests', 'DataCollectors', __DIR__) . '/../Resources/js/ajaxHandler.js', ]; @@ -84,14 +84,14 @@ public function testRenderWithUrlGenerator() $generator->shouldReceive('generate') ->once() ->andReturn('path_js'); - $profiler = $this->mock(WebProfilerContract::class); + $profiler = $this->mock(ProfilerContract::class); $profiler->shouldReceive('getUrlGenerator') ->once() ->andReturn($generator); $profiler->shouldReceive('getCollectors') ->twice(); $assets = new AssetsRenderer(); - $assets->setWebProfiler($profiler); + $assets->setProfiler($profiler); static::assertSame('', $assets->render()); } diff --git a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php similarity index 51% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php index 1d2b71efc..cb1e206a6 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php @@ -1,13 +1,13 @@ getPsr6CacheDataCollector(); static::assertSame( - '
Cache calls0
Total time0μs
Cache hits0
Cache writes0
', + '
Cache calls0
Total time0μs
Cache hits0
Cache writes0
', $collector->getTooltip() ); } @@ -40,7 +40,7 @@ public function testGetPanel() $collector = $this->getPsr6CacheDataCollector(); static::assertSame( - $this->removeTabId('

Statistics

  • 0calls
  • 0μstime
  • 0reads
  • 0hits
  • 0misses
  • 0writes
  • 0deletes
  • N/Ahits/reads

Calls

Empty
'), + $this->removeTabId('

Statistics

  • 0calls
  • 0μstime
  • 0reads
  • 0hits
  • 0misses
  • 0writes
  • 0deletes
  • N/Ahits/reads

Calls

Empty
'), $this->removeSymfonyVarDumper($collector->getPanel()) ); } diff --git a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php similarity index 97% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php index e27a89b0a..522a0e678 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php @@ -1,10 +1,10 @@
testtest
', + '
testtest
', $collector->getTooltippGroupDefault() ); } @@ -56,7 +56,7 @@ public function testCreateTooltipGroupDefaultWithLink() $collector = new FixtureDataCollector(); static::assertSame( - '', + '', $collector->getTooltippGroupDefaultWithLink() ); } @@ -66,7 +66,7 @@ public function testCreateTooltipGroupArray() $collector = new FixtureDataCollector(); static::assertSame( - '
testtesttest2
', + '
testtesttest2
', $collector->getTooltippGroupArray() ); } @@ -76,7 +76,7 @@ public function testCreateTabs() $collector = new FixtureDataCollector(); static::assertSame( - $this->removeTabId('
test
'), + $this->removeTabId('
test
'), $this->removeTabId($collector->getTabs()) ); } diff --git a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/MemoryDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php similarity index 73% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/MemoryDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php index 7e5a5ff88..7165f912a 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/MemoryDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php @@ -1,11 +1,11 @@ getData(); static::assertSame( - '
Peak memory usage' . $data['memory'] / 1024 / 1024 . ' MB
PHP memory limitUnlimited MB
', + '
Peak memory usage' . $data['memory'] / 1024 / 1024 . ' MB
PHP memory limitUnlimited MB
', $collect->getTooltip() ); } diff --git a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/MessagesDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php similarity index 91% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/MessagesDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php index 7a08157e9..2a4e435d1 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/MessagesDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php @@ -1,11 +1,11 @@ - +
+ -
+
-
-
- +
+
+ - + diff --git a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithajaxcollector.html.php b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithajaxcollector.html.php similarity index 95% rename from src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithajaxcollector.html.php rename to src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithajaxcollector.html.php index 4cb91e57c..0cc132a88 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithajaxcollector.html.php +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithajaxcollector.html.php @@ -1,10 +1,10 @@ -
- +
+
-
+
diff --git a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithcollector.html.php b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithcollector.html.php similarity index 94% rename from src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithcollector.html.php rename to src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithcollector.html.php index 6bac5d657..2366862e1 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithcollector.html.php +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithcollector.html.php @@ -1,13 +1,13 @@ - +
+
-
+
diff --git a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithpanelcollector.html.php b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithpanelcollector.html.php similarity index 95% rename from src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithpanelcollector.html.php rename to src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithpanelcollector.html.php index 9624fd244..3011d3042 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profilewithpanelcollector.html.php +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithpanelcollector.html.php @@ -1,10 +1,10 @@ -
- +
+
-
+
diff --git a/src/Viserio/Component/WebProfiler/Tests/Middleware/WebProfilerMiddlewareTest.php b/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php similarity index 71% rename from src/Viserio/Component/WebProfiler/Tests/Middleware/WebProfilerMiddlewareTest.php rename to src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php index 8e1f0265a..cf284d20a 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Middleware/WebProfilerMiddlewareTest.php +++ b/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php @@ -1,26 +1,26 @@ enable(); - $middleware = new WebProfilerMiddleware($profiler); + $middleware = new ProfilerMiddleware($profiler); $template = new TemplateManager( [], $profiler->getTemplate(), @@ -52,7 +52,7 @@ private function removeId(string $html): string str_replace( "\r\n", '', - preg_replace('/="webprofiler-(.*?)"/', '', $html) + preg_replace('/="profiler-(.*?)"/', '', $html) ) ); } diff --git a/src/Viserio/Component/WebProfiler/Tests/ProfileTest.php b/src/Viserio/Component/Profiler/Tests/ProfileTest.php similarity index 93% rename from src/Viserio/Component/WebProfiler/Tests/ProfileTest.php rename to src/Viserio/Component/Profiler/Tests/ProfileTest.php index 3305bb358..278a4d950 100644 --- a/src/Viserio/Component/WebProfiler/Tests/ProfileTest.php +++ b/src/Viserio/Component/Profiler/Tests/ProfileTest.php @@ -1,10 +1,10 @@ getWebProfiler(); + $profiler = $this->getProfiler(); $profiler->setUrlGenerator($this->mock(UrlGeneratorContract::class)); @@ -25,7 +25,7 @@ public function testSetAndGetUrlGenerator() public function testSetAndGetTemplate() { - $profiler = $this->getWebProfiler(); + $profiler = $this->getProfiler(); $profiler->setTemplate(__DIR__); @@ -34,7 +34,7 @@ public function testSetAndGetTemplate() public function testAddHasAndGetCollectors() { - $profiler = $this->getWebProfiler(); + $profiler = $this->getProfiler(); $collector = new PhpInfoDataCollector(); $profiler->addCollector($collector); @@ -58,7 +58,7 @@ public function testAddHasAndGetCollectors() */ public function testAddCollectorThrowsException() { - $profiler = $this->getWebProfiler(); + $profiler = $this->getProfiler(); $collector = new PhpInfoDataCollector(); $profiler->addCollector($collector); @@ -68,7 +68,7 @@ public function testAddCollectorThrowsException() public function testModifyResponse() { $assets = new AssetsRenderer(); - $profiler = new WebProfiler($assets); + $profiler = new Profiler($assets); $server = $_SERVER; $server['SERVER_ADDR'] = '127.0.0.1'; @@ -100,7 +100,7 @@ public function testModifyResponse() public function testModifyResponseWithOldContent() { $assets = new AssetsRenderer(); - $profiler = new WebProfiler($assets); + $profiler = new Profiler($assets); $profiler->enable(); $stream = (new StreamFactory())->createStream( @@ -137,7 +137,7 @@ public function testModifyResponseWithOldContent() public function testDontModifyResponse() { $assets = new AssetsRenderer(); - $profiler = new WebProfiler($assets); + $profiler = new Profiler($assets); $server = $_SERVER; $server['SERVER_ADDR'] = '127.0.0.1'; @@ -156,11 +156,11 @@ public function testDontModifyResponse() private function removeId(string $html): string { - return trim(preg_replace('/="webprofiler-(.*?)"/', '', $html)); + return trim(preg_replace('/="profiler-(.*?)"/', '', $html)); } - private function getWebProfiler() + private function getProfiler() { - return new WebProfiler(new AssetsRenderer()); + return new Profiler(new AssetsRenderer()); } } diff --git a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPDOBridgeServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php similarity index 60% rename from src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPDOBridgeServiceProviderTest.php rename to src/Viserio/Component/Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php index 9f286f520..c38bb82ee 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPDOBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php @@ -1,19 +1,19 @@ instance(ServerRequestInterface::class, $this->getRequest()); $container->register(new HttpFactoryServiceProvider()); $container->register(new OptionsResolverServiceProvider()); - $container->register(new WebProfilerServiceProvider()); - $container->register(new WebProfilerPDOBridgeServiceProvider()); + $container->register(new ProfilerServiceProvider()); + $container->register(new ProfilerPDOBridgeServiceProvider()); - $container->instance('config', ['viserio' => ['webprofiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); - self::assertInstanceOf(WebProfilerContract::class, $container->get(WebProfilerContract::class)); + self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); self::assertInstanceOf(TraceablePDODecorater::class, $container->get(PDO::class)); } diff --git a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPsr6CacheBridgeServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php similarity index 61% rename from src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPsr6CacheBridgeServiceProviderTest.php rename to src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php index c5a26942a..c0a307d0a 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPsr6CacheBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php @@ -1,19 +1,19 @@ instance(ServerRequestInterface::class, $this->getRequest()); $container->register(new HttpFactoryServiceProvider()); $container->register(new OptionsResolverServiceProvider()); - $container->register(new WebProfilerServiceProvider()); - $container->register(new WebProfilerPsr6CacheBridgeServiceProvider()); + $container->register(new ProfilerServiceProvider()); + $container->register(new ProfilerPsr6CacheBridgeServiceProvider()); - $container->instance('config', ['viserio' => ['webprofiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); - self::assertInstanceOf(WebProfilerContract::class, $container->get(WebProfilerContract::class)); + self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); self::assertInstanceOf(TraceableCacheItemDecorater::class, $container->get(CacheItemPoolInterface::class)); } diff --git a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php similarity index 64% rename from src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerServiceProviderTest.php rename to src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php index 14fa612f2..6aad33572 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php @@ -1,21 +1,21 @@ register(new HttpFactoryServiceProvider()); $container->register(new EventsServiceProvider()); $container->register(new OptionsResolverServiceProvider()); - $container->register(new WebProfilerServiceProvider()); + $container->register(new ProfilerServiceProvider()); - $container->instance('config', ['viserio' => ['webprofiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); self::assertInstanceOf(AssetsRenderer::class, $container->get(AssetsRenderer::class)); - self::assertInstanceOf(WebProfiler::class, $container->get(WebProfiler::class)); - self::assertInstanceOf(WebProfilerContract::class, $container->get(WebProfilerContract::class)); + self::assertInstanceOf(Profiler::class, $container->get(ProfilerContract::class)); + self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); } public function testRouteGroups() @@ -41,17 +41,17 @@ public function testRouteGroups() $container->register(new RoutingServiceProvider()); $container->register(new EventsServiceProvider()); $container->register(new OptionsResolverServiceProvider()); - $container->register(new WebProfilerServiceProvider()); + $container->register(new ProfilerServiceProvider()); - $container->instance('config', ['viserio' => ['webprofiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); $router = $container->get(RouterContract::class); $routes = $router->getRoutes()->getRoutes(); $action1 = $routes[0]->getAction(); $action2 = $routes[1]->getAction(); - self::assertEquals('Viserio\Component\WebProfiler\Controllers\AssetController@css', $action1['controller']); - self::assertEquals('Viserio\Component\WebProfiler\Controllers\AssetController@js', $action2['controller']); + self::assertEquals('Viserio\Component\Profiler\Controllers\AssetController@css', $action1['controller']); + self::assertEquals('Viserio\Component\Profiler\Controllers\AssetController@js', $action2['controller']); } private function getRequest() diff --git a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerSwiftMailerBridgeServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php similarity index 62% rename from src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerSwiftMailerBridgeServiceProviderTest.php rename to src/Viserio/Component/Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php index f8e041fa4..f9fa7111e 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerSwiftMailerBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php @@ -1,19 +1,19 @@ instance(Swift_Mailer::class, Swift_Mailer::newInstance(Swift_SmtpTransport::newInstance('smtp.example.org', 25))); $container->register(new HttpFactoryServiceProvider()); $container->register(new OptionsResolverServiceProvider()); - $container->register(new WebProfilerServiceProvider()); - $container->register(new WebProfilerSwiftMailerBridgeServiceProvider()); + $container->register(new ProfilerServiceProvider()); + $container->register(new ProfilerSwiftMailerBridgeServiceProvider()); - $container->instance('config', ['viserio' => ['webprofiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); - self::assertInstanceOf(WebProfilerContract::class, $container->get(WebProfilerContract::class)); + self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); } private function getRequest() diff --git a/src/Viserio/Component/WebProfiler/Tests/Stub/database.sqlite b/src/Viserio/Component/Profiler/Tests/Stub/database.sqlite similarity index 100% rename from src/Viserio/Component/WebProfiler/Tests/Stub/database.sqlite rename to src/Viserio/Component/Profiler/Tests/Stub/database.sqlite diff --git a/src/Viserio/Component/WebProfiler/Tests/TemplateManagerTest.php b/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php similarity index 83% rename from src/Viserio/Component/WebProfiler/Tests/TemplateManagerTest.php rename to src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php index 9f938f299..a38d5f8a7 100644 --- a/src/Viserio/Component/WebProfiler/Tests/TemplateManagerTest.php +++ b/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php @@ -1,17 +1,17 @@ getIcons() ); @@ -65,7 +65,7 @@ public function testRenderWithCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/webprofiler.html.php', + __DIR__ . '/../Resources/views/Profiler.html.php', 'fds4f6as', $assets->getIcons() ); @@ -89,7 +89,7 @@ public function testRenderWithAjaxRequestsDataCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/webprofiler.html.php', + __DIR__ . '/../Resources/views/Profiler.html.php', 'fds4f6as', $assets->getIcons() ); @@ -113,7 +113,7 @@ public function testRenderWithAPanelCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/webprofiler.html.php', + __DIR__ . '/../Resources/views/Profiler.html.php', 'fds4f6as', $assets->getIcons() ); @@ -128,6 +128,6 @@ private function removeId(string $html): string { $html = preg_replace('/[ \t]+/', ' ', preg_replace('/[\r\n]+/', "\n", $html)); - return trim(preg_replace('/="webprofiler-(.*?)"/', '', $html)); + return trim(preg_replace('/="profiler-(.*?)"/', '', $html)); } } diff --git a/src/Viserio/Component/WebProfiler/Tests/Util/HtmlDumperOutputTest.php b/src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php similarity index 87% rename from src/Viserio/Component/WebProfiler/Tests/Util/HtmlDumperOutputTest.php rename to src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php index 9bde43183..944df9be7 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Util/HtmlDumperOutputTest.php +++ b/src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php @@ -1,9 +1,9 @@ - + ./Tests/ diff --git a/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php b/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php index b2f115ff3..3d9b4355d 100644 --- a/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php +++ b/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php @@ -5,8 +5,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Routing\RouteCollection as RouteCollectionContract; -use Viserio\Component\Contracts\WebProfiler\PanelAware as PanelAwareContract; -use Viserio\Component\WebProfiler\DataCollectors\AbstractDataCollector; +use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; +use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; class RoutingDataCollector extends AbstractDataCollector implements PanelAwareContract { diff --git a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php index ffce60ae9..94b107916 100644 --- a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php @@ -7,7 +7,7 @@ use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\OptionsResolver\OptionsResolver; use Viserio\Component\Routing\DataCollectors\RoutingDataCollector; @@ -29,7 +29,7 @@ class RoutingDataCollectorServiceProvider implements public function getServices() { return [ - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -38,7 +38,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'Profiler']; } /** @@ -59,9 +59,9 @@ public function getDefaultOptions(): iterable * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { self::resolveOptions($container); diff --git a/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php b/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php index aad381407..3370152b7 100644 --- a/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php @@ -7,11 +7,11 @@ use Viserio\Component\Container\Container; use Viserio\Component\Contracts\Routing\RouteCollection as RouteCollectionContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; use Viserio\Component\Routing\Providers\RoutingDataCollectorServiceProvider; -use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; class RoutingDataCollectorServiceProviderTest extends MockeryTestCase { @@ -30,13 +30,13 @@ public function testGetServices() $container->instance(RouterContract::class, $router); $container->register(new OptionsResolverServiceProvider()); $container->register(new HttpFactoryServiceProvider()); - $container->register(new WebProfilerServiceProvider()); + $container->register(new ProfilerServiceProvider()); $container->register(new RoutingDataCollectorServiceProvider()); $container->instance('config', [ 'viserio' => [ - 'webprofiler' => [ + 'Profiler' => [ 'enable' => true, 'collector' => [ 'routes' => true, @@ -46,9 +46,9 @@ public function testGetServices() ] ); - $profiler = $container->get(WebProfilerContract::class); + $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(WebProfilerContract::class, $profiler); + static::assertInstanceOf(ProfilerContract::class, $profiler); static::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); static::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); diff --git a/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php b/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php index 025fe36ac..effb2c8a2 100644 --- a/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php +++ b/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php @@ -6,9 +6,9 @@ use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Translation\Traits\TranslatorAwareTrait; use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; -use Viserio\Component\Contracts\WebProfiler\PanelAware as PanelAwareContract; -use Viserio\Component\Contracts\WebProfiler\TooltipAware as TooltipAwareContract; -use Viserio\Component\WebProfiler\DataCollectors\AbstractDataCollector; +use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; +use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; +use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; class ViserioTranslationDataCollector extends AbstractDataCollector implements TooltipAwareContract, diff --git a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php index ebaed6b49..e3cd1e8f2 100644 --- a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php @@ -7,7 +7,7 @@ use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\OptionsResolver\OptionsResolver; use Viserio\Component\Translation\DataCollectors\ViserioTranslationDataCollector; @@ -29,7 +29,7 @@ class TranslationDataCollectorServiceProvider implements public function getServices() { return [ - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -38,7 +38,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'Profiler']; } /** @@ -59,9 +59,9 @@ public function getDefaultOptions(): iterable * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { self::resolveOptions($container); diff --git a/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php b/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php index f86284670..3ee883340 100644 --- a/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php +++ b/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php @@ -58,7 +58,7 @@ public function testGetTooltip() { $collector = new ViserioTranslationDataCollector($this->translator); - static::assertSame('
Missing messages
Fallback messages
Defined messages
', $collector->getTooltip()); + static::assertSame('
Missing messages
Fallback messages
Defined messages
', $collector->getTooltip()); } public function testGetPanel() @@ -70,7 +70,7 @@ public function testGetPanel() ); static::assertSame( - $this->removeId('

These messages are correctly translated into the given locale.

Empty

These messages are not available for the given locale but Symfony found them in the fallback locale catalog.

Empty

These messages are not available for the given locale and cannot be found in the fallback locales.
Add them to the translation catalogue to avoid Narrowspark outputting untranslated contents.

Empty
'), + $this->removeId('

These messages are correctly translated into the given locale.

Empty

These messages are not available for the given locale but Symfony found them in the fallback locale catalog.

Empty

These messages are not available for the given locale and cannot be found in the fallback locales.
Add them to the translation catalogue to avoid Narrowspark outputting untranslated contents.

Empty
'), $this->removeId($collector->getPanel()) ); } @@ -89,7 +89,7 @@ public function testGetPanelWithTranslation() ); static::assertSame( - '

These messages are correctly translated into the given locale.

LocaleDomainTimes usedMessage IDMessage Preview
"en"
+            '

These messages are correctly translated into the given locale.

LocaleDomainTimes usedMessage IDMessage Preview
"en"
 
"messages"
 
@@ -99,7 +99,7 @@ public function testGetPanelWithTranslation()
"bar"
 
-

These messages are not available for the given locale but Symfony found them in the fallback locale catalog.

LocaleDomainTimes usedMessage IDMessage Preview
"fr"
+

These messages are not available for the given locale but Symfony found them in the fallback locale catalog.

LocaleDomainTimes usedMessage IDMessage Preview
"fr"
 
"messages"
 
@@ -109,7 +109,7 @@ public function testGetPanelWithTranslation()
"bar"
 
-

These messages are not available for the given locale and cannot be found in the fallback locales.
Add them to the translation catalogue to avoid Narrowspark outputting untranslated contents.

LocaleDomainTimes usedMessage IDMessage Preview
"en"
+

These messages are not available for the given locale and cannot be found in the fallback locales.
Add them to the translation catalogue to avoid Narrowspark outputting untranslated contents.

LocaleDomainTimes usedMessage IDMessage Preview
"en"
 
"messages"
 
diff --git a/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php b/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php index d5bde55dc..cf9dee806 100644 --- a/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php @@ -6,7 +6,7 @@ use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Container\Container; use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; use Viserio\Component\Translation\MessageCatalogue; @@ -14,7 +14,7 @@ use Viserio\Component\Translation\PluralizationRules; use Viserio\Component\Translation\Providers\TranslationDataCollectorServiceProvider; use Viserio\Component\Translation\Translator; -use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; class TranslationDataCollectorServiceProviderTest extends MockeryTestCase { @@ -43,12 +43,12 @@ public function testProvider() )); $container->register(new HttpFactoryServiceProvider()); $container->register(new OptionsResolverServiceProvider()); - $container->register(new WebProfilerServiceProvider()); + $container->register(new ProfilerServiceProvider()); $container->register(new TranslationDataCollectorServiceProvider()); $container->instance('config', [ 'viserio' => [ - 'webprofiler' => [ + 'Profiler' => [ 'collector' => [ 'translation' => true, ], @@ -56,7 +56,7 @@ public function testProvider() ], ]); - self::assertInstanceOf(WebProfilerContract::class, $container->get(WebProfilerContract::class)); + self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); } private function getRequest() diff --git a/src/Viserio/Component/View/Engines/MarkdownEngine.php b/src/Viserio/Component/View/Engines/MarkdownEngine.php index e6a388341..8de54ae07 100644 --- a/src/Viserio/Component/View/Engines/MarkdownEngine.php +++ b/src/Viserio/Component/View/Engines/MarkdownEngine.php @@ -20,7 +20,6 @@ class MarkdownEngine implements EngineContract * Create a new markdown engine instance. * * @param \Parsedown|\ParsedownExtra|null - * @param ?Parsedown $markdown * * @throws \RuntimeException */ diff --git a/src/Viserio/Component/WebProfiler/Middleware/WebProfilerMiddleware.php b/src/Viserio/Component/WebProfiler/Middleware/WebProfilerMiddleware.php deleted file mode 100644 index cd180db57..000000000 --- a/src/Viserio/Component/WebProfiler/Middleware/WebProfilerMiddleware.php +++ /dev/null @@ -1,40 +0,0 @@ -webprofiler = $webprofiler; - } - - /** - * {@inheritdoc} - */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface - { - $response = $delegate->process($request); - - // Modify the response to add the webprofiler - return $this->webprofiler->modifyResponse($request, $response); - } -} diff --git a/src/Viserio/Component/WebProfiler/Resources/css/webprofiler-grid.css b/src/Viserio/Component/WebProfiler/Resources/css/webprofiler-grid.css deleted file mode 100644 index 307e8f25c..000000000 --- a/src/Viserio/Component/WebProfiler/Resources/css/webprofiler-grid.css +++ /dev/null @@ -1,54 +0,0 @@ -.webprofiler * { - -webkit-box-sizing: content-box; - -moz-box-sizing: content-box; - box-sizing: content-box; - vertical-align: baseline; -} -.webprofiler .row:after, -.webprofiler .col:after, -.webprofiler .clearfix:after { - content: ""; - display: table; - clear: both; -} -.webprofiler .row { padding-bottom: 0em; -} -.webprofiler .col { - display: block; - float: left; - width: 100%; -} -@media ( min-width : 768px ) { - .webprofiler .gutters .col { - margin-left: 2%; - } - .webprofiler .gutters .col:first-child { - margin-left: 0; - } -} -@media ( min-width : 768px ) { - .webprofiler .span_1 { width: 8.33333333333%; } - .webprofiler .span_2 { width: 16.6666666667%; } - .webprofiler .span_3 { width: 25%; } - .webprofiler .span_4 { width: 33.3333333333%; } - .webprofiler .span_5 { width: 41.6666666667%; } - .webprofiler .span_6 { width: 50%; } - .webprofiler .span_7 { width: 58.3333333333%; } - .webprofiler .span_8 { width: 66.6666666667%; } - .webprofiler .span_9 { width: 75%; } - .webprofiler .span_10 { width: 83.3333333333%; } - .webprofiler .span_11 { width: 91.6666666667%; } - .webprofiler .span_12 { width: 100%; } - .webprofiler .gutters .span_1 { width: 6.5%; } - .webprofiler .gutters .span_2 { width: 15.0%; } - .webprofiler .gutters .span_3 { width: 23.5%; } - .webprofiler .gutters .span_4 { width: 32.0%; } - .webprofiler .gutters .span_5 { width: 40.5%; } - .webprofiler .gutters .span_6 { width: 49.0%; } - .webprofiler .gutters .span_7 { width: 57.5%; } - .webprofiler .gutters .span_8 { width: 66.0%; } - .webprofiler .gutters .span_9 { width: 74.5%; } - .webprofiler .gutters .span_10 { width: 83.0%; } - .webprofiler .gutters .span_11 { width: 91.5%; } - .webprofiler .gutters .span_12 { width: 100%; } -} diff --git a/src/Viserio/Component/WebProfiler/Resources/css/webprofiler.css b/src/Viserio/Component/WebProfiler/Resources/css/webprofiler.css deleted file mode 100644 index 0510b715b..000000000 --- a/src/Viserio/Component/WebProfiler/Resources/css/webprofiler.css +++ /dev/null @@ -1,424 +0,0 @@ -.webprofiler { - bottom: 0; - color: #EEE; - font: 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif; - left: 0; - margin: 0; - padding: 0; - position: fixed; - right: 0; - text-align: left; - text-transform: none; - - /* neutralize the aliasing defined by external CSS styles */ - -webkit-font-smoothing: subpixel-antialiased; - -moz-osx-font-smoothing: auto; -} - -.webprofiler .webprofiler-header.hide, -.webprofiler .webprofiler-body .webprofiler-panel .selected-content { - display: none; -} -.webprofiler .webprofiler-show-button.active, -.webprofiler .webprofiler-body.active, -.webprofiler .webprofiler-body .webprofiler-panel.active, -.webprofiler .webprofiler-body .webprofiler-panel .selected-content.active { - display: block; -} - -.webprofiler .webprofiler-header { - bottom: 0; - left: 0; - position: absolute; - right: 0; - border-top: 1px solid #383838; - box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2); - background-color: #222; - z-index: 9999; -} - -.webprofiler .webprofiler-show-button { - background-color: #222; - border-top-left-radius: 4px; - bottom: 0; - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; - display: none; - height: 36px; - padding: 6px; - position: fixed; - right: 0; - z-index: 99999; - cursor: pointer; -} -.webprofiler .webprofiler-header .webprofiler-hide-button, -.webprofiler .webprofiler-body .webprofiler-body-close-panel, -.webprofiler .webprofiler-body .webprofiler-body-menu .webprofiler-body-resize-panel { - background: #444; - display: block; - width: 36px; - height: 36px; - cursor: pointer; - text-align: center; - float: right; -} -.webprofiler .webprofiler-header .webprofiler-hide-button svg, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu svg { - position: relative; - top: 6px; - max-height: 24px; -} - -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu { - cursor: default; - display: block; - height: 36px; - margin-right: 0; - white-space: nowrap; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-red, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-yellow, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-green { - display: inline-block; - color: #FFF; - background-color: #666; - padding: 3px 6px; - margin-bottom: 2px; - vertical-align: middle; - min-width: 15px; - min-height: 13px; - text-align: center; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-red + .status-red, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-yellow + .status-yellow, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-green + .status-green { - border-left: 5px solid #444; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-green { - background-color: #4F805D; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-yellow { - background-color: #A46A1F; - color: #FFF; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .status-red { - background-color: #B0413E; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.active, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu:hover { - background-color: #444; - position: relative; - z-index: 10002; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover { - cursor: help; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-panel:hover { - cursor: pointer; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip .webprofiler-menu-tooltip { - display: none; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip { - display: block; - padding: 10px; - max-width: 480px; - max-height: 480px; - word-wrap: break-word; - overflow: hidden; - overflow-y: auto; - background-color: #444; - bottom: 36px; - color: #F5F5F5; - position: absolute; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip .webprofiler-menu-tooltip-group { - margin-bottom: 4px; - padding-bottom: 4px; - border-bottom: 1px solid #333333; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip .webprofiler-menu-tooltip-group:last-child { - margin-bottom: 0; - padding-bottom: 0; - border-bottom: none; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip .webprofiler-menu-tooltip-group-piece { - border-bottom: solid transparent 3px; - display: table-row; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip .webprofiler-menu-tooltip-group b { - color: #AAA; - display: table-cell; - font-size: 11px; - padding: 4px 8px 4px 0; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip .webprofiler-menu-tooltip-group span { - color: #F5F5F5; - font-size: 12px; - display: table-cell; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip .webprofiler-menu-tooltip-group a { - color: #FFF; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-position-left.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip { - left: 0; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-position-right.webprofiler-menu-has-tooltip:hover .webprofiler-menu-tooltip { - right: 0; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-position-left { - float: left; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-position-right { - float: right; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .webprofiler-menu-content { - display: block; - height: 36px; - line-height: 36px; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-position-left .webprofiler-menu-content, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-position-right .webprofiler-menu-content { - padding: 0 7px; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .webprofiler-menu-content .webprofiler-menu-icon, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .webprofiler-menu-content .webprofiler-menu-label, -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .webprofiler-menu-content .webprofiler-menu-value { - display: inline-block; - color: #F5F5F5; - font-size: 13px; - line-height: 36px; - padding: 0; -} -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu .webprofiler-menu-icon .webprofiler-menu-value { - margin-left: 4px; -} - -.webprofiler .webprofiler-body { - height: 324px; - background-color: #222; - margin-bottom: 37px; - display: none; - position: relative; - z-index: 9998; -} -.webprofiler .webprofiler-body pre { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; -} -.webprofiler .webprofiler-body pre.sf-dump, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-num, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-const, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-str, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-note, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-ref, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-public, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-protected, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-private, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-meta, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-key, -.webprofiler .webprofiler-body pre.sf-dump .sf-dump-index { - margin: 0; - padding: 0; - color: #2B2A28; -} -.webprofiler .webprofiler-body .webprofiler-panel { - height: 270px; - display: none; -} -.webprofiler .webprofiler-body .webprofiler-panel.webprofiler-body-has-table, -.webprofiler .webprofiler-body .webprofiler-panel.webprofiler-body-has-selector, -.webprofiler .webprofiler-body .webprofiler-panel.webprofiler-body-has-metrics { - overflow-y: auto; - overflow-x: hidden; - padding: 15px; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs { - position: relative; - min-height: 180px; - display: block; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs-tab { - display: inline-block; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs-tab label { - cursor: pointer; - background: #2B2A28; - color: #FFF; - display: block; - margin: 0 0 0 -1px; - padding: 10px 15px; - border-bottom: 3px solid #FFF; - text-align: center; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs-tab label span.counter { - display: inline-block; - color: #FFF; - background-color: #666; - padding: 3px 6px; - margin-bottom: 2px; - vertical-align: middle; - min-width: 15px; - min-height: 13px; - text-align: center; - margin-bottom: 0; - margin-left: 10px; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs-tab [type=radio] { - position: absolute; - height: 0; - width: 0; - overflow: hidden; - clip: rect(0, 0, 0, 0); -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs-tab [type=radio]:focus + label { - /* */ -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs-tab-content { - position: absolute; - left: 0; - right: 0; - opacity: 0; - padding: 15px; - overflow-y: auto; - height: 236px; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs .webprofiler-tabs-tab [type=radio]:checked ~ label { - background: #FFF; - color: #2B2A28; - z-index: 2; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs .webprofiler-tabs-tab [type=radio]:checked ~ label span.counter { - background: #ECECEC; - color: #2B2A28; -} -.webprofiler .webprofiler-body .webprofiler-panel .webprofiler-tabs .webprofiler-tabs-tab [type=radio]:checked ~ label ~ .webprofiler-tabs-tab-content { - z-index: 1; - opacity: 1; -} - -.webprofiler .webprofiler-body h3:first-child { - margin-top: 0; -} - -.webprofiler .webprofiler-body .webprofiler-panel table, -.webprofiler .webprofiler-body .webprofiler-panel tr, -.webprofiler .webprofiler-body .webprofiler-panel th, -.webprofiler .webprofiler-body .webprofiler-panel td { - background: #FFF; - border-collapse: collapse; - line-height: 1.5; - vertical-align: top; -} -.webprofiler .webprofiler-body .webprofiler-panel table { - background: #FFF; - box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); - margin: 0; - width: 100%; -} -.webprofiler .webprofiler-body .webprofiler-panel table + table { - margin-top: 30px; -} - -.webprofiler .webprofiler-body .webprofiler-panel table th, -.webprofiler .webprofiler-body .webprofiler-panel table td { - padding: 8px 10px; -} -.webprofiler .webprofiler-body .webprofiler-panel table th { - font-weight: bold; - text-align: left; -} -.webprofiler .webprofiler-body .webprofiler-panel table thead th { - background-color: #2B2A28; - color: #FFF; -} -.webprofiler .webprofiler-body .webprofiler-panel table thead th.key { - width: 19%; -} -.webprofiler .webprofiler-body .webprofiler-panel table tbody th, -.webprofiler .webprofiler-body .webprofiler-panel table tbody td { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; - font-size: 13px; - font-size-adjust: 0.5; - border: 1px solid #E0E0E0; - border-width: 1px 0; - color: #2B2A28; -} -.webprofiler .webprofiler-body .webprofiler-panel table tbody td { - -ms-word-break: break-all; - word-break: break-all; - -webkit-hyphens: auto; - -moz-hyphens: auto; - hyphens: auto; -} -.webprofiler .webprofiler-body .webprofiler-panel table tbody div { - margin: .25em 0; -} -.webprofiler .webprofiler-body .webprofiler-panel table tbody ul { - margin: 0; - padding: 0 0 0 1em; -} -.webprofiler .webprofiler-body .webprofiler-panel .empty { - border: 4px dashed #E0E0E0; - color: #FFF; - font-size: 16px; - margin: 1em 0; - padding: .5em 2em; - text-align: center; - font-weight: bold; -} - -.webprofiler .webprofiler-body .webprofiler-panel .metrics { - overflow: auto; - list-style: none; - margin: 0; - padding: 0; -} -.webprofiler .webprofiler-body .webprofiler-panel .metrics .metric { - margin: 0 1em 1em 0; - background: #FFF; - box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); - min-width: 100px; - min-height: 65px; - display: inline-block; -} -.webprofiler .webprofiler-body .webprofiler-panel .metrics .metric .value { - display: block; - font-size: 28px; - padding: 8px 15px 4px; - text-align: center; - color: #2B2A28; -} -.webprofiler .webprofiler-body .webprofiler-panel .metrics .metric .label { - background: #444; - color: #FFF; - display: block; - font-size: 12px; - padding: 5px; - text-align: center; -} - -.webprofiler .webprofiler-body .webprofiler-panel select { - width: 100%; - padding: 10px 0; - cursor: pointer; - margin-bottom: 15px; - font-weight: bold; - border: 0; -} - -.webprofiler .webprofiler-body .webprofiler-body-menu { - height: 24px; - border-bottom: 1px solid #383838; - box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); - background-color: #222; -} -.webprofiler .webprofiler-body .webprofiler-body-menu .webprofiler-body-close-panel, -.webprofiler .webprofiler-body .webprofiler-body-menu .webprofiler-body-resize-panel { - width: 24px; - height: 24px; - float: right; -} -.webprofiler .webprofiler-body .webprofiler-body-menu .webprofiler-body-resize-panel.orginal-size-panel svg { - transform: rotate(180deg); -} diff --git a/src/Viserio/Component/WebProfiler/Resources/js/ajaxHandler.js b/src/Viserio/Component/WebProfiler/Resources/js/ajaxHandler.js deleted file mode 100644 index 583837ee7..000000000 --- a/src/Viserio/Component/WebProfiler/Resources/js/ajaxHandler.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * AjaxHandler - * - * Extract data from headers of an XMLHttpRequest and adds a new dataset - */ -var AjaxHandler = WebProfiler.AjaxHandler = function(webprofiler, headerName) { - this.webprofiler = webprofiler; - this.headerName = headerName || 'webprofiler'; -}; - -WebProfiler.$.extend(AjaxHandler.prototype, { - -}); diff --git a/src/Viserio/helpers.php b/src/Viserio/helpers.php index 103ee6aaf..21d53cbad 100644 --- a/src/Viserio/helpers.php +++ b/src/Viserio/helpers.php @@ -23,8 +23,7 @@ function env(string $key, $default = null) /** * Dump the passed variables and end the script. * - * @param mixed - * @param ... $args + * @param array $args * * @return void */ From d22e3c1a74548ecf1cf8f156dd675ba48db758f5 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 14:22:53 +0000 Subject: [PATCH 02/99] Apply fixes from StyleCI --- .../Providers/TwigBridgeDataCollectorsServiceProvider.php | 2 +- .../TwigBridgeDataCollectorsServiceProviderTest.php | 2 +- src/Viserio/Component/Contracts/Profiler/Profiler.php | 4 ++-- .../Foundation/DataCollectors/NarrowsparkDataCollector.php | 2 +- .../Foundation/DataCollectors/ViserioHttpDataCollector.php | 6 +++--- src/Viserio/Component/Foundation/Http/Kernel.php | 2 +- .../Providers/FoundationDataCollectorServiceProvider.php | 2 +- src/Viserio/Component/Foundation/Tests/Http/KernelTest.php | 2 +- .../FoundationDataCollectorServiceProviderTest.php | 2 +- .../Log/Providers/LogsDataCollectorServiceProvider.php | 2 +- src/Viserio/Component/Profiler/AssetsRenderer.php | 2 +- .../Component/Profiler/Controllers/AssetController.php | 6 +++--- .../Profiler/DataCollectors/AbstractDataCollector.php | 2 +- src/Viserio/Component/Profiler/Profiler.php | 2 +- .../Providers/ProfilerPsr6CacheBridgeServiceProvider.php | 2 +- .../Profiler/Providers/ProfilerServiceProvider.php | 6 +++--- src/Viserio/Component/Profiler/Proxies/WebProfiler.php | 2 +- .../Component/Profiler/Resources/views/profiler.html.php | 6 +++--- src/Viserio/Component/Profiler/TemplateManager.php | 2 +- src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php | 4 ++-- .../ProfilerPsr6CacheBridgeServiceProviderTest.php | 2 +- .../Tests/Providers/ProfilerServiceProviderTest.php | 6 +++--- .../Routing/DataCollectors/RoutingDataCollector.php | 2 +- .../Providers/RoutingDataCollectorServiceProvider.php | 2 +- .../Providers/RoutingDataCollectorServiceProviderTest.php | 4 ++-- .../DataCollectors/ViserioTranslationDataCollector.php | 4 ++-- .../Providers/TranslationDataCollectorServiceProvider.php | 2 +- .../TranslationDataCollectorServiceProviderTest.php | 4 ++-- 28 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php index fb4b99209..ba8c6ba87 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php @@ -33,7 +33,7 @@ public function getServices() return [ Twig_Profiler_Profile::class => [self::class, 'createTwigProfilerProfile'], TwigEnvironment::class => [self::class, 'createTwigEnvironment'], - ProfilerContract::class => [self::class, 'createProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } diff --git a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php index 74a1a8fcc..713d112dc 100644 --- a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php +++ b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php @@ -13,8 +13,8 @@ use Viserio\Component\Filesystem\Providers\FilesServiceProvider; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; -use Viserio\Component\View\Providers\ViewServiceProvider; use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; +use Viserio\Component\View\Providers\ViewServiceProvider; /** * @runTestsInSeparateProcesses diff --git a/src/Viserio/Component/Contracts/Profiler/Profiler.php b/src/Viserio/Component/Contracts/Profiler/Profiler.php index 0fe5fdece..4ed792f14 100644 --- a/src/Viserio/Component/Contracts/Profiler/Profiler.php +++ b/src/Viserio/Component/Contracts/Profiler/Profiler.php @@ -4,8 +4,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Viserio\Component\Contracts\Routing\UrlGenerator as UrlGeneratorContract; use Viserio\Component\Contracts\Profiler\DataCollector as DataCollectorContract; +use Viserio\Component\Contracts\Routing\UrlGenerator as UrlGeneratorContract; interface Profiler { @@ -43,7 +43,7 @@ public function getTemplate(): string; * Adds a data collector. * * @param \Viserio\Component\Contracts\Profiler\DataCollector $collector - * @param int $priority + * @param int $priority * * @throws \RuntimeException * diff --git a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php index d233c1f02..ea875f4de 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php @@ -6,8 +6,8 @@ use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; use Viserio\Component\Foundation\Application; -use Viserio\Component\Support\Env; use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; +use Viserio\Component\Support\Env; class NarrowsparkDataCollector extends PhpInfoDataCollector implements TooltipAwareContract { diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 4d7f62358..2b395af49 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -8,12 +8,12 @@ use ReflectionFunction; use ReflectionMethod; use Viserio\Component\Contracts\Config\Repository as RepositoryContract; -use Viserio\Component\Contracts\Routing\Route as RouteContract; -use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\Session\Store as StoreContract; use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract; use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; +use Viserio\Component\Contracts\Routing\Route as RouteContract; +use Viserio\Component\Contracts\Routing\Router as RouterContract; +use Viserio\Component\Contracts\Session\Store as StoreContract; use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; class ViserioHttpDataCollector extends AbstractDataCollector implements diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index 2f90e5049..f2f6c76bc 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -12,8 +12,8 @@ use Viserio\Component\Contracts\Foundation\Application as ApplicationContract; use Viserio\Component\Contracts\Foundation\Kernel as KernelContract; use Viserio\Component\Contracts\Foundation\Terminable as TerminableContract; -use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Foundation\Bootstrap\HandleExceptions; use Viserio\Component\Foundation\Bootstrap\LoadConfiguration; use Viserio\Component\Foundation\Bootstrap\LoadEnvironmentVariables; diff --git a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php index f8661a75e..720110883 100644 --- a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php @@ -8,8 +8,8 @@ use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\OptionsResolver\RequiresMandatoryOptions as RequiresMandatoryOptionsContract; -use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Foundation\DataCollectors\FilesLoadedCollector; use Viserio\Component\Foundation\DataCollectors\NarrowsparkDataCollector; use Viserio\Component\Foundation\DataCollectors\ViserioHttpDataCollector; diff --git a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php index b6e08f04f..e2c98430a 100644 --- a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php +++ b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php @@ -10,8 +10,8 @@ use Viserio\Component\Contracts\Events\EventManager as EventManagerContract; use Viserio\Component\Contracts\Exception\Handler as HandlerContract; use Viserio\Component\Contracts\Foundation\Application as ApplicationContract; -use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Contracts\Profiler\Profiler as Profilertract; +use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Foundation\Bootstrap\HandleExceptions; use Viserio\Component\Foundation\Bootstrap\LoadConfiguration; use Viserio\Component\Foundation\Bootstrap\LoadEnvironmentVariables; diff --git a/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php b/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php index a057cbad3..06845b5f6 100644 --- a/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php @@ -7,9 +7,9 @@ use Viserio\Component\Config\Providers\ConfigServiceProvider; use Viserio\Component\Container\Container; use Viserio\Component\Contracts\Config\Repository as RepositoryContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Routing\Route as RouteContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Foundation\Providers\FoundationDataCollectorServiceProvider; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; diff --git a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php index 023390bf7..87aa097a0 100644 --- a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php @@ -32,7 +32,7 @@ public function getServices() { return [ LogParser::class => [self::class, 'createLogParser'], - ProfilerContract::class => [self::class, 'createProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index c2f260c9a..aa0d67856 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -2,9 +2,9 @@ declare(strict_types=1); namespace Viserio\Component\Profiler; -use Viserio\Component\Contracts\Support\Renderable as RenderableContract; use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Support\Renderable as RenderableContract; use Viserio\Component\Support\Traits\NormalizePathAndDirectorySeparatorTrait; class AssetsRenderer implements RenderableContract diff --git a/src/Viserio/Component/Profiler/Controllers/AssetController.php b/src/Viserio/Component/Profiler/Controllers/AssetController.php index 619d2d3bc..ad9dd6f28 100644 --- a/src/Viserio/Component/Profiler/Controllers/AssetController.php +++ b/src/Viserio/Component/Profiler/Controllers/AssetController.php @@ -6,8 +6,8 @@ use Interop\Http\Factory\StreamFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Viserio\Component\Routing\AbstractController; use Viserio\Component\Profiler\Profiler; +use Viserio\Component\Routing\AbstractController; class AssetController extends AbstractController { @@ -38,7 +38,7 @@ class AssetController extends AbstractController * @param \IPsr\Http\Message\ServerRequestInterface $serverRequest * @param \Interop\Http\Factory\ResponseFactoryInterface $responseFactory * @param \Interop\Http\Factory\StreamFactoryInterface $streamFactory - * @param \Viserio\Component\Profiler\Profiler $Profiler + * @param \Viserio\Component\Profiler\Profiler $Profiler */ public function __construct( ServerRequestInterface $serverRequest, @@ -48,7 +48,7 @@ public function __construct( ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; - $this->Profiler = $Profiler; + $this->Profiler = $Profiler; if ($session = $serverRequest->getAttribute('session')) { $session->reflash(); diff --git a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php index 920af7955..005aeafd2 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php @@ -10,9 +10,9 @@ use Symfony\Component\VarDumper\Cloner\Stub; use Symfony\Component\VarDumper\Cloner\VarCloner; use Viserio\Component\Contracts\Profiler\DataCollector as DataCollectorContract; +use Viserio\Component\Profiler\Util\HtmlDumperOutput; use Viserio\Component\Support\Debug\HtmlDumper; use Viserio\Component\Support\Str; -use Viserio\Component\Profiler\Util\HtmlDumperOutput; abstract class AbstractDataCollector implements DataCollectorContract { diff --git a/src/Viserio/Component/Profiler/Profiler.php b/src/Viserio/Component/Profiler/Profiler.php index 14679b913..82ea5be37 100644 --- a/src/Viserio/Component/Profiler/Profiler.php +++ b/src/Viserio/Component/Profiler/Profiler.php @@ -12,9 +12,9 @@ use Viserio\Component\Contracts\Events\Traits\EventsAwareTrait; use Viserio\Component\Contracts\HttpFactory\Traits\StreamFactoryAwareTrait; use Viserio\Component\Contracts\Log\Traits\LoggerAwareTrait; -use Viserio\Component\Contracts\Routing\UrlGenerator as UrlGeneratorContract; use Viserio\Component\Contracts\Profiler\DataCollector as DataCollectorContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Routing\UrlGenerator as UrlGeneratorContract; use Viserio\Component\Support\Http\ClientIp; class Profiler implements ProfilerContract, LoggerAwareInterface diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php index 6e4628f80..c3bf71397 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php @@ -18,7 +18,7 @@ public function getServices() { return [ CacheItemPoolInterface::class => [self::class, 'createCacheItemPoolDecorater'], - ProfilerContract::class => [self::class, 'createProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php index 570758a06..c4b3fec66 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php @@ -11,9 +11,9 @@ use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\OptionsResolver\RequiresMandatoryOptions as RequiresMandatoryOptionsContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Contracts\Routing\UrlGenerator as UrlGeneratorContract; -use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\OptionsResolver\OptionsResolver; use Viserio\Component\Profiler\AssetsRenderer; use Viserio\Component\Profiler\DataCollectors\AjaxRequestsDataCollector; @@ -43,8 +43,8 @@ public function getServices() return [ RouterContract::class => [self::class, 'registerProfilerAssetsControllers'], AssetsRenderer::class => [self::class, 'createAssetsRenderer'], - ProfilerContract::class => [self::class, 'createProfiler'], - Profiler::class => function (ContainerInterface $container) { + ProfilerContract::class => [self::class, 'createProfiler'], + Profiler::class => function (ContainerInterface $container) { return $container->get(ProfilerContract::class); }, ]; diff --git a/src/Viserio/Component/Profiler/Proxies/WebProfiler.php b/src/Viserio/Component/Profiler/Proxies/WebProfiler.php index ddd7b07be..db35750ac 100644 --- a/src/Viserio/Component/Profiler/Proxies/WebProfiler.php +++ b/src/Viserio/Component/Profiler/Proxies/WebProfiler.php @@ -4,7 +4,7 @@ use Viserio\Component\StaticalProxy\StaticalProxy; -class Profiler extends StaticalProxy +class WebProfiler extends StaticalProxy { /** * {@inheritdoc} diff --git a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php index 4bb99ed78..0c53bea8b 100644 --- a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php +++ b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php @@ -1,4 +1,4 @@ - diff --git a/src/Viserio/Component/Profiler/TemplateManager.php b/src/Viserio/Component/Profiler/TemplateManager.php index e9295e300..4c16161ba 100644 --- a/src/Viserio/Component/Profiler/TemplateManager.php +++ b/src/Viserio/Component/Profiler/TemplateManager.php @@ -2,9 +2,9 @@ declare(strict_types=1); namespace Viserio\Component\Profiler; -use Viserio\Component\Contracts\Support\Renderable as RenderableContract; use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; +use Viserio\Component\Contracts\Support\Renderable as RenderableContract; class TemplateManager implements RenderableContract { diff --git a/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php index 9d30e3323..753cef78f 100644 --- a/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php +++ b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php @@ -4,10 +4,10 @@ use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; -use Viserio\Component\Routing\Generator\UrlGenerator; -use Viserio\Component\Support\Traits\NormalizePathAndDirectorySeparatorTrait; use Viserio\Component\Profiler\AssetsRenderer; use Viserio\Component\Profiler\DataCollectors\AjaxRequestsDataCollector; +use Viserio\Component\Routing\Generator\UrlGenerator; +use Viserio\Component\Support\Traits\NormalizePathAndDirectorySeparatorTrait; class AssetsRendererTest extends MockeryTestCase { diff --git a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php index c0a307d0a..6e985b48c 100644 --- a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php @@ -13,7 +13,7 @@ use Viserio\Component\Profiler\Providers\ProfilerPsr6CacheBridgeServiceProvider; use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; -class Profiler6CacheBridgeServiceProviderTest extends MockeryTestCase +class ProfilerPsr6CacheBridgeServiceProviderTest extends MockeryTestCase { public function testProvider() { diff --git a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php index 6aad33572..37afe6d8b 100644 --- a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php @@ -5,15 +5,15 @@ use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Container\Container; -use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Events\Providers\EventsServiceProvider; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; -use Viserio\Component\Routing\Providers\RoutingServiceProvider; use Viserio\Component\Profiler\AssetsRenderer; -use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; use Viserio\Component\Profiler\Profiler; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; +use Viserio\Component\Routing\Providers\RoutingServiceProvider; class ProfilerServiceProviderTest extends MockeryTestCase { diff --git a/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php b/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php index 3d9b4355d..d84bff839 100644 --- a/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php +++ b/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php @@ -4,8 +4,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Viserio\Component\Contracts\Routing\RouteCollection as RouteCollectionContract; use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; +use Viserio\Component\Contracts\Routing\RouteCollection as RouteCollectionContract; use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; class RoutingDataCollector extends AbstractDataCollector implements PanelAwareContract diff --git a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php index 94b107916..b60a6a35b 100644 --- a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php @@ -6,8 +6,8 @@ use Interop\Container\ServiceProvider; use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; -use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\OptionsResolver\OptionsResolver; use Viserio\Component\Routing\DataCollectors\RoutingDataCollector; diff --git a/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php b/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php index 3370152b7..3f6bfb7d1 100644 --- a/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php @@ -5,13 +5,13 @@ use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Container\Container; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Routing\RouteCollection as RouteCollectionContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; -use Viserio\Component\Routing\Providers\RoutingDataCollectorServiceProvider; use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; +use Viserio\Component\Routing\Providers\RoutingDataCollectorServiceProvider; class RoutingDataCollectorServiceProviderTest extends MockeryTestCase { diff --git a/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php b/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php index effb2c8a2..84b882b6b 100644 --- a/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php +++ b/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php @@ -4,10 +4,10 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Viserio\Component\Contracts\Translation\Traits\TranslatorAwareTrait; -use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; +use Viserio\Component\Contracts\Translation\Traits\TranslatorAwareTrait; +use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; class ViserioTranslationDataCollector extends AbstractDataCollector implements diff --git a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php index e3cd1e8f2..aa54ebc53 100644 --- a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php @@ -6,8 +6,8 @@ use Interop\Container\ServiceProvider; use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; -use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; use Viserio\Component\OptionsResolver\OptionsResolver; use Viserio\Component\Translation\DataCollectors\ViserioTranslationDataCollector; diff --git a/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php b/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php index cf9dee806..1e1b00fe3 100644 --- a/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php @@ -5,16 +5,16 @@ use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Container\Container; -use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; use Viserio\Component\Translation\MessageCatalogue; use Viserio\Component\Translation\MessageSelector; use Viserio\Component\Translation\PluralizationRules; use Viserio\Component\Translation\Providers\TranslationDataCollectorServiceProvider; use Viserio\Component\Translation\Translator; -use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; class TranslationDataCollectorServiceProviderTest extends MockeryTestCase { From 28adabb56d1fa83114eb13a60ed2ca64db3132e1 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 16:50:42 +0200 Subject: [PATCH 03/99] fix tests --- .../Profiler/Controllers/AssetController.php | 8 ++++---- .../Profiler/Controllers/OpenHandlerController.php | 14 +++++++------- src/Viserio/Component/Profiler/Profiler.php | 2 +- .../Profiler/Resources/views/profiler.html.php | 4 ++-- .../Profiler/Tests/TemplateManagerTest.php | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Viserio/Component/Profiler/Controllers/AssetController.php b/src/Viserio/Component/Profiler/Controllers/AssetController.php index ad9dd6f28..3fc83dfe3 100644 --- a/src/Viserio/Component/Profiler/Controllers/AssetController.php +++ b/src/Viserio/Component/Profiler/Controllers/AssetController.php @@ -6,7 +6,7 @@ use Interop\Http\Factory\StreamFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Viserio\Component\Profiler\Profiler; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Routing\AbstractController; class AssetController extends AbstractController @@ -28,7 +28,7 @@ class AssetController extends AbstractController /** * Profiler instance. * - * @var \Viserio\Component\Profiler\Profiler + * @var \Viserio\Component\Contracts\Profiler\Profiler */ protected $Profiler; @@ -38,13 +38,13 @@ class AssetController extends AbstractController * @param \IPsr\Http\Message\ServerRequestInterface $serverRequest * @param \Interop\Http\Factory\ResponseFactoryInterface $responseFactory * @param \Interop\Http\Factory\StreamFactoryInterface $streamFactory - * @param \Viserio\Component\Profiler\Profiler $Profiler + * @param \Viserio\Component\Contracts\Profiler\Profiler $Profiler */ public function __construct( ServerRequestInterface $serverRequest, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, - Profiler $Profiler + ProfilerContract $Profiler ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; diff --git a/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php b/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php index 2d9c7cb74..a727e904c 100644 --- a/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php +++ b/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php @@ -6,7 +6,7 @@ use Interop\Http\Factory\StreamFactoryInterface; use Psr\Http\Message\ResponseInterface; use Viserio\Component\Routing\AbstractController; -use Viserio\Component\Profiler\Profiler; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; class OpenHandlerController extends AbstractController { @@ -27,25 +27,25 @@ class OpenHandlerController extends AbstractController /** * Profilerstance. * - * @var \Viserio\Component\Profiler\Profiler + * @var \Viserio\Component\Contracts\Profiler\Profiler */ - protected $Profiler + protected $profiler; /** - * [__construct description]. + * Create a new OpenHandler Controller instance. * * @param \Interop\Http\Factory\ResponseFactoryInterface $responseFactory * @param \Interop\Http\Factory\StreamFactoryInterface $streamFactory - * @param \Viserio\Component\Profiler\Profiler $Profiler + * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler */ public function __construct( ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, - ProfilerroProfiler + ProfilerContract $profiler ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; - $this->Profiler = $ProfilerContract + $this->profiler = $profiler; } /** diff --git a/src/Viserio/Component/Profiler/Profiler.php b/src/Viserio/Component/Profiler/Profiler.php index 82ea5be37..b2e025ca7 100644 --- a/src/Viserio/Component/Profiler/Profiler.php +++ b/src/Viserio/Component/Profiler/Profiler.php @@ -64,7 +64,7 @@ class Profiler implements ProfilerContract, LoggerAwareInterface * * @var string */ - protected $template = __DIR__ . '/Resources/views/Profiler.html.php'; + protected $template = __DIR__ . '/Resources/views/profiler.html.php'; /** * Create new Profiler instance. diff --git a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php index 0c53bea8b..24f0ad742 100644 --- a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php +++ b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php @@ -35,10 +35,10 @@ - + - + diff --git a/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php b/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php index a38d5f8a7..69e53d6cf 100644 --- a/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php +++ b/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php @@ -43,7 +43,7 @@ public function testRender() $assets = new AssetsRenderer(); $template = new TemplateManager( [], - __DIR__ . '/../Resources/views/Profiler.html.php', + __DIR__ . '/../Resources/views/profiler.html.php', 'fds4f6as', $assets->getIcons() ); @@ -65,7 +65,7 @@ public function testRenderWithCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/Profiler.html.php', + __DIR__ . '/../Resources/views/profiler.html.php', 'fds4f6as', $assets->getIcons() ); @@ -89,7 +89,7 @@ public function testRenderWithAjaxRequestsDataCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/Profiler.html.php', + __DIR__ . '/../Resources/views/profiler.html.php', 'fds4f6as', $assets->getIcons() ); @@ -113,7 +113,7 @@ public function testRenderWithAPanelCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/Profiler.html.php', + __DIR__ . '/../Resources/views/profiler.html.php', 'fds4f6as', $assets->getIcons() ); From 3ecf2395bfe50d727b773346c25d50eb0846fdb3 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 14:52:03 +0000 Subject: [PATCH 04/99] Apply fixes from StyleCI --- .../Component/Profiler/Controllers/OpenHandlerController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php b/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php index a727e904c..d7798ea4a 100644 --- a/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php +++ b/src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php @@ -5,8 +5,8 @@ use Interop\Http\Factory\ResponseFactoryInterface; use Interop\Http\Factory\StreamFactoryInterface; use Psr\Http\Message\ResponseInterface; -use Viserio\Component\Routing\AbstractController; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Viserio\Component\Routing\AbstractController; class OpenHandlerController extends AbstractController { @@ -45,7 +45,7 @@ public function __construct( ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; - $this->profiler = $profiler; + $this->profiler = $profiler; } /** From cb6732445e72cb0dc1f05d08ada1535c485834ee Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 17:19:28 +0200 Subject: [PATCH 05/99] fix names --- .../Component/Profiler/AssetsRenderer.php | 20 +++++++++---------- .../Profiler/Controllers/AssetController.php | 8 ++++---- .../Middleware/ProfilerMiddleware.php | 2 +- .../Profiler/Tests/AssetsRendererTest.php | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index aa0d67856..7cb6586ea 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -28,7 +28,7 @@ class AssetsRenderer implements RenderableContract */ protected $jsFiles = [ 'js/zepto.min.js', - 'js/Profiler.js', + 'js/profiler.js', ]; /** @@ -52,11 +52,11 @@ class AssetsRenderer implements RenderableContract ]; /** - * The Profiler instance. + * The profiler instance. * * @var \Viserio\Component\Contracts\Profiler\Profiler */ - protected $Profiler; + protected $profiler; /** * Root path to the resources. @@ -94,13 +94,13 @@ public function __construct(bool $jqueryIsUsed = false, string $rootPath = null) /** * Set the Profiler. * - * @param \Viserio\Component\Contracts\Profiler\Profiler $Profiler + * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler * * @return $this */ - public function setProfiler(ProfilerContract $Profiler): self + public function setProfiler(ProfilerContract $profiler): self { - $this->Profiler = $Profiler; + $this->profiler = $profiler; return $this; } @@ -159,11 +159,11 @@ public function getIgnoredCollectors(): array */ public function render(): string { - if (($urlGenerator = $this->Profiler->getUrlGenerator()) !== null) { - $cssRoute = $urlGenerator->generate('Profiler.assets.css', [ + if (($urlGenerator = $this->profiler->getUrlGenerator()) !== null) { + $cssRoute = $urlGenerator->generate('profiler.assets.css', [ 'v' => $this->getModifiedTime('css'), ]); - $jsRoute = $urlGenerator->generate('Profiler.assets.js', [ + $jsRoute = $urlGenerator->generate('profiler.assets.js', [ 'v' => $this->getModifiedTime('js'), ]); @@ -231,7 +231,7 @@ function ($js) { $additionalAssets = []; // finds assets provided by collectors - foreach ($this->Profiler->getCollectors() as $collector) { + foreach ($this->profiler->getCollectors() as $collector) { if ($collector instanceof AssetAwareContract && ! in_array($collector->getName(), $this->ignoredCollectors) ) { diff --git a/src/Viserio/Component/Profiler/Controllers/AssetController.php b/src/Viserio/Component/Profiler/Controllers/AssetController.php index 3fc83dfe3..16c520c22 100644 --- a/src/Viserio/Component/Profiler/Controllers/AssetController.php +++ b/src/Viserio/Component/Profiler/Controllers/AssetController.php @@ -30,7 +30,7 @@ class AssetController extends AbstractController * * @var \Viserio\Component\Contracts\Profiler\Profiler */ - protected $Profiler; + protected $profiler; /** * Create a new AssetController instance. @@ -38,17 +38,17 @@ class AssetController extends AbstractController * @param \IPsr\Http\Message\ServerRequestInterface $serverRequest * @param \Interop\Http\Factory\ResponseFactoryInterface $responseFactory * @param \Interop\Http\Factory\StreamFactoryInterface $streamFactory - * @param \Viserio\Component\Contracts\Profiler\Profiler $Profiler + * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler */ public function __construct( ServerRequestInterface $serverRequest, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, - ProfilerContract $Profiler + ProfilerContract $profiler ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; - $this->Profiler = $Profiler; + $this->Profiler = $profiler; if ($session = $serverRequest->getAttribute('session')) { $session->reflash(); diff --git a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php index d23c339d5..7cca77031 100644 --- a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php +++ b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php @@ -20,7 +20,7 @@ class ProfilerMiddleware implements MiddlewareInterface /** * Create a new middleware instance. * - * @param \Viserio\Component\Contracts\Profiler\Profiler $Profiler + * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler */ public function __construct(ProfilerContract $profiler) { diff --git a/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php index 753cef78f..a23c665f7 100644 --- a/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php +++ b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php @@ -46,7 +46,7 @@ public function testGetAssets() ]; $jsAssets = [ __DIR__ . '/js/zepto.min.js', - __DIR__ . '/js/Profiler.js', + __DIR__ . '/js/profiler.js', ]; static::assertSame($cssAssets, $assets->getAssets('css')); @@ -68,7 +68,7 @@ public function testGetAssetsFromCollectors() str_replace('Tests', 'DataCollectors', __DIR__) . '/../Resources/css/ajax-requests.css', ]; $jsAssets = [ - __DIR__ . '/js/Profiler.js', + __DIR__ . '/js/profiler.js', str_replace('Tests', 'DataCollectors', __DIR__) . '/../Resources/js/ajaxHandler.js', ]; From 03015038784fffe9b5e2ad30901c7cc133b90774 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 17:32:32 +0200 Subject: [PATCH 06/99] fix names --- .../Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php | 2 +- .../Providers/TwigBridgeDataCollectorsServiceProviderTest.php | 2 +- src/Viserio/Bridge/Twig/composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php index ba8c6ba87..4fd7bf952 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php @@ -42,7 +42,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'Profiler']; + return ['viserio', 'profiler']; } /** diff --git a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php index 713d112dc..c0c8baa7e 100644 --- a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php +++ b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php @@ -35,7 +35,7 @@ public function testGetServices() $container->instance('config', [ 'viserio' => [ - 'Profiler' => [ + 'profiler' => [ 'enable' => true, 'collector' => [ 'twig' => true, diff --git a/src/Viserio/Bridge/Twig/composer.json b/src/Viserio/Bridge/Twig/composer.json index 15502e2b4..d6b08502d 100644 --- a/src/Viserio/Bridge/Twig/composer.json +++ b/src/Viserio/Bridge/Twig/composer.json @@ -35,7 +35,7 @@ "viserio/session" : "self.version", "viserio/support" : "self.version", "viserio/translation" : "self.version", - "viserio/web-profiler" : "self.version" + "viserio/profiler" : "self.version" }, "autoload": { "psr-4": { From 0b597397a5c152424f2c02dc89af8a1b2d9fd58b Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 20:11:01 +0200 Subject: [PATCH 07/99] phpstan is happy --- phpstan.neon | 2 +- .../Contracts/Profiler/AssetsRenderer.php | 68 +++++++++++++++++++ .../Component/Contracts/Profiler/Profiler.php | 7 ++ .../Component/Profiler/AssetsRenderer.php | 49 ++++--------- .../Profiler/Controllers/AssetController.php | 2 +- src/Viserio/Component/Profiler/Profiler.php | 13 ++-- 6 files changed, 96 insertions(+), 45 deletions(-) create mode 100644 src/Viserio/Component/Contracts/Profiler/AssetsRenderer.php diff --git a/phpstan.neon b/phpstan.neon index 51ccc0d0e..c1d2f9d3d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -129,7 +129,7 @@ parameters: - '#Method Viserio\\Component\\Cookie\\AbstractCookieCollector::forget#' # Wrapper - - '#Viserio\\Component\\WebProfiler\\DataCollectors\\Bridge\\PDO\\TraceablePDODecorater::__construct#' + - '#Viserio\\Component\\Profiler\\DataCollectors\\Bridge\\PDO\\TraceablePDODecorater::__construct#' # Ignore missing container property for ConfigurationTrait - '#Access to an undefined property Viserio\\Component\\Exception\\Displayers\\HtmlDisplayer::\$container#' diff --git a/src/Viserio/Component/Contracts/Profiler/AssetsRenderer.php b/src/Viserio/Component/Contracts/Profiler/AssetsRenderer.php new file mode 100644 index 000000000..dc26e19cf --- /dev/null +++ b/src/Viserio/Component/Contracts/Profiler/AssetsRenderer.php @@ -0,0 +1,68 @@ +profiler = $profiler; @@ -106,14 +102,9 @@ public function setProfiler(ProfilerContract $profiler): self } /** - * Add icon to list. - * - * @param string $name - * @param string $path - * - * @return $this + * {@inheritdoc} */ - public function setIcon(string $name, string $path): self + public function setIcon(string $name, string $path): AssetsRendererContract { $this->icons[$name] = self::normalizePath($path . '/' . $name); @@ -121,9 +112,7 @@ public function setIcon(string $name, string $path): self } /** - * Get all registered icons. - * - * @return array + * {@inheritdoc} */ public function getIcons(): array { @@ -131,13 +120,9 @@ public function getIcons(): array } /** - * Ignores widgets provided by a collector. - * - * @param string $name - * - * @return $this + * {@inheritdoc} */ - public function setIgnoredCollector(string $name) + public function setIgnoredCollector(string $name): AssetsRendererContract { $this->ignoredCollectors[] = $name; @@ -145,9 +130,7 @@ public function setIgnoredCollector(string $name) } /** - * Returns the list of ignored collectors. - * - * @return array + * {@inheritdoc} */ public function getIgnoredCollectors(): array { @@ -183,11 +166,7 @@ public function render(): string } /** - * Return assets as a string. - * - * @param string $type 'js' or 'css' - * - * @return string + * {@inheritdoc} */ public function dumpAssetsToString(string $type): string { @@ -202,11 +181,7 @@ public function dumpAssetsToString(string $type): string } /** - * Returns the list of asset files. - * - * @param string|null $type Only return css or js files - * - * @return array + * {@inheritdoc} */ public function getAssets(?string $type = null): array { diff --git a/src/Viserio/Component/Profiler/Controllers/AssetController.php b/src/Viserio/Component/Profiler/Controllers/AssetController.php index 16c520c22..9c9a5c48c 100644 --- a/src/Viserio/Component/Profiler/Controllers/AssetController.php +++ b/src/Viserio/Component/Profiler/Controllers/AssetController.php @@ -48,7 +48,7 @@ public function __construct( ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; - $this->Profiler = $profiler; + $this->profiler = $profiler; if ($session = $serverRequest->getAttribute('session')) { $session->reflash(); diff --git a/src/Viserio/Component/Profiler/Profiler.php b/src/Viserio/Component/Profiler/Profiler.php index b2e025ca7..b7b200286 100644 --- a/src/Viserio/Component/Profiler/Profiler.php +++ b/src/Viserio/Component/Profiler/Profiler.php @@ -16,6 +16,7 @@ use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Routing\UrlGenerator as UrlGeneratorContract; use Viserio\Component\Support\Http\ClientIp; +use Viserio\Component\Contracts\Profiler\AssetsRenderer as AssetsRendererContract; class Profiler implements ProfilerContract, LoggerAwareInterface { @@ -46,9 +47,9 @@ class Profiler implements ProfilerContract, LoggerAwareInterface protected $urlGenerator; /** - * Url generator instance. + * Assets renderer instance. * - * @var \Viserio\Component\Profiler\AssetsRenderer + * @var \Viserio\Component\Contracts\Profiler\AssetsRenderer */ protected $assetsRenderer; @@ -69,9 +70,9 @@ class Profiler implements ProfilerContract, LoggerAwareInterface /** * Create new Profiler instance. * - * @param \Viserio\Component\Profiler\AssetsRenderer $assetsRenderer + * @param \Viserio\Component\Contracts\Profiler\AssetsRenderer $assetsRenderer */ - public function __construct(AssetsRenderer $assetsRenderer) + public function __construct(AssetsRendererContract $assetsRenderer) { $this->assetsRenderer = $assetsRenderer->setProfiler($this); } @@ -208,9 +209,9 @@ public function modifyResponse( /** * Returns a AssetsRenderer for this instance. * - * @return \Viserio\Component\Profiler\AssetsRenderer + * @return \Viserio\Component\Contracts\Profiler\AssetsRenderer */ - public function getAssetsRenderer(): AssetsRenderer + public function getAssetsRenderer(): AssetsRendererContract { return $this->assetsRenderer; } From 466eb17ad9bd5ce9a36a31c31f45f026dc5fd821 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 18:11:20 +0000 Subject: [PATCH 08/99] Apply fixes from StyleCI --- src/Viserio/Component/Profiler/AssetsRenderer.php | 2 +- src/Viserio/Component/Profiler/Profiler.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index 22bfbb3e9..7bf75b0a7 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -3,8 +3,8 @@ namespace Viserio\Component\Profiler; use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract; -use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Profiler\AssetsRenderer as AssetsRendererContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Support\Traits\NormalizePathAndDirectorySeparatorTrait; class AssetsRenderer implements AssetsRendererContract diff --git a/src/Viserio/Component/Profiler/Profiler.php b/src/Viserio/Component/Profiler/Profiler.php index b7b200286..73ec71f95 100644 --- a/src/Viserio/Component/Profiler/Profiler.php +++ b/src/Viserio/Component/Profiler/Profiler.php @@ -12,11 +12,11 @@ use Viserio\Component\Contracts\Events\Traits\EventsAwareTrait; use Viserio\Component\Contracts\HttpFactory\Traits\StreamFactoryAwareTrait; use Viserio\Component\Contracts\Log\Traits\LoggerAwareTrait; +use Viserio\Component\Contracts\Profiler\AssetsRenderer as AssetsRendererContract; use Viserio\Component\Contracts\Profiler\DataCollector as DataCollectorContract; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Routing\UrlGenerator as UrlGeneratorContract; use Viserio\Component\Support\Http\ClientIp; -use Viserio\Component\Contracts\Profiler\AssetsRenderer as AssetsRendererContract; class Profiler implements ProfilerContract, LoggerAwareInterface { From c7c590ee64a75e6d886a9fe60e6516c82d84c20c Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 23:13:34 +0200 Subject: [PATCH 09/99] profiler fixes --- .../Log/Providers/LogsDataCollectorServiceProvider.php | 2 +- .../Routing/Providers/RoutingDataCollectorServiceProvider.php | 2 +- .../Providers/TranslationDataCollectorServiceProvider.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php index 87aa097a0..585a04a56 100644 --- a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php @@ -41,7 +41,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'Profiler']; + return ['viserio', 'profiler']; } /** diff --git a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php index b60a6a35b..fc8ed137a 100644 --- a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php @@ -38,7 +38,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'Profiler']; + return ['viserio', 'profiler']; } /** diff --git a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php index aa54ebc53..7a92682dc 100644 --- a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php @@ -38,7 +38,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'Profiler']; + return ['viserio', 'profiler']; } /** From c8bb66fd5d6615534278d6fa202686141d0f4964 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Tue, 11 Apr 2017 00:52:16 +0200 Subject: [PATCH 10/99] working on profiler --- .../Providers/DatabaseServiceProvider.php | 4 +- .../Providers/MigrationsServiceProvider.php | 4 +- ...wigBridgeDataCollectorsServiceProvider.php | 67 +++++++++---- .../Providers/TwigBridgeServiceProvider.php | 4 +- .../Providers/ConsoleServiceProvider.php | 4 +- src/Viserio/Component/Container/Container.php | 11 +-- .../Providers/CookieServiceProvider.php | 4 +- .../Cron/Providers/CronServiceProvider.php | 4 +- .../Providers/EncrypterServiceProvider.php | 4 +- .../Component/Foundation/Application.php | 12 +-- .../Bootstrap/LoadConfiguration.php | 4 +- .../Bootstrap/LoadServiceProvider.php | 2 +- .../Bootstrap/RegisterStaticalProxys.php | 2 +- .../Bootstrap/SetRequestForConsole.php | 2 +- .../Component/Foundation/Http/Kernel.php | 14 ++- .../ConfigureLoggingServiceProvider.php | 14 ++- ...FoundationDataCollectorServiceProvider.php | 12 +-- .../ConfigureLoggingServiceProviderTest.php | 94 +++++++++---------- .../Providers/HashingServiceProvider.php | 4 +- .../Log/Providers/LoggerServiceProvider.php | 4 +- .../LogsDataCollectorServiceProvider.php | 4 +- .../Providers/ParsersServiceProvider.php | 4 +- .../ProfilerPDOBridgeServiceProvider.php | 6 +- ...ProfilerPsr6CacheBridgeServiceProvider.php | 7 +- .../Providers/ProfilerServiceProvider.php | 4 +- ...ofilerSwiftMailerBridgeServiceProvider.php | 6 +- .../RoutingDataCollectorServiceProvider.php | 12 +-- .../Providers/AliasLoaderServiceProvider.php | 4 +- ...ranslationDataCollectorServiceProvider.php | 12 +-- .../Providers/TranslationServiceProvider.php | 4 +- 30 files changed, 182 insertions(+), 151 deletions(-) diff --git a/src/Viserio/Bridge/Doctrine/Providers/DatabaseServiceProvider.php b/src/Viserio/Bridge/Doctrine/Providers/DatabaseServiceProvider.php index fa6f28c74..8cfddb859 100644 --- a/src/Viserio/Bridge/Doctrine/Providers/DatabaseServiceProvider.php +++ b/src/Viserio/Bridge/Doctrine/Providers/DatabaseServiceProvider.php @@ -27,7 +27,7 @@ class DatabaseServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -130,7 +130,7 @@ private static function parseConfig(array $config): array */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Bridge/Doctrine/Providers/MigrationsServiceProvider.php b/src/Viserio/Bridge/Doctrine/Providers/MigrationsServiceProvider.php index 83a4449bf..8f9636340 100644 --- a/src/Viserio/Bridge/Doctrine/Providers/MigrationsServiceProvider.php +++ b/src/Viserio/Bridge/Doctrine/Providers/MigrationsServiceProvider.php @@ -26,7 +26,7 @@ class MigrationsServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -104,7 +104,7 @@ public static function createMigrationsCommands(ContainerInterface $container): */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php index 4fd7bf952..ea048d0cb 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php @@ -23,7 +23,7 @@ class TwigBridgeDataCollectorsServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -57,40 +57,69 @@ public function getMandatoryOptions(): iterable ]; } - public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ProfilerContract + /** + * Extend viserio profiler with data collector. + * + * @param \Interop\Container\ContainerInterface $container + * @param null|callable $getPrevious + * + * @return null|\Viserio\Component\Contracts\Profiler\Profiler + */ + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - self::resolveOptions($container); + if ($getPrevious !== null) { + self::resolveOptions($container); + + $profiler = $getPrevious(); - $profiler = $getPrevious(); + if (self::$options['collector']['twig'] === true) { + $profiler->addCollector(new TwigDataCollector( + $container->get(Twig_Profiler_Profile::class), + $container->get(TwigEnvironment::class) + )); + } - if (self::$options['collector']['twig'] === true) { - $profiler->addCollector(new TwigDataCollector( - $container->get(Twig_Profiler_Profile::class), - $container->get(TwigEnvironment::class) - )); + return $profiler; } - return $profiler; + return null; } + /** + * Create a new Twig_Profiler_Profile instance. + * + * @return \Twig_Profiler_Profile + */ public static function createTwigProfilerProfile(): Twig_Profiler_Profile { return new Twig_Profiler_Profile(); } - public static function createTwigEnvironment(ContainerInterface $container, ?callable $getPrevious = null): TwigEnvironment + /** + * Wrap Twig_Environment. + * + * @param \Interop\Container\ContainerInterface $container + * @param null|callable $getPrevious + * + * @return null|\Twig_Environment + */ + public static function createTwigEnvironment(ContainerInterface $container, ?callable $getPrevious = null): ?TwigEnvironment { - self::resolveOptions($container); + if ($getPrevious !== null) { + self::resolveOptions($container); + + $twig = $getPrevious(); - $twig = $getPrevious(); + if (self::$options['collector']['twig'] === true) { + $twig->addExtension(new Twig_Extension_Profiler( + $container->get(Twig_Profiler_Profile::class) + )); + } - if (self::$options['collector']['twig'] === true) { - $twig->addExtension(new Twig_Extension_Profiler( - $container->get(Twig_Profiler_Profile::class) - )); + return $twig; } - return $twig; + return null; } /** @@ -102,7 +131,7 @@ public static function createTwigEnvironment(ContainerInterface $container, ?cal */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Bridge/Twig/Providers/TwigBridgeServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeServiceProvider.php index 8ce347037..35630494d 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeServiceProvider.php @@ -37,7 +37,7 @@ class TwigBridgeServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -210,7 +210,7 @@ protected static function registerViserioTwigExtension(TwigEnvironment $twig, Co */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Console/Providers/ConsoleServiceProvider.php b/src/Viserio/Component/Console/Providers/ConsoleServiceProvider.php index 0d226b428..56544cb24 100644 --- a/src/Viserio/Component/Console/Providers/ConsoleServiceProvider.php +++ b/src/Viserio/Component/Console/Providers/ConsoleServiceProvider.php @@ -23,7 +23,7 @@ class ConsoleServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -96,7 +96,7 @@ public static function createCerebro(ContainerInterface $container): Application */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Container/Container.php b/src/Viserio/Component/Container/Container.php index 46a72713c..3369c5fc2 100644 --- a/src/Viserio/Component/Container/Container.php +++ b/src/Viserio/Component/Container/Container.php @@ -405,19 +405,18 @@ public function call($callable, array $parameters = []) public function register(ServiceProvider $provider, array $parameters = []): ContainerContract { $entries = $provider->getServices(); + $container = $this; foreach ($entries as $key => $callable) { if ($this->has($key)) { // Extend a previous entry - $this->extend($key, function ($previous, ContainerInterface $container) use ($callable) { - $getPrevious = function () use ($previous) { + $this->extend($key, function ($previous) use ($container, $callable) { + return $callable($container, function () use ($previous) { return $previous; - }; - - return $callable($container, $getPrevious); + }); }); } else { - $this->singleton($key, function (ContainerInterface $container) use ($callable) { + $this->singleton($key, function () use ($container, $callable) { return $callable($container, null); }); } diff --git a/src/Viserio/Component/Cookie/Providers/CookieServiceProvider.php b/src/Viserio/Component/Cookie/Providers/CookieServiceProvider.php index 974c489e2..444c5a15e 100644 --- a/src/Viserio/Component/Cookie/Providers/CookieServiceProvider.php +++ b/src/Viserio/Component/Cookie/Providers/CookieServiceProvider.php @@ -22,7 +22,7 @@ class CookieServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -86,7 +86,7 @@ public static function createCookieJar(ContainerInterface $container): CookieJar */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Cron/Providers/CronServiceProvider.php b/src/Viserio/Component/Cron/Providers/CronServiceProvider.php index 65c1663e2..5a5a8a812 100644 --- a/src/Viserio/Component/Cron/Providers/CronServiceProvider.php +++ b/src/Viserio/Component/Cron/Providers/CronServiceProvider.php @@ -20,7 +20,7 @@ class CronServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -72,7 +72,7 @@ public static function createSchedule(ContainerInterface $container): Schedule */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Encryption/Providers/EncrypterServiceProvider.php b/src/Viserio/Component/Encryption/Providers/EncrypterServiceProvider.php index a5637003b..58065593a 100644 --- a/src/Viserio/Component/Encryption/Providers/EncrypterServiceProvider.php +++ b/src/Viserio/Component/Encryption/Providers/EncrypterServiceProvider.php @@ -20,7 +20,7 @@ class EncrypterServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -72,7 +72,7 @@ public static function createEncrypter(ContainerInterface $container): Encrypter */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Foundation/Application.php b/src/Viserio/Component/Foundation/Application.php index a102466fe..225f5bc14 100644 --- a/src/Viserio/Component/Foundation/Application.php +++ b/src/Viserio/Component/Foundation/Application.php @@ -83,7 +83,7 @@ public function __construct(array $paths) $config = $this->get(RepositoryContract::class); $config->set( - 'app.maintenance', + 'viserio.app.maintenance', file_exists($config->get('path.storage') . '/framework/down'), false ); @@ -128,7 +128,7 @@ public function hasBeenBootstrapped(): bool */ public function getLocale(): string { - return $this->get(RepositoryContract::class)->get('app.locale'); + return $this->get(RepositoryContract::class)->get('viserio.app.locale'); } /** @@ -136,7 +136,7 @@ public function getLocale(): string */ public function setLocale(string $locale): ApplicationContract { - $this->get(RepositoryContract::class)->set('app.locale', $locale); + $this->get(RepositoryContract::class)->set('viserio.app.locale', $locale); if ($this->has(TranslationManager::class)) { $this->get(TranslationManager::class)->setLocale($locale); @@ -160,7 +160,7 @@ public function isLocale(string $locale): bool */ public function getFallbackLocale(): string { - return $this->get(RepositoryContract::class)->get('app.fallback_locale'); + return $this->get(RepositoryContract::class)->get('viserio.app.fallback_locale'); } /** @@ -168,7 +168,7 @@ public function getFallbackLocale(): string */ public function hasLocale(string $locale): bool { - return in_array($locale, $this->get(RepositoryContract::class)->get('app.locales')); + return in_array($locale, $this->get(RepositoryContract::class)->get('viserio.app.locales')); } /** @@ -331,7 +331,7 @@ protected function registerBaseBindings(): void } /** - * Bind needed cache paths to our config manager. + * Set needed cache paths to our config manager. * * @return void */ diff --git a/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php b/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php index 5a3841fc1..89e12f388 100644 --- a/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php +++ b/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php @@ -33,10 +33,10 @@ public function bootstrap(ApplicationContract $app): void } $app->detectEnvironment(function () use ($config) { - return $config->get('app.env', 'production'); + return $config->get('viserio.app.env', 'production'); }); - date_default_timezone_set($config->get('app.timezone', 'UTC')); + date_default_timezone_set($config->get('viserio.app.timezone', 'UTC')); mb_internal_encoding('UTF-8'); } diff --git a/src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php b/src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php index 3667e5bbb..40b329e8e 100644 --- a/src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php +++ b/src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php @@ -13,7 +13,7 @@ class LoadServiceProvider implements BootstrapContract */ public function bootstrap(ApplicationContract $app): void { - $providers = $app->get(RepositoryContract::class)->get('app.serviceproviders', []); + $providers = $app->get(RepositoryContract::class)->get('viserio.app.serviceproviders', []); if (count($providers) > 0) { foreach ($providers as $provider) { diff --git a/src/Viserio/Component/Foundation/Bootstrap/RegisterStaticalProxys.php b/src/Viserio/Component/Foundation/Bootstrap/RegisterStaticalProxys.php index 12c8791d1..2f0052f24 100644 --- a/src/Viserio/Component/Foundation/Bootstrap/RegisterStaticalProxys.php +++ b/src/Viserio/Component/Foundation/Bootstrap/RegisterStaticalProxys.php @@ -19,6 +19,6 @@ public function bootstrap(ApplicationContract $app): void StaticalProxy::setContainer($app); - (new AliasLoader($app->get(RepositoryContract::class)->get('app.aliases', [])))->register(); + (new AliasLoader($app->get(RepositoryContract::class)->get('viserio.app.aliases', [])))->register(); } } diff --git a/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php b/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php index b3ab29d5c..0945123de 100644 --- a/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php +++ b/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php @@ -37,7 +37,7 @@ public function getServices() */ public static function createRequest(ContainerInterface $container): ServerRequestInterface { - $url = $container->get(RepositoryContract::class)->get('app.url', 'http://localhost'); + $url = $container->get(RepositoryContract::class)->get('viserio.app.url', 'http://localhost'); return $container->get(ServerRequestFactoryInterface::class)->createServerRequest('GET', $url); } diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index f2f6c76bc..d5bc66123 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -216,11 +216,15 @@ protected function handleRequest(ServerRequestInterface $serverRequest): Respons $response = $this->sendRequestThroughRouter($serverRequest); if ($this->app->has(ProfilerContract::class)) { - // Modify the response to add the Profiler - $response = $this->app->get(ProfilerContract::class)->modifyResponse( - $serverRequest, - $response - ); + $profiler = $this->app->get(ProfilerContract::class); + + if ($profiler !== null) { + // Modify the response to add the Profiler + $response = $profiler->modifyResponse( + $serverRequest, + $response + ); + } } $this->events->trigger(new KernelResponseEvent($this, $serverRequest, $response)); diff --git a/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php b/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php index 9ced6fddb..c941c93e8 100644 --- a/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php @@ -14,6 +14,7 @@ use Viserio\Component\Log\Traits\ParseLevelTrait; use Viserio\Component\Log\Writer; use Viserio\Component\OptionsResolver\OptionsResolver; +use Viserio\Component\Contracts\Config\Repository as RepositoryContract; class ConfigureLoggingServiceProvider implements ServiceProvider, @@ -28,7 +29,7 @@ class ConfigureLoggingServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -54,9 +55,7 @@ public function getDimensions(): iterable public function getMandatoryOptions(): iterable { return [ - 'path' => [ - 'storage', - ], + 'name', ]; } @@ -66,7 +65,6 @@ public function getMandatoryOptions(): iterable public function getDefaultOptions(): iterable { return [ - 'name' => 'Narrowspark', 'log' => [ 'handler' => 'single', 'level' => 'debug', @@ -125,7 +123,7 @@ private static function configureHandlers(ContainerInterface $container, LogCont private static function configureSingleHandler(ContainerInterface $container, LogContract $log, string $level): void { $log->useFiles( - self::$options['path']['storage'] . '/logs/narrowspark.log', + $container->get(RepositoryContract::class)->get('path.storage') . '/logs/narrowspark.log', $level ); } @@ -142,7 +140,7 @@ private static function configureSingleHandler(ContainerInterface $container, Lo private static function configureDailyHandler(ContainerInterface $container, LogContract $log, string $level): void { $log->useDailyFiles( - self::$options['path']['storage'] . '/logs/narrowspark.log', + $container->get(RepositoryContract::class)->get('path.storage') . '/logs/narrowspark.log', self::$options['log']['max_files'], $level ); @@ -197,7 +195,7 @@ private static function configureSyslogHandler(ContainerInterface $container, Lo */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php index 720110883..4d9745dac 100644 --- a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php @@ -26,7 +26,7 @@ class FoundationDataCollectorServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -80,10 +80,10 @@ public function getDefaultOptions(): iterable */ public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - if ($getPrevious !== null) { - self::resolveOptions($container); + $profiler = $getPrevious(); - $profiler = $getPrevious(); + if ($profiler !== null) { + self::resolveOptions($container); if (self::$options['collector']['narrowspark']) { $profiler->addCollector(static::createNarrowsparkDataCollector(), -100); @@ -100,7 +100,7 @@ public static function createProfiler(ContainerInterface $container, ?callable $ return $profiler; } // @codeCoverageIgnoreStart - return null; + return $profiler; // @codeCoverageIgnoreEnd } @@ -133,7 +133,7 @@ private static function createFilesLoadedCollector(ContainerInterface $container */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php b/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php index d2873d7cc..0f9866a99 100644 --- a/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php +++ b/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php @@ -8,6 +8,11 @@ use Viserio\Component\Log\HandlerParser; use Viserio\Component\Log\Writer; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; +use Viserio\Component\Config\Repository; +use Viserio\Component\Contracts\Config\Repository as RepositoryContract; +use Monolog\Handler\ErrorLogHandler; +use Monolog\Handler\SyslogHandler; +use Mockery as Mock; class ConfigureLoggingServiceProviderTest extends MockeryTestCase { @@ -26,15 +31,11 @@ public function testGetServicesWithSingle() $container->instance(Writer::class, $writer); - $container->instance('config', [ - 'viserio' => [ - 'app' => [ - 'path' => [ - 'storage' => '', - ], - ], - ], - ]); + $config = new Repository(); + $config->set('path.storage', ''); + $config->set('viserio.app.name', 'Narrowspark'); + + $container->instance(RepositoryContract::class, $config); $container->register(new ConfigureLoggingServiceProvider()); @@ -55,18 +56,13 @@ public function testGetServicesWithDaily() ->with('/logs/narrowspark.log', 5, 'debug'); $container->instance(Writer::class, $writer); - $container->instance('config', [ - 'viserio' => [ - 'app' => [ - 'log' => [ - 'handler' => 'daily', - ], - 'path' => [ - 'storage' => '', - ], - ], - ], - ]); + + $config = new Repository(); + $config->set('path.storage', ''); + $config->set('viserio.app.log.handler', 'daily'); + $config->set('viserio.app.name', 'Narrowspark'); + + $container->instance(RepositoryContract::class, $config); $container->register(new ConfigureLoggingServiceProvider()); @@ -84,22 +80,24 @@ public function testGetServicesWithErrorlog() $writer = $this->mock(Writer::class); $handler = $this->mock(HandlerParser::class); $handler->shouldReceive('parseHandler') - ->once(); + ->once() + ->with( + Mock::type(ErrorLogHandler::class), + '', + '', + null, + 'line' + ); $container->instance(Writer::class, $writer); $container->instance(HandlerParser::class, $handler); - $container->instance('config', [ - 'viserio' => [ - 'app' => [ - 'log' => [ - 'handler' => 'errorlog', - ], - 'path' => [ - 'storage' => '', - ], - ], - ], - ]); + + $config = new Repository(); + $config->set('path.storage', ''); + $config->set('viserio.app.log.handler', 'errorlog'); + $config->set('viserio.app.name', 'Narrowspark'); + + $container->instance(RepositoryContract::class, $config); $container->register(new ConfigureLoggingServiceProvider()); @@ -117,22 +115,24 @@ public function testGetServicesWithSyslog() $writer = $this->mock(Writer::class); $handler = $this->mock(HandlerParser::class); $handler->shouldReceive('parseHandler') - ->once(); + ->once() + ->with( + Mock::type(SyslogHandler::class), + '', + '', + null, + 'line' + ); $container->instance(Writer::class, $writer); $container->instance(HandlerParser::class, $handler); - $container->instance('config', [ - 'viserio' => [ - 'app' => [ - 'log' => [ - 'handler' => 'syslog', - ], - 'path' => [ - 'storage' => '', - ], - ], - ], - ]); + + $config = new Repository(); + $config->set('path.storage', ''); + $config->set('viserio.app.log.handler', 'syslog'); + $config->set('viserio.app.name', 'Narrowspark'); + + $container->instance(RepositoryContract::class, $config); $container->register(new ConfigureLoggingServiceProvider()); diff --git a/src/Viserio/Component/Hashing/Providers/HashingServiceProvider.php b/src/Viserio/Component/Hashing/Providers/HashingServiceProvider.php index 22f2e3ea8..55a63be14 100644 --- a/src/Viserio/Component/Hashing/Providers/HashingServiceProvider.php +++ b/src/Viserio/Component/Hashing/Providers/HashingServiceProvider.php @@ -20,7 +20,7 @@ class HashingServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -70,7 +70,7 @@ public static function createPassword(ContainerInterface $container): Password */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php b/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php index 9a48bcbd8..15fa9ebb8 100644 --- a/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php +++ b/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php @@ -24,7 +24,7 @@ class LoggerServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -111,7 +111,7 @@ public static function createLogger(ContainerInterface $container): MonologWrite */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php index 585a04a56..a0b789db2 100644 --- a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php @@ -23,7 +23,7 @@ class LogsDataCollectorServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -112,7 +112,7 @@ public static function createProfiler(ContainerInterface $container, ?callable $ */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Parsers/Providers/ParsersServiceProvider.php b/src/Viserio/Component/Parsers/Providers/ParsersServiceProvider.php index 19a72cd86..af1986467 100644 --- a/src/Viserio/Component/Parsers/Providers/ParsersServiceProvider.php +++ b/src/Viserio/Component/Parsers/Providers/ParsersServiceProvider.php @@ -22,7 +22,7 @@ class ParsersServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -86,7 +86,7 @@ public static function createTaggableParser(): TaggableParser */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php index 698a8cb79..d6071ff0d 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php @@ -54,9 +54,9 @@ public static function createTraceablePDODecorater(ContainerInterface $container */ public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - if ($getPrevious !== null) { - $profiler = $getPrevious(); + $profiler = $getPrevious(); + if ($profiler !== null) { $profiler->addCollector(new PDODataCollector( $container->get(TraceablePDODecorater::class) )); @@ -64,6 +64,6 @@ public static function createProfiler(ContainerInterface $container, ?callable $ return $profiler; } - return null; + return $profiler; } } diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php index c3bf71397..239c28560 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6CacheBridgeServiceProvider.php @@ -37,8 +37,9 @@ public static function createCacheItemPoolDecorater(ContainerInterface $containe */ public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - if ($getPrevious !== null) { - $profiler = $getPrevious(); + $profiler = $getPrevious(); + + if ($profiler !== null) { $cache = new Psr6CacheDataCollector(); if ($container->has(CacheItemPoolInterface::class)) { @@ -50,6 +51,6 @@ public static function createProfiler(ContainerInterface $container, ?callable $ return $profiler; } - return null; + return $profiler; } } diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php index c4b3fec66..801ecc01f 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php @@ -33,7 +33,7 @@ class ProfilerServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -195,7 +195,7 @@ private static function registerCollectorsFromConfig(ContainerInterface $contain */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php index 66a078369..0a4155b3f 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php @@ -30,9 +30,9 @@ public function getServices() */ public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - if ($getPrevious !== null) { - $profiler = $getPrevious(); + $profiler = $getPrevious(); + if ($profiler !== null) { $profiler->addCollector(new SwiftMailDataCollector( $container->get(Swift_Mailer::class) )); @@ -40,6 +40,6 @@ public static function createProfiler(ContainerInterface $container, ?callable $ return $profiler; } - return null; + return $profiler; } } diff --git a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php index fc8ed137a..813d44c94 100644 --- a/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Routing/Providers/RoutingDataCollectorServiceProvider.php @@ -21,7 +21,7 @@ class RoutingDataCollectorServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -63,10 +63,10 @@ public function getDefaultOptions(): iterable */ public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - if ($getPrevious !== null) { - self::resolveOptions($container); + $profiler = $getPrevious(); - $profiler = $getPrevious(); + if ($profiler !== null) { + self::resolveOptions($container); if (self::$options['collector']['routes']) { $profiler->addCollector( @@ -79,7 +79,7 @@ public static function createProfiler(ContainerInterface $container, ?callable $ return $profiler; } // @codeCoverageIgnoreStart - return null; + return $profiler; // @codeCoverageIgnoreEnd } @@ -92,7 +92,7 @@ public static function createProfiler(ContainerInterface $container, ?callable $ */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/StaticalProxy/Providers/AliasLoaderServiceProvider.php b/src/Viserio/Component/StaticalProxy/Providers/AliasLoaderServiceProvider.php index e1baa7a78..08bd91651 100644 --- a/src/Viserio/Component/StaticalProxy/Providers/AliasLoaderServiceProvider.php +++ b/src/Viserio/Component/StaticalProxy/Providers/AliasLoaderServiceProvider.php @@ -20,7 +20,7 @@ class AliasLoaderServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -72,7 +72,7 @@ public static function createAliasLoader(ContainerInterface $container): AliasLo */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php index 7a92682dc..ec695bf60 100644 --- a/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Translation/Providers/TranslationDataCollectorServiceProvider.php @@ -21,7 +21,7 @@ class TranslationDataCollectorServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -63,10 +63,10 @@ public function getDefaultOptions(): iterable */ public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - if ($getPrevious !== null) { - self::resolveOptions($container); + $profiler = $getPrevious(); - $profiler = $getPrevious(); + if ($profiler !== null) { + self::resolveOptions($container); if (self::$options['collector']['translation']) { $profiler->addCollector(new ViserioTranslationDataCollector( @@ -77,7 +77,7 @@ public static function createProfiler(ContainerInterface $container, ?callable $ return $profiler; } - return null; + return $profiler; } /** @@ -89,7 +89,7 @@ public static function createProfiler(ContainerInterface $container, ?callable $ */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); diff --git a/src/Viserio/Component/Translation/Providers/TranslationServiceProvider.php b/src/Viserio/Component/Translation/Providers/TranslationServiceProvider.php index 825194495..3c45dc9a0 100644 --- a/src/Viserio/Component/Translation/Providers/TranslationServiceProvider.php +++ b/src/Viserio/Component/Translation/Providers/TranslationServiceProvider.php @@ -25,7 +25,7 @@ class TranslationServiceProvider implements * * @var array */ - private static $options; + private static $options = []; /** * {@inheritdoc} @@ -110,7 +110,7 @@ public static function createTranslator(ContainerInterface $container): Translat */ private static function resolveOptions(ContainerInterface $container): void { - if (self::$options === null) { + if (count(self::$options) === 0) { self::$options = $container->get(OptionsResolver::class) ->configure(new static(), $container) ->resolve(); From 99475206607e5adc7eb9bc7f886e6f87e47ae77e Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 10 Apr 2017 22:52:35 +0000 Subject: [PATCH 11/99] Apply fixes from StyleCI --- src/Viserio/Component/Container/Container.php | 2 +- .../Providers/ConfigureLoggingServiceProvider.php | 2 +- .../Providers/ConfigureLoggingServiceProviderTest.php | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Viserio/Component/Container/Container.php b/src/Viserio/Component/Container/Container.php index 3369c5fc2..bb0110640 100644 --- a/src/Viserio/Component/Container/Container.php +++ b/src/Viserio/Component/Container/Container.php @@ -404,7 +404,7 @@ public function call($callable, array $parameters = []) */ public function register(ServiceProvider $provider, array $parameters = []): ContainerContract { - $entries = $provider->getServices(); + $entries = $provider->getServices(); $container = $this; foreach ($entries as $key => $callable) { diff --git a/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php b/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php index c941c93e8..bcf257906 100644 --- a/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php @@ -6,6 +6,7 @@ use Interop\Container\ServiceProvider; use Monolog\Handler\ErrorLogHandler; use Monolog\Handler\SyslogHandler; +use Viserio\Component\Contracts\Config\Repository as RepositoryContract; use Viserio\Component\Contracts\Log\Log as LogContract; use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; @@ -14,7 +15,6 @@ use Viserio\Component\Log\Traits\ParseLevelTrait; use Viserio\Component\Log\Writer; use Viserio\Component\OptionsResolver\OptionsResolver; -use Viserio\Component\Contracts\Config\Repository as RepositoryContract; class ConfigureLoggingServiceProvider implements ServiceProvider, diff --git a/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php b/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php index 0f9866a99..c249ad847 100644 --- a/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php +++ b/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php @@ -2,17 +2,17 @@ declare(strict_types=1); namespace Viserio\Component\Foundation\Tests\Providers; +use Mockery as Mock; +use Monolog\Handler\ErrorLogHandler; +use Monolog\Handler\SyslogHandler; use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; +use Viserio\Component\Config\Repository; use Viserio\Component\Container\Container; +use Viserio\Component\Contracts\Config\Repository as RepositoryContract; use Viserio\Component\Foundation\Providers\ConfigureLoggingServiceProvider; use Viserio\Component\Log\HandlerParser; use Viserio\Component\Log\Writer; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; -use Viserio\Component\Config\Repository; -use Viserio\Component\Contracts\Config\Repository as RepositoryContract; -use Monolog\Handler\ErrorLogHandler; -use Monolog\Handler\SyslogHandler; -use Mockery as Mock; class ConfigureLoggingServiceProviderTest extends MockeryTestCase { From cdb996f25e62cc6817da79d57f356a6c1d1ef4c3 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Tue, 11 Apr 2017 09:37:17 +0200 Subject: [PATCH 12/99] Added new Event | Changed config names --- .../Console/Traits/ConfirmableTrait.php | 4 +-- .../Component/Foundation/Application.php | 3 ++- .../Console/Commands/KeyGenerateCommand.php | 4 +-- .../Foundation/Events/BootstrappedEvent.php | 4 +-- .../Foundation/Events/BootstrappingEvent.php | 4 +-- .../Foundation/Events/LocaleChangedEvent.php | 26 +++++++++++++++++++ .../Component/Foundation/Http/Kernel.php | 6 ++--- 7 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/Viserio/Component/Foundation/Events/LocaleChangedEvent.php diff --git a/src/Viserio/Component/Console/Traits/ConfirmableTrait.php b/src/Viserio/Component/Console/Traits/ConfirmableTrait.php index a7d918078..356eff53e 100644 --- a/src/Viserio/Component/Console/Traits/ConfirmableTrait.php +++ b/src/Viserio/Component/Console/Traits/ConfirmableTrait.php @@ -90,8 +90,8 @@ protected function getDefaultConfirmCallback(): Closure if ($container->has('env')) { return $container->get('env') == 'production'; - } elseif ($container->has('app.env')) { - return $container->get('app.env') == 'production'; + } elseif ($container->has('viserio.app.env')) { + return $container->get('viserio.app.env') == 'production'; } return true; diff --git a/src/Viserio/Component/Foundation/Application.php b/src/Viserio/Component/Foundation/Application.php index 225f5bc14..32e729ecf 100644 --- a/src/Viserio/Component/Foundation/Application.php +++ b/src/Viserio/Component/Foundation/Application.php @@ -15,6 +15,7 @@ use Viserio\Component\Events\Providers\EventsServiceProvider; use Viserio\Component\Foundation\Events\BootstrappedEvent; use Viserio\Component\Foundation\Events\BootstrappingEvent; +use Viserio\Component\Foundation\Events\LocaleChangedEvent; use Viserio\Component\Foundation\Providers\ConfigureLoggingServiceProvider; use Viserio\Component\Log\Providers\LoggerServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; @@ -142,7 +143,7 @@ public function setLocale(string $locale): ApplicationContract $this->get(TranslationManager::class)->setLocale($locale); } - $this->get(EventManagerContract::class)->trigger('locale.changed', $this, ['locale' => $locale]); + $this->get(EventManagerContract::class)->trigger(new LocaleChangedEvent($this, $locale)); return $this; } diff --git a/src/Viserio/Component/Foundation/Console/Commands/KeyGenerateCommand.php b/src/Viserio/Component/Foundation/Console/Commands/KeyGenerateCommand.php index aca9344b2..50bb44f24 100644 --- a/src/Viserio/Component/Foundation/Console/Commands/KeyGenerateCommand.php +++ b/src/Viserio/Component/Foundation/Console/Commands/KeyGenerateCommand.php @@ -43,7 +43,7 @@ public function handle() return; } - $config->set('app.key', $key); + $config->set('viserio.app.key', $key); $this->info("Application key [$key] set successfully."); } @@ -58,7 +58,7 @@ public function handle() */ protected function setKeyInEnvironmentFile(RepositoryContract $config, string $key): bool { - $currentKey = $config->get('app.key', ''); + $currentKey = $config->get('viserio.app.key', ''); if (mb_strlen($currentKey) !== 0 && (! $this->confirmToProceed())) { return false; diff --git a/src/Viserio/Component/Foundation/Events/BootstrappedEvent.php b/src/Viserio/Component/Foundation/Events/BootstrappedEvent.php index ebb496bbf..f31fe4668 100644 --- a/src/Viserio/Component/Foundation/Events/BootstrappedEvent.php +++ b/src/Viserio/Component/Foundation/Events/BootstrappedEvent.php @@ -18,7 +18,7 @@ class BootstrappedEvent implements EventContract */ public function __construct(string $name, ApplicationContract $app) { - $this->name = 'bootstrapped.' . str_replace('\\', '', $name); - $this->target = $app; + $this->name = 'bootstrapped.' . str_replace('\\', '', $name); + $this->target = $app; } } diff --git a/src/Viserio/Component/Foundation/Events/BootstrappingEvent.php b/src/Viserio/Component/Foundation/Events/BootstrappingEvent.php index e185ebde2..33bce7826 100644 --- a/src/Viserio/Component/Foundation/Events/BootstrappingEvent.php +++ b/src/Viserio/Component/Foundation/Events/BootstrappingEvent.php @@ -18,7 +18,7 @@ class BootstrappingEvent implements EventContract */ public function __construct(string $name, ApplicationContract $app) { - $this->name = 'bootstrapping.' . str_replace('\\', '', $name); - $this->target = $app; + $this->name = 'bootstrapping.' . str_replace('\\', '', $name); + $this->target = $app; } } diff --git a/src/Viserio/Component/Foundation/Events/LocaleChangedEvent.php b/src/Viserio/Component/Foundation/Events/LocaleChangedEvent.php new file mode 100644 index 000000000..51d9533c3 --- /dev/null +++ b/src/Viserio/Component/Foundation/Events/LocaleChangedEvent.php @@ -0,0 +1,26 @@ +name = 'locale.changed'; + $this->target = $app; + $this->param = ['locale' => $locale]; + } +} diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index d5bc66123..289bf447f 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -276,13 +276,13 @@ protected function sendRequestThroughRouter(ServerRequestInterface $request): Re $router = $this->router; $config = $this->app->get(RepositoryContract::class); - $router->setCachePath($config->get('routing.path')); - $router->refreshCache($config->get('app.env', 'production') !== 'production'); + $router->setCachePath($config->get('viserio.routing.path')); + $router->refreshCache($config->get('viserio.app.env', 'production') !== 'production'); return (new Pipeline()) ->setContainer($this->app) ->send($request) - ->through($config->get('app.skip_middlewares', false) ? [] : $this->middlewares) + ->through($config->get('viserio.app.skip_middlewares', false) ? [] : $this->middlewares) ->then(function ($request) use ($router) { $this->app->instance(ServerRequestInterface::class, $request); From 1e6d8125c7734635b53841c260ca68e96c5d5d47 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 23 Apr 2017 20:53:53 +0200 Subject: [PATCH 13/99] changes --- src/Viserio/Component/Container/Container.php | 36 +++----- .../Container/Tests/ContainerTest.php | 3 + .../Fixture/SimpleFixtureServiceProvider.php | 2 +- .../Contracts/Container/Container.php | 28 ++++-- .../Contracts/Events/EventManager.php | 6 +- .../Component/Contracts/Routing/Route.php | 13 ++- src/Viserio/Component/Events/EventManager.php | 2 +- .../Component/Foundation/AbstractKernel.php | 27 +++++- .../Bootstrap/LoadConfiguration.php | 7 +- .../Bootstrap/LoadServiceProvider.php | 22 ----- .../NarrowsparkDataCollector.php | 1 + .../Http/Events/KernelResponseEvent.php | 31 +++++++ .../Component/Foundation/Http/Kernel.php | 6 +- .../ConfigureLoggingServiceProvider.php | 6 +- .../Bootstrap/LoadServiceProviderTest.php | 38 -------- .../LogsDataCollectorServiceProviderTest.php | 2 +- .../Component/Profiler/AssetsRenderer.php | 4 +- .../Middleware/ProfilerMiddleware.php | 17 +++- .../Providers/ProfilerServiceProvider.php | 91 ++++++++++++------- .../Profiler/Resources/css/profiler.css | 22 +++-- .../Resources/views/profiler.html.php | 2 +- .../Profiler/Tests/Fixture/View/profile.html | 2 +- .../View/profilewithajaxcollector.html.php | 2 +- .../View/profilewithcollector.html.php | 2 +- .../View/profilewithpanelcollector.html.php | 2 +- .../ProfilerPDOBridgeServiceProviderTest.php | 2 +- ...ilerPsr6CacheBridgeServiceProviderTest.php | 2 +- .../Providers/ProfilerServiceProviderTest.php | 4 +- ...erSwiftMailerBridgeServiceProviderTest.php | 2 +- src/Viserio/Component/Profiler/composer.json | 16 ++-- .../Routing/AbstractRouteDispatcher.php | 17 +--- .../Routing/Events/RouteMatchedEvent.php | 33 +++++-- .../Providers/RoutingServiceProvider.php | 12 +-- src/Viserio/Component/Routing/Route.php | 10 +- src/Viserio/Component/Support/Str.php | 17 +++- .../Support/Traits/MacroableTrait.php | 2 +- 36 files changed, 288 insertions(+), 203 deletions(-) delete mode 100644 src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php delete mode 100644 src/Viserio/Component/Foundation/Tests/Bootstrap/LoadServiceProviderTest.php diff --git a/src/Viserio/Component/Container/Container.php b/src/Viserio/Component/Container/Container.php index c6a4e4ff7..a6c4d10cf 100644 --- a/src/Viserio/Component/Container/Container.php +++ b/src/Viserio/Component/Container/Container.php @@ -104,7 +104,7 @@ public function __construct() /** * {@inheritdoc} */ - public function bind($abstract, $concrete = null) + public function bind($abstract, $concrete = null): void { $concrete = ($concrete) ? $concrete : $abstract; @@ -121,7 +121,7 @@ public function bind($abstract, $concrete = null) * * @codeCoverageIgnore */ - public function bindIf(string $abstract, $concrete = null) + public function bindIf(string $abstract, $concrete = null): void { if (! $this->has($abstract)) { $this->bind($abstract, $concrete); @@ -131,7 +131,7 @@ public function bindIf(string $abstract, $concrete = null) /** * {@inheritdoc} */ - public function instance(string $abstract, $instance) + public function instance(string $abstract, $instance): void { $this->bindPlain($abstract, $instance); } @@ -139,7 +139,7 @@ public function instance(string $abstract, $instance) /** * {@inheritdoc} */ - public function singleton(string $abstract, $concrete = null) + public function singleton(string $abstract, $concrete = null): void { $concrete = ($concrete) ? $concrete : $abstract; @@ -149,7 +149,7 @@ public function singleton(string $abstract, $concrete = null) /** * {@inheritdoc} */ - public function alias(string $abstract, string $alias) + public function alias(string $abstract, string $alias): void { $this->bindings[$alias] = &$this->bindings[$abstract]; } @@ -157,9 +157,9 @@ public function alias(string $abstract, string $alias) /** * {@inheritdoc} */ - public function extend(string $abstract, Closure $closure) + public function extend(string $abstract, Closure $closure): void { - $this->extendAbstract($abstract, $closure); + $this->extenders[$abstract][] = $closure; } /** @@ -189,7 +189,7 @@ public function hasInDelegate(string $abstract): bool /** * {@inheritdoc} */ - public function forget(string $abstract) + public function forget(string $abstract): void { unset($this->bindings[$abstract]); } @@ -399,19 +399,16 @@ public function call($callable, array $parameters = []) */ public function register(ServiceProvider $provider, array $parameters = []): ContainerContract { - $entries = $provider->getServices(); - $container = $this; - - foreach ($entries as $key => $callable) { + foreach ($provider->getServices() as $key => $callable) { if ($this->has($key)) { + $this->extend($key, function ($previous, $container) use ($callable) { // Extend a previous entry - $this->extend($key, function ($previous) use ($container, $callable) { return $callable($container, function () use ($previous) { return $previous; }); }); } else { - $this->singleton($key, function () use ($container, $callable) { + $this->singleton($key, function ($container) use ($callable) { return $callable($container, null); }); } @@ -655,17 +652,6 @@ protected function extendResolved($abstract, &$resolved) } } - /** - * "Extend" an abstract type in the container. - * - * @param string $abstract - * @param \Closure $closure - */ - protected function extendAbstract(string $abstract, Closure $closure) - { - $this->extenders[$abstract][] = $closure; - } - /** * Call the given closure. * diff --git a/src/Viserio/Component/Container/Tests/ContainerTest.php b/src/Viserio/Component/Container/Tests/ContainerTest.php index 8126d79e0..d5d016f3e 100644 --- a/src/Viserio/Component/Container/Tests/ContainerTest.php +++ b/src/Viserio/Component/Container/Tests/ContainerTest.php @@ -622,8 +622,11 @@ public function testExtendIsLazyInitialized() return $obj; }); + self::assertFalse(ContainerLazyExtendFixture::$initialized); + $container->resolve(ContainerLazyExtendFixture::class); + self::assertTrue(ContainerLazyExtendFixture::$initialized); } diff --git a/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php b/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php index a4b2dd603..78461e43e 100644 --- a/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php +++ b/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php @@ -25,6 +25,6 @@ public static function getParam() public static function getPrevious(ContainerInterface $container, callable $getPrevious = null) { - return $getPrevious; + return $getPrevious . 'bar'; } } diff --git a/src/Viserio/Component/Contracts/Container/Container.php b/src/Viserio/Component/Contracts/Container/Container.php index ecfb83058..a21ec9811 100644 --- a/src/Viserio/Component/Contracts/Container/Container.php +++ b/src/Viserio/Component/Contracts/Container/Container.php @@ -14,40 +14,50 @@ interface Container extends ContainerInterface, Factory, ArrayAccess * * @param string $abstract * @param string $alias + * + * @return void */ - public function alias(string $abstract, string $alias); + public function alias(string $abstract, string $alias): void; /** * Register a binding with the container. * * @param string|array $abstract * @param \Closure|string|null $concrete + * + * @return void */ - public function bind($abstract, $concrete = null); + public function bind($abstract, $concrete = null): void; /** * Register a binding if it hasn't already been registered. * * @param string $abstract * @param \Closure|string|null $concrete + * + * @return void */ - public function bindIf(string $abstract, $concrete = null); + public function bindIf(string $abstract, $concrete = null): void; /** * Register a shared binding in the container. * * @param string $abstract * @param \Closure|string|null $concrete + * + * @return void */ - public function singleton(string $abstract, $concrete = null); + public function singleton(string $abstract, $concrete = null): void; /** * Register an existing instance as shared in the container. * * @param string $abstract * @param mixed $instance + * + * @return void */ - public function instance(string $abstract, $instance); + public function instance(string $abstract, $instance): void; /** * Delegate a backup container to be checked for services if it @@ -72,16 +82,20 @@ public function hasInDelegate(string $abstract): bool; * Removes an entry from the container. * * @param string $abstract Identifier of the entry to remove + * + * @return void */ - public function forget(string $abstract); + public function forget(string $abstract): void; /** * "Extend" an abstract type in the container. * * @param string $binding * @param \Closure $closure + * + * @return void */ - public function extend(string $binding, Closure $closure); + public function extend(string $binding, Closure $closure): void; /** * Resolve a bound type from container. diff --git a/src/Viserio/Component/Contracts/Events/EventManager.php b/src/Viserio/Component/Contracts/Events/EventManager.php index 6798fc23a..9641315d3 100644 --- a/src/Viserio/Component/Contracts/Events/EventManager.php +++ b/src/Viserio/Component/Contracts/Events/EventManager.php @@ -10,8 +10,10 @@ interface EventManager * @param string $eventName * @param mixed $listener * @param int $priority + * + * @return void */ - public function attach(string $eventName, $listener, int $priority = 0); + public function attach(string $eventName, $listener, int $priority = 0): void; /** * Removes a specific listener from an event. @@ -32,7 +34,7 @@ public function detach(string $eventName, $listener): bool; * If the eventName argument is specified, all listeners for that event are * removed. * - * @param string|null $eventName + * @param string $eventName * * @return void */ diff --git a/src/Viserio/Component/Contracts/Routing/Route.php b/src/Viserio/Component/Contracts/Routing/Route.php index ca2a79ed0..8dbab3cdd 100644 --- a/src/Viserio/Component/Contracts/Routing/Route.php +++ b/src/Viserio/Component/Contracts/Routing/Route.php @@ -206,11 +206,18 @@ public function getSegments(): array; public function getController(); /** - * Run the route action and return the response. + * Bind the route to a given server request. + * + * @param\Psr\Http\Message\ServerRequestInterface $request * - * @param \Psr\Http\Message\ServerRequestInterface $request + * @return $this + */ + public function bindServerRequest(ServerRequestInterface $request): Route; + + /** + * Run the route action and return the response. * * @return \Psr\Http\Message\ResponseInterface */ - public function run(ServerRequestInterface $request): ResponseInterface; + public function run(): ResponseInterface; } diff --git a/src/Viserio/Component/Events/EventManager.php b/src/Viserio/Component/Events/EventManager.php index bb3ba9764..f39800cd7 100644 --- a/src/Viserio/Component/Events/EventManager.php +++ b/src/Viserio/Component/Events/EventManager.php @@ -41,7 +41,7 @@ class EventManager implements EventManagerContract /** * {@inheritdoc} */ - public function attach(string $eventName, $listener, int $priority = 0) + public function attach(string $eventName, $listener, int $priority = 0): void { $this->validateEventName($eventName); diff --git a/src/Viserio/Component/Foundation/AbstractKernel.php b/src/Viserio/Component/Foundation/AbstractKernel.php index 440535492..ca4c61b3d 100644 --- a/src/Viserio/Component/Foundation/AbstractKernel.php +++ b/src/Viserio/Component/Foundation/AbstractKernel.php @@ -97,9 +97,15 @@ public function __construct() $this->initializeContainer(); + $this->registerBaseBindings(); + $this->registerBaseServiceProviders(); - $this->registerBaseBindings(); + $container = $this->getContainer(); + + foreach ($this->registerServiceProviders($this) as $provider) { + $container->register($container->resolve($provider)); + } } /** @@ -120,7 +126,6 @@ public function getDefaultOptions(): iterable 'locale' => 'en', 'fallback_locale' => 'en', 'skip_middlewares' => false, - 'serviceproviders' => [], 'aliases' => [], ], ]; @@ -388,6 +393,24 @@ public function detectEnvironment(Closure $callback): string return $env; } + /** + * Register all of the application / kernel service providers. + * + * @param \Viserio\Component\Contracts\Foundation\Kernel $kernel + * + * @return array + */ + protected function registerServiceProviders(KernelContract $kernel): array + { + $providers = $kernel->getConfigPath('/serviceproviders.php'); + + if (file_exists($providers)) { + return require_once $providers; + } + + return []; + } + /** * Register all of the base service providers. * diff --git a/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php b/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php index 0a0cb9866..f24fb08a1 100644 --- a/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php +++ b/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php @@ -49,13 +49,16 @@ public function bootstrap(KernelContract $kernel): void /** * Load the configuration items from all of the files. * - * @param \Viserio\Component\Contracts\Foundation\Kernel $app + * @param \Viserio\Component\Contracts\Foundation\Kernel $kernel * @param \Viserio\Component\Contracts\Config\Repository $config - * @param KernelContract $kernel */ protected function loadConfigurationFiles(KernelContract $kernel, RepositoryContract $config) { foreach ($this->getFiles($kernel->getConfigPath()) as $key => $path) { + if ($key === 'serviceproviders') { + continue; + } + $config->import($path); } } diff --git a/src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php b/src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php deleted file mode 100644 index d8d7e34f9..000000000 --- a/src/Viserio/Component/Foundation/Bootstrap/LoadServiceProvider.php +++ /dev/null @@ -1,22 +0,0 @@ -getContainer(); - $config = $kernel->getKernelConfigurations(); - - foreach ($config['app']['serviceproviders'] as $provider) { - $container->register($container->resolve($provider)); - } - } -} diff --git a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php index 303dd2c66..2cc2c1b83 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php @@ -7,6 +7,7 @@ use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; use Viserio\Component\Foundation\AbstractKernel; use Viserio\Component\Support\Env; +use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; class NarrowsparkDataCollector extends PhpInfoDataCollector implements TooltipAwareContract { diff --git a/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php b/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php index a9eb159d5..49cb657e2 100644 --- a/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php +++ b/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php @@ -12,6 +12,13 @@ class KernelResponseEvent implements EventContract { use EventTrait; + /** + * Modified or original response. + * + * @var \Psr\Http\Message\ResponseInterface $response + */ + protected $response; + /** * Create a new kernel response event. * @@ -25,4 +32,28 @@ public function __construct(HttpKernelContract $kernel, ServerRequestInterface $ $this->target = $kernel; $this->parameters = ['server_request' => $serverRequest, 'response' => $response]; } + + /** + * Set a response. + * + * @param \Psr\Http\Message\ResponseInterface $response + * + * @return void + */ + public function setResponse(ResponseInterface $response): void + { + $this->response = $response; + } + + /** + * Get a modified or original response. + * + * @param \Psr\Http\Message\ResponseInterface $response + * + * @return \Psr\Http\Message\ResponseInterface + */ + public function getResponse($value='') + { + return $this->response ?? $this->parameters['response']; + } } diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index f8a39cba7..e231e88ee 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -24,6 +24,7 @@ use Viserio\Component\Session\Middleware\StartSessionMiddleware; use Viserio\Component\StaticalProxy\StaticalProxy; use Viserio\Component\View\Middleware\ShareErrorsFromSessionMiddleware; +use Viserio\Component\Profiler\Middleware\ProfilerMiddleware; class Kernel extends AbstractKernel implements HttpKernelContract, TerminableContract { @@ -65,6 +66,7 @@ class Kernel extends AbstractKernel implements HttpKernelContract, TerminableCon protected $middlewarePriority = [ StartSessionMiddleware::class, ShareErrorsFromSessionMiddleware::class, + 99999 => ProfilerMiddleware::class, ]; /** @@ -201,7 +203,9 @@ protected function handleRequest(ServerRequestInterface $serverRequest, EventMan $response = $this->sendRequestThroughRouter($serverRequest); - $events->trigger(new KernelResponseEvent($this, $serverRequest, $response)); + $events->trigger($event = new KernelResponseEvent($this, $serverRequest, $response)); + + $response = $event->getResponse(); } catch (Throwable $exception) { $this->reportException($exception); diff --git a/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php b/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php index b27a47b2c..1abc5f445 100644 --- a/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/ConfigureLoggingServiceProvider.php @@ -83,16 +83,16 @@ public function getDefaultOptions(): iterable */ public static function createConfiguredWriter(ContainerInterface $container, ?callable $getPrevious = null): ?Writer { - if ($getPrevious !== null) { - $log = $getPrevious(); + $log = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + if ($log !== null) { self::resolveOptions($container); self::configureHandlers($container, $log); return $log; } // @codeCoverageIgnoreStart - return null; + return $log; // @codeCoverageIgnoreEnd } diff --git a/src/Viserio/Component/Foundation/Tests/Bootstrap/LoadServiceProviderTest.php b/src/Viserio/Component/Foundation/Tests/Bootstrap/LoadServiceProviderTest.php deleted file mode 100644 index 3476febcf..000000000 --- a/src/Viserio/Component/Foundation/Tests/Bootstrap/LoadServiceProviderTest.php +++ /dev/null @@ -1,38 +0,0 @@ -mock(ContainerContract::class); - $container->shouldReceive('resolve') - ->once() - ->with(ConfigureLoggingServiceProvider::class) - ->andReturn($provider); - $container->shouldReceive('register') - ->once() - ->with($provider); - - $kernel = $this->mock(KernelContract::class); - $kernel->shouldReceive('getContainer') - ->once() - ->andReturn($container); - $kernel->shouldReceive('getKernelConfigurations') - ->once() - ->andReturn(['app' => ['serviceproviders' => [ConfigureLoggingServiceProvider::class]]]); - - $bootstraper->bootstrap($kernel); - } -} diff --git a/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php b/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php index 48e19ed42..1ac582ebf 100644 --- a/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php @@ -25,7 +25,7 @@ public function testProvider() $container->instance('config', [ 'viserio' => [ - 'Profiler' => [ + 'profiler' => [ 'enable' => true, 'logs_storages' => [__DIR__], 'collector' => [ diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index 7bf75b0a7..c16653852 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -234,8 +234,8 @@ function ($js) { */ protected function renderIntoHtml(): string { - $html = ''; - $html .= "'; + $html = sprintf('', $this->dumpAssetsToString('css')); + $html .= sprintf('', $this->dumpAssetsToString('js')); return $html; } diff --git a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php index 7cca77031..51e5e4ef4 100644 --- a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php +++ b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php @@ -7,23 +7,30 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Interop\Container\ContainerInterface; class ProfilerMiddleware implements MiddlewareInterface { /** * The Profiler instance. * - * @var \Viserio\Component\Contracts\Profiler\Profiler + * @var \Viserio\Component\Contracts\Profiler\Profiler|null */ protected $profiler; /** * Create a new middleware instance. * - * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler + * @param \Interop\Container\ContainerInterface $container */ - public function __construct(ProfilerContract $profiler) + public function __construct(ContainerInterface $container) { + $profiler = null; + + if ($container->has(ProfilerContract::class)) { + $profiler = $container->get(ProfilerContract::class); + } + $this->profiler = $profiler; } @@ -34,6 +41,10 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele { $response = $delegate->process($request); + if ($this->profiler === null) { + return $response; + } + // Modify the response to add the Profiler return $this->profiler->modifyResponse($request, $response); } diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php index 801ecc01f..8f495170a 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php @@ -41,10 +41,10 @@ class ProfilerServiceProvider implements public function getServices() { return [ - RouterContract::class => [self::class, 'registerProfilerAssetsControllers'], - AssetsRenderer::class => [self::class, 'createAssetsRenderer'], - ProfilerContract::class => [self::class, 'createProfiler'], - Profiler::class => function (ContainerInterface $container) { + RouterContract::class => [self::class, 'registerProfilerAssetsControllers'], + AssetsRenderer::class => [self::class, 'createAssetsRenderer'], + ProfilerContract::class => [self::class, 'createProfiler'], + Profiler::class => function (ContainerInterface $container) { return $container->get(ProfilerContract::class); }, ]; @@ -82,7 +82,7 @@ public function getDefaultOptions(): iterable ], 'jquery_is_used' => false, 'path' => null, - 'collectors' => null, + 'collectors' => [], ]; } @@ -109,13 +109,11 @@ public static function createProfiler(ContainerInterface $container): ProfilerCo ); if ($container->has(UrlGeneratorContract::class)) { - // $profiler->setUrlGenerator( - // $container->get(UrlGeneratorContract::class) - // ); + $profiler->setUrlGenerator($container->get(UrlGeneratorContract::class)); } self::registerCollectorsFromConfig($container, $profiler); - self::registerCollectors($container, $profiler); + self::registerBaseCollectors($container, $profiler); return $profiler; } @@ -124,37 +122,52 @@ public static function createAssetsRenderer(ContainerInterface $container): Asse { self::resolveOptions($container); - return new AssetsRenderer( - self::$options['jquery_is_used'], - self::$options['path'] - ); + return new AssetsRenderer(self::$options['jquery_is_used'], self::$options['path']); } - public static function registerProfilerAssetsControllers(ContainerInterface $container): RouterContract + /** + * Register profiler asset controllers. + * + * @param \Interop\Container\ContainerInterface $container + * @param null|callable $getPrevious + * + * @return \Viserio\Component\Contracts\Routing\Router + */ + public static function registerProfilerAssetsControllers(ContainerInterface $container, ?callable $getPrevious = null): RouterContract { - $router = $container->get(RouterContract::class); - - $router->group( - [ - 'namespace' => 'Viserio\Component\Profiler\Controllers', - 'prefix' => 'Profiler', - ], - function ($router) { - $router->get('assets/stylesheets', [ - 'uses' => 'AssetController@css', - 'as' => 'Profiler.assets.css', - ]); - $router->get('assets/javascript', [ - 'uses' => 'AssetController@js', - 'as' => 'Profiler.assets.js', - ]); - } - ); + $router = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + + if ($router !== null) { + $router->group( + [ + 'namespace' => 'Viserio\Component\Profiler\Controllers', + 'prefix' => 'profiler', + ], + function ($router) { + $router->get('assets/stylesheets', [ + 'uses' => 'AssetController@css', + 'as' => 'profiler.assets.css', + ]); + $router->get('assets/javascript', [ + 'uses' => 'AssetController@js', + 'as' => 'profiler.assets.js', + ]); + } + ); + } return $router; } - protected static function registerCollectors(ContainerInterface $container, Profiler $profiler) + /** + * Register base collectors. + * + * @param \Interop\Container\ContainerInterface $container + * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler + * + * @return void + */ + protected static function registerBaseCollectors(ContainerInterface $container, ProfilerContract $profiler): void { self::resolveOptions($container); @@ -177,9 +190,17 @@ protected static function registerCollectors(ContainerInterface $container, Prof } } - private static function registerCollectorsFromConfig(ContainerInterface $container, Profiler $profiler) + /** + * Register all found collectors in config. + * + * @param \Interop\Container\ContainerInterface $container + * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler + * + * @return void + */ + private static function registerCollectorsFromConfig(ContainerInterface $container, ProfilerContract $profiler): void { - if (($collectors = self::$options['collectors']) !== null) { + if ($collectors = self::$options['collectors']) { foreach ($collectors as $collector) { $profiler->addCollector($container->get($collector)); } diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler.css b/src/Viserio/Component/Profiler/Resources/css/profiler.css index db06455e4..9972c7fe1 100644 --- a/src/Viserio/Component/Profiler/Resources/css/profiler.css +++ b/src/Viserio/Component/Profiler/Resources/css/profiler.css @@ -1,3 +1,12 @@ +:root { + --main-font-color: #EEE; + --main-profiler-background-color: #222; + --main-status-default-color: #666; + --main-status-red-color: #CC0000; + --main-status-yellow-color: #FFCC00; + --main-status-green-color: #88C425; +} + .profiler { bottom: 0; color: #EEE; @@ -32,13 +41,12 @@ position: absolute; right: 0; border-top: 1px solid #383838; - box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2); - background-color: #222; + background-color: var(--main-profiler-background-color); z-index: 9999; } .profiler .profiler-show-button { - background-color: #222; + background-color: var(--main-profiler-background-color); border-top-left-radius: 4px; bottom: 0; -webkit-box-sizing: border-box; @@ -82,7 +90,7 @@ .profiler .profiler-header .profiler-menus .profiler-menu .status-green { display: inline-block; color: #FFF; - background-color: #666; + background-color: var(--main-status-default-color); padding: 3px 6px; margin-bottom: 2px; vertical-align: middle; @@ -96,14 +104,14 @@ border-left: 5px solid #444; } .profiler .profiler-header .profiler-menus .profiler-menu .status-green { - background-color: #4F805D; + background-color: var(--main-status-green-color); } .profiler .profiler-header .profiler-menus .profiler-menu .status-yellow { - background-color: #A46A1F; + background-color: var(--main-status-yellow-color); color: #FFF; } .profiler .profiler-header .profiler-menus .profiler-menu .status-red { - background-color: #B0413E; + background-color: var(--main-status-red-color); } .profiler .profiler-header .profiler-menus .profiler-menu.active, .profiler .profiler-header .profiler-menus .profiler-menu:hover { diff --git a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php index 24f0ad742..8e7a8985b 100644 --- a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php +++ b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php @@ -5,7 +5,7 @@ return; } ?> -
+
diff --git a/src/Viserio/Component/Profiler/Tests/Fixture/View/profile.html b/src/Viserio/Component/Profiler/Tests/Fixture/View/profile.html index 63c662dd3..922833442 100644 --- a/src/Viserio/Component/Profiler/Tests/Fixture/View/profile.html +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profile.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithajaxcollector.html.php b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithajaxcollector.html.php index 0cc132a88..df3f32b20 100644 --- a/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithajaxcollector.html.php +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithajaxcollector.html.php @@ -1,4 +1,4 @@ -
+
diff --git a/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithcollector.html.php b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithcollector.html.php index 2366862e1..8fbdd19e3 100644 --- a/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithcollector.html.php +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithcollector.html.php @@ -1,7 +1,7 @@ +
diff --git a/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithpanelcollector.html.php b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithpanelcollector.html.php index 3011d3042..35dcdb287 100644 --- a/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithpanelcollector.html.php +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profilewithpanelcollector.html.php @@ -1,4 +1,4 @@ -
+
diff --git a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php index c38bb82ee..a176baaf3 100644 --- a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPDOBridgeServiceProviderTest.php @@ -25,7 +25,7 @@ public function testProvider() $container->register(new ProfilerServiceProvider()); $container->register(new ProfilerPDOBridgeServiceProvider()); - $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['profiler' => ['enable' => true]]]); self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); self::assertInstanceOf(TraceablePDODecorater::class, $container->get(PDO::class)); diff --git a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php index 6e985b48c..aa6e1bbff 100644 --- a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6CacheBridgeServiceProviderTest.php @@ -25,7 +25,7 @@ public function testProvider() $container->register(new ProfilerServiceProvider()); $container->register(new ProfilerPsr6CacheBridgeServiceProvider()); - $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['profiler' => ['enable' => true]]]); self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); self::assertInstanceOf(TraceableCacheItemDecorater::class, $container->get(CacheItemPoolInterface::class)); diff --git a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php index 37afe6d8b..482076e2b 100644 --- a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerServiceProviderTest.php @@ -26,7 +26,7 @@ public function testProvider() $container->register(new OptionsResolverServiceProvider()); $container->register(new ProfilerServiceProvider()); - $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['profiler' => ['enable' => true]]]); self::assertInstanceOf(AssetsRenderer::class, $container->get(AssetsRenderer::class)); self::assertInstanceOf(Profiler::class, $container->get(ProfilerContract::class)); @@ -43,7 +43,7 @@ public function testRouteGroups() $container->register(new OptionsResolverServiceProvider()); $container->register(new ProfilerServiceProvider()); - $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['profiler' => ['enable' => true]]]); $router = $container->get(RouterContract::class); $routes = $router->getRoutes()->getRoutes(); diff --git a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php index f9fa7111e..e9355b9c3 100644 --- a/src/Viserio/Component/Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerSwiftMailerBridgeServiceProviderTest.php @@ -25,7 +25,7 @@ public function testProvider() $container->register(new ProfilerServiceProvider()); $container->register(new ProfilerSwiftMailerBridgeServiceProvider()); - $container->instance('config', ['viserio' => ['Profiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['profiler' => ['enable' => true]]]); self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); } diff --git a/src/Viserio/Component/Profiler/composer.json b/src/Viserio/Component/Profiler/composer.json index 7e7ba457b..7ee03c9aa 100644 --- a/src/Viserio/Component/Profiler/composer.json +++ b/src/Viserio/Component/Profiler/composer.json @@ -18,14 +18,14 @@ } ], "require": { - "php" : "^7.1", - "http-interop/http-factory" : "^0.3", - "psr/cache" : "^1.0", - "psr/http-message" : "^1.0", - "symfony/stopwatch" : "^3.2", - "symfony/var-dumper" : "^3.2", - "viserio/contracts" : "self.version", - "viserio/support" : "self.version" + "php" : "^7.1", + "http-interop/http-factory" : "^0.3", + "psr/cache" : "^1.0", + "psr/http-message" : "^1.0", + "symfony/stopwatch" : "^3.2", + "symfony/var-dumper" : "^3.2", + "viserio/contracts" : "self.version", + "viserio/support" : "self.version" }, "require-dev": { "cache/array-adapter" : "^0.4", diff --git a/src/Viserio/Component/Routing/AbstractRouteDispatcher.php b/src/Viserio/Component/Routing/AbstractRouteDispatcher.php index 01be7f560..6010a143f 100644 --- a/src/Viserio/Component/Routing/AbstractRouteDispatcher.php +++ b/src/Viserio/Component/Routing/AbstractRouteDispatcher.php @@ -237,18 +237,13 @@ protected function handleFound( // Add route to the request's attributes in case a middleware or handler needs access to the route $serverRequest = $serverRequest->withAttribute('_route', $route); - $this->current = $route; + $this->current = $route->bindServerRequest($serverRequest); if ($this->events !== null) { - $this->getEventManager()->trigger( - new RouteMatchedEvent( - $this, - ['route' => $route, 'server_request' => $serverRequest] - ) - ); + $this->getEventManager()->trigger(new RouteMatchedEvent($this, $this->current, $serverRequest)); } - return $this->runRouteWithinStack($route, $serverRequest); + return $this->runRouteWithinStack($this->current, $serverRequest); } /** @@ -274,14 +269,12 @@ protected function generateRouterFile(): void */ protected function runRouteWithinStack(RouteContract $route, ServerRequestInterface $request): ResponseInterface { - $middlewares = $this->getRouteMiddlewares($route); - return (new Pipeline()) ->setContainer($this->getContainer()) ->send($request) - ->through($middlewares) + ->through($this->getRouteMiddlewares($route)) ->then(function ($request) use ($route) { - return $route->run($request); + return $route->run(); }); } diff --git a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php index 313f9efcf..9886dee5c 100644 --- a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php +++ b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php @@ -4,6 +4,8 @@ use Viserio\Component\Contracts\Events\Event as EventContract; use Viserio\Component\Events\Traits\EventTrait; +use Viserio\Component\Contracts\Routing\Router as RouterContract; +use Viserio\Component\Contracts\Routing\Route as RouteContract; class RouteMatchedEvent implements EventContract { @@ -12,15 +14,34 @@ class RouteMatchedEvent implements EventContract /** * Create a new route matched event. * - * @param $router - * @param array $param - * - * @codeCoverageIgnore + * @param Viserio\Component\Contracts\Routing\Router $router + * @param \Viserio\Component\Contracts\Routing\Route $route + * @param \Psr\Http\Message\ServerRequestInterface $request */ - public function __construct($router, array $param) + public function __construct(RouterContract $router, RouteContract $route, ServerRequestInterface $request) { $this->name = 'route.matched'; $this->target = $router; - $this->parameters = $param; + $this->parameters = ['route' => $route, 'server_request' => $request]; + } + + /** + * Get matched route instance. + * + * @return \Viserio\Component\Contracts\Routing\Route + */ + public function getRoute(): RouteContract + { + return $this->parameters['route']; + } + + /** + * Get server request instance. + * + * @return \Psr\Http\Message\ServerRequestInterface + */ + public function getServerRequest(): ServerRequestInterface + { + return $this->parameters['server_request']; } } diff --git a/src/Viserio/Component/Routing/Providers/RoutingServiceProvider.php b/src/Viserio/Component/Routing/Providers/RoutingServiceProvider.php index 8c4c050c0..2488b87a8 100644 --- a/src/Viserio/Component/Routing/Providers/RoutingServiceProvider.php +++ b/src/Viserio/Component/Routing/Providers/RoutingServiceProvider.php @@ -21,11 +21,11 @@ public function getServices() { return [ RouterContract::class => [self::class, 'createRouter'], - 'router' => function (ContainerInterface $container) { + 'route' => function (ContainerInterface $container) { return $container->get(RouterContract::class); }, - 'route' => function (ContainerInterface $container) { - return $container->get(Router::class); + 'router' => function (ContainerInterface $container) { + return $container->get(RouterContract::class); }, Router::class => function (ContainerInterface $container) { return $container->get(RouterContract::class); @@ -41,9 +41,9 @@ public static function createRouter(ContainerInterface $container): Router { $router = new Router($container); - if ($container->has(EventManagerContract::class)) { - $router->setEventManager($container->get(EventManagerContract::class)); - } + // if ($container->has(EventManagerContract::class)) { + // $router->setEventManager($container->get(EventManagerContract::class)); + // } return $router; } diff --git a/src/Viserio/Component/Routing/Route.php b/src/Viserio/Component/Routing/Route.php index d16ca14a3..a9e956f7b 100644 --- a/src/Viserio/Component/Routing/Route.php +++ b/src/Viserio/Component/Routing/Route.php @@ -376,10 +376,18 @@ public function getController() /** * {@inheritdoc} */ - public function run(ServerRequestInterface $request): ResponseInterface + public function bindServerRequest(ServerRequestInterface $request): RouteContract { $this->serverRequest = $request; + return $this; + } + + /** + * {@inheritdoc} + */ + public function run(): ResponseInterface + { if ($this->isControllerAction()) { return $this->getController()->{$this->getControllerMethod()}(); } diff --git a/src/Viserio/Component/Support/Str.php b/src/Viserio/Component/Support/Str.php index 164183f7c..defb60519 100644 --- a/src/Viserio/Component/Support/Str.php +++ b/src/Viserio/Component/Support/Str.php @@ -3,11 +3,17 @@ namespace Viserio\Component\Support; use BadMethodCallException; +use Stringy\Stringy; use Stringy\StaticStringy; use Viserio\Component\Contracts\Support\CharacterType; +use Viserio\Component\Support\Traits\MacroableTrait; class Str { + use MacroableTrait { + __callStatic as macroableCallStatic; + } + /** * The cache of snake-cased words. * @@ -41,11 +47,14 @@ class Str public static function __callStatic($name, $arguments) { if (class_exists(StaticStringy::class)) { - return forward_static_call_array([StaticStringy::class, $name], $arguments); + try { + return self::macroableCallStatic($name, $arguments); + } catch(BadMethodCallException $exception) { + return forward_static_call_array([StaticStringy::class, $name], $arguments); + } } - // @codeCoverageIgnoreStart - throw new BadMethodCallException($name . ' is not a valid method'); - // @codeCoverageIgnoreEnd + + return self::macroableCallStatic($name, $arguments); } /** diff --git a/src/Viserio/Component/Support/Traits/MacroableTrait.php b/src/Viserio/Component/Support/Traits/MacroableTrait.php index 6ac8ee7f9..1b508b30a 100644 --- a/src/Viserio/Component/Support/Traits/MacroableTrait.php +++ b/src/Viserio/Component/Support/Traits/MacroableTrait.php @@ -27,7 +27,7 @@ trait MacroableTrait public static function __callStatic($method, $parameters) { if (! static::hasMacro($method)) { - throw new BadMethodCallException("Method {$method} does not exist."); + throw new BadMethodCallException(sprintf("Method [%s] does not exist.", $method)); } return static::resolveMacroCall($method, $parameters, Closure::bind(static::$macros[$method], null, static::class)); From 0812775535075d062f954b9852537b93253b303d Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 23 Apr 2017 18:54:23 +0000 Subject: [PATCH 14/99] Apply fixes from StyleCI --- src/Viserio/Component/Container/Container.php | 2 +- .../Foundation/DataCollectors/NarrowsparkDataCollector.php | 2 +- .../Component/Foundation/Http/Events/KernelResponseEvent.php | 3 ++- src/Viserio/Component/Foundation/Http/Kernel.php | 2 +- .../Component/Profiler/Middleware/ProfilerMiddleware.php | 2 +- .../Component/Profiler/Providers/ProfilerServiceProvider.php | 4 ++-- src/Viserio/Component/Routing/Events/RouteMatchedEvent.php | 4 ++-- src/Viserio/Component/Support/Str.php | 4 ++-- src/Viserio/Component/Support/Traits/MacroableTrait.php | 2 +- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Viserio/Component/Container/Container.php b/src/Viserio/Component/Container/Container.php index a6c4d10cf..2292a3646 100644 --- a/src/Viserio/Component/Container/Container.php +++ b/src/Viserio/Component/Container/Container.php @@ -402,7 +402,7 @@ public function register(ServiceProvider $provider, array $parameters = []): Con foreach ($provider->getServices() as $key => $callable) { if ($this->has($key)) { $this->extend($key, function ($previous, $container) use ($callable) { - // Extend a previous entry + // Extend a previous entry return $callable($container, function () use ($previous) { return $previous; }); diff --git a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php index 2cc2c1b83..f679d1cc8 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php @@ -6,8 +6,8 @@ use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; use Viserio\Component\Foundation\AbstractKernel; -use Viserio\Component\Support\Env; use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; +use Viserio\Component\Support\Env; class NarrowsparkDataCollector extends PhpInfoDataCollector implements TooltipAwareContract { diff --git a/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php b/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php index 49cb657e2..adeea6275 100644 --- a/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php +++ b/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php @@ -15,7 +15,7 @@ class KernelResponseEvent implements EventContract /** * Modified or original response. * - * @var \Psr\Http\Message\ResponseInterface $response + * @var \Psr\Http\Message\ResponseInterface */ protected $response; @@ -49,6 +49,7 @@ public function setResponse(ResponseInterface $response): void * Get a modified or original response. * * @param \Psr\Http\Message\ResponseInterface $response + * @param mixed $value * * @return \Psr\Http\Message\ResponseInterface */ diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index e231e88ee..28556985f 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -19,12 +19,12 @@ use Viserio\Component\Foundation\Http\Events\KernelRequestEvent; use Viserio\Component\Foundation\Http\Events\KernelResponseEvent; use Viserio\Component\Foundation\Http\Events\KernelTerminateEvent; +use Viserio\Component\Profiler\Middleware\ProfilerMiddleware; use Viserio\Component\Routing\Pipeline; use Viserio\Component\Routing\Router; use Viserio\Component\Session\Middleware\StartSessionMiddleware; use Viserio\Component\StaticalProxy\StaticalProxy; use Viserio\Component\View\Middleware\ShareErrorsFromSessionMiddleware; -use Viserio\Component\Profiler\Middleware\ProfilerMiddleware; class Kernel extends AbstractKernel implements HttpKernelContract, TerminableContract { diff --git a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php index 51e5e4ef4..81be9ab2c 100644 --- a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php +++ b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php @@ -2,12 +2,12 @@ declare(strict_types=1); namespace Viserio\Component\Profiler\Middleware; +use Interop\Container\ContainerInterface; use Interop\Http\ServerMiddleware\DelegateInterface; use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; -use Interop\Container\ContainerInterface; class ProfilerMiddleware implements MiddlewareInterface { diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php index 8f495170a..4631d2623 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php @@ -162,7 +162,7 @@ function ($router) { /** * Register base collectors. * - * @param \Interop\Container\ContainerInterface $container + * @param \Interop\Container\ContainerInterface $container * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler * * @return void @@ -193,7 +193,7 @@ protected static function registerBaseCollectors(ContainerInterface $container, /** * Register all found collectors in config. * - * @param \Interop\Container\ContainerInterface $container + * @param \Interop\Container\ContainerInterface $container * @param \Viserio\Component\Contracts\Profiler\Profiler $profiler * * @return void diff --git a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php index 9886dee5c..1e8719cfb 100644 --- a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php +++ b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php @@ -3,9 +3,9 @@ namespace Viserio\Component\Routing\Events; use Viserio\Component\Contracts\Events\Event as EventContract; -use Viserio\Component\Events\Traits\EventTrait; -use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Contracts\Routing\Route as RouteContract; +use Viserio\Component\Contracts\Routing\Router as RouterContract; +use Viserio\Component\Events\Traits\EventTrait; class RouteMatchedEvent implements EventContract { diff --git a/src/Viserio/Component/Support/Str.php b/src/Viserio/Component/Support/Str.php index defb60519..ebbe77e70 100644 --- a/src/Viserio/Component/Support/Str.php +++ b/src/Viserio/Component/Support/Str.php @@ -3,8 +3,8 @@ namespace Viserio\Component\Support; use BadMethodCallException; -use Stringy\Stringy; use Stringy\StaticStringy; +use Stringy\Stringy; use Viserio\Component\Contracts\Support\CharacterType; use Viserio\Component\Support\Traits\MacroableTrait; @@ -49,7 +49,7 @@ public static function __callStatic($name, $arguments) if (class_exists(StaticStringy::class)) { try { return self::macroableCallStatic($name, $arguments); - } catch(BadMethodCallException $exception) { + } catch (BadMethodCallException $exception) { return forward_static_call_array([StaticStringy::class, $name], $arguments); } } diff --git a/src/Viserio/Component/Support/Traits/MacroableTrait.php b/src/Viserio/Component/Support/Traits/MacroableTrait.php index 1b508b30a..f398a00ec 100644 --- a/src/Viserio/Component/Support/Traits/MacroableTrait.php +++ b/src/Viserio/Component/Support/Traits/MacroableTrait.php @@ -27,7 +27,7 @@ trait MacroableTrait public static function __callStatic($method, $parameters) { if (! static::hasMacro($method)) { - throw new BadMethodCallException(sprintf("Method [%s] does not exist.", $method)); + throw new BadMethodCallException(sprintf('Method [%s] does not exist.', $method)); } return static::resolveMacroCall($method, $parameters, Closure::bind(static::$macros[$method], null, static::class)); From 797c823d35d21b4b2dec80486a1db29f871e5ec7 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 23 Apr 2017 20:54:22 +0200 Subject: [PATCH 15/99] changes --- .../Resources/css/request-response.css | 8 ++++---- .../Profiler/Resources/js/profiler.js | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css b/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css index 03f92097e..41e9e583f 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css +++ b/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css @@ -5,16 +5,16 @@ margin-right: 5px; } .profiler-menu.profiler-menu-viserio-http-data-collector.response-status-green .profiler-menu-label { - background-color: #4F805D; + background-color: var(--main-status-green-color); } .profiler-menu.profiler-menu-viserio-http-data-collector.response-status-yellow .profiler-menu-label { - background-color: #A46A1F; + background-color: var(--main-status-yellow-color); color: #FFF; } .profiler-menu.profiler-menu-viserio-http-data-collector.response-status-red .profiler-menu-label { - background-color: #B0413E; + background-color: var(--main-status-red-color); } -.Profiler .profiler-header .profiler-menus .profiler-menu-position-left.profiler-menu-viserio-http-data-collector .profiler-menu-content { +.profiler .profiler-header .profiler-menus .profiler-menu-position-left.profiler-menu-viserio-http-data-collector .profiler-menu-content { padding-left: 0; padding-right: 7px; } diff --git a/src/Viserio/Component/Profiler/Resources/js/profiler.js b/src/Viserio/Component/Profiler/Resources/js/profiler.js index 2ebb8826b..e965ca212 100644 --- a/src/Viserio/Component/Profiler/Resources/js/profiler.js +++ b/src/Viserio/Component/Profiler/Resources/js/profiler.js @@ -21,9 +21,9 @@ if (typeof(Profiler) == 'undefined') { var openPanel = false; // helper vars for long class names - var panelBodyClass = '.Profiler .profiler-body'; + var panelBodyClass = '.profiler .profiler-body'; var panelClass = panelBodyClass + ' .profiler-panel'; - var menuHasPanel = '.Profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-panel'; + var menuHasPanel = '.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-panel'; var bodyMenu = panelBodyClass + ' .profiler-body-menu'; var getPreference = function(name) { if (!window.localStorage) { @@ -99,22 +99,22 @@ if (typeof(Profiler) == 'undefined') { }); // close Profiler button - $('.Profiler .profiler-header .profiler-hide-button').on('click', function(e) { + $('.profiler .profiler-header .profiler-hide-button').on('click', function(e) { e.preventDefault(); openPanel = false; - $('.Profiler .profiler-body, ' + panelClass).removeClass('active'); - $('.Profiler .profiler-header').addClass('hide'); - $('.Profiler .profiler-show-button').addClass('active'); + $('.profiler .profiler-body, ' + panelClass).removeClass('active'); + $('.profiler .profiler-header').addClass('hide'); + $('.profiler .profiler-show-button').addClass('active'); }); // open button - $('.Profiler .profiler-show-button').on('click', function(e) { + $('.profiler .profiler-show-button').on('click', function(e) { e.preventDefault(); - $('.Profiler .profiler-header').removeClass('hide'); - $('.Profiler .profiler-show-button').removeClass('active'); + $('.profiler .profiler-header').removeClass('hide'); + $('.profiler .profiler-show-button').removeClass('active'); }); }; From 54a2b915bd1f50b1aff962553c41e4decf0da9c0 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 24 Apr 2017 00:32:36 +0200 Subject: [PATCH 16/99] fixed getCollectors --- .../Component/Profiler/AssetsRenderer.php | 22 ++++++++++--------- src/Viserio/Component/Profiler/Profiler.php | 2 +- .../Profiler/Resources/css/profiler.css | 1 - .../Profiler/Resources/js/profiler.js | 2 +- .../Component/Profiler/TemplateManager.php | 2 ++ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index c16653852..b4c45013b 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -203,16 +203,18 @@ function ($js) { $this->jsFiles ); - $additionalAssets = []; - - // finds assets provided by collectors - foreach ($this->profiler->getCollectors() as $collector) { - if ($collector instanceof AssetAwareContract && - ! in_array($collector->getName(), $this->ignoredCollectors) - ) { - $additionalAssets[] = $collector->getAssets(); - } - } + $additionalAssets = array_filter( + array_map( + function($collector) { + $collector = $collector['collector']; + + if ($collector instanceof AssetAwareContract && ! in_array($collector->getName(), $this->ignoredCollectors)) { + return $collector->getAssets(); + } + }, + $this->profiler->getCollectors() + ) + ); foreach ($additionalAssets as $assets) { if (isset($assets['css'])) { diff --git a/src/Viserio/Component/Profiler/Profiler.php b/src/Viserio/Component/Profiler/Profiler.php index 73ec71f95..489e62446 100644 --- a/src/Viserio/Component/Profiler/Profiler.php +++ b/src/Viserio/Component/Profiler/Profiler.php @@ -283,7 +283,7 @@ private function collectData( foreach ($this->collectors as $name => $collector) { $collector['collector']->collect($serverRequest, $response); - $this->collectors[$name] = $collector['collector']; + $this->collectors[$name]['collector'] = $collector['collector']; } if ($this->cachePool !== null) { diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler.css b/src/Viserio/Component/Profiler/Resources/css/profiler.css index 9972c7fe1..336f45637 100644 --- a/src/Viserio/Component/Profiler/Resources/css/profiler.css +++ b/src/Viserio/Component/Profiler/Resources/css/profiler.css @@ -40,7 +40,6 @@ left: 0; position: absolute; right: 0; - border-top: 1px solid #383838; background-color: var(--main-profiler-background-color); z-index: 9999; } diff --git a/src/Viserio/Component/Profiler/Resources/js/profiler.js b/src/Viserio/Component/Profiler/Resources/js/profiler.js index e965ca212..2f0e16b99 100644 --- a/src/Viserio/Component/Profiler/Resources/js/profiler.js +++ b/src/Viserio/Component/Profiler/Resources/js/profiler.js @@ -98,7 +98,7 @@ if (typeof(Profiler) == 'undefined') { openPanel = false; }); - // close Profiler button + // close button $('.profiler .profiler-header .profiler-hide-button').on('click', function(e) { e.preventDefault(); diff --git a/src/Viserio/Component/Profiler/TemplateManager.php b/src/Viserio/Component/Profiler/TemplateManager.php index 4c16161ba..ca7910222 100644 --- a/src/Viserio/Component/Profiler/TemplateManager.php +++ b/src/Viserio/Component/Profiler/TemplateManager.php @@ -122,6 +122,8 @@ public function getSortedData(): array ]; foreach ($this->collectors as $name => $collector) { + $collector = $collector['collector']; + if ($collector instanceof TooltipAwareContract) { $data['menus'][$collector->getName()] = [ 'menu' => $collector->getMenu(), From 33b408e4bba33885654c696344421889b032db8d Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 23 Apr 2017 22:32:48 +0000 Subject: [PATCH 17/99] Apply fixes from StyleCI --- src/Viserio/Component/Profiler/AssetsRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index b4c45013b..360ac7b79 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -205,7 +205,7 @@ function ($js) { $additionalAssets = array_filter( array_map( - function($collector) { + function ($collector) { $collector = $collector['collector']; if ($collector instanceof AssetAwareContract && ! in_array($collector->getName(), $this->ignoredCollectors)) { From f5c24b1a0ddc18a8b0979dd971618ed86432215f Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 24 Apr 2017 20:50:28 +0200 Subject: [PATCH 18/99] improving profiler css --- .../Profiler/Resources/css/profiler.css | 305 ++++++++++++------ 1 file changed, 198 insertions(+), 107 deletions(-) diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler.css b/src/Viserio/Component/Profiler/Resources/css/profiler.css index 336f45637..1d5a2e502 100644 --- a/src/Viserio/Component/Profiler/Resources/css/profiler.css +++ b/src/Viserio/Component/Profiler/Resources/css/profiler.css @@ -1,21 +1,28 @@ :root { - --main-font-color: #EEE; - --main-profiler-background-color: #222; + --main-font-color: #eee; + --main-profiler-background-color: #212121; + --main-menu-background-color: #424242; --main-status-default-color: #666; - --main-status-red-color: #CC0000; - --main-status-yellow-color: #FFCC00; - --main-status-green-color: #88C425; + --main-status-red-color: #b71c1c; + --main-status-yellow-color: #fdd835; + --main-status-green-color: #7cb342; + --main-tab-default-color: #2b2a28; + --main-tab-active-color: #fff; + --main-tab-active-font-color: #2b2a28; + --main-tab-counter-color: #2b2a28; } .profiler { + font: 11px -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif; + + position: fixed; + right: 0; bottom: 0; - color: #EEE; - font: 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif; left: 0; + margin: 0; padding: 0; - position: fixed; - right: 0; + text-align: left; text-transform: none; @@ -36,66 +43,80 @@ } .profiler .profiler-header { - bottom: 0; - left: 0; position: absolute; + z-index: 9999; right: 0; + bottom: 0; + left: 0; + background-color: var(--main-profiler-background-color); - z-index: 9999; } .profiler .profiler-show-button { - background-color: var(--main-profiler-background-color); - border-top-left-radius: 4px; + position: fixed; + z-index: 99999; + right: 0; bottom: 0; - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; + display: none; + + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; height: 36px; padding: 6px; - position: fixed; - right: 0; - z-index: 99999; + cursor: pointer; + + border-top-left-radius: 4px; + background-color: var(--main-profiler-background-color); } .profiler .profiler-header .profiler-hide-button, .profiler .profiler-body .profiler-body-close-panel, .profiler .profiler-body .profiler-body-menu .profiler-body-resize-panel { - background: #444; display: block; + float: right; + width: 36px; height: 36px; + cursor: pointer; text-align: center; - float: right; + + background: var(--main-menu-background-color); } .profiler .profiler-header .profiler-hide-button svg, .profiler .profiler-header .profiler-menus .profiler-menu svg { position: relative; top: 6px; + max-height: 24px; } .profiler .profiler-header .profiler-menus .profiler-menu { - cursor: default; display: block; + height: 36px; margin-right: 0; + + cursor: default; white-space: nowrap; } .profiler .profiler-header .profiler-menus .profiler-menu .status-red, .profiler .profiler-header .profiler-menus .profiler-menu .status-yellow, .profiler .profiler-header .profiler-menus .profiler-menu .status-green { display: inline-block; - color: #FFF; - background-color: var(--main-status-default-color); - padding: 3px 6px; - margin-bottom: 2px; - vertical-align: middle; + min-width: 15px; min-height: 13px; + margin-bottom: 2px; + padding: 3px 6px; + text-align: center; + vertical-align: middle; + + color: #fff; + background-color: var(--main-status-default-color); } .profiler .profiler-header .profiler-menus .profiler-menu .status-red + .status-red, .profiler .profiler-header .profiler-menus .profiler-menu .status-yellow + .status-yellow, @@ -106,17 +127,18 @@ background-color: var(--main-status-green-color); } .profiler .profiler-header .profiler-menus .profiler-menu .status-yellow { + color: #fff; background-color: var(--main-status-yellow-color); - color: #FFF; } .profiler .profiler-header .profiler-menus .profiler-menu .status-red { background-color: var(--main-status-red-color); } .profiler .profiler-header .profiler-menus .profiler-menu.active, .profiler .profiler-header .profiler-menus .profiler-menu:hover { - background-color: #444; position: relative; z-index: 10002; + + background-color: var(--main-menu-background-color); } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover { cursor: help; @@ -128,45 +150,56 @@ display: none; } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip { + position: absolute; + bottom: 36px; + display: block; - padding: 10px; + overflow: hidden; + overflow-y: auto; + max-width: 480px; max-height: 480px; + padding: 10px; + word-wrap: break-word; - overflow: hidden; - overflow-y: auto; - background-color: #444; - bottom: 36px; - color: #F5F5F5; - position: absolute; + + background-color: var(--main-menu-background-color); } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group { margin-bottom: 4px; padding-bottom: 4px; - border-bottom: 1px solid #333333; + + border-bottom: 1px solid #333; } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group:last-child { margin-bottom: 0; padding-bottom: 0; + border-bottom: none; } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group-piece { - border-bottom: solid transparent 3px; display: table-row; + + border-bottom: solid transparent 3px; } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group b { - color: #AAA; - display: table-cell; font-size: 11px; + + display: table-cell; + padding: 4px 8px 4px 0; + + color: #aaa; } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group span { - color: #F5F5F5; font-size: 12px; + display: table-cell; + + color: var(--main-font-color); } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group a { - color: #FFF; + color: #fff; } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-position-left.profiler-menu-has-tooltip:hover .profiler-menu-tooltip { left: 0; @@ -181,9 +214,11 @@ float: right; } .profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-content { + line-height: 36px; + display: block; + height: 36px; - line-height: 36px; } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-position-left .profiler-menu-content, .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-position-right .profiler-menu-content { @@ -192,26 +227,33 @@ .profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-content .profiler-menu-icon, .profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-content .profiler-menu-label, .profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-content .profiler-menu-value { - display: inline-block; - color: #F5F5F5; font-size: 13px; line-height: 36px; + + display: inline-block; + padding: 0; + + color: var(--main-font-color); } .profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-icon .profiler-menu-value { margin-left: 4px; } .profiler .profiler-body { - height: 324px; - background-color: #222; - margin-bottom: 37px; - display: none; position: relative; z-index: 9998; + + display: none; + + height: 324px; + margin-bottom: 36px; + + background-color: var(--main-profiler-background-color); + color: var(--main-font-color); } .profiler .profiler-body pre { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace; } .profiler .profiler-body pre.sf-dump, .profiler .profiler-body pre.sf-dump .sf-dump-num, @@ -227,101 +269,122 @@ .profiler .profiler-body pre.sf-dump .sf-dump-index { margin: 0; padding: 0; - color: #2B2A28; + + color: #2b2a28; } .profiler .profiler-body .profiler-panel { - height: 270px; display: none; + + height: 270px; } .profiler .profiler-body .profiler-panel.profiler-body-has-table, .profiler .profiler-body .profiler-panel.profiler-body-has-selector, .profiler .profiler-body .profiler-panel.profiler-body-has-metrics { - overflow-y: auto; overflow-x: hidden; + overflow-y: auto; + padding: 15px; } .profiler .profiler-body .profiler-panel .profiler-tabs { position: relative; - min-height: 180px; + display: block; + + min-height: 180px; } .profiler .profiler-body .profiler-panel .profiler-tabs-tab { display: inline-block; } .profiler .profiler-body .profiler-panel .profiler-tabs-tab label { - cursor: pointer; - background: #2B2A28; - color: #FFF; display: block; + margin: 0 0 0 -1px; padding: 10px 15px; - border-bottom: 3px solid #FFF; + + cursor: pointer; text-align: center; + + color: #fff; + border-bottom: 3px solid #fff; + background: var(--main-tab-default-color); } .profiler .profiler-body .profiler-panel .profiler-tabs-tab label span.counter { display: inline-block; - color: #FFF; - background-color: #666; - padding: 3px 6px; - margin-bottom: 2px; - vertical-align: middle; + min-width: 15px; min-height: 13px; - text-align: center; - margin-bottom: 0; + margin-bottom: 2px; margin-left: 10px; + padding: 2px 6px 3px 6px; + + text-align: center; + vertical-align: middle; + + color: var(--main-tab-active-font-color); + background-color: #fff; } .profiler .profiler-body .profiler-panel .profiler-tabs-tab [type=radio] { position: absolute; - height: 0; - width: 0; + overflow: hidden; clip: rect(0, 0, 0, 0); + + width: 0; + height: 0; } .profiler .profiler-body .profiler-panel .profiler-tabs-tab [type=radio]:focus + label { /* */ } .profiler .profiler-body .profiler-panel .profiler-tabs-tab-content { position: absolute; - left: 0; right: 0; - opacity: 0; - padding: 15px; + left: 0; + overflow-y: auto; + height: 236px; + padding: 15px 15px 0 15px; + + opacity: 0; } .profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label { - background: #FFF; - color: #2B2A28; z-index: 2; + + color: var(--main-tab-active-font-color); + background: var(--main-tab-active-color); } .profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label span.counter { - background: #ECECEC; - color: #2B2A28; + color: var(--main-tab-active-color); + background: var(--main-tab-counter-color); } .profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label ~ .profiler-tabs-tab-content { z-index: 1; + opacity: 1; } .profiler .profiler-body h3:first-child { - margin-top: 0; + margin-top: 0; } .profiler .profiler-body .profiler-panel table, .profiler .profiler-body .profiler-panel tr, .profiler .profiler-body .profiler-panel th, .profiler .profiler-body .profiler-panel td { - background: #FFF; - border-collapse: collapse; line-height: 1.5; + + border-collapse: collapse; + vertical-align: top; + + background: #fff; } .profiler .profiler-body .profiler-panel table { - background: #FFF; - box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); - margin: 0; width: 100%; + margin: 0; + + background: #fff; + box-shadow: 0 0 1px rgba(128, 128, 128, .2); } .profiler .profiler-body .profiler-panel table + table { margin-top: 30px; @@ -333,30 +396,32 @@ } .profiler .profiler-body .profiler-panel table th { font-weight: bold; + text-align: left; } .profiler .profiler-body .profiler-panel table thead th { - background-color: #2B2A28; - color: #FFF; + color: #fff; + background-color: #2b2a28; } .profiler .profiler-body .profiler-panel table thead th.key { width: 19%; } .profiler .profiler-body .profiler-panel table tbody th, .profiler .profiler-body .profiler-panel table tbody td { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; - font-size-adjust: 0.5; - border: 1px solid #E0E0E0; + font-size-adjust: .5; + + color: #2b2a28; + border: 1px solid #e0e0e0; border-width: 1px 0; - color: #2B2A28; } .profiler .profiler-body .profiler-panel table tbody td { + word-break: break-all; -ms-word-break: break-all; - word-break: break-all; -webkit-hyphens: auto; - -moz-hyphens: auto; - hyphens: auto; + -moz-hyphens: auto; + hyphens: auto; } .profiler .profiler-body .profiler-panel table tbody div { margin: .25em 0; @@ -366,66 +431,92 @@ padding: 0 0 0 1em; } .profiler .profiler-body .profiler-panel .empty { - border: 4px dashed #E0E0E0; - color: #FFF; font-size: 16px; + font-weight: bold; + margin: 1em 0; padding: .5em 2em; + text-align: center; - font-weight: bold; + + color: #fff; + border: 4px dashed #e0e0e0; } .profiler .profiler-body .profiler-panel .metrics { overflow: auto; - list-style: none; + margin: 0; padding: 0; + + list-style: none; } .profiler .profiler-body .profiler-panel .metrics .metric { - margin: 0 1em 1em 0; - background: #FFF; - box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); + display: inline-block; + min-width: 100px; min-height: 65px; - display: inline-block; + margin: 0 1em 1em 0; + + background: #fff; + box-shadow: 0 0 1px rgba(128, 128, 128, .2); } .profiler .profiler-body .profiler-panel .metrics .metric .value { - display: block; font-size: 28px; + + display: block; + padding: 8px 15px 4px; + text-align: center; - color: #2B2A28; + + color: #2b2a28; } .profiler .profiler-body .profiler-panel .metrics .metric .label { - background: #444; - color: #FFF; - display: block; font-size: 12px; + + display: block; + padding: 5px; + text-align: center; + + color: #fff; + background: #444; } .profiler .profiler-body .profiler-panel select { + font-weight: bold; + width: 100%; + margin-bottom: 15px; padding: 10px 0; + cursor: pointer; - margin-bottom: 15px; - font-weight: bold; + border: 0; } .profiler .profiler-body .profiler-body-menu { height: 24px; + border-bottom: 1px solid #383838; - box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); background-color: #222; + box-shadow: 0 1px 0 rgba(0, 0, 0, .2); } .profiler .profiler-body .profiler-body-menu .profiler-body-close-panel, .profiler .profiler-body .profiler-body-menu .profiler-body-resize-panel { + float: right; + width: 24px; height: 24px; - float: right; } .profiler .profiler-body .profiler-body-menu .profiler-body-resize-panel.orginal-size-panel svg { transform: rotate(180deg); } + +@media (max-width: 768px) { + .profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-content .profiler-menu-value { + display: none; + } +} From 0becee27c03fb7eea3494fd625b8594bc5dbc86d Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Tue, 25 Apr 2017 00:53:58 +0200 Subject: [PATCH 19/99] more changes --- .../Twig/DataCollector/Resources/css/twig.css | 12 +-- ...wigBridgeDataCollectorsServiceProvider.php | 10 +- .../Resources/css/request-response.css | 6 +- .../ViserioHttpDataCollector.php | 101 +++++++++++++++--- .../DataCollectors/AbstractDataCollector.php | 27 ++--- .../Proxies/{WebProfiler.php => Profiler.php} | 4 +- .../Profiler/Resources/css/profiler-grid.css | 47 +++----- .../Profiler/Resources/css/profiler.css | 94 +++++++++------- .../Profiler/Resources/js/profiler.js | 21 ++-- .../Resources/views/profiler.html.php | 2 +- 10 files changed, 190 insertions(+), 134 deletions(-) rename src/Viserio/Component/Profiler/Proxies/{WebProfiler.php => Profiler.php} (78%) diff --git a/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css b/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css index 30f38d074..975c52063 100644 --- a/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css +++ b/src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css @@ -1,20 +1,20 @@ .profiler-panel.profiler-panel-twig-data-collector.active .twig-graph { - margin-top: 25px; + margin: 25px 0; } .profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre { font-size: 14px; - color: #2B2A28; + color: var(--profiler-second-font-color); padding: 10px; - background-color: #fff; + background-color: #FFF; } .profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-success { - color: #4F805D; + color: var(--profiler-status-green-color); } .profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-warning { - background-color: #A46A1F; + background-color: var(--profiler-status-yellow-color); color: #FFF; padding: 0px 5px; } .profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-error { - color: #B0413E; + color: var(--profiler-status-red-color); } diff --git a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php index 688cd0d0a..f794fcbf2 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php @@ -10,7 +10,7 @@ use Viserio\Bridge\Twig\DataCollector\TwigDataCollector; use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract; use Viserio\Component\Contracts\OptionsResolver\RequiresMandatoryOptions as RequiresMandatoryOptionsContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; +use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; use Viserio\Component\OptionsResolver\OptionsResolver; class TwigBridgeDataCollectorsServiceProvider implements @@ -35,7 +35,7 @@ public function getServices() return new Twig_Profiler_Profile(); }, TwigEnvironment::class => [self::class, 'createTwigEnvironment'], - WebProfilerContract::class => [self::class, 'createProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } @@ -44,7 +44,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'profiler']; } /** @@ -65,9 +65,9 @@ public function getMandatoryOptions(): iterable * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { if ($getPrevious !== null) { self::resolveOptions($container); diff --git a/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css b/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css index 41e9e583f..7b6e5adc7 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css +++ b/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css @@ -5,14 +5,14 @@ margin-right: 5px; } .profiler-menu.profiler-menu-viserio-http-data-collector.response-status-green .profiler-menu-label { - background-color: var(--main-status-green-color); + background-color: var(--profiler-status-green-color); } .profiler-menu.profiler-menu-viserio-http-data-collector.response-status-yellow .profiler-menu-label { - background-color: var(--main-status-yellow-color); + background-color: var(--profiler-status-yellow-color); color: #FFF; } .profiler-menu.profiler-menu-viserio-http-data-collector.response-status-red .profiler-menu-label { - background-color: var(--main-status-red-color); + background-color: var(--profiler-status-red-color); } .profiler .profiler-header .profiler-menus .profiler-menu-position-left.profiler-menu-viserio-http-data-collector .profiler-menu-content { padding-left: 0; diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 2b395af49..5bbfc35fb 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -157,7 +157,9 @@ public function getTooltip(): string */ public function getPanel(): string { - $session = $this->serverRequest->getAttribute('session'); + $request = $this->serverRequest; + $response = $this->response; + $session = $request->getAttribute('session'); $sessionMeta = []; if ($session !== null) { @@ -174,55 +176,82 @@ public function getPanel(): string [ 'name' => 'Request', 'content' => $this->createTable( - $this->serverRequest->getQueryParams(), - ['name' => 'Get Parameters'] + $request->getQueryParams(), + [ + 'name' => 'Get Parameters', + 'empty_text' => 'No GET parameters', + ] ) . $this->createTable( - $this->serverRequest->getParsedBody() ?? [], - ['name' => 'Post Parameters'] + $request->getParsedBody() ?? [], + [ + 'name' => 'Post Parameters', + 'empty_text' => 'No POST parameters', + ] ) . $this->createTable( - $this->prepareRequestAttributes($this->serverRequest->getAttributes()), + $this->prepareRequestAttributes($request->getAttributes()), ['name' => 'Request Attributes'] ) . $this->createTable( - $this->splitOnAttributeDelimiter($this->serverRequest->getHeaderLine('Cookie')), - ['name' => 'Cookies'] - ) . $this->createTable( - $this->prepareRequestHeaders($this->serverRequest->getHeaders()), + $this->prepareRequestHeaders($request->getHeaders()), ['name' => 'Request Headers'] ) . $this->createTable( - $this->prepareServerParams($this->serverRequest->getServerParams()), + $this->prepareServerParams($request->getServerParams()), ['name' => 'Server Parameters'] ), ], [ 'name' => 'Response', 'content' => $this->createTable( - $this->response->getHeaders(), + $response->getHeaders(), [ 'name' => 'Response Headers', 'headers' => [ 'key' => 'Header', ], ] + ), + ], + [ + 'name' => 'Cookies', + 'content' => $this->createTable( + $this->splitOnAttributeDelimiter($request->getHeaderLine('Cookie')), + [ + 'name' => 'Request Cookies', + 'empty_text' => 'No request cookies' + ] ) . $this->createTable( - $this->serverRequest->getHeader('Set-Cookie'), - ['name' => 'Cookies'] + array_map(function ($setCookieString) { + return $this->fromStringCookie($setCookieString); + }, $response->getHeader('Set-Cookie')), + [ + 'name' => 'Response Cookies', + 'empty_text' => 'No response cookies' + ] ), ], [ 'name' => 'Session', 'content' => $this->createTable( $sessionMeta, - ['name' => 'Session Metadata'] + [ + 'name' => 'Session Metadata', + 'empty_text' => 'No session metadata', + ] ) . $this->createTable( $session !== null ? $session->getAll() : [], - ['name' => 'Session Attributes'] + [ + 'name' => 'Session Attributes', + 'empty_text' => 'No session attributes', + ] ), ], [ 'name' => 'Flashes', 'content' => $this->createTable( $session !== null ? $session->get('_flash') : [], - ['name' => 'Flashes'] + [ + 'name' => 'Flashes', + 'empty_text' => 'No flash messages were created' + ] ), ], ]); @@ -332,6 +361,44 @@ protected function splitOnAttributeDelimiter(string $string): array return array_filter(preg_split('@\s*[;]\s*@', $string)); } + /** + * Split a string to array. + * + * @param string $string + * + * @return array + */ + protected function splitCookiePair(string $string): array + { + $pairParts = explode('=', $string, 2); + + if (count($pairParts) === 1) { + $pairParts[1] = ''; + } + + return array_map(function ($part) { + if ($part === null) { + return ''; + } + + return urldecode($part); + }, $pairParts); + } + + /** + * Creates a Cookie instance from a Set-Cookie header value. + * + * @param string $string + * + * @return \Viserio\Component\Contracts\Cookie\Cookie + */ + protected static function fromStringCookie(string $string): CookieContract + { + $rawAttributes = $this->splitOnAttributeDelimiter($string); + + list($cookieName, $cookieValue) = $this->splitCookiePair(array_shift($rawAttributes)); + } + /** * Prepare request attributes, check of route object. * diff --git a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php index f0f488fff..3f9de94f4 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php @@ -198,18 +198,12 @@ protected function createTooltipGroup(array $data): string */ protected function createTabs(array $data): string { - $grid = ''; - - if (($counted = count($data)) < 12) { - $grid = ' col span_' . floor(12 / $counted); - } - - $html = '
'; + $html = '
'; foreach ($data as $key => $value) { $id = uniqid($key . '-'); - $html .= '
'; + $html .= '
'; $html .= ''; $html .= ''; $html .= '
'; @@ -233,15 +227,16 @@ protected function createTabs(array $data): string protected function createTable(array $data, array $settings = []): string { $options = array_merge([ - 'name' => null, - 'headers' => ['Key', 'Value'], - 'vardumper' => true, + 'name' => null, + 'headers' => ['Key', 'Value'], + 'vardumper' => true, + 'empty_text' => 'Empty', ], $settings); $html = $options['name'] !== null ? '

' . $options['name'] . '

' : ''; if (count($data) !== 0) { - $html .= ''; + $html .= '
'; foreach ((array) $options['headers'] as $header) { $html .= ''; @@ -253,17 +248,17 @@ protected function createTable(array $data, array $settings = []): string if (is_string($key)) { $html .= ''; $html .= ''; - $html .= ''; + $html .= sprintf('', ($options['vardumper'] ? $this->cloneVar($values) : $values)); $html .= ''; } else { $html .= ''; if (is_array($values)) { foreach ($values as $key => $value) { - $html .= ''; + $html .= sprintf('', ($options['vardumper'] ? $this->cloneVar($value) : $value)); } } else { - $html .= ''; + $html .= sprintf('', ($options['vardumper'] ? $this->cloneVar($values) : $values)); } $html .= ''; @@ -272,7 +267,7 @@ protected function createTable(array $data, array $settings = []): string $html .= '
' . $header . '
' . $key . '' . ($options['vardumper'] ? $this->cloneVar($values) : $values) . '%s
' . ($options['vardumper'] ? $this->cloneVar($value) : $value) . '%s' . ($options['vardumper'] ? $this->cloneVar($values) : $values) . '%s
'; } else { - $html .= '
Empty
'; + $html .= sprintf('
%s
', $options['empty_text']); } return $html; diff --git a/src/Viserio/Component/Profiler/Proxies/WebProfiler.php b/src/Viserio/Component/Profiler/Proxies/Profiler.php similarity index 78% rename from src/Viserio/Component/Profiler/Proxies/WebProfiler.php rename to src/Viserio/Component/Profiler/Proxies/Profiler.php index db35750ac..81322d457 100644 --- a/src/Viserio/Component/Profiler/Proxies/WebProfiler.php +++ b/src/Viserio/Component/Profiler/Proxies/Profiler.php @@ -4,7 +4,7 @@ use Viserio\Component\StaticalProxy\StaticalProxy; -class WebProfiler extends StaticalProxy +class Profiler extends StaticalProxy { /** * {@inheritdoc} @@ -13,6 +13,6 @@ class WebProfiler extends StaticalProxy */ public static function getInstanceIdentifier() { - return 'web_profiler'; + return 'profiler'; } } diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler-grid.css b/src/Viserio/Component/Profiler/Resources/css/profiler-grid.css index 9e9e86eed..8c7c0ccc8 100644 --- a/src/Viserio/Component/Profiler/Resources/css/profiler-grid.css +++ b/src/Viserio/Component/Profiler/Resources/css/profiler-grid.css @@ -11,44 +11,21 @@ display: table; clear: both; } -.profiler .row { padding-bottom: 0em; +.profiler .row { + display: -webkit-flex; + display: -ms-flexbox; + display: flex; } .profiler .col { - display: block; - float: left; - width: 100%; + -webkit-flex: 1; + -ms-flex: 1; + flex: 1; } -@media ( min-width : 768px ) { - .profiler .gutters .col { - margin-left: 2%; +@media (max-width : 480px) { + .profiler .row { + display: block; } - .profiler .gutters .col:first-child { - margin-left: 0; + .profiler .col { + width: 100%; } } -@media ( min-width : 768px ) { - .profiler .span_1 { width: 8.33333333333%; } - .profiler .span_2 { width: 16.6666666667%; } - .profiler .span_3 { width: 25%; } - .profiler .span_4 { width: 33.3333333333%; } - .profiler .span_5 { width: 41.6666666667%; } - .profiler .span_6 { width: 50%; } - .profiler .span_7 { width: 58.3333333333%; } - .profiler .span_8 { width: 66.6666666667%; } - .profiler .span_9 { width: 75%; } - .profiler .span_10 { width: 83.3333333333%; } - .profiler .span_11 { width: 91.6666666667%; } - .profiler .span_12 { width: 100%; } - .profiler .gutters .span_1 { width: 6.5%; } - .profiler .gutters .span_2 { width: 15.0%; } - .profiler .gutters .span_3 { width: 23.5%; } - .profiler .gutters .span_4 { width: 32.0%; } - .profiler .gutters .span_5 { width: 40.5%; } - .profiler .gutters .span_6 { width: 49.0%; } - .profiler .gutters .span_7 { width: 57.5%; } - .profiler .gutters .span_8 { width: 66.0%; } - .profiler .gutters .span_9 { width: 74.5%; } - .profiler .gutters .span_10 { width: 83.0%; } - .profiler .gutters .span_11 { width: 91.5%; } - .profiler .gutters .span_12 { width: 100%; } -} diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler.css b/src/Viserio/Component/Profiler/Resources/css/profiler.css index 1d5a2e502..1cac3a3ee 100644 --- a/src/Viserio/Component/Profiler/Resources/css/profiler.css +++ b/src/Viserio/Component/Profiler/Resources/css/profiler.css @@ -1,15 +1,18 @@ :root { - --main-font-color: #eee; - --main-profiler-background-color: #212121; - --main-menu-background-color: #424242; - --main-status-default-color: #666; - --main-status-red-color: #b71c1c; - --main-status-yellow-color: #fdd835; - --main-status-green-color: #7cb342; - --main-tab-default-color: #2b2a28; - --main-tab-active-color: #fff; - --main-tab-active-font-color: #2b2a28; - --main-tab-counter-color: #2b2a28; + --profiler-font-color: #eee; + --profiler-second-font-color: #2b2a28; + --profiler-profiler-background-color: #212121; + --profiler-menu-background-active-color: #424242; + --profiler-status-default-color: #666; + --profiler-status-red-color: #b71c1c; + --profiler-status-yellow-color: #fdd835; + --profiler-status-green-color: #7cb342; + --profiler-tab-default-color: #424242; + --profiler-tab-active-color: #fff; + --profiler-tab-active-font-color: #2b2a28; + --profiler-tab-counter-color: #424242; + --profiler-table-head-background-color: #424242; + --profiler-table-body-background-color: #fff; } .profiler { @@ -31,6 +34,18 @@ -moz-osx-font-smoothing: auto; } + +.profiler ::-webkit-scrollbar-track { + background-color: #FFF; +} +.profiler ::-webkit-scrollbar { + width: 10px; + background-color: #F5F5F5; +} +.profiler ::-webkit-scrollbar-thumb { + background-color: var(--profiler-tab-default-color); +} + .profiler .profiler-header.hide, .profiler .profiler-body .profiler-panel .selected-content { display: none; @@ -49,7 +64,7 @@ bottom: 0; left: 0; - background-color: var(--main-profiler-background-color); + background-color: var(--profiler-profiler-background-color); } .profiler .profiler-show-button { @@ -69,7 +84,7 @@ cursor: pointer; border-top-left-radius: 4px; - background-color: var(--main-profiler-background-color); + background-color: var(--profiler-profiler-background-color); } .profiler .profiler-header .profiler-hide-button, .profiler .profiler-body .profiler-body-close-panel, @@ -83,7 +98,7 @@ cursor: pointer; text-align: center; - background: var(--main-menu-background-color); + background: var(--profiler-menu-background-active-color); } .profiler .profiler-header .profiler-hide-button svg, .profiler .profiler-header .profiler-menus .profiler-menu svg { @@ -116,7 +131,7 @@ vertical-align: middle; color: #fff; - background-color: var(--main-status-default-color); + background-color: var(--profiler-status-default-color); } .profiler .profiler-header .profiler-menus .profiler-menu .status-red + .status-red, .profiler .profiler-header .profiler-menus .profiler-menu .status-yellow + .status-yellow, @@ -124,21 +139,21 @@ border-left: 5px solid #444; } .profiler .profiler-header .profiler-menus .profiler-menu .status-green { - background-color: var(--main-status-green-color); + background-color: var(--profiler-status-green-color); } .profiler .profiler-header .profiler-menus .profiler-menu .status-yellow { color: #fff; - background-color: var(--main-status-yellow-color); + background-color: var(--profiler-status-yellow-color); } .profiler .profiler-header .profiler-menus .profiler-menu .status-red { - background-color: var(--main-status-red-color); + background-color: var(--profiler-status-red-color); } .profiler .profiler-header .profiler-menus .profiler-menu.active, .profiler .profiler-header .profiler-menus .profiler-menu:hover { position: relative; z-index: 10002; - background-color: var(--main-menu-background-color); + background-color: var(--profiler-menu-background-active-color); } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover { cursor: help; @@ -163,7 +178,7 @@ word-wrap: break-word; - background-color: var(--main-menu-background-color); + background-color: var(--profiler-menu-background-active-color); } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group { margin-bottom: 4px; @@ -196,7 +211,7 @@ display: table-cell; - color: var(--main-font-color); + color: var(--profiler-font-color); } .profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip .profiler-menu-tooltip-group a { color: #fff; @@ -234,7 +249,7 @@ padding: 0; - color: var(--main-font-color); + color: var(--profiler-font-color); } .profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-icon .profiler-menu-value { margin-left: 4px; @@ -249,8 +264,8 @@ height: 324px; margin-bottom: 36px; - background-color: var(--main-profiler-background-color); - color: var(--main-font-color); + background-color: var(--profiler-profiler-background-color); + color: var(--profiler-font-color); } .profiler .profiler-body pre { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace; @@ -288,13 +303,8 @@ .profiler .profiler-body .profiler-panel .profiler-tabs { position: relative; - display: block; - min-height: 180px; } -.profiler .profiler-body .profiler-panel .profiler-tabs-tab { - display: inline-block; -} .profiler .profiler-body .profiler-panel .profiler-tabs-tab label { display: block; @@ -306,7 +316,7 @@ color: #fff; border-bottom: 3px solid #fff; - background: var(--main-tab-default-color); + background: var(--profiler-tab-default-color); } .profiler .profiler-body .profiler-panel .profiler-tabs-tab label span.counter { display: inline-block; @@ -320,7 +330,7 @@ text-align: center; vertical-align: middle; - color: var(--main-tab-active-font-color); + color: var(--profiler-tab-active-font-color); background-color: #fff; } .profiler .profiler-body .profiler-panel .profiler-tabs-tab [type=radio] { @@ -342,7 +352,7 @@ overflow-y: auto; - height: 236px; + height: 247px; padding: 15px 15px 0 15px; opacity: 0; @@ -350,12 +360,12 @@ .profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label { z-index: 2; - color: var(--main-tab-active-font-color); - background: var(--main-tab-active-color); + color: var(--profiler-tab-active-font-color); + background: var(--profiler-tab-active-color); } .profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label span.counter { - color: var(--main-tab-active-color); - background: var(--main-tab-counter-color); + color: var(--profiler-tab-active-color); + background: var(--profiler-tab-counter-color); } .profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label ~ .profiler-tabs-tab-content { z-index: 1; @@ -377,15 +387,17 @@ vertical-align: top; - background: #fff; + background: var(--profiler-table-body-background-color); } .profiler .profiler-body .profiler-panel table { width: 100%; margin: 0; - background: #fff; box-shadow: 0 0 1px rgba(128, 128, 128, .2); } +.profiler .profiler-body .profiler-panel table:last-child { + margin-bottom: 25px; +} .profiler .profiler-body .profiler-panel table + table { margin-top: 30px; } @@ -401,7 +413,7 @@ } .profiler .profiler-body .profiler-panel table thead th { color: #fff; - background-color: #2b2a28; + background-color: var(--profiler-table-head-background-color); } .profiler .profiler-body .profiler-panel table thead th.key { width: 19%; @@ -413,7 +425,7 @@ font-size-adjust: .5; color: #2b2a28; - border: 1px solid #e0e0e0; + border: 1px solid var(--profiler-table-body-background-color); border-width: 1px 0; } .profiler .profiler-body .profiler-panel table tbody td { @@ -440,7 +452,7 @@ text-align: center; color: #fff; - border: 4px dashed #e0e0e0; + border: 4px dashed var(--profiler-table-body-background-color); } .profiler .profiler-body .profiler-panel .metrics { diff --git a/src/Viserio/Component/Profiler/Resources/js/profiler.js b/src/Viserio/Component/Profiler/Resources/js/profiler.js index 2f0e16b99..ceb23af89 100644 --- a/src/Viserio/Component/Profiler/Resources/js/profiler.js +++ b/src/Viserio/Component/Profiler/Resources/js/profiler.js @@ -25,6 +25,7 @@ if (typeof(Profiler) == 'undefined') { var panelClass = panelBodyClass + ' .profiler-panel'; var menuHasPanel = '.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-panel'; var bodyMenu = panelBodyClass + ' .profiler-body-menu'; + var profilerHeader = '.profiler .profiler-header'; var getPreference = function(name) { if (!window.localStorage) { return null; @@ -105,7 +106,7 @@ if (typeof(Profiler) == 'undefined') { openPanel = false; $('.profiler .profiler-body, ' + panelClass).removeClass('active'); - $('.profiler .profiler-header').addClass('hide'); + $(profilerHeader).addClass('hide'); $('.profiler .profiler-show-button').addClass('active'); }); @@ -113,7 +114,7 @@ if (typeof(Profiler) == 'undefined') { $('.profiler .profiler-show-button').on('click', function(e) { e.preventDefault(); - $('.profiler .profiler-header').removeClass('hide'); + $(profilerHeader).removeClass('hide'); $('.profiler .profiler-show-button').removeClass('active'); }); }; @@ -141,19 +142,20 @@ if (typeof(Profiler) == 'undefined') { Profiler.resize = function() { var resizeIsActive = false; - var panelHeight = $(window).height() - 38; - var tabContentHeight = $(panelBodyClass).height() - 87; - $(bodyMenu + ' .profiler-body-resize-panel').on('click', function(e) { + $(bodyMenu + ' .profiler-body-resize-panel').on('click', function (e) { if (resizeIsActive) { resizeIsActive = false; $(panelBodyClass).height(null); - $('.profiler-tabs-tab-content').height(null); + $(panelClass + ' .profiler-tabs .profiler-tabs-tab-content').height(null); $(this).removeClass('orginal-size-panel'); } else { + var panelHeight = $(window).height() - 38; + var contentHeight = $(window).height() - $(panelClass + ' .profiler-tabs').height() + ($(profilerHeader).height() + $(bodyMenu).height()); + resizeIsActive = true; - resizeBodyAndTabContent(panelHeight, tabContentHeight); + resizeBodyAndTabContent(panelHeight, $(window).height() + $(bodyMenu).height() - $(panelClass + ' .profiler-tabs').height() + $(profilerHeader).height() + 4); $(this).addClass('orginal-size-panel'); } @@ -161,7 +163,10 @@ if (typeof(Profiler) == 'undefined') { $(window).resize(function() { if (resizeIsActive) { - resizeBodyAndTabContent(panelHeight, tabContentHeight); + var panelHeight = $(window).height() - 38; + var contentHeight = $(window).height() - $(panelClass + ' .profiler-tabs').height() + ($(profilerHeader).height() + $(bodyMenu).height()); + + resizeBodyAndTabContent(panelHeight, contentHeight); } }); }; diff --git a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php index 8e7a8985b..768047097 100644 --- a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php +++ b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php @@ -52,7 +52,7 @@
-
+
From 05c0bc381dd3a527d73a41f8441c24f032140644 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Mon, 24 Apr 2017 22:54:12 +0000 Subject: [PATCH 20/99] Apply fixes from StyleCI --- .../TwigBridgeDataCollectorsServiceProvider.php | 2 +- .../DataCollectors/ViserioHttpDataCollector.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php index f794fcbf2..cd983f0f7 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeDataCollectorsServiceProvider.php @@ -35,7 +35,7 @@ public function getServices() return new Twig_Profiler_Profile(); }, TwigEnvironment::class => [self::class, 'createTwigEnvironment'], - ProfilerContract::class => [self::class, 'createProfiler'], + ProfilerContract::class => [self::class, 'createProfiler'], ]; } diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 5bbfc35fb..e6ecb3a0d 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -184,7 +184,7 @@ public function getPanel(): string ) . $this->createTable( $request->getParsedBody() ?? [], [ - 'name' => 'Post Parameters', + 'name' => 'Post Parameters', 'empty_text' => 'No POST parameters', ] ) . $this->createTable( @@ -216,7 +216,7 @@ public function getPanel(): string $this->splitOnAttributeDelimiter($request->getHeaderLine('Cookie')), [ 'name' => 'Request Cookies', - 'empty_text' => 'No request cookies' + 'empty_text' => 'No request cookies', ] ) . $this->createTable( array_map(function ($setCookieString) { @@ -224,7 +224,7 @@ public function getPanel(): string }, $response->getHeader('Set-Cookie')), [ 'name' => 'Response Cookies', - 'empty_text' => 'No response cookies' + 'empty_text' => 'No response cookies', ] ), ], @@ -233,7 +233,7 @@ public function getPanel(): string 'content' => $this->createTable( $sessionMeta, [ - 'name' => 'Session Metadata', + 'name' => 'Session Metadata', 'empty_text' => 'No session metadata', ] ) . $this->createTable( @@ -250,7 +250,7 @@ public function getPanel(): string $session !== null ? $session->get('_flash') : [], [ 'name' => 'Flashes', - 'empty_text' => 'No flash messages were created' + 'empty_text' => 'No flash messages were created', ] ), ], From 1b05fd012e12d1343c4aa695360adc698ab65b4e Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 23 Apr 2017 20:53:53 +0200 Subject: [PATCH 21/99] changes --- .../Foundation/DataCollectors/NarrowsparkDataCollector.php | 1 + .../Component/Foundation/Http/Events/KernelResponseEvent.php | 5 +---- src/Viserio/Component/Foundation/Http/Kernel.php | 1 + .../Component/Profiler/Middleware/ProfilerMiddleware.php | 1 + src/Viserio/Component/Routing/Events/RouteMatchedEvent.php | 2 ++ 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php index f679d1cc8..4e5bdf804 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php @@ -8,6 +8,7 @@ use Viserio\Component\Foundation\AbstractKernel; use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; use Viserio\Component\Support\Env; +use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; class NarrowsparkDataCollector extends PhpInfoDataCollector implements TooltipAwareContract { diff --git a/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php b/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php index adeea6275..44c9be11c 100644 --- a/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php +++ b/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php @@ -48,12 +48,9 @@ public function setResponse(ResponseInterface $response): void /** * Get a modified or original response. * - * @param \Psr\Http\Message\ResponseInterface $response - * @param mixed $value - * * @return \Psr\Http\Message\ResponseInterface */ - public function getResponse($value='') + public function getResponse() { return $this->response ?? $this->parameters['response']; } diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index 28556985f..97f494cf0 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -25,6 +25,7 @@ use Viserio\Component\Session\Middleware\StartSessionMiddleware; use Viserio\Component\StaticalProxy\StaticalProxy; use Viserio\Component\View\Middleware\ShareErrorsFromSessionMiddleware; +use Viserio\Component\Profiler\Middleware\ProfilerMiddleware; class Kernel extends AbstractKernel implements HttpKernelContract, TerminableContract { diff --git a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php index 81be9ab2c..8d9a7057f 100644 --- a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php +++ b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php @@ -8,6 +8,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; +use Interop\Container\ContainerInterface; class ProfilerMiddleware implements MiddlewareInterface { diff --git a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php index 1e8719cfb..b11bf3c22 100644 --- a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php +++ b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php @@ -6,6 +6,8 @@ use Viserio\Component\Contracts\Routing\Route as RouteContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Events\Traits\EventTrait; +use Viserio\Component\Contracts\Routing\Router as RouterContract; +use Viserio\Component\Contracts\Routing\Route as RouteContract; class RouteMatchedEvent implements EventContract { From 96edddbf98a85f2ffe1ac7cfc855f0ec60aa83b6 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 23 Apr 2017 18:54:23 +0000 Subject: [PATCH 22/99] Apply fixes from StyleCI --- .../Foundation/DataCollectors/NarrowsparkDataCollector.php | 1 - src/Viserio/Component/Foundation/Http/Kernel.php | 1 - .../Component/Profiler/Middleware/ProfilerMiddleware.php | 1 - src/Viserio/Component/Routing/Events/RouteMatchedEvent.php | 2 -- 4 files changed, 5 deletions(-) diff --git a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php index 4e5bdf804..f679d1cc8 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php @@ -8,7 +8,6 @@ use Viserio\Component\Foundation\AbstractKernel; use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; use Viserio\Component\Support\Env; -use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; class NarrowsparkDataCollector extends PhpInfoDataCollector implements TooltipAwareContract { diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index 97f494cf0..28556985f 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -25,7 +25,6 @@ use Viserio\Component\Session\Middleware\StartSessionMiddleware; use Viserio\Component\StaticalProxy\StaticalProxy; use Viserio\Component\View\Middleware\ShareErrorsFromSessionMiddleware; -use Viserio\Component\Profiler\Middleware\ProfilerMiddleware; class Kernel extends AbstractKernel implements HttpKernelContract, TerminableContract { diff --git a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php index 8d9a7057f..81be9ab2c 100644 --- a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php +++ b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php @@ -8,7 +8,6 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract; -use Interop\Container\ContainerInterface; class ProfilerMiddleware implements MiddlewareInterface { diff --git a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php index b11bf3c22..1e8719cfb 100644 --- a/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php +++ b/src/Viserio/Component/Routing/Events/RouteMatchedEvent.php @@ -6,8 +6,6 @@ use Viserio\Component\Contracts\Routing\Route as RouteContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; use Viserio\Component\Events\Traits\EventTrait; -use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\Routing\Route as RouteContract; class RouteMatchedEvent implements EventContract { From f83b1175e1802e7747b24bde05e9b2224118d8bc Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Tue, 25 Apr 2017 23:38:24 +0200 Subject: [PATCH 23/99] readme update --- src/Viserio/Component/Profiler/README.md | 41 +++++++++++--------- src/Viserio/Component/Profiler/composer.json | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Viserio/Component/Profiler/README.md b/src/Viserio/Component/Profiler/README.md index 42ad16888..3bc4b66e3 100644 --- a/src/Viserio/Component/Profiler/README.md +++ b/src/Viserio/Component/Profiler/README.md @@ -1,33 +1,36 @@ -# Viserio Profiler package +

Viserio Profiler Component

+

+ + + + + +

-This package is part of the [Narrowspark framework](http://github.com/narrowspark/framework). -[![Author](http://img.shields.io/badge/author-@anolilab-blue.svg?style=flat-square)](https://twitter.com/anolilab) -[![Quality Score](https://img.shields.io/scrutinizer/g/narrowspark/framework.svg?style=flat-square)](https://scrutinizer-ci.com/g/narrowspark/framework/code-structure/master) -[![Build Status](https://api.travis-ci.org/narrowspark/framework.svg?branch=master&style=flat-square)](https://travis-ci.org/narrowspark/framework) -[![Latest Version](https://img.shields.io/packagist/v/narrowspark/framework.svg?style=flat-square)](https://github.com/narrowspark/framework/releases) -[![Minimum PHP Version](https://img.shields.io/badge/php-%5E7.1.0-8892BF.svg?style=flat-square)](https://php.net/) -[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -> **Note:** If you want to build an application using Narrowspark, visit the main [![Source Code](http://img.shields.io/badge/source-narrowspark/narrowspark-blue.svg?style=flat-square)](https://github.com/narrowspark/narrowspark). +> **Note:** This package is part of the [Narrowspark framework](http://github.com/narrowspark/framework).
If you want to build an application using Narrowspark, visit the main [source](https://github.com/narrowspark/framework). -## Contributing - -Issues for this package shall be posted on [Narrowspark framework issues](http://github.com/narrowspark/framework/issues). -Thank you for considering contributing to the Narrowspark framework! The contribution guide can be found in the [Narrowspark documentation](http://narrowspark.de/docs/contributions). - -## Installation +Installation +------------- Use [Composer](https://getcomposer.org/) to install this package: ```sh -composer require viserio/web-profiler +composer require viserio/profiler ``` -## Official Documentation +Official Documentation +------------- + +Documentation for the framework can be found on the [Narrowspark website](http://narrowspark.com/docs). -Documentation for the framework can be found on the [Narrowspark website](http://narrowspark.de/docs). +Contributing +------------- +Issues for this package shall be posted on [Narrowspark framework issues](http://github.com/narrowspark/framework/issues).
+Thank you for considering contributing to the Narrowspark framework! The contribution guide can be found in the [Narrowspark contributing](/CONTRIBUTING.md). -### License +License +------------- The Narrowspark framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). diff --git a/src/Viserio/Component/Profiler/composer.json b/src/Viserio/Component/Profiler/composer.json index 7ee03c9aa..eba22f1c2 100644 --- a/src/Viserio/Component/Profiler/composer.json +++ b/src/Viserio/Component/Profiler/composer.json @@ -2,7 +2,7 @@ "name" : "viserio/profiler", "type" : "library", "description": "The Viserio Profiler package.", - "keywords" : ["narrowspark", "viserio", "profiler", "web-profiler"], + "keywords" : ["narrowspark", "viserio", "profiler", "web-profiler", "debugbar"], "license" : "MIT", "homepage" : "http://github.com/narrowspark/framework", "support" : { From 70f93163c1db8c4c8fbebb943ff50f5eda50d725 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Tue, 25 Apr 2017 23:58:32 +0200 Subject: [PATCH 24/99] remove stopwatch --- composer.json | 1 - src/Viserio/Component/Profiler/composer.json | 1 - 2 files changed, 2 deletions(-) diff --git a/composer.json b/composer.json index aa43172c3..44ed1bb98 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,6 @@ "symfony/polyfill-mbstring" : "^1.0", "symfony/polyfill-intl-icu" : "^1.0", "symfony/process" : "^3.2", - "symfony/stopwatch" : "^3.2", "symfony/var-dumper" : "^3.2", "swiftmailer/swiftmailer" : "^5.4", "vlucas/phpdotenv" : "^2.3" diff --git a/src/Viserio/Component/Profiler/composer.json b/src/Viserio/Component/Profiler/composer.json index eba22f1c2..8e590339f 100644 --- a/src/Viserio/Component/Profiler/composer.json +++ b/src/Viserio/Component/Profiler/composer.json @@ -22,7 +22,6 @@ "http-interop/http-factory" : "^0.3", "psr/cache" : "^1.0", "psr/http-message" : "^1.0", - "symfony/stopwatch" : "^3.2", "symfony/var-dumper" : "^3.2", "viserio/contracts" : "self.version", "viserio/support" : "self.version" From ef8cb1fe2fb5bf27e990d730fdfbabff5c2d4a41 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Wed, 26 Apr 2017 00:09:52 +0200 Subject: [PATCH 25/99] using given server request --- .../DataCollectors/ViserioHttpDataCollector.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index e6ecb3a0d..3e9b2ea9d 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -64,9 +64,8 @@ class ViserioHttpDataCollector extends AbstractDataCollector implements */ public function __construct(RouterContract $router, RepositoryContract $config) { - $this->route = $router->getCurrentRoute(); - $this->serverRequest = $this->route->getServerRequest(); - $this->config = $config; + $this->route = $router->getCurrentRoute(); + $this->config = $config; } /** @@ -74,7 +73,8 @@ public function __construct(RouterContract $router, RepositoryContract $config) */ public function collect(ServerRequestInterface $serverRequest, ResponseInterface $response): void { - $this->response = $response; + $this->response = $response; + $this->serverRequest = $serverRequest; $sessions = []; From 1bd17698c43443ffdd0d3015fdc058b6174231d3 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Fri, 5 May 2017 00:28:02 +0200 Subject: [PATCH 26/99] added tfold | rename all.sh to before_install.sh (#524) fixes #525 --- .travis.yml | 10 ++-- appveyor.yml | 2 +- build/travis/{all.sh => before_install.sh} | 0 build/travis/script.sh | 46 ++++++++++++------- phpunit.xml.dist | 4 +- ...lationDataCollectorServiceProviderTest.php | 1 + 6 files changed, 41 insertions(+), 22 deletions(-) rename build/travis/{all.sh => before_install.sh} (100%) diff --git a/.travis.yml b/.travis.yml index 5ed3ef716..d16585dca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: php sudo: false +env: + global: + - TEST="./vendor/bin/phpunit" + services: - memcached - mongodb @@ -24,7 +28,7 @@ matrix: env: SETUP=stable PHPUNIT=true - php: 7.1 env: SETUP=lowest PHPUNIT=true - # PHPSTAN + # phpstan - php: 7.1 env: SETUP=basic PHPSTAN=true # Nightly @@ -46,8 +50,8 @@ cache: before_install: - mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d - - chmod a+x ./build/travis/all.sh && chmod a+x ./build/travis/script.sh && chmod a+x ./build/travis/after_success.sh - - ./build/travis/all.sh + - chmod a+x ./build/travis/before_install.sh && chmod a+x ./build/travis/script.sh && chmod a+x ./build/travis/after_success.sh + - ./build/travis/before_install.sh install: - if [[ "$SETUP" = "basic" ]]; then travis_retry composer install --no-interaction --prefer-dist --no-progress --profile --no-suggest; fi diff --git a/appveyor.yml b/appveyor.yml index e6408b5bc..224f144b6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -40,7 +40,7 @@ init: install: # Install redis and start - - nuget install redis-64 -excludeversion + - nuget install redis-64 -excludeversion -Verbosity quiet - redis-64\tools\redis-server.exe --service-install - redis-64\tools\redis-server.exe --service-start # PHP diff --git a/build/travis/all.sh b/build/travis/before_install.sh similarity index 100% rename from build/travis/all.sh rename to build/travis/before_install.sh diff --git a/build/travis/script.sh b/build/travis/script.sh index 36ed01630..c2bdd9140 100644 --- a/build/travis/script.sh +++ b/build/travis/script.sh @@ -1,21 +1,35 @@ #!/usr/bin/env bash -# Create logs dir -mkdir -p build/logs -#!/bin/bash +# tfold is a helper to create folded reports +# Arguments: +# $1 fold name +# $2 command to execute +tfold () { + title=$1 + fold=$(echo $title | sed -r 's/[^-_A-Za-z\d]+/./g') + shift + echo -e "travis_fold:start:$fold\\n\\e[1;34m$title\\e[0m" + bash -xc "$*" 2>&1 && echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold" || ( echo -e "\\e[41mKO\\e[0m $title\\n" && exit 1 ) +} +export -f tfold -set +e -bash -e < - + ./src/Viserio/Bridge/Twig/Tests diff --git a/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php b/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php index d5bde55dc..e6ee34bc1 100644 --- a/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php @@ -49,6 +49,7 @@ public function testProvider() $container->instance('config', [ 'viserio' => [ 'webprofiler' => [ + 'enable' => true, 'collector' => [ 'translation' => true, ], From bd234480e2f0a5d9d6ccc1d037ad3a35a3665f37 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Fri, 5 May 2017 00:40:44 +0200 Subject: [PATCH 27/99] fix wrong dispatcher call in http kernel --- src/Viserio/Component/Foundation/Http/Kernel.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index 9ff01f707..a25d7c25f 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -244,11 +244,12 @@ protected function renderException( */ protected function sendRequestThroughRouter(ServerRequestInterface $request): ResponseInterface { - $container = $this->getContainer(); - $router = $container->get(RouterContract::class); + $container = $this->getContainer(); + $router = $container->get(RouterContract::class); + $dispatcher = $container->get(DispatcherContract::class); - $router->setCachePath($this->getStoragePath('framework/routes.cache.php')); - $router->refreshCache($this->options['app']['env'] !== 'production'); + $dispatcher->setCachePath($this->getStoragePath('framework/routes.cache.php')); + $dispatcher->refreshCache($this->options['app']['env'] !== 'production'); return (new Pipeline()) ->setContainer($container) From 08f21b08b77b40d9a8ff591912bbcc5e6eee4354 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Fri, 5 May 2017 00:40:52 +0200 Subject: [PATCH 28/99] fix datacollector --- .../ViserioHttpDataCollector.php | 39 +------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 3e9b2ea9d..3c7ec2789 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -308,47 +308,12 @@ protected function getRouteInformation(RouteContract $route): array $result['file'] = $filename . ': ' . $reflector->getStartLine() . ' - ' . $reflector->getEndLine(); } - $middlewares = $route->gatherMiddleware(); - - if ($middleware = $this->getMiddlewares($middlewares)) { - $result['middlewares'] = $middleware; - } - - if ($middleware = $this->getWithoutMiddlewares($middlewares)) { - $result['without_middlewares'] = $middleware; - } + $result['middlewares'] = implode(', ', $route->gatherMiddleware()); + $result['without_middlewares'] = implode(', ', $route->gatherDisabledMiddlewares()); return $result; } - /** - * Get middleware. - * - * @param array $middlewares - * - * @return string - */ - protected function getMiddlewares(array $middlewares): string - { - $middleware = array_keys($middlewares['middlewares']); - - return implode(', ', $middleware); - } - - /** - * Get without middleware. - * - * @param array $middlewares - * - * @return string - */ - protected function getWithoutMiddlewares(array $middlewares): string - { - $middleware = array_keys($middlewares['without_middlewares']); - - return implode(', ', $middleware); - } - /** * spplit string on attributes delimiter to array. * From 641dcca19278e6b9aae04516f7172add0889f031 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Thu, 4 May 2017 22:41:03 +0000 Subject: [PATCH 29/99] Apply fixes from StyleCI --- .../Foundation/DataCollectors/ViserioHttpDataCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 3c7ec2789..35f9f50dc 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -308,7 +308,7 @@ protected function getRouteInformation(RouteContract $route): array $result['file'] = $filename . ': ' . $reflector->getStartLine() . ' - ' . $reflector->getEndLine(); } - $result['middlewares'] = implode(', ', $route->gatherMiddleware()); + $result['middlewares'] = implode(', ', $route->gatherMiddleware()); $result['without_middlewares'] = implode(', ', $route->gatherDisabledMiddlewares()); return $result; From f1845e019bf274f31fad489766c2f440e1804505 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Fri, 5 May 2017 00:40:44 +0200 Subject: [PATCH 30/99] fix wrong dispatcher call in http kernel --- src/Viserio/Component/Foundation/Http/Kernel.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php index 5f07b2b45..b0634b3de 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -240,11 +240,12 @@ protected function renderException( */ protected function sendRequestThroughRouter(ServerRequestInterface $request): ResponseInterface { - $container = $this->getContainer(); - $router = $container->get(RouterContract::class); + $container = $this->getContainer(); + $router = $container->get(RouterContract::class); + $dispatcher = $container->get(DispatcherContract::class); - $router->setCachePath($this->getStoragePath('framework/routes.cache.php')); - $router->refreshCache($this->options['app']['env'] !== 'production'); + $dispatcher->setCachePath($this->getStoragePath('framework/routes.cache.php')); + $dispatcher->refreshCache($this->options['app']['env'] !== 'production'); return (new Pipeline()) ->setContainer($container) From 90b704925bac891a959f7ff111ca1038c02fedd3 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 7 May 2017 01:29:18 +0200 Subject: [PATCH 31/99] working on monolog profiler support --- src/Viserio/Component/Http/Stream.php | 4 +- .../Log/DataCollectors/LogParser.php | 152 -------------- .../Log/DataCollectors/LogsDataCollector.php | 116 ----------- .../Log/Providers/LoggerServiceProvider.php | 4 +- .../Tests/DataCollectors/LogParserTest.php | 33 --- .../Bridge/Log/DebugProcessor.php | 68 +++++++ .../Bridge/Log/MonologLoggerDataCollector.php | 191 ++++++++++++++++++ ...erMonologDataCollectorServiceProvider.php} | 62 +++--- .../Resources/views/profiler.html.php | 12 +- .../DataCollectors/LogsDataCollectorTest.php | 6 +- ...nologDataCollectorServiceProviderTest.php} | 17 +- 11 files changed, 308 insertions(+), 357 deletions(-) delete mode 100644 src/Viserio/Component/Log/DataCollectors/LogParser.php delete mode 100644 src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php delete mode 100644 src/Viserio/Component/Log/Tests/DataCollectors/LogParserTest.php create mode 100644 src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/DebugProcessor.php create mode 100644 src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php rename src/Viserio/Component/{Log/Providers/LogsDataCollectorServiceProvider.php => Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php} (59%) rename src/Viserio/Component/{Log => Profiler}/Tests/DataCollectors/LogsDataCollectorTest.php (96%) rename src/Viserio/Component/{Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php => Profiler/Tests/Providers/ProfilerMonologDataCollectorServiceProviderTest.php} (74%) diff --git a/src/Viserio/Component/Http/Stream.php b/src/Viserio/Component/Http/Stream.php index 5d9db9bd2..5e0f961bc 100644 --- a/src/Viserio/Component/Http/Stream.php +++ b/src/Viserio/Component/Http/Stream.php @@ -14,6 +14,8 @@ class Stream implements StreamInterface * Bit mask to determine if the stream is a pipe. * * This is octal as per header stat.h + * + * @var int */ public const FSTAT_MODE_S_IFIFO = 0010000; @@ -137,8 +139,6 @@ public function __destruct() } /** - * @var string - * * @param mixed $name * * @throws \RuntimeException|\BadMethodCallException diff --git a/src/Viserio/Component/Log/DataCollectors/LogParser.php b/src/Viserio/Component/Log/DataCollectors/LogParser.php deleted file mode 100644 index 36d2c8fa6..000000000 --- a/src/Viserio/Component/Log/DataCollectors/LogParser.php +++ /dev/null @@ -1,152 +0,0 @@ -tailFile($path, 124); - } - - $log = $this->parseRawData($raw); - - // @codeCoverageIgnoreStart - if (! is_array($log)) { - return []; - } - // @codeCoverageIgnoreEnd - - $parsed = []; - - foreach ($log as $heading) { - for ($i = 0, $j = count($heading); $i < $j; ++$i) { - $parsed[] = $this->populateEntries($heading, $i); - } - } - - unset($log); - - return array_reverse($parsed); - } - - /** - * Parse raw log data. - * - * @param string $raw - * - * @return array - */ - protected function parseRawData(string $raw): array - { - $pattern = '/\[' . self::REGEX_DATE_PATTERN . '\ ' . self::REGEX_TIME_PATTERN . '\].*/'; - - preg_match_all($pattern, $raw, $log); - - return $log; - } - - /** - * Populate entries. - * - * @param array $heading - * @param int $key - * - * @return array - */ - protected function populateEntries(array $heading, int $key): array - { - foreach (self::$levels as $level => $monologLevel) { - if (mb_strpos(mb_strtolower($heading[$key]), mb_strtolower('.' . $level)) !== false) { - return [ - $level, - $heading[$key], - ]; - } - } - } - - /** - * By Ain Tohvri (ain). - * - * @link http://tekkie.flashbit.net/php/tail-functionality-in-php - * - * @param string $file - * @param int $lines - * - * @return array - * - * @codeCoverageIgnore - */ - protected function tailFile(string $file, int $lines): array - { - $handle = fopen($file, 'r'); - $linecounter = $lines; - $pos = -2; - $beginning = false; - $text = []; - - while ($linecounter > 0) { - $t = ' '; - - while ($t != "\n") { - if (fseek($handle, $pos, SEEK_END) == -1) { - $beginning = true; - break; - } - - $t = fgetc($handle); - --$pos; - } - - --$linecounter; - - if ($beginning) { - rewind($handle); - } - - $text[$lines - $linecounter - 1] = fgets($handle); - - if ($beginning) { - break; - } - } - - fclose($handle); - - return array_reverse($text); - } -} diff --git a/src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php b/src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php deleted file mode 100644 index c0ce2c10d..000000000 --- a/src/Viserio/Component/Log/DataCollectors/LogsDataCollector.php +++ /dev/null @@ -1,116 +0,0 @@ -logParser = $logParser; - $this->storages = (array) $storages; - } - - /** - * {@inheritdoc} - */ - public function getMenu(): array - { - return [ - 'label' => 'Logs', - 'value' => $this->data['counted'], - ]; - } - - /** - * {@inheritdoc} - */ - public function getPanel(): string - { - $html = ''; - $logs = []; - - foreach ($this->data['messages'] as $file) { - $name = ''; - - foreach ($this->storages as $storage) { - $name = $this->stripBasePath($storage, $file); - } - - $logs[str_replace('.log', '', $name)] = $this->createTable( - $this->logParser->parse($file), - ['headers' => ['Type', 'Message']] - ); - } - - $html .= $this->createDropdownMenuContent($logs); - - return $html; - } - - /** - * Get counted logs. - * - * @return int - */ - public function getCountedLogs(): int - { - return $this->data['counted'] ?? 0; - } - - /** - * {@inheritdoc} - */ - public function getMessages(): array - { - $files = []; - - foreach ($this->storages as $storage) { - $files = array_merge($files, glob($storage . '*.{log,txt}', GLOB_BRACE)); - } - - $files = array_reverse($files); - $files = array_filter($files, 'is_file'); - - return array_values($files); - } - - /** - * Remove the base path from the paths, so they are relative to the base. - * - * @param string $storage - * @param string $path - * - * @return string - */ - protected function stripBasePath(string $storage, string $path): string - { - $storage = str_replace('*', '', $storage); - - return ltrim(str_replace($storage, '', $path), '/'); - } -} diff --git a/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php b/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php index a646256d9..83c31feb7 100644 --- a/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php +++ b/src/Viserio/Component/Log/Providers/LoggerServiceProvider.php @@ -32,7 +32,7 @@ class LoggerServiceProvider implements public function getServices() { return [ - MonologWriter::class => [self::class, 'createLogger'], + MonologWriter::class => [self::class, 'createMonologWriter'], HandlerParser::class => [self::class, 'createHandlerParser'], 'log' => function (ContainerInterface $container) { return $container->get(MonologWriter::class); @@ -91,7 +91,7 @@ public static function createHandlerParser(ContainerInterface $container): Handl * * @return \Viserio\Component\Log\Writer */ - public static function createLogger(ContainerInterface $container): MonologWriter + public static function createMonologWriter(ContainerInterface $container): MonologWriter { $logger = new MonologWriter($container->get(HandlerParser::class)); diff --git a/src/Viserio/Component/Log/Tests/DataCollectors/LogParserTest.php b/src/Viserio/Component/Log/Tests/DataCollectors/LogParserTest.php deleted file mode 100644 index e5917af49..000000000 --- a/src/Viserio/Component/Log/Tests/DataCollectors/LogParserTest.php +++ /dev/null @@ -1,33 +0,0 @@ -removeId([ - [ - 'error', - '[2017-01-03 18:58:03] develop.ERROR: Viserio\Contracts\Container\Exceptions\NotFoundException: Abstract (Viserio\Translation\DataCollectors\ViserioTranslationDataCollector) is not being managed by the container in \src\Viserio\Container\Container.php:378 Stack trace: #0 \src\Viserio\WebProfiler\Providers\WebProfilerServiceProvider.php(131): Viserio\Container\Container->get(\'Viserio\\\\Transla...\') #1 \src\Viserio\WebProfiler\Providers\WebProfilerServiceProvider.php(68): Viserio\WebProfiler\Providers\WebProfilerServiceProvider::registerCollectorsFromConfig(Object(Viserio\Foundation\Application), Object(Viserio\WebProfiler\WebProfiler)) #2 \src\Viserio\Container\Container.php(433): Viserio\WebProfiler\Providers\WebProfilerServiceProvider::createWebProfiler(Object(Viserio\Foundation\Application), NULL) #3 [internal function]: Viserio\Container\Container::Viserio\Container\{closure}(Object(Viserio\Foundation\Application)) #4 \src\Viserio\Container\ContainerResolver.php(131): ReflectionFunction->invokeArgs(Array) #5 \src\Viserio\Container\ContainerResolver.php(37): Viserio\Container\ContainerResolver->resolveFunction(Object(Closure), Array) #6 \src\Viserio\Container\Container.php(621): Viserio\Container\ContainerResolver->resolve(Object(Closure), Array) #7 \src\Viserio\Container\Container.php(260): Viserio\Container\Container->resolveSingleton(\'Viserio\\\\Contrac...\', Array) #8 \src\Viserio\Container\Container.php(232): Viserio\Container\Container->resolveBound(\'Viserio\\\\Contrac...\', Array) #9 \src\Viserio\Container\Container.php(373): Viserio\Container\Container->resolve(\'Viserio\\\\Contrac...\') #10 \src\Viserio\Foundation\Http\Kernel.php(216): Viserio\Container\Container->get(\'Viserio\\\\Contrac...\') #11 \src\Viserio\Foundation\Http\Kernel.php(174): Viserio\Foundation\Http\Kernel->handleRequest(Object(Viserio\Http\ServerRequest)) #12 D:\Anolilab\Github\Php\narrowspark\public\index.php(36): Viserio\Foundation\Http\Kernel->handle(Object(Viserio\Http\ServerRequest)) #13 {main} {"identification":{}} []', - ], - ]), - $this->removeId($parse->parse(__DIR__ . '/../Fixture/test.log')) - ); - } - - private function removeId(array $array): array - { - foreach ($array as $key => $value) { - $array[$key][1] = trim(preg_replace('/"id":"(.*?)"/', '', $value[1])); - } - - return $array; - } -} diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/DebugProcessor.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/DebugProcessor.php new file mode 100644 index 000000000..db4634321 --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/DebugProcessor.php @@ -0,0 +1,68 @@ +records[] = [ + 'timestamp' => $record['datetime']->getTimestamp(), + 'message' => $record['message'], + 'priority' => $record['level'], + 'priorityName' => $record['level_name'], + 'context' => $record['context'], + 'channel' => $record['channel'] ?? '', + ]; + + switch ($record['level']) { + case Logger::ERROR: + case Logger::CRITICAL: + case Logger::ALERT: + case Logger::EMERGENCY: + ++$this->errorCount; + } + + return $record; + } + + /** + * Returns an array of logs. + * + * A log is an array with the following mandatory keys: + * timestamp, message, priority, and priorityName. + * It can also have an optional context key containing an array. + * + * @return array + */ + public function getLogs(): array + { + return $this->records; + } + + /** + * Returns the number of errors. + * + * @return int + */ + public function countErrors(): int + { + return $this->errorCount; + } +} diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php new file mode 100644 index 000000000..0609ac0ae --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php @@ -0,0 +1,191 @@ +logger = $logger; + } + + /** + * {@inheritdoc} + */ + public function getMenu(): array + { + return [ + 'label' => 'Logs', + 'value' => $this->data['counted'], + ]; + } + + /** + * {@inheritdoc} + */ + public function getPanel(): string + { + $html = ''; + + $messages = $this->sanitizeLogs($this->getMessages()); + + return $html; + } + + /** + * Get counted logs. + * + * @return int + */ + public function getCountedLogs(): int + { + return $this->data['counted'] ?? 0; + } + + /** + * {@inheritdoc} + */ + public function getMessages(): array + { + if ($logger = $this->getDebugLogger()) { + return $logger->getLogs(); + } + + return []; + } + + /** + * Returns the number of errors. + * + * @return int + */ + private function getCountedErrors(): int + { + if ($logger = $this->getDebugLogger()) { + return $logger->countErrors(); + } + + return 0; + } + + /** + * Returns a DebugProcessor instance if one is registered with this logger. + * + * @return Viserio\Component\Profiler\DataCollectors\Bridge\Log\DebugProcessor|null + */ + private function getDebugLogger(): ?DebugProcessor + { + foreach ($this->logger->getProcessors() as $processor) { + if ($processor instanceof DebugProcessor) { + return $processor; + } + } + + return null; + } + + private function sanitizeLogs(array $logs) + { + $sanitizedLogs = []; + + foreach ($logs as $log) { + if (! $this->isSilencedOrDeprecationErrorLog($log)) { + $sanitizedLogs[] = $log; + continue; + } + + $exception = $log['context']['exception']; + $errorId = md5("{$exception->getSeverity()}/{$exception->getLine()}/{$exception->getFile()}\0{$log['message']}", true); + + if (isset($sanitizedLogs[$errorId])) { + ++$sanitizedLogs[$errorId]['errorCount']; + } else { + $log += [ + 'errorCount' => 1, + 'scream' => $exception instanceof SilencedErrorContext, + ]; + + $sanitizedLogs[$errorId] = $log; + } + } + + return array_values($sanitizedLogs); + } + + private function isSilencedOrDeprecationErrorLog(array $log): bool + { + if (! isset($log['context']['exception'])) { + return false; + } + + $exception = $log['context']['exception']; + + if ($exception instanceof SilencedErrorContext) { + return true; + } + + if ($exception instanceof ErrorException && in_array($exception->getSeverity(), [E_DEPRECATED, E_USER_DEPRECATED], true)) { + return true; + } + + return false; + } + + private function computeErrorsCount() + { + $count = [ + 'error_count' => $this->getCountedErrors(), + 'deprecation_count' => 0, + 'warning_count' => 0, + 'scream_count' => 0, + 'priorities' => [], + ]; + + foreach ($this->getMessages() as $log) { + if (isset($count['priorities'][$log['priority']])) { + ++$count['priorities'][$log['priority']]['count']; + } else { + $count['priorities'][$log['priority']] = [ + 'count' => 1, + 'name' => $log['priorityName'], + ]; + } + + if ('WARNING' === $log['priorityName']) { + ++$count['warning_count']; + } + + if ($this->isSilencedOrDeprecationErrorLog($log)) { + if ($log['context']['exception'] instanceof SilencedErrorContext) { + ++$count['scream_count']; + } else { + ++$count['deprecation_count']; + } + } + } + + ksort($count['priorities']); + + return $count; + } +} diff --git a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php similarity index 59% rename from src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php index a0b789db2..e8fc29f1f 100644 --- a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php @@ -1,22 +1,21 @@ [self::class, 'createLogParser'], - ProfilerContract::class => [self::class, 'createProfiler'], + ProfilerContract::class => [self::class, 'extendProfiler'], + Logger::class => [self::class, 'extendLogger'], ]; } @@ -44,14 +43,6 @@ public function getDimensions(): iterable return ['viserio', 'profiler']; } - /** - * {@inheritdoc} - */ - public function getMandatoryOptions(): iterable - { - return ['logs_storages']; - } - /** * {@inheritdoc} */ @@ -65,42 +56,47 @@ public function getDefaultOptions(): iterable } /** - * Create a handler parser. + * Extend monolog with a processor. * - * @return \Viserio\Component\Log\DataCollectors\LogParser + * @param \Interop\Container\ContainerInterface $container + * @param null|callable $getPrevious + * + * @return null|\Monolog\Logger|\Viserio\Component\Log\Writer */ - public static function createLogParser(): LogParser + public static function extendLogger(ContainerInterface $container, ?callable $getPrevious = null) { - return new LogParser(); + $log = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + + if ($log !== null) { + $log->pushProcessor(new DebugProcessor()); + } + + return $log; } /** - * Extend viserio profiler with data collector. + * Extend viserio profiler with a data collector. * * @param \Interop\Container\ContainerInterface $container * @param null|callable $getPrevious * * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract + public static function extendProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - if ($getPrevious !== null) { - self::resolveOptions($container); + $profiler = is_callable($getPrevious) ? $getPrevious() : $getPrevious; - $profiler = $getPrevious(); + if ($profiler !== null) { + self::resolveOptions($container); if (self::$options['collector']['logs']) { - $profiler->addCollector(new LogsDataCollector( - $container->get(LogParser::class), - self::$options['logs_storages'] - )); + $profiler->addCollector(new MonologLoggerDataCollector($container->get(Logger::class))); } return $profiler; } - // @codeCoverageIgnoreStart - return null; - // @codeCoverageIgnoreEnd + + return $profiler; } /** diff --git a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php index 768047097..8c20c904c 100644 --- a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php +++ b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php @@ -27,23 +27,23 @@ $hasTooltip = $tooltip ? ' profiler-menu-has-tooltip' : ''; $cssClasses = isset($menu['menu']['class']) ? ' ' . $menu['menu']['class'] : ''; ?> -
class="profiler-menu profiler-menu- profiler-menu-position-"> +
class="profiler-menu profiler-menu- profiler-menu-position-">
- + - + - +
- +
@@ -62,7 +62,7 @@
$panel): ?>
- +
diff --git a/src/Viserio/Component/Log/Tests/DataCollectors/LogsDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php similarity index 96% rename from src/Viserio/Component/Log/Tests/DataCollectors/LogsDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php index 1cdf36ab7..b88d08370 100644 --- a/src/Viserio/Component/Log/Tests/DataCollectors/LogsDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php @@ -1,12 +1,12 @@ register(new OptionsResolverServiceProvider()); $container->instance(ServerRequestInterface::class, $this->getRequest()); + $container->register(new OptionsResolverServiceProvider()); $container->register(new HttpFactoryServiceProvider()); $container->register(new ProfilerServiceProvider()); - $container->register(new LogsDataCollectorServiceProvider()); + $container->register(new ProfilerMonologDataCollectorServiceProvider()); $container->instance('config', [ 'viserio' => [ 'profiler' => [ - 'enable' => true, - 'logs_storages' => [__DIR__], - 'collector' => [ + 'enable' => true, + 'collector' => [ 'logs' => true, ], ], ], ]); - self::assertInstanceOf(LogParser::class, $container->get(LogParser::class)); self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); } From 65c5b688f21401e9aca444049749b13ab486bdfc Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 7 May 2017 18:54:21 +0200 Subject: [PATCH 32/99] added monologer collector --- .../ViserioHttpDataCollector.php | 6 +- .../Component/Profiler/AssetsRenderer.php | 1 + .../DataCollectors/AbstractDataCollector.php | 2 +- .../Bridge/Log/MonologLoggerDataCollector.php | 245 ++++++++++++++++-- .../Profiler/Resources/css/profiler.css | 3 + .../icons/ic_library_books_white_24px.svg | 4 + 6 files changed, 234 insertions(+), 27 deletions(-) create mode 100644 src/Viserio/Component/Profiler/Resources/icons/ic_library_books_white_24px.svg diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 35f9f50dc..4a775ac3b 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -108,11 +108,12 @@ public function getMenu(): array $tabInfos = [ 'label' => $statusCode, + 'class' => $status, 'value' => '', ]; if ($this->route !== null && $this->route->getName() !== null) { - $tabInfos = array_merge( + return array_merge( $tabInfos, [ 'label' => '@', @@ -120,10 +121,9 @@ public function getMenu(): array ] ); } elseif ($this->route !== null) { - $tabInfos = array_merge( + return array_merge( $tabInfos, [ - 'class' => $status, 'value' => implode(' | ', $this->route->getMethods()), ] ); diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index 360ac7b79..ad6ee949a 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -49,6 +49,7 @@ class AssetsRenderer implements AssetsRendererContract 'ic_repeat_white_24px.svg' => __DIR__ . '/Resources/icons/ic_repeat_white_24px.svg', 'ic_layers_white_24px.svg' => __DIR__ . '/Resources/icons/ic_layers_white_24px.svg', 'ic_insert_drive_file_white_24px.svg' => __DIR__ . '/Resources/icons/ic_insert_drive_file_white_24px.svg', + 'ic_library_books_white_24px.svg' => __DIR__ . '/Resources/icons/ic_library_books_white_24px.svg', ]; /** diff --git a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php index 3f9de94f4..0e2619181 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php @@ -239,7 +239,7 @@ protected function createTable(array $data, array $settings = []): string $html .= ''; foreach ((array) $options['headers'] as $header) { - $html .= ''; + $html .= ''; } $html .= ''; diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php index 0609ac0ae..fd2dec99c 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php @@ -4,11 +4,16 @@ use ErrorException; use Monolog\Logger; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; use Symfony\Component\Debug\Exception\SilencedErrorContext; use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; -use Viserio\Component\Profiler\DataCollectors\MessagesDataCollector; +use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; +use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; -class MonologLoggerDataCollector extends MessagesDataCollector implements PanelAwareContract +class MonologLoggerDataCollector extends AbstractDataCollector implements + TooltipAwareContract, + PanelAwareContract { /** * Monolog logger instance. @@ -24,8 +29,6 @@ class MonologLoggerDataCollector extends MessagesDataCollector implements PanelA */ public function __construct($logger) { - parent::__construct('logs'); - $this->logger = $logger; } @@ -34,8 +37,20 @@ public function __construct($logger) */ public function getMenu(): array { + $status = ''; + + if ($this->getCountedErrors() !== 0) { + $status = 'status-red'; + } elseif ($this->getCountedWarnings() !== 0) { + $status = 'status-yellow'; + } elseif ($this->getCountedDeprecations() !== 0) { + $status = 'status-yellow'; + } + return [ + 'class' => $status, 'label' => 'Logs', + 'icon' => 'ic_library_books_white_24px.svg', 'value' => $this->data['counted'], ]; } @@ -43,49 +58,166 @@ public function getMenu(): array /** * {@inheritdoc} */ - public function getPanel(): string + public function getTooltip(): string { - $html = ''; + $html = $this->createTooltipGroup([ + 'Errors' => $this->getCountedErrors(), + 'Warnings' => $this->getCountedWarnings(), + 'Deprecations' => $this->getCountedDeprecations(), + ]); + + return $html; + } - $messages = $this->sanitizeLogs($this->getMessages()); + /** + * {@inheritdoc} + */ + public function getPanel(): string + { + $html = ''; + $tableHeaders = [ + 'Level', + 'Channel', + 'Message', + ]; + $logs = $this->groupLogLevels(); + + $html = $this->createTabs([ + [ + 'name' => 'Info. & Errors ' . count($logs['info_error']) . '', + 'content' => $this->createTable( + $logs['info_error'], + [ + 'headers' => $tableHeaders, + 'vardumper' => false, + ] + ), + ], [ + 'name' => 'Deprecations ' . $this->getCountedDeprecations() . '', + 'content' => $this->createTable( + $logs['deprecation'], + [ + 'headers' => $tableHeaders, + 'vardumper' => false, + ] + ), + ], [ + 'name' => 'Debug ' . count($logs['debug']) . '', + 'content' => $this->createTable( + $logs['debug'], + [ + 'headers' => $tableHeaders, + 'vardumper' => false, + ] + ), + ], [ + 'name' => 'Silenced PHP Notices ' . count($logs['silenced']) . '', + 'content' => $this->createTable( + $logs['silenced'], + [ + 'headers' => $tableHeaders, + 'vardumper' => false, + ] + ), + ], + ]); return $html; } /** - * Get counted logs. + * {@inheritdoc} + */ + public function collect(ServerRequestInterface $serverRequest, ResponseInterface $response): void + { + $data = $this->getComputedErrorsCount(); + + $data['logs'] = $this->sanitizeLogs($this->getMessages()); + $data['counted'] = count($data['logs']); + + $this->data = $data; + } + + /** + * Gets the logs. + * + * @return array An array of logs + */ + public function getLogs(): array + { + return $this->data['logs'] ?? []; + } + + /** + * Get log error priorities. + * + * @return array + */ + public function getPriorities(): array + { + return $this->data['priorities'] ?? []; + } + + /** + * Get counted errors. * * @return int */ - public function getCountedLogs(): int + public function getCountedErrors(): int { - return $this->data['counted'] ?? 0; + return $this->data['error_count'] ?? 0; } /** - * {@inheritdoc} + * Get counted deprecations. + * + * @return int */ - public function getMessages(): array + public function getCountedDeprecations(): int { - if ($logger = $this->getDebugLogger()) { - return $logger->getLogs(); - } + return $this->data['deprecation_count'] ?? 0; + } - return []; + /** + * Get counted warnings. + * + * @return int + */ + public function getCountedWarnings(): int + { + return $this->data['warning_count'] ?? 0; + } + + /** + * Get counted screams. + * + * @return int + */ + public function getCountedScreams(): int + { + return $this->data['scream_count'] ?? 0; } /** - * Returns the number of errors. + * Get counted logs. * * @return int */ - private function getCountedErrors(): int + public function getCountedLogs(): int + { + return $this->data['counted'] ?? 0; + } + + /** + * {@inheritdoc} + */ + public function getMessages(): array { if ($logger = $this->getDebugLogger()) { - return $logger->countErrors(); + return $logger->getLogs(); } - return 0; + return []; } /** @@ -104,7 +236,14 @@ private function getDebugLogger(): ?DebugProcessor return null; } - private function sanitizeLogs(array $logs) + /** + * Undocumented function + * + * @param array $logs + * + * @return array + */ + private function sanitizeLogs(array $logs): array { $sanitizedLogs = []; @@ -132,6 +271,13 @@ private function sanitizeLogs(array $logs) return array_values($sanitizedLogs); } + /** + * Undocumented function + * + * @param array $log + * + * @return bool + */ private function isSilencedOrDeprecationErrorLog(array $log): bool { if (! isset($log['context']['exception'])) { @@ -151,10 +297,21 @@ private function isSilencedOrDeprecationErrorLog(array $log): bool return false; } - private function computeErrorsCount() + /** + * Get computed log error levels. + * + * @return array + */ + private function getComputedErrorsCount(): array { + $errorCount = 0; + + if ($logger = $this->getDebugLogger()) { + $errorCount = $logger->countErrors(); + } + $count = [ - 'error_count' => $this->getCountedErrors(), + 'error_count' => $errorCount, 'deprecation_count' => 0, 'warning_count' => 0, 'scream_count' => 0, @@ -188,4 +345,46 @@ private function computeErrorsCount() return $count; } + + /** + * Group log level together. + * + * @return array + */ + private function groupLogLevels(): array + { + $deprecationLogs = []; + $debugLogs = []; + $infoAndErrorLogs = []; + $silencedLogs = []; + + $formatLog = function($log) { + return[ + $log['priorityName'] . '
' . '
' . date('H:i:s', $log['timestamp']) . '
', + $log['channel'], + $log['message'] . '
' . (! empty($log['context']) ? $this->cloneVar($log['context']) : '') + ]; + }; + + foreach ($this->data['logs'] as $log) { + if (isset($log['priority']) && (in_array($log['priority'], [Logger::ERROR, Logger::INFO]))) { + $infoAndErrorLogs[] = $formatLog($log); + } elseif (isset($log['priority']) && $log['priority'] === Logger::DEBUG) { + $debugLogs[] = $formatLog($log); + } elseif ($this->isSilencedOrDeprecationErrorLog($log)) { + if (isset($log['context']) && $log['context']['exception'] instanceof SilencedErrorContext) { + $silencedLogs[] = $formatLog($log); + } else { + $deprecationLogs[] = $formatLog($log); + } + } + } + + return [ + 'deprecation' => $deprecationLogs, + 'debug' => $debugLogs, + 'info_error' => $infoAndErrorLogs, + 'silenced' => $silencedLogs, + ]; + } } diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler.css b/src/Viserio/Component/Profiler/Resources/css/profiler.css index 1cac3a3ee..2f4e3c104 100644 --- a/src/Viserio/Component/Profiler/Resources/css/profiler.css +++ b/src/Viserio/Component/Profiler/Resources/css/profiler.css @@ -287,6 +287,9 @@ color: #2b2a28; } +.profiler .profiler-body .text-muted { + color: #999; +} .profiler .profiler-body .profiler-panel { display: none; diff --git a/src/Viserio/Component/Profiler/Resources/icons/ic_library_books_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_library_books_white_24px.svg new file mode 100644 index 000000000..f53d67bf8 --- /dev/null +++ b/src/Viserio/Component/Profiler/Resources/icons/ic_library_books_white_24px.svg @@ -0,0 +1,4 @@ + + + + From 5e74fc71828a7ee3f22840fefc64204e1b90418e Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 7 May 2017 16:54:41 +0000 Subject: [PATCH 33/99] Apply fixes from StyleCI --- .../DataCollectors/AbstractDataCollector.php | 2 +- .../Bridge/Log/MonologLoggerDataCollector.php | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php index 0e2619181..e2a0a11f9 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php @@ -239,7 +239,7 @@ protected function createTable(array $data, array $settings = []): string $html .= '
' . $header . '' . $header . '
'; foreach ((array) $options['headers'] as $header) { - $html .= ''; + $html .= ''; } $html .= ''; diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php index fd2dec99c..af5c4ef27 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php @@ -88,7 +88,7 @@ public function getPanel(): string 'content' => $this->createTable( $logs['info_error'], [ - 'headers' => $tableHeaders, + 'headers' => $tableHeaders, 'vardumper' => false, ] ), @@ -97,7 +97,7 @@ public function getPanel(): string 'content' => $this->createTable( $logs['deprecation'], [ - 'headers' => $tableHeaders, + 'headers' => $tableHeaders, 'vardumper' => false, ] ), @@ -106,7 +106,7 @@ public function getPanel(): string 'content' => $this->createTable( $logs['debug'], [ - 'headers' => $tableHeaders, + 'headers' => $tableHeaders, 'vardumper' => false, ] ), @@ -115,7 +115,7 @@ public function getPanel(): string 'content' => $this->createTable( $logs['silenced'], [ - 'headers' => $tableHeaders, + 'headers' => $tableHeaders, 'vardumper' => false, ] ), @@ -237,7 +237,7 @@ private function getDebugLogger(): ?DebugProcessor } /** - * Undocumented function + * Undocumented function. * * @param array $logs * @@ -272,7 +272,7 @@ private function sanitizeLogs(array $logs): array } /** - * Undocumented function + * Undocumented function. * * @param array $log * @@ -358,11 +358,11 @@ private function groupLogLevels(): array $infoAndErrorLogs = []; $silencedLogs = []; - $formatLog = function($log) { + $formatLog = function ($log) { return[ $log['priorityName'] . '
' . '
' . date('H:i:s', $log['timestamp']) . '
', $log['channel'], - $log['message'] . '
' . (! empty($log['context']) ? $this->cloneVar($log['context']) : '') + $log['message'] . '
' . (! empty($log['context']) ? $this->cloneVar($log['context']) : ''), ]; }; @@ -382,9 +382,9 @@ private function groupLogLevels(): array return [ 'deprecation' => $deprecationLogs, - 'debug' => $debugLogs, - 'info_error' => $infoAndErrorLogs, - 'silenced' => $silencedLogs, + 'debug' => $debugLogs, + 'info_error' => $infoAndErrorLogs, + 'silenced' => $silencedLogs, ]; } } From 75042a51c7cfb5f6825c4beccd7eaffb630856d8 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 7 May 2017 22:28:02 +0200 Subject: [PATCH 34/99] change static to self in tests --- .../DataCollector/TwigDataCollectorTest.php | 10 +- .../Twig/Tests/Engine/TwigEngineTest.php | 4 +- ...ridgeDataCollectorsServiceProviderTest.php | 8 +- .../Traits/RequestFactoryAwareTraitTest.php | 2 +- .../Traits/ResponseFactoryAwareTraitTest.php | 2 +- .../ServerRequestFactoryAwareTraitTest.php | 2 +- .../Traits/StreamFactoryAwareTraitTest.php | 2 +- .../UploadedFileFactoryAwareTraitTest.php | 2 +- .../Traits/UriFactoryAwareTraitTest.php | 2 +- ...ClassNotFoundFatalErrorTransformerTest.php | 8 +- ...finedFunctionFatalErrorTransformerTest.php | 8 +- ...definedMethodFatalErrorTransformerTest.php | 8 +- .../FilesLoadedCollectorTest.php | 4 +- .../NarrowsparkDataCollectorTest.php | 73 ++++---- .../ViserioHttpDataCollectorTest.php | 4 +- .../ConfigureLoggingServiceProviderTest.php | 8 +- ...dationDataCollectorServiceProviderTest.php | 12 +- .../HttpFactoryServiceProviderTest.php | 24 +-- .../Component/Profiler/AssetsRenderer.php | 2 +- .../Bridge/Cache/Psr6CacheDataCollector.php | 8 +- .../Cache/TraceableCacheItemDecorater.php | 35 ++-- .../Bridge/Log/MonologLoggerDataCollector.php | 39 +++-- .../Profiler/Tests/AssetsRendererTest.php | 12 +- .../Cache/Psr6CacheDataCollectorTest.php | 6 +- .../Cache/TraceableCacheItemDecoraterTest.php | 159 +++++++++--------- .../Log/MonologLoggerDataCollectorTest.php | 0 .../Bridge/SwiftMailDataCollectorTest.php | 4 +- .../DataCollectors/DataCollectorTest.php | 18 +- .../DataCollectors/LogsDataCollectorTest.php | 16 +- .../MemoryDataCollectorTest.php | 4 +- .../MessagesDataCollectorTest.php | 12 +- .../PhpInfoDataCollectorTest.php | 10 +- .../DataCollectors/TimeDataCollectorTest.php | 14 +- .../Middleware/ProfilerMiddlewareTest.php | 2 +- .../Component/Profiler/Tests/ProfileTest.php | 24 +-- .../Component/Profiler/Tests/ProfilerTest.php | 14 +- .../Profiler/Tests/TemplateManagerTest.php | 8 +- .../Tests/Util/HtmlDumperOutputTest.php | 4 +- ...outingDataCollectorServiceProviderTest.php | 8 +- .../Routing/Tests/SortedMiddlewareTest.php | 10 +- .../Support/Tests/Http/ClientIpTest.php | 4 +- .../ViserioTranslationDataCollectorTest.php | 8 +- .../ShareErrorsFromSessionMiddlewareTest.php | 2 +- 43 files changed, 302 insertions(+), 304 deletions(-) create mode 100644 src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Log/MonologLoggerDataCollectorTest.php diff --git a/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php b/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php index 03f8c6e18..b67d3df63 100644 --- a/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php +++ b/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php @@ -17,7 +17,7 @@ public function testGetMenuAndPosition() { $collect = $this->getTwigDataCollector(); - static::assertSame( + self::assertSame( [ 'icon' => file_get_contents(__DIR__ . '/../../DataCollector/Resources/icons/ic_view_quilt_white_24px.svg'), 'label' => 'Twig', @@ -25,7 +25,7 @@ public function testGetMenuAndPosition() ], $collect->getMenu() ); - static::assertSame('left', $collect->getMenuPosition()); + self::assertSame('left', $collect->getMenuPosition()); } public function testGetTooltip() @@ -36,7 +36,7 @@ public function testGetTooltip() $this->mock(ResponseInterface::class) ); - static::assertSame('
Template calls1
Block calls0
Macro calls0
', $collect->getTooltip()); + self::assertSame('
Template calls1
Block calls0
Macro calls0
', $collect->getTooltip()); } public function testGetPanel() @@ -58,14 +58,14 @@ public function testGetPanel() $expect = preg_replace('/(\r\n|\n\r|\r)/', "\n", '

Twig Metrics

  • ' . $this->formatDuration($collect->getTime()) . 'Render time
  • 1Template calls
  • 0Block calls
  • 0Macro calls

Rendered Templates

' . $header . '' . $header . '
Template NameRender Count
test.twig1

Rendering Call Graph

' . $collect->getHtmlCallGraph() . '
Extension
Twig_Extension_Core
Twig_Extension_Escaper
Twig_Extension_Optimizer
Twig_Extension_Profiler
'); - static::assertSame($this->removeTabId($expect), $this->removeTabId(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collect->getPanel()))); + self::assertSame($this->removeTabId($expect), $this->removeTabId(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collect->getPanel()))); } public function testGetProfile() { $collect = $this->getTwigDataCollector(); - static::assertInstanceOf(Twig_Profiler_Profile::class, $collect->getProfile()); + self::assertInstanceOf(Twig_Profiler_Profile::class, $collect->getProfile()); } private function removeTabId(string $html): string diff --git a/src/Viserio/Bridge/Twig/Tests/Engine/TwigEngineTest.php b/src/Viserio/Bridge/Twig/Tests/Engine/TwigEngineTest.php index 42148255c..e2cc50a1f 100644 --- a/src/Viserio/Bridge/Twig/Tests/Engine/TwigEngineTest.php +++ b/src/Viserio/Bridge/Twig/Tests/Engine/TwigEngineTest.php @@ -52,7 +52,7 @@ public function testGet() $template = $engine->get(['name' => 'twightml.twig.html']); - static::assertSame(trim(' + self::assertSame(trim(' @@ -110,7 +110,7 @@ public function testAddTwigExtensions() $template = $engine->get(['name' => 'twightml2.twig.html']); - static::assertSame(trim(' + self::assertSame(trim(' diff --git a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php index c0c8baa7e..3d9a69dc4 100644 --- a/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php +++ b/src/Viserio/Bridge/Twig/Tests/Providers/TwigBridgeDataCollectorsServiceProviderTest.php @@ -63,11 +63,11 @@ public function testGetServices() $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(ProfilerContract::class, $profiler); + self::assertInstanceOf(ProfilerContract::class, $profiler); - static::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); - static::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); - static::assertTrue(array_key_exists('twig-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('twig-data-collector', $profiler->getCollectors())); self::assertInstanceOf(Twig_Profiler_Profile::class, $container->get(Twig_Profiler_Profile::class)); self::assertInstanceOf(Twig_Environment::class, $container->get(Twig_Environment::class)); diff --git a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/RequestFactoryAwareTraitTest.php b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/RequestFactoryAwareTraitTest.php index 61f61e0f9..9cb5c8765 100644 --- a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/RequestFactoryAwareTraitTest.php +++ b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/RequestFactoryAwareTraitTest.php @@ -14,7 +14,7 @@ public function testSetAndGetRequestFactory() { $this->setRequestFactory($this->mock(RequestFactoryInterface::class)); - static::assertInstanceOf(RequestFactoryInterface::class, $this->getRequestFactory()); + self::assertInstanceOf(RequestFactoryInterface::class, $this->getRequestFactory()); } /** diff --git a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ResponseFactoryAwareTraitTest.php b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ResponseFactoryAwareTraitTest.php index e14037f1a..02b9a1436 100644 --- a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ResponseFactoryAwareTraitTest.php +++ b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ResponseFactoryAwareTraitTest.php @@ -14,7 +14,7 @@ public function testSetAndGetResponseFactory() { $this->setResponseFactory($this->mock(ResponseFactoryInterface::class)); - static::assertInstanceOf(ResponseFactoryInterface::class, $this->getResponseFactory()); + self::assertInstanceOf(ResponseFactoryInterface::class, $this->getResponseFactory()); } /** diff --git a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ServerRequestFactoryAwareTraitTest.php b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ServerRequestFactoryAwareTraitTest.php index 56b696ae8..81db2872b 100644 --- a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ServerRequestFactoryAwareTraitTest.php +++ b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/ServerRequestFactoryAwareTraitTest.php @@ -14,7 +14,7 @@ public function testSetAndGetServerRequestFactory() { $this->setServerRequestFactory($this->mock(ServerRequestFactoryInterface::class)); - static::assertInstanceOf(ServerRequestFactoryInterface::class, $this->getServerRequestFactory()); + self::assertInstanceOf(ServerRequestFactoryInterface::class, $this->getServerRequestFactory()); } /** diff --git a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/StreamFactoryAwareTraitTest.php b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/StreamFactoryAwareTraitTest.php index e4758c35f..b363a9082 100644 --- a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/StreamFactoryAwareTraitTest.php +++ b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/StreamFactoryAwareTraitTest.php @@ -14,7 +14,7 @@ public function testSetAndGetStreamFactory() { $this->setStreamFactory($this->mock(StreamFactoryInterface::class)); - static::assertInstanceOf(StreamFactoryInterface::class, $this->getStreamFactory()); + self::assertInstanceOf(StreamFactoryInterface::class, $this->getStreamFactory()); } /** diff --git a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UploadedFileFactoryAwareTraitTest.php b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UploadedFileFactoryAwareTraitTest.php index c5fed8806..7d84b378c 100644 --- a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UploadedFileFactoryAwareTraitTest.php +++ b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UploadedFileFactoryAwareTraitTest.php @@ -14,7 +14,7 @@ public function testSetAndGetUploadedFileFactory() { $this->setUploadedFileFactory($this->mock(UploadedFileFactoryInterface::class)); - static::assertInstanceOf(UploadedFileFactoryInterface::class, $this->getUploadedFileFactory()); + self::assertInstanceOf(UploadedFileFactoryInterface::class, $this->getUploadedFileFactory()); } /** diff --git a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UriFactoryAwareTraitTest.php b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UriFactoryAwareTraitTest.php index e82d0fa46..9c0e705bf 100644 --- a/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UriFactoryAwareTraitTest.php +++ b/src/Viserio/Component/Contracts/Tests/HttpFactory/Traits/UriFactoryAwareTraitTest.php @@ -14,7 +14,7 @@ public function testSetAndGetUriFactory() { $this->setUriFactory($this->mock(UriFactoryInterface::class)); - static::assertInstanceOf(UriFactoryInterface::class, $this->getUriFactory()); + self::assertInstanceOf(UriFactoryInterface::class, $this->getUriFactory()); } /** diff --git a/src/Viserio/Component/Exception/Tests/Transformers/ClassNotFoundFatalErrorTransformerTest.php b/src/Viserio/Component/Exception/Tests/Transformers/ClassNotFoundFatalErrorTransformerTest.php index ac64f3eb4..e96fdba5e 100644 --- a/src/Viserio/Component/Exception/Tests/Transformers/ClassNotFoundFatalErrorTransformerTest.php +++ b/src/Viserio/Component/Exception/Tests/Transformers/ClassNotFoundFatalErrorTransformerTest.php @@ -16,11 +16,11 @@ public function testExceptionIsWrapped() new FatalErrorException('Class \'WhizBangFactory\' not found', 0, 1, 'foo.php', 12) ); - static::assertInstanceOf( + self::assertInstanceOf( ClassNotFoundException::class, $exception ); - static::assertSame('Attempted to load class "WhizBangFactory" from the global namespace. + self::assertSame('Attempted to load class "WhizBangFactory" from the global namespace. Did you forget a "use" statement?', $exception->getMessage()); } @@ -31,10 +31,10 @@ public function testExceptionIsNotWrapped() new FatalErrorException('', 0, 1, 'foo.php', 12) ); - static::assertInstanceOf( + self::assertInstanceOf( FatalErrorException::class, $exception ); - static::assertSame('', $exception->getMessage()); + self::assertSame('', $exception->getMessage()); } } diff --git a/src/Viserio/Component/Exception/Tests/Transformers/UndefinedFunctionFatalErrorTransformerTest.php b/src/Viserio/Component/Exception/Tests/Transformers/UndefinedFunctionFatalErrorTransformerTest.php index b6c8a7375..51abec342 100644 --- a/src/Viserio/Component/Exception/Tests/Transformers/UndefinedFunctionFatalErrorTransformerTest.php +++ b/src/Viserio/Component/Exception/Tests/Transformers/UndefinedFunctionFatalErrorTransformerTest.php @@ -16,11 +16,11 @@ public function testExceptionIsWrapped() new FatalErrorException('Call to undefined function test_namespaced_function()', 0, 1, 'foo.php', 12) ); - static::assertInstanceOf( + self::assertInstanceOf( UndefinedFunctionException::class, $exception ); - static::assertSame('Attempted to call function "test_namespaced_function" from the global namespace.', $exception->getMessage()); + self::assertSame('Attempted to call function "test_namespaced_function" from the global namespace.', $exception->getMessage()); } public function testExceptionIsNotWrapped() @@ -30,10 +30,10 @@ public function testExceptionIsNotWrapped() new FatalErrorException('', 0, 1, 'foo.php', 12) ); - static::assertInstanceOf( + self::assertInstanceOf( FatalErrorException::class, $exception ); - static::assertSame('', $exception->getMessage()); + self::assertSame('', $exception->getMessage()); } } diff --git a/src/Viserio/Component/Exception/Tests/Transformers/UndefinedMethodFatalErrorTransformerTest.php b/src/Viserio/Component/Exception/Tests/Transformers/UndefinedMethodFatalErrorTransformerTest.php index eb52e6c0b..ee1bc4e37 100644 --- a/src/Viserio/Component/Exception/Tests/Transformers/UndefinedMethodFatalErrorTransformerTest.php +++ b/src/Viserio/Component/Exception/Tests/Transformers/UndefinedMethodFatalErrorTransformerTest.php @@ -16,11 +16,11 @@ public function testExceptionIsWrapped() new FatalErrorException('Call to undefined method SplObjectStorage::what()', 0, 1, 'foo.php', 12) ); - static::assertInstanceOf( + self::assertInstanceOf( UndefinedMethodException::class, $exception ); - static::assertSame('Attempted to call an undefined method named "what" of class "SplObjectStorage".', $exception->getMessage()); + self::assertSame('Attempted to call an undefined method named "what" of class "SplObjectStorage".', $exception->getMessage()); } public function testExceptionIsNotWrapped() @@ -30,10 +30,10 @@ public function testExceptionIsNotWrapped() new FatalErrorException('', 0, 1, 'foo.php', 12) ); - static::assertInstanceOf( + self::assertInstanceOf( FatalErrorException::class, $exception ); - static::assertSame('', $exception->getMessage()); + self::assertSame('', $exception->getMessage()); } } diff --git a/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php b/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php index 317fe848c..be76fd16e 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php @@ -13,7 +13,7 @@ public function testGetMenu() { $collector = new FilesLoadedCollector(__DIR__); - static::assertSame( + self::assertSame( [ 'icon' => 'ic_insert_drive_file_white_24px.svg', 'label' => '', @@ -31,6 +31,6 @@ public function testGetPanel() $this->mock(ResponseInterface::class) ); - static::assertTrue(is_string($collector->getPanel())); + self::assertTrue(is_string($collector->getPanel())); } } diff --git a/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php b/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php index 4502a5f2d..d9f07f3e9 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/NarrowsparkDataCollectorTest.php @@ -2,43 +2,44 @@ declare(strict_types=1); namespace Viserio\Component\Foundation\Tests\DataCollectors; -// use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; -// use Psr\Http\Message\ResponseInterface; -// use Psr\Http\Message\ServerRequestInterface; -// use Viserio\Component\Foundation\DataCollectors\NarrowsparkDataCollector; +use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Viserio\Component\Foundation\DataCollectors\NarrowsparkDataCollector; +use Viserio\Component\Foundation\Http\Kernel; -// class NarrowsparkDataCollectorTest extends MockeryTestCase -// { -// public function testGetMenuAndPosition() -// { -// $collect = new NarrowsparkDataCollector(); +class NarrowsparkDataCollectorTest extends MockeryTestCase +{ + public function testGetMenuAndPosition() + { + $collect = new NarrowsparkDataCollector(); -// static::assertSame( -// [ -// 'icon' => 'ic_narrowspark_white_24px.svg', -// 'label' => '', -// 'value' => Application::VERSION, -// ], -// $collect->getMenu() -// ); -// static::assertSame('right', $collect->getMenuPosition()); -// } + self::assertSame( + [ + 'icon' => 'ic_narrowspark_white_24px.svg', + 'label' => '', + 'value' => Kernel::VERSION, + ], + $collect->getMenu() + ); + self::assertSame('right', $collect->getMenuPosition()); + } -// public function testGetTooltip() -// { -// $collect = new NarrowsparkDataCollector(); -// $request = $this->mock(ServerRequestInterface::class); -// $request->shouldReceive('getHeaderLine') -// ->once() -// ->with('X-Debug-Token'); -// $collect->collect( -// $request, -// $this->mock(ResponseInterface::class) -// ); -// $xdebug = extension_loaded('xdebug') ? 'status-green' : 'status-red'; -// $opcache = (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) ? 'status-green' : 'status-red'; -// $version = Application::VERSION; + public function testGetTooltip() + { + $collect = new NarrowsparkDataCollector(); + $request = $this->mock(ServerRequestInterface::class); + $request->shouldReceive('getHeaderLine') + ->once() + ->with('X-Debug-Token'); + $collect->collect( + $request, + $this->mock(ResponseInterface::class) + ); + $xdebug = extension_loaded('xdebug') ? 'status-green' : 'status-red'; + $opcache = (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) ? 'status-green' : 'status-red'; + $version = Kernel::VERSION; -// static::assertSame('
Profiler token
Application name
Environmentdevelop
Debugdisabled
PHP version' . phpversion() . '
Architecture' . PHP_INT_SIZE * 8 . '
Timezone' . date_default_timezone_get() . '
PHP ExtensionsXdebugOPcache
PHP SAPIcli
', $collect->getTooltip()); -// } -// } + self::assertSame('
Profiler token
Application name
Environmentdevelop
Debugdisabled
PHP version' . phpversion() . '
Architecture' . PHP_INT_SIZE * 8 . '
Timezone' . date_default_timezone_get() . '
PHP ExtensionsXdebugOPcache
PHP SAPIcli
', $collect->getTooltip()); + } +} diff --git a/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php b/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php index 4cc2c0075..0263de7cf 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php @@ -41,7 +41,7 @@ public function testGetMenuAndPosition() $collect = new ViserioHttpDataCollector($router, $this->mock(RepositoryContract::class)); $collect->collect($serverRequest, $response); - static::assertSame( + self::assertSame( [ 'label' => '@', 'value' => 'Home', @@ -49,6 +49,6 @@ public function testGetMenuAndPosition() $collect->getMenu() ); - static::assertSame('left', $collect->getMenuPosition()); + self::assertSame('left', $collect->getMenuPosition()); } } diff --git a/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php b/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php index ab9164524..a03b7d153 100644 --- a/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php +++ b/src/Viserio/Component/Foundation/Tests/Providers/ConfigureLoggingServiceProviderTest.php @@ -47,7 +47,7 @@ public function bootstrap(): void $container->register(new ConfigureLoggingServiceProvider()); - static::assertInstanceOf(Writer::class, $container->get(Writer::class)); + self::assertInstanceOf(Writer::class, $container->get(Writer::class)); } /** @@ -80,7 +80,7 @@ public function bootstrap(): void $container->register(new ConfigureLoggingServiceProvider()); - static::assertInstanceOf(Writer::class, $container->get(Writer::class)); + self::assertInstanceOf(Writer::class, $container->get(Writer::class)); } /** @@ -122,7 +122,7 @@ public function bootstrap(): void $container->register(new ConfigureLoggingServiceProvider()); - static::assertInstanceOf(Writer::class, $container->get(Writer::class)); + self::assertInstanceOf(Writer::class, $container->get(Writer::class)); } /** @@ -164,6 +164,6 @@ public function bootstrap(): void $container->register(new ConfigureLoggingServiceProvider()); - static::assertInstanceOf(Writer::class, $container->get(Writer::class)); + self::assertInstanceOf(Writer::class, $container->get(Writer::class)); } } diff --git a/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php b/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php index b606ec08b..494f6f7a5 100644 --- a/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php @@ -50,13 +50,13 @@ public function testGetServices() $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(ProfilerContract::class, $profiler); + self::assertInstanceOf(ProfilerContract::class, $profiler); - static::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); - static::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); - static::assertTrue(array_key_exists('narrowspark', $profiler->getCollectors())); - static::assertTrue(array_key_exists('viserio-http-data-collector', $profiler->getCollectors())); - static::assertTrue(array_key_exists('files-loaded-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('narrowspark', $profiler->getCollectors())); + self::assertTrue(array_key_exists('viserio-http-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('files-loaded-collector', $profiler->getCollectors())); } private function getRequest() diff --git a/src/Viserio/Component/HttpFactory/Tests/Providers/HttpFactoryServiceProviderTest.php b/src/Viserio/Component/HttpFactory/Tests/Providers/HttpFactoryServiceProviderTest.php index b5f947fa0..4bf5d5079 100644 --- a/src/Viserio/Component/HttpFactory/Tests/Providers/HttpFactoryServiceProviderTest.php +++ b/src/Viserio/Component/HttpFactory/Tests/Providers/HttpFactoryServiceProviderTest.php @@ -25,22 +25,22 @@ public function testProvider() $container = new Container(); $container->register(new HttpFactoryServiceProvider()); - static::assertInstanceOf(RequestFactoryInterface::class, $container->get(RequestFactoryInterface::class)); - static::assertInstanceOf(RequestFactoryInterface::class, $container->get(RequestFactory::class)); + self::assertInstanceOf(RequestFactoryInterface::class, $container->get(RequestFactoryInterface::class)); + self::assertInstanceOf(RequestFactoryInterface::class, $container->get(RequestFactory::class)); - static::assertInstanceOf(ResponseFactoryInterface::class, $container->get(ResponseFactoryInterface::class)); - static::assertInstanceOf(ResponseFactoryInterface::class, $container->get(ResponseFactory::class)); + self::assertInstanceOf(ResponseFactoryInterface::class, $container->get(ResponseFactoryInterface::class)); + self::assertInstanceOf(ResponseFactoryInterface::class, $container->get(ResponseFactory::class)); - static::assertInstanceOf(ServerRequestFactoryInterface::class, $container->get(ServerRequestFactoryInterface::class)); - static::assertInstanceOf(ServerRequestFactoryInterface::class, $container->get(ServerRequestFactory::class)); + self::assertInstanceOf(ServerRequestFactoryInterface::class, $container->get(ServerRequestFactoryInterface::class)); + self::assertInstanceOf(ServerRequestFactoryInterface::class, $container->get(ServerRequestFactory::class)); - static::assertInstanceOf(StreamFactoryInterface::class, $container->get(StreamFactoryInterface::class)); - static::assertInstanceOf(StreamFactoryInterface::class, $container->get(StreamFactory::class)); + self::assertInstanceOf(StreamFactoryInterface::class, $container->get(StreamFactoryInterface::class)); + self::assertInstanceOf(StreamFactoryInterface::class, $container->get(StreamFactory::class)); - static::assertInstanceOf(UploadedFileFactoryInterface::class, $container->get(UploadedFileFactoryInterface::class)); - static::assertInstanceOf(UploadedFileFactoryInterface::class, $container->get(UploadedFileFactory::class)); + self::assertInstanceOf(UploadedFileFactoryInterface::class, $container->get(UploadedFileFactoryInterface::class)); + self::assertInstanceOf(UploadedFileFactoryInterface::class, $container->get(UploadedFileFactory::class)); - static::assertInstanceOf(UriFactoryInterface::class, $container->get(UriFactoryInterface::class)); - static::assertInstanceOf(UriFactoryInterface::class, $container->get(UriFactory::class)); + self::assertInstanceOf(UriFactoryInterface::class, $container->get(UriFactoryInterface::class)); + self::assertInstanceOf(UriFactoryInterface::class, $container->get(UriFactory::class)); } } diff --git a/src/Viserio/Component/Profiler/AssetsRenderer.php b/src/Viserio/Component/Profiler/AssetsRenderer.php index ad6ee949a..f9d599de7 100644 --- a/src/Viserio/Component/Profiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -74,7 +74,7 @@ class AssetsRenderer implements AssetsRendererContract protected $ignoredCollectors = []; /** - * jQuery is used, remove zapto js. + * If jQuery is used, remove zapto. * * @var bool */ diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php index 0de9d7a29..209b83cb4 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php @@ -217,10 +217,10 @@ private function calculateStatistics(): array $statistics[$name]['time'] = $statistics[$name]['time']; if ($statistics[$name]['reads']) { - $statistics[$name]['hits/reads'] = + $statistics[$name]['hit_read_ratio'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2) . '%'; } else { - $statistics[$name]['hits/reads'] = 'N/A'; + $statistics[$name]['hit_read_ratio'] = null; } } @@ -249,9 +249,9 @@ private function calculateTotalStatistics(): array } if ($totals['reads']) { - $totals['hits/reads'] = round(100 * $totals['hits'] / $totals['reads'], 2) . '%'; + $totals['hit_read_ratio'] = round(100 * $totals['hits'] / $totals['reads'], 2) . '%'; } else { - $totals['hits/reads'] = 'N/A'; + $totals['hit_read_ratio'] = null; } return $totals; diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php index 05c3b86cb..52268be22 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php @@ -45,7 +45,7 @@ public function __construct(CacheItemPoolInterface $pool) */ public function getItem($key) { - $event = $this->start(__FUNCTION__, $key); + $event = $this->start(__FUNCTION__); try { $item = $this->pool->getItem($key); @@ -53,14 +53,12 @@ public function getItem($key) $event->end = microtime(true); } - if ($item->isHit()) { + if ($event->result[$key] = $item->isHit()) { ++$event->hits; } else { ++$event->misses; } - $event->result = $item->get(); - return $item; } @@ -69,10 +67,10 @@ public function getItem($key) */ public function hasItem($key) { - $event = $this->start(__FUNCTION__, $key); + $event = $this->start(__FUNCTION__); try { - return $event->result = $this->pool->hasItem($key); + return $event->result[$key] = $this->pool->hasItem($key); } finally { $event->end = microtime(true); } @@ -83,10 +81,10 @@ public function hasItem($key) */ public function deleteItem($key) { - $event = $this->start(__FUNCTION__, $key); + $event = $this->start(__FUNCTION__); try { - return $event->result = $this->pool->deleteItem($key); + return $event->result[$key] = $this->pool->deleteItem($key); } finally { $event->end = microtime(true); } @@ -97,10 +95,10 @@ public function deleteItem($key) */ public function save(CacheItemInterface $item) { - $event = $this->start(__FUNCTION__, $item); + $event = $this->start(__FUNCTION__); try { - return $event->result = $this->pool->save($item); + return $event->result[$item->getKey()] = $this->pool->save($item); } finally { $event->end = microtime(true); } @@ -111,10 +109,10 @@ public function save(CacheItemInterface $item) */ public function saveDeferred(CacheItemInterface $item) { - $event = $this->start(__FUNCTION__, $item); + $event = $this->start(__FUNCTION__); try { - return $event->result = $this->pool->saveDeferred($item); + return $event->result[$item->getKey()] = $this->pool->saveDeferred($item); } finally { $event->end = microtime(true); } @@ -137,14 +135,12 @@ public function getItems(array $keys = []) $event->result = []; foreach ($result as $key => $item) { - if ($item->isHit()) { + if ($event->result[$key] = $item->isHit()) { ++$event->hits; } else { ++$event->misses; } - $event->result[$key] = $item->get(); - yield $key => $item; } }; @@ -220,15 +216,13 @@ public function getName(): string * Start new event. * * @param string $name - * @param mixed $argument * * @return object */ - private function start(string $name, $argument = null) + private function start(string $name) { $this->calls[] = $event = new class() { public $name; - public $argument; public $start; public $end; public $result; @@ -236,9 +230,8 @@ private function start(string $name, $argument = null) public $misses = 0; }; - $event->name = $name; - $event->argument = $argument; - $event->start = microtime(true); + $event->name = $name; + $event->start = microtime(true); return $event; } diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php index af5c4ef27..ba00ef7a6 100644 --- a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php @@ -3,7 +3,9 @@ namespace Viserio\Component\Profiler\DataCollectors\Bridge\Log; use ErrorException; +use RuntimeException; use Monolog\Logger; +use Viserio\Component\Log\Writer; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Symfony\Component\Debug\Exception\SilencedErrorContext; @@ -29,7 +31,20 @@ class MonologLoggerDataCollector extends AbstractDataCollector implements */ public function __construct($logger) { - $this->logger = $logger; + if ($logger instanceof Logger || $logger instanceof Writer) { + $this->logger = $logger; + } else { + throw new RuntimeException(sprintf( + 'Class [%s] or [%s] is required; Instance of [%s] given.', + Logger::class, + Writer::class, + get_class($logger) + )); + } + + if ($this->getDebugLogger() === null) { + throw new RuntimeException(sprintf('Processor %s is missing from %s', DebugProcessor::class, get_class($logger))); + } } /** @@ -37,7 +52,7 @@ public function __construct($logger) */ public function getMenu(): array { - $status = ''; + $status = ''; if ($this->getCountedErrors() !== 0) { $status = 'status-red'; @@ -132,22 +147,12 @@ public function collect(ServerRequestInterface $serverRequest, ResponseInterface { $data = $this->getComputedErrorsCount(); - $data['logs'] = $this->sanitizeLogs($this->getMessages()); + $data['logs'] = $this->sanitizeLogs($this->getLogs()); $data['counted'] = count($data['logs']); $this->data = $data; } - /** - * Gets the logs. - * - * @return array An array of logs - */ - public function getLogs(): array - { - return $this->data['logs'] ?? []; - } - /** * Get log error priorities. * @@ -209,9 +214,11 @@ public function getCountedLogs(): int } /** - * {@inheritdoc} + * Returns collected logs. + * + * @return array */ - public function getMessages(): array + public function getLogs(): array { if ($logger = $this->getDebugLogger()) { return $logger->getLogs(); @@ -318,7 +325,7 @@ private function getComputedErrorsCount(): array 'priorities' => [], ]; - foreach ($this->getMessages() as $log) { + foreach ($this->getLogs() as $log) { if (isset($count['priorities'][$log['priority']])) { ++$count['priorities'][$log['priority']]['count']; } else { diff --git a/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php index a23c665f7..1d22a4c3b 100644 --- a/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php +++ b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php @@ -19,7 +19,7 @@ public function testSetndGetIcon() $assets->setIcon('ic_clear_white_24px.svg', __DIR__ . 'Fixture/Icons/'); - static::assertSame(self::normalizePath(__DIR__ . 'Fixture/Icons/ic_clear_white_24px.svg'), $assets->getIcons()['ic_clear_white_24px.svg']); + self::assertSame(self::normalizePath(__DIR__ . 'Fixture/Icons/ic_clear_white_24px.svg'), $assets->getIcons()['ic_clear_white_24px.svg']); } public function testSetAndGetIgnoredCollectors() @@ -28,7 +28,7 @@ public function testSetAndGetIgnoredCollectors() $assets->setIgnoredCollector('test'); - static::assertSame('test', $assets->getIgnoredCollectors()[0]); + self::assertSame('test', $assets->getIgnoredCollectors()[0]); } public function testGetAssets() @@ -49,8 +49,8 @@ public function testGetAssets() __DIR__ . '/js/profiler.js', ]; - static::assertSame($cssAssets, $assets->getAssets('css')); - static::assertSame($jsAssets, $assets->getAssets('js')); + self::assertSame($cssAssets, $assets->getAssets('css')); + self::assertSame($jsAssets, $assets->getAssets('js')); } public function testGetAssetsFromCollectors() @@ -72,7 +72,7 @@ public function testGetAssetsFromCollectors() str_replace('Tests', 'DataCollectors', __DIR__) . '/../Resources/js/ajaxHandler.js', ]; - static::assertSame([$cssAssets, $jsAssets], $assets->getAssets()); + self::assertSame([$cssAssets, $jsAssets], $assets->getAssets()); } public function testRenderWithUrlGenerator() @@ -93,6 +93,6 @@ public function testRenderWithUrlGenerator() $assets = new AssetsRenderer(); $assets->setProfiler($profiler); - static::assertSame('', $assets->render()); + self::assertSame('', $assets->render()); } } diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php index cb1e206a6..971df1c4e 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php @@ -15,7 +15,7 @@ public function testGetMenu() { $collector = $this->getPsr6CacheDataCollector(); - static::assertSame( + self::assertSame( [ 'icon' => 'ic_layers_white_24px.svg', 'label' => '0 in', @@ -29,7 +29,7 @@ public function testGetTooltip() { $collector = $this->getPsr6CacheDataCollector(); - static::assertSame( + self::assertSame( '
Cache calls0
Total time0μs
Cache hits0
Cache writes0
', $collector->getTooltip() ); @@ -39,7 +39,7 @@ public function testGetPanel() { $collector = $this->getPsr6CacheDataCollector(); - static::assertSame( + self::assertSame( $this->removeTabId('

Statistics

  • 0calls
  • 0μstime
  • 0reads
  • 0hits
  • 0misses
  • 0writes
  • 0deletes
  • N/Ahits/reads

Calls

Empty
'), $this->removeSymfonyVarDumper($collector->getPanel()) ); diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php index 522a0e678..8d2242deb 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php @@ -8,26 +8,25 @@ class TraceableCacheItemDecoraterTest extends MockeryTestCase { - public function testGetItemMiss() + public function testGetItemMissTrace() { $pool = $this->createCachePool(); $pool->getItem('k'); $calls = $pool->getCalls(); - static::assertCount(1, $calls); + self::assertCount(1, $calls); $call = $calls[0]; - static::assertEquals('getItem', $call->name); - static::assertEquals('k', $call->argument); - static::assertEquals(0, $call->hits); - static::assertEquals(1, $call->misses); - static::assertNull($call->result); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('getItem', $call->name); + self::assertSame(array('k' => false), $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(1, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testGetItemHit() + public function testGetItemHitTrace() { $pool = $this->createCachePool(); $item = $pool->getItem('k')->set('foo'); @@ -35,15 +34,15 @@ public function testGetItemHit() $pool->getItem('k'); $calls = $pool->getCalls(); - static::assertCount(3, $calls); + self::assertCount(3, $calls); $call = $calls[2]; - static::assertEquals(1, $call->hits); - static::assertEquals(0, $call->misses); + self::assertEquals(1, $call->hits); + self::assertEquals(0, $call->misses); } - public function testGetItemsMiss() + public function testGetItemsMissTrace() { $pool = $this->createCachePool(); $arg = ['k0', 'k1']; @@ -54,35 +53,34 @@ public function testGetItemsMiss() $calls = $pool->getCalls(); - static::assertCount(1, $calls); + self::assertCount(1, $calls); $call = $calls[0]; - static::assertEquals('getItems', $call->name); - static::assertEquals($arg, $call->argument); - static::assertEquals(2, $call->misses); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('getItems', $call->name); + self::assertSame(array('k0' => false, 'k1' => false), $call->result); + self::assertEquals(2, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testHasItemMiss() + public function testHasItemMissTrace() { $pool = $this->createCachePool(); $pool->hasItem('k'); $calls = $pool->getCalls(); - static::assertCount(1, $calls); + self::assertCount(1, $calls); $call = $calls[0]; - static::assertEquals('hasItem', $call->name); - static::assertEquals('k', $call->argument); - static::assertFalse($call->result); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('hasItem', $call->name); + self::assertSame(array('k' => false), $call->result); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testHasItemHit() + public function testHasItemHitTrace() { $pool = $this->createCachePool(); $item = $pool->getItem('k')->set('foo'); @@ -90,108 +88,107 @@ public function testHasItemHit() $pool->hasItem('k'); $calls = $pool->getCalls(); - static::assertCount(3, $calls); + self::assertCount(3, $calls); $call = $calls[2]; - static::assertEquals('hasItem', $call->name); - static::assertEquals('k', $call->argument); - static::assertTrue($call->result); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('hasItem', $call->name); + self::assertSame(array('k' => true), $call->result); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testDeleteItem() + public function testDeleteItemTrace() { $pool = $this->createCachePool(); $pool->deleteItem('k'); $calls = $pool->getCalls(); - static::assertCount(1, $calls); + self::assertCount(1, $calls); $call = $calls[0]; - static::assertEquals('deleteItem', $call->name); - static::assertEquals('k', $call->argument); - static::assertEquals(0, $call->hits); - static::assertEquals(0, $call->misses); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('deleteItem', $call->name); + self::assertSame(array('k' => true), $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testDeleteItems() + public function testDeleteItemsTrace() { $pool = $this->createCachePool(); $arg = ['k0', 'k1']; $pool->deleteItems($arg); $calls = $pool->getCalls(); - static::assertCount(1, $calls); + self::assertCount(1, $calls); $call = $calls[0]; - static::assertEquals('deleteItems', $call->name); - static::assertEquals($arg, $call->argument); - static::assertEquals(0, $call->hits); - static::assertEquals(0, $call->misses); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('deleteItems', $call->name); + self::assertSame(array('keys' => $arg, 'result' => true), $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testSave() + public function testSaveTrace() { $pool = $this->createCachePool(); $item = $pool->getItem('k')->set('foo'); $pool->save($item); $calls = $pool->getCalls(); - static::assertCount(2, $calls); + self::assertCount(2, $calls); $call = $calls[1]; - static::assertEquals('save', $call->name); - static::assertEquals($item, $call->argument); - static::assertEquals(0, $call->hits); - static::assertEquals(0, $call->misses); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('save', $call->name); + self::assertSame(array('k' => true), $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testSaveDeferred() + public function testSaveDeferredTrace() { $pool = $this->createCachePool(); $item = $pool->getItem('k')->set('foo'); $pool->saveDeferred($item); $calls = $pool->getCalls(); - static::assertCount(2, $calls); + self::assertCount(2, $calls); $call = $calls[1]; - static::assertEquals('saveDeferred', $call->name); - static::assertEquals($item, $call->argument); - static::assertEquals(0, $call->hits); - static::assertEquals(0, $call->misses); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('saveDeferred', $call->name); + self::assertSame(array('k' => true), $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } - public function testCommit() + public function testCommitTrace() { $pool = $this->createCachePool(); $pool->commit(); $calls = $pool->getCalls(); - static::assertCount(1, $calls); + self::assertCount(1, $calls); $call = $calls[0]; - static::assertEquals('commit', $call->name); - static::assertNull(null, $call->argument); - static::assertEquals(0, $call->hits); - static::assertEquals(0, $call->misses); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('commit', $call->name); + self::assertTrue($call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } public function testClear() @@ -200,16 +197,16 @@ public function testClear() $pool->clear(); $calls = $pool->getCalls(); - static::assertCount(1, $calls); + self::assertCount(1, $calls); $call = $calls[0]; - static::assertEquals('clear', $call->name); - static::assertNull(null, $call->argument); - static::assertEquals(0, $call->hits); - static::assertEquals(0, $call->misses); - static::assertNotEmpty($call->start); - static::assertNotEmpty($call->end); + self::assertEquals('clear', $call->name); + self::assertNull(null, $call->argument); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); } private function createCachePool() diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Log/MonologLoggerDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Log/MonologLoggerDataCollectorTest.php new file mode 100644 index 000000000..e69de29bb diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php index e723a8471..c94b7cb6f 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php @@ -15,7 +15,7 @@ public function testGetMenu() { $collector = $this->getSwiftDataCollector(); - static::assertSame( + self::assertSame( [ 'icon' => 'ic_mail_outline_white_24px.svg', 'label' => 'Mails', @@ -29,7 +29,7 @@ public function testGetPanel() { $collector = $this->getSwiftDataCollector(); - static::assertSame( + self::assertSame( '
Empty
', $collector->getPanel() ); diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/DataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/DataCollectorTest.php index c2cb31558..9ae1df5db 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/DataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/DataCollectorTest.php @@ -11,12 +11,12 @@ public function testGetName() { $collector = new FixtureDataCollector(); - static::assertSame('fixture-data-collector', $collector->getName()); + self::assertSame('fixture-data-collector', $collector->getName()); } public function testGetMenuPosition() { - static::assertSame('left', (new FixtureDataCollector())->getMenuPosition()); + self::assertSame('left', (new FixtureDataCollector())->getMenuPosition()); } public function testCreateTableDefault() @@ -24,7 +24,7 @@ public function testCreateTableDefault() $collector = new FixtureDataCollector(); $defaultTable = file_get_contents(__DIR__ . '/../Fixture/View/default_table.html'); - static::assertSame( + self::assertSame( $this->removeSymfonyVarDumper(preg_replace('/(\r\n|\n\r|\r)/', "\n", $defaultTable)), $this->removeSymfonyVarDumper(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collector->getTableDefault())) ); @@ -35,7 +35,7 @@ public function testCreateTableArray() $collector = new FixtureDataCollector(); $defaultTable = file_get_contents(__DIR__ . '/../Fixture/View/array_table.html'); - static::assertSame( + self::assertSame( $this->removeSymfonyVarDumper(preg_replace('/(\r\n|\n\r|\r)/', "\n", $defaultTable)), $this->removeSymfonyVarDumper(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collector->getTableArray())) ); @@ -45,7 +45,7 @@ public function testCreateTooltipGroupDefault() { $collector = new FixtureDataCollector(); - static::assertSame( + self::assertSame( '
testtest
', $collector->getTooltippGroupDefault() ); @@ -55,7 +55,7 @@ public function testCreateTooltipGroupDefaultWithLink() { $collector = new FixtureDataCollector(); - static::assertSame( + self::assertSame( '', $collector->getTooltippGroupDefaultWithLink() ); @@ -65,7 +65,7 @@ public function testCreateTooltipGroupArray() { $collector = new FixtureDataCollector(); - static::assertSame( + self::assertSame( '
testtesttest2
', $collector->getTooltippGroupArray() ); @@ -75,7 +75,7 @@ public function testCreateTabs() { $collector = new FixtureDataCollector(); - static::assertSame( + self::assertSame( $this->removeTabId('
test
'), $this->removeTabId($collector->getTabs()) ); @@ -85,7 +85,7 @@ public function testCreateDropdownMenuContent() { $collector = new FixtureDataCollector(); - static::assertSame( + self::assertSame( $this->removeDropdownMenuId('
content
'), $this->removeDropdownMenuId($collector->getDropdownMenuContent()) ); diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php index b88d08370..4d3db4279 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php @@ -17,17 +17,17 @@ public function testAddMessageAndLog() $msgs = $collector->getMessages(); - static::assertCount(1, $msgs); + self::assertCount(1, $msgs); $collector->addMessage(['hello'], 'notice'); - static::assertCount(1, $collector->getMessages()); + self::assertCount(1, $collector->getMessages()); $collector->flush(); $msgs = $collector->getMessages(); - static::assertCount(1, $msgs); + self::assertCount(1, $msgs); } public function testCollect() @@ -42,9 +42,9 @@ public function testCollect() $data = $collector->getData(); - static::assertEquals(1, $data['counted']); - static::assertEquals(1, $collector->getCountedLogs()); - static::assertEquals($collector->getMessages(), $data['messages']); + self::assertEquals(1, $data['counted']); + self::assertEquals(1, $collector->getCountedLogs()); + self::assertEquals($collector->getMessages(), $data['messages']); } public function testGetMenu() @@ -56,7 +56,7 @@ public function testGetMenu() $this->mock(ResponseInterface::class) ); - static::assertSame(['label' => 'Logs', 'value' => 1], $collector->getMenu()); + self::assertSame(['label' => 'Logs', 'value' => 1], $collector->getMenu()); } public function testGetPanel() @@ -68,7 +68,7 @@ public function testGetPanel() $this->mock(ResponseInterface::class) ); - static::assertSame( + self::assertSame( preg_replace('/(\r\n|\n\r|\r)/', "\n", '
TypeMessage
"error"
 
"[2017-01-03 18:58:03] develop.ERROR: Viserio\Contracts\Container\Exceptions\NotFoundException: Abstract (Viserio\Translation\DataCollectors\ViserioTranslationDataCollector) is not being managed by the container in \src\Viserio\Container\Container.php:378 Stack trace: #0 \src\Viserio\WebProfiler\Providers\WebProfilerServiceProvider.php(131): Viserio\Container\Container->get('Viserio\\\\Transla...') #1 \src\Viserio\WebProfiler\Providers\WebProfilerServiceProvider.php(68): Viserio\WebProfiler\Providers\WebProfilerServiceProvider::registerCollectorsFromConfig(Object(Viserio\Foundation\Application), Object(Viserio\WebProfiler\WebProfiler)) #2 \src\Viserio\Container\Container.php(433): Viserio\WebProfiler\Providers\WebProfilerServiceProvider::createWebProfiler(Object(Viserio\Foundation\Application), NULL) #3 [internal function]: Viserio\Container\Container::Viserio\Container\{closure}(Object(Viserio\Foundation\Application)) #4 \src\Viserio\Container\ContainerResolver.php(131): ReflectionFunction->invokeArgs(Array) #5 \src\Viserio\Container\ContainerResolver.php(37): Viserio\Container\ContainerResolver->resolveFunction(Object(Closure), Array) #6 \src\Viserio\Container\Container.php(621): Viserio\Container\ContainerResolver->resolve(Object(Closure), Array) #7 \src\Viserio\Container\Container.php(260): Viserio\Container\Container->resolveSingleton('Viserio\\\\Contrac...', Array) #8 \src\Viserio\Container\Container.php(232): Viserio\Container\Container->resolveBound('Viserio\\\\Contrac...', Array) #9 \src\Viserio\Container\Container.php(373): Viserio\Container\Container->resolve('Viserio\\\\Contrac...') #10 \src\Viserio\Foundation\Http\Kernel.php(216): Viserio\Container\Container->get('Viserio\\\\Contrac...') #11 \src\Viserio\Foundation\Http\Kernel.php(174): Viserio\Foundation\Http\Kernel->handleRequest(Object(Viserio\Http\ServerRequest)) #12 D:\Anolilab\Github\Php\narrowspark\public\index.php(36): Viserio\Foundation\Http\Kernel->handle(Object(Viserio\Http\ServerRequest)) #13 {main} {"identification":{}} []"
diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php
index 7165f912a..b21ea20bb 100644
--- a/src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php
+++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php
@@ -19,7 +19,7 @@ public function testGetMenu()
 
         $data = $collect->getData();
 
-        static::assertSame(
+        self::assertSame(
             [
                 'icon'  => 'ic_memory_white_24px.svg',
                 'label' => $data['memory'] / 1024 / 1024,
@@ -41,7 +41,7 @@ public function testGetTooltip()
         $collect->updateMemoryUsage();
         $data = $collect->getData();
 
-        static::assertSame(
+        self::assertSame(
             '
Peak memory usage' . $data['memory'] / 1024 / 1024 . ' MB
PHP memory limitUnlimited MB
', $collect->getTooltip() ); diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php index 2a4e435d1..33eec4cf5 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php @@ -16,17 +16,17 @@ public function testAddMessageAndLog() $msgs = $collector->getMessages(); - static::assertCount(1, $msgs); + self::assertCount(1, $msgs); $collector->addMessage(['hello'], 'notice'); - static::assertCount(2, $collector->getMessages()); + self::assertCount(2, $collector->getMessages()); $collector->flush(); $msgs = $collector->getMessages(); - static::assertCount(0, $msgs); + self::assertCount(0, $msgs); } public function testCollect() @@ -41,8 +41,8 @@ public function testCollect() $data = $collector->getData(); - static::assertEquals(1, $data['counted']); - static::assertEquals($collector->getMessages(), $data['messages']); + self::assertEquals(1, $data['counted']); + self::assertEquals($collector->getMessages(), $data['messages']); } public function testGetMenu() @@ -54,6 +54,6 @@ public function testGetMenu() $this->mock(ResponseInterface::class) ); - static::assertSame(['label' => 'Messages', 'value' => 0], $collector->getMenu()); + self::assertSame(['label' => 'Messages', 'value' => 0], $collector->getMenu()); } } diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php index e83d47a38..3273e8115 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php @@ -17,10 +17,10 @@ public function testCollect() $this->mock(ResponseInterface::class) ); - static::assertRegExp('~^' . preg_quote($collect->getPhpVersion(), '~') . '~', PHP_VERSION); - static::assertRegExp('~' . preg_quote((string) $collect->getPhpVersionExtra(), '~') . '$~', PHP_VERSION); - static::assertSame(PHP_INT_SIZE * 8, $collect->getPhpArchitecture()); - static::assertSame(date_default_timezone_get(), $collect->getPhpTimezone()); + self::assertRegExp('~^' . preg_quote($collect->getPhpVersion(), '~') . '~', PHP_VERSION); + self::assertRegExp('~' . preg_quote((string) $collect->getPhpVersionExtra(), '~') . '$~', PHP_VERSION); + self::assertSame(PHP_INT_SIZE * 8, $collect->getPhpArchitecture()); + self::assertSame(date_default_timezone_get(), $collect->getPhpTimezone()); } public function testGetMenu() @@ -31,7 +31,7 @@ public function testGetMenu() $this->mock(ResponseInterface::class) ); - static::assertSame( + self::assertSame( [ 'label' => 'PHP Version', 'value' => PHP_VERSION, diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/TimeDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/TimeDataCollectorTest.php index 0cc9e8af7..490274072 100644 --- a/src/Viserio/Component/Profiler/Tests/DataCollectors/TimeDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/TimeDataCollectorTest.php @@ -14,8 +14,8 @@ public function testGetMenuAndPosition() $collect = $this->getTimeDataCollector(); $data = $collect->getData(); - static::assertSame('right', $collect->getMenuPosition()); - static::assertSame( + self::assertSame('right', $collect->getMenuPosition()); + self::assertSame( [ 'icon' => 'ic_schedule_white_24px.svg', 'label' => '', @@ -30,7 +30,7 @@ public function testGetRequestDuration() $collect = $this->getTimeDataCollector(); $data = $collect->getData(); - static::assertSame($data['duration'], $collect->getRequestDuration()); + self::assertSame($data['duration'], $collect->getRequestDuration()); $request = $this->mock(ServerRequestInterface::class); $request->shouldReceive('getHeaderLine') @@ -43,7 +43,7 @@ public function testGetRequestDuration() ->andReturn(''); $collect = new TimeDataCollector($request); - static::assertTrue(is_float($collect->getRequestDuration())); + self::assertTrue(is_float($collect->getRequestDuration())); } public function testStartHasStopMeasure() @@ -52,13 +52,13 @@ public function testStartHasStopMeasure() $collect->startMeasure('test'); - static::assertTrue($collect->hasStartedMeasure('test')); + self::assertTrue($collect->hasStartedMeasure('test')); $collect->stopMeasure('test'); $measure = $collect->getMeasures()[0]; - static::assertSame('test', $measure['label']); + self::assertSame('test', $measure['label']); $keysExistCheck = [ 'label', @@ -73,7 +73,7 @@ public function testStartHasStopMeasure() ]; foreach ($keysExistCheck as $key => $value) { - static::assertTrue(array_key_exists($value, $measure)); + self::assertTrue(array_key_exists($value, $measure)); } } diff --git a/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php b/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php index cf284d20a..758d49373 100644 --- a/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php +++ b/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php @@ -40,7 +40,7 @@ public function testProcess() return (new ResponseFactory())->createResponse(200); })); - static::assertEquals( + self::assertEquals( $this->removeId($renderedContent), $this->removeId((string) $response->getBody()) ); diff --git a/src/Viserio/Component/Profiler/Tests/ProfileTest.php b/src/Viserio/Component/Profiler/Tests/ProfileTest.php index 278a4d950..166c78b2f 100644 --- a/src/Viserio/Component/Profiler/Tests/ProfileTest.php +++ b/src/Viserio/Component/Profiler/Tests/ProfileTest.php @@ -12,11 +12,11 @@ public function testSetAndGetToken() { $profile = new Profile('d78a9fa'); - static::assertSame('d78a9fa', $profile->getToken()); + self::assertSame('d78a9fa', $profile->getToken()); $profile->setToken('4dasda5sd'); - static::assertSame('4dasda5sd', $profile->getToken()); + self::assertSame('4dasda5sd', $profile->getToken()); } public function testSetAndGetIp() @@ -25,7 +25,7 @@ public function testSetAndGetIp() $profile->setIp('127.0.0.1'); - static::assertSame('127.0.0.1', $profile->getIp()); + self::assertSame('127.0.0.1', $profile->getIp()); } public function testSetAndGetMethod() @@ -34,7 +34,7 @@ public function testSetAndGetMethod() $profile->setMethod('GET'); - static::assertSame('GET', $profile->getMethod()); + self::assertSame('GET', $profile->getMethod()); } public function testSetAndGetUrl() @@ -43,20 +43,20 @@ public function testSetAndGetUrl() $profile->setUrl('/'); - static::assertSame('/', $profile->getUrl()); + self::assertSame('/', $profile->getUrl()); } public function testSetAndGetTime() { $profile = new Profile('5d7asd57as2'); - static::assertSame('0', $profile->getTime()); + self::assertSame('0', $profile->getTime()); $profile = new Profile('a7das6d'); $profile->setTime(12115.13); - static::assertSame('12115.13', $profile->getTime()); + self::assertSame('12115.13', $profile->getTime()); } public function testGetAndSetDate() @@ -65,7 +65,7 @@ public function testGetAndSetDate() $profile->setDate('12/12/2012'); - static::assertSame('12/12/2012', $profile->getDate()); + self::assertSame('12/12/2012', $profile->getDate()); } public function testSetAndGetStatus() @@ -74,7 +74,7 @@ public function testSetAndGetStatus() $profile->setStatusCode(500); - static::assertSame('500', $profile->getStatusCode()); + self::assertSame('500', $profile->getStatusCode()); } public function testSetGetHasAllCollectors() @@ -87,9 +87,9 @@ public function testSetGetHasAllCollectors() $collector, ]); - static::assertInstanceOf(PhpInfoDataCollector::class, $profile->getCollector('php-info-data-collector')); - static::assertTrue($profile->hasCollector('php-info-data-collector')); - static::assertEquals( + self::assertInstanceOf(PhpInfoDataCollector::class, $profile->getCollector('php-info-data-collector')); + self::assertTrue($profile->hasCollector('php-info-data-collector')); + self::assertEquals( [ 'php-info-data-collector' => new PhpInfoDataCollector(), ], diff --git a/src/Viserio/Component/Profiler/Tests/ProfilerTest.php b/src/Viserio/Component/Profiler/Tests/ProfilerTest.php index 600039e48..d92efe057 100644 --- a/src/Viserio/Component/Profiler/Tests/ProfilerTest.php +++ b/src/Viserio/Component/Profiler/Tests/ProfilerTest.php @@ -20,7 +20,7 @@ public function testSetAndGetUrlGenerator() $profiler->setUrlGenerator($this->mock(UrlGeneratorContract::class)); - static::assertInstanceOf(UrlGeneratorContract::class, $profiler->getUrlGenerator()); + self::assertInstanceOf(UrlGeneratorContract::class, $profiler->getUrlGenerator()); } public function testSetAndGetTemplate() @@ -29,7 +29,7 @@ public function testSetAndGetTemplate() $profiler->setTemplate(__DIR__); - static::assertSame(__DIR__, $profiler->getTemplate()); + self::assertSame(__DIR__, $profiler->getTemplate()); } public function testAddHasAndGetCollectors() @@ -39,9 +39,9 @@ public function testAddHasAndGetCollectors() $profiler->addCollector($collector); - static::assertTrue($profiler->hasCollector('php-info-data-collector')); + self::assertTrue($profiler->hasCollector('php-info-data-collector')); - static::assertSame( + self::assertSame( [ 'php-info-data-collector' => [ 'collector' => $collector, @@ -91,7 +91,7 @@ public function testModifyResponse() $renderedContent = $assets->render() . $template->render(); - static::assertEquals( + self::assertEquals( $this->removeId($renderedContent), $this->removeId((string) $response->getBody()) ); @@ -128,7 +128,7 @@ public function testModifyResponseWithOldContent() $renderedContent = $assets->render() . $template->render(); - static::assertEquals( + self::assertEquals( $this->removeId('' . $renderedContent . ''), $this->removeId((string) $response->getBody()) ); @@ -151,7 +151,7 @@ public function testDontModifyResponse() $orginalResponse ); - static::assertEquals($response, $orginalResponse); + self::assertEquals($response, $orginalResponse); } private function removeId(string $html): string diff --git a/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php b/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php index 69e53d6cf..138ab85e5 100644 --- a/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php +++ b/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php @@ -48,7 +48,7 @@ public function testRender() $assets->getIcons() ); - static::assertSame( + self::assertSame( $this->removeId(file_get_contents(__DIR__ . '/Fixture/View/profile.html')), $this->removeId($template->render()) ); @@ -72,7 +72,7 @@ public function testRenderWithCollector() require_once __DIR__ . '/Fixture/View/profilewithcollector.html.php'; - static::assertSame( + self::assertSame( $this->removeId($text), $this->removeId($template->render()) ); @@ -94,7 +94,7 @@ public function testRenderWithAjaxRequestsDataCollector() $assets->getIcons() ); - static::assertSame( + self::assertSame( $this->removeId(file_get_contents(__DIR__ . '/Fixture/View/profilewithajaxcollector.html.php')), $this->removeId($template->render()) ); @@ -118,7 +118,7 @@ public function testRenderWithAPanelCollector() $assets->getIcons() ); - static::assertSame( + self::assertSame( $this->removeId(file_get_contents(__DIR__ . '/Fixture/View/profilewithpanelcollector.html.php')), $this->removeId($template->render()) ); diff --git a/src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php b/src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php index 944df9be7..a8c937a6e 100644 --- a/src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php +++ b/src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php @@ -18,7 +18,7 @@ public function testOutput() string; - static::assertSame($expectedOutput, $htmlDumperOutput->getOutput()); + self::assertSame($expectedOutput, $htmlDumperOutput->getOutput()); } public function testClear() @@ -28,6 +28,6 @@ public function testClear() $htmlDumperOutput('second line', 2); $htmlDumperOutput->flush(); - static::assertNull($htmlDumperOutput->getOutput()); + self::assertNull($htmlDumperOutput->getOutput()); } } diff --git a/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php b/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php index 3f6bfb7d1..51eca1750 100644 --- a/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php @@ -48,11 +48,11 @@ public function testGetServices() $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(ProfilerContract::class, $profiler); + self::assertInstanceOf(ProfilerContract::class, $profiler); - static::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); - static::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); - static::assertTrue(array_key_exists('routing-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors())); + self::assertTrue(array_key_exists('routing-data-collector', $profiler->getCollectors())); } private function getRequest() diff --git a/src/Viserio/Component/Routing/Tests/SortedMiddlewareTest.php b/src/Viserio/Component/Routing/Tests/SortedMiddlewareTest.php index 9815a39c8..23b05c298 100644 --- a/src/Viserio/Component/Routing/Tests/SortedMiddlewareTest.php +++ b/src/Viserio/Component/Routing/Tests/SortedMiddlewareTest.php @@ -35,13 +35,13 @@ public function testMiddlewareCanBeSortedByPriority() 'Third', ]; - static::assertEquals($expected, (new SortedMiddleware($priority, $middleware))->getAll()); - static::assertEquals([], (new SortedMiddleware(['First'], []))->getAll()); - static::assertEquals(['First'], (new SortedMiddleware(['First'], ['First']))->getAll()); - static::assertEquals(['First', 'Second'], (new SortedMiddleware(['First', 'Second'], ['Second', 'First']))->getAll()); + self::assertEquals($expected, (new SortedMiddleware($priority, $middleware))->getAll()); + self::assertEquals([], (new SortedMiddleware(['First'], []))->getAll()); + self::assertEquals(['First'], (new SortedMiddleware(['First'], ['First']))->getAll()); + self::assertEquals(['First', 'Second'], (new SortedMiddleware(['First', 'Second'], ['Second', 'First']))->getAll()); $closure = function () { }; - static::assertEquals(['Second', $closure], (new SortedMiddleware(['First', 'Second'], ['Second', $closure]))->getAll()); + self::assertEquals(['Second', $closure], (new SortedMiddleware(['First', 'Second'], ['Second', $closure]))->getAll()); } } diff --git a/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php b/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php index 256f57b2b..3c001084c 100644 --- a/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php +++ b/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php @@ -21,7 +21,7 @@ public function testGetIpAddress() $clientIp = new ClientIp($request); - static::assertSame('111.111.111.111', $clientIp->getIpAddress()); + self::assertSame('111.111.111.111', $clientIp->getIpAddress()); $request = $this->mock(ServerRequestInterface::class); $request->shouldReceive('hasHeader') @@ -38,6 +38,6 @@ public function testGetIpAddress() $clientIp = new ClientIp($request); - static::assertSame('100.8.116.127', $clientIp->getIpAddress()); + self::assertSame('100.8.116.127', $clientIp->getIpAddress()); } } diff --git a/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php b/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php index 3ee883340..fce0198e9 100644 --- a/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php +++ b/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php @@ -44,7 +44,7 @@ public function testGetMenu() { $collector = new ViserioTranslationDataCollector($this->translator); - static::assertEquals( + self::assertEquals( [ 'icon' => file_get_contents(__DIR__ . '/../../DataCollectors/Resources/icons/ic_translate_white_24px.svg'), 'label' => '', @@ -58,7 +58,7 @@ public function testGetTooltip() { $collector = new ViserioTranslationDataCollector($this->translator); - static::assertSame('
Missing messages
Fallback messages
Defined messages
', $collector->getTooltip()); + self::assertSame('
Missing messages
Fallback messages
Defined messages
', $collector->getTooltip()); } public function testGetPanel() @@ -69,7 +69,7 @@ public function testGetPanel() $this->mock(ResponseInterface::class) ); - static::assertSame( + self::assertSame( $this->removeId('

These messages are correctly translated into the given locale.

Empty

These messages are not available for the given locale but Symfony found them in the fallback locale catalog.

Empty

These messages are not available for the given locale and cannot be found in the fallback locales.
Add them to the translation catalogue to avoid Narrowspark outputting untranslated contents.

Empty
'), $this->removeId($collector->getPanel()) ); @@ -88,7 +88,7 @@ public function testGetPanelWithTranslation() $this->mock(ResponseInterface::class) ); - static::assertSame( + self::assertSame( '

These messages are correctly translated into the given locale.

LocaleDomainTimes usedMessage IDMessage Preview
"en"
 
"messages"
diff --git a/src/Viserio/Component/View/Tests/Middleware/ShareErrorsFromSessionMiddlewareTest.php b/src/Viserio/Component/View/Tests/Middleware/ShareErrorsFromSessionMiddlewareTest.php
index a33095367..5aff988bc 100644
--- a/src/Viserio/Component/View/Tests/Middleware/ShareErrorsFromSessionMiddlewareTest.php
+++ b/src/Viserio/Component/View/Tests/Middleware/ShareErrorsFromSessionMiddlewareTest.php
@@ -39,6 +39,6 @@ public function testProcess()
             return (new ResponseFactory())->createResponse(200);
         }));
 
-        static::assertInstanceOf(ResponseInterface::class, $response);
+        self::assertInstanceOf(ResponseInterface::class, $response);
     }
 }

From 5bb6993bec46cd803b0839639ff6e454fa205f39 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Sun, 7 May 2017 22:29:37 +0200
Subject: [PATCH 35/99] cs fixes

---
 .../Bridge/Log/MonologLoggerDataCollector.php    |  4 ++--
 .../Cache/TraceableCacheItemDecoraterTest.php    | 16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php
index ba00ef7a6..27947c480 100644
--- a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php
+++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php
@@ -3,14 +3,14 @@
 namespace Viserio\Component\Profiler\DataCollectors\Bridge\Log;
 
 use ErrorException;
-use RuntimeException;
 use Monolog\Logger;
-use Viserio\Component\Log\Writer;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
+use RuntimeException;
 use Symfony\Component\Debug\Exception\SilencedErrorContext;
 use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract;
 use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract;
+use Viserio\Component\Log\Writer;
 use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector;
 
 class MonologLoggerDataCollector extends AbstractDataCollector implements
diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php
index 8d2242deb..e8d5adc82 100644
--- a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php
+++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php
@@ -19,7 +19,7 @@ public function testGetItemMissTrace()
         $call = $calls[0];
 
         self::assertEquals('getItem', $call->name);
-        self::assertSame(array('k' => false), $call->result);
+        self::assertSame(['k' => false], $call->result);
         self::assertEquals(0, $call->hits);
         self::assertEquals(1, $call->misses);
         self::assertNotEmpty($call->start);
@@ -58,7 +58,7 @@ public function testGetItemsMissTrace()
         $call = $calls[0];
 
         self::assertEquals('getItems', $call->name);
-        self::assertSame(array('k0' => false, 'k1' => false), $call->result);
+        self::assertSame(['k0' => false, 'k1' => false], $call->result);
         self::assertEquals(2, $call->misses);
         self::assertNotEmpty($call->start);
         self::assertNotEmpty($call->end);
@@ -75,7 +75,7 @@ public function testHasItemMissTrace()
         $call = $calls[0];
 
         self::assertEquals('hasItem', $call->name);
-        self::assertSame(array('k' => false), $call->result);
+        self::assertSame(['k' => false], $call->result);
         self::assertNotEmpty($call->start);
         self::assertNotEmpty($call->end);
     }
@@ -93,7 +93,7 @@ public function testHasItemHitTrace()
         $call = $calls[2];
 
         self::assertEquals('hasItem', $call->name);
-        self::assertSame(array('k' => true), $call->result);
+        self::assertSame(['k' => true], $call->result);
         self::assertNotEmpty($call->start);
         self::assertNotEmpty($call->end);
     }
@@ -109,7 +109,7 @@ public function testDeleteItemTrace()
         $call = $calls[0];
 
         self::assertEquals('deleteItem', $call->name);
-        self::assertSame(array('k' => true), $call->result);
+        self::assertSame(['k' => true], $call->result);
         self::assertEquals(0, $call->hits);
         self::assertEquals(0, $call->misses);
         self::assertNotEmpty($call->start);
@@ -128,7 +128,7 @@ public function testDeleteItemsTrace()
         $call = $calls[0];
 
         self::assertEquals('deleteItems', $call->name);
-        self::assertSame(array('keys' => $arg, 'result' => true), $call->result);
+        self::assertSame(['keys' => $arg, 'result' => true], $call->result);
         self::assertEquals(0, $call->hits);
         self::assertEquals(0, $call->misses);
         self::assertNotEmpty($call->start);
@@ -147,7 +147,7 @@ public function testSaveTrace()
         $call = $calls[1];
 
         self::assertEquals('save', $call->name);
-        self::assertSame(array('k' => true), $call->result);
+        self::assertSame(['k' => true], $call->result);
         self::assertEquals(0, $call->hits);
         self::assertEquals(0, $call->misses);
         self::assertNotEmpty($call->start);
@@ -166,7 +166,7 @@ public function testSaveDeferredTrace()
         $call = $calls[1];
 
         self::assertEquals('saveDeferred', $call->name);
-        self::assertSame(array('k' => true), $call->result);
+        self::assertSame(['k' => true], $call->result);
         self::assertEquals(0, $call->hits);
         self::assertEquals(0, $call->misses);
         self::assertNotEmpty($call->start);

From b69fbe9f682585cbbb06a0a580808f0bbda19e0e Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Tue, 9 May 2017 00:54:56 +0200
Subject: [PATCH 36/99] wrap script code in a try (#529)

Add try catch to bash script.sh

fix getallheaders call

remove normalizeServer function
---
 build/travis/script.sh                        | 26 ++++++---
 .../HttpFactory/ServerRequestFactory.php      | 53 +++----------------
 2 files changed, 27 insertions(+), 52 deletions(-)

diff --git a/build/travis/script.sh b/build/travis/script.sh
index c2bdd9140..51591968d 100644
--- a/build/travis/script.sh
+++ b/build/travis/script.sh
@@ -6,20 +6,30 @@
 #   $2 command to execute
 tfold () {
     title=$1
-    fold=$(echo $title | sed -r 's/[^-_A-Za-z\d]+/./g')
+    fold=$(echo "$title" | sed -r 's/[^-_A-Za-z\d]+/./g')
     shift
     echo -e "travis_fold:start:$fold\\n\\e[1;34m$title\\e[0m"
     bash -xc "$*" 2>&1 && echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold" || ( echo -e "\\e[41mKO\\e[0m $title\\n" && exit 1 )
 }
-export -f tfold
+
+function try () {
+    [[ $- = *e* ]]; SAVED_EXCEPTION=$?
+    set +e
+}
+
+function catch () {
+    export ex_code=$?
+    (( $SAVED_EXCEPTION )) && set +e
+    return $ex_code
+}
 
 if [[ "$PHPUNIT" = true && "$SEND_COVERAGE" = true ]]; then
-    bash -xc ""$TEST" -c ./phpunit.xml.dist --verbose --coverage-clover=coverage.xml";
+    bash -xc "$TEST -c ./phpunit.xml.dist --verbose --coverage-clover=coverage.xml";
 elif [[ "$PHPUNIT" = true ]]; then
     for f in ./src/Viserio/*/*; do
         if [[ -d "$f" && ! -L "$f" ]]; then
-            SLUG="$(basename $f)";
-            TYPE="$(basename ${f%/*})";
+            SLUG="$(basename "$f")";
+            TYPE="$(basename "${f%/*}")";
 
             if [[ "$TYPE" = "Component" ]]; then
                 TESTSUITE="Narrowspark $SLUG Component Test Suite";
@@ -27,7 +37,11 @@ elif [[ "$PHPUNIT" = true ]]; then
                 TESTSUITE="Narrowspark $SLUG Bridge Test Suite";
             fi
 
-            tfold "$TESTSUITE" "$TEST -c ./phpunit.xml.dist --verbose --testsuite=\"$TESTSUITE\"";
+            try
+                tfold "$TESTSUITE" "$TEST -c ./phpunit.xml.dist --verbose --testsuite=\"$TESTSUITE\"";
+            catch || {
+                exit 1
+            }
         fi
     done
 elif [[ "$PHPSTAN" = true ]]; then
diff --git a/src/Viserio/Component/HttpFactory/ServerRequestFactory.php b/src/Viserio/Component/HttpFactory/ServerRequestFactory.php
index 1587f1866..e63a16116 100644
--- a/src/Viserio/Component/HttpFactory/ServerRequestFactory.php
+++ b/src/Viserio/Component/HttpFactory/ServerRequestFactory.php
@@ -24,15 +24,14 @@ public function createServerRequest($method, $uri): ServerRequestInterface
      */
     public function createServerRequestFromArray(array $server): ServerRequestInterface
     {
-        $server  = $this->normalizeServer($server);
-        $headers = function_exists('allheaders') ? allheaders() : $this->allHeaders($server);
+        $headers = $this->getHeaders($server);
         $method  = $server['REQUEST_METHOD'] ?? 'GET';
 
         return $this->buildServerRequest($server, $headers, $method, Uri::createFromServer($server));
     }
 
     /**
-     * Build a server request from given datas.
+     * Build a server request from given data.
      *
      * @param array                                 $server
      * @param array                                 $headers
@@ -53,44 +52,6 @@ protected function buildServerRequest(array $server, array $headers, string $met
         );
     }
 
-    /**
-     * Marshal the $_SERVER array.
-     *
-     * Pre-processes and returns the $_SERVER superglobal.
-     *
-     * @param array $server
-     *
-     * @return array
-     */
-    protected function normalizeServer(array $server): array
-    {
-        // This seems to be the only way to get the Authorization header on Apache
-        if (! function_exists('apache_request_headers') ||
-            isset($server['HTTP_AUTHORIZATION'])
-        ) {
-            return $server;
-        }
-
-        // Can only be testet on a apache server
-        // @codeCoverageIgnoreStart
-        $headers = apache_request_headers();
-
-        if (isset($headers['Authorization'])) {
-            $server['HTTP_AUTHORIZATION'] = $headers['Authorization'];
-
-            return $server;
-        }
-
-        if (isset($headers['authorization'])) {
-            $server['HTTP_AUTHORIZATION'] = $headers['authorization'];
-
-            return $server;
-        }
-        // @codeCoverageIgnoreStop
-
-        return $server;
-    }
-
     /**
      * Return HTTP protocol version (X.Y).
      *
@@ -123,7 +84,7 @@ protected function marshalProtocolVersion(array $server): string
      *
      * @return array
      */
-    protected function allHeaders(array $server): array
+    protected function getHeaders(array $server): array
     {
         $headers = [];
         $content = [
@@ -147,12 +108,12 @@ protected function allHeaders(array $server): array
 
         if (! isset($headers['Authorization'])) {
             if (isset($server['REDIRECT_HTTP_AUTHORIZATION'])) {
-                $headers['Authorization'] = $server['REDIRECT_HTTP_AUTHORIZATION'];
+                $headers['HTTP_AUTHORIZATION'] = $server['REDIRECT_HTTP_AUTHORIZATION'];
             } elseif (isset($server['PHP_AUTH_USER'])) {
-                $basicPass                = isset($server['PHP_AUTH_PW']) ? $server['PHP_AUTH_PW'] : '';
-                $headers['Authorization'] = 'Basic ' . base64_encode($server['PHP_AUTH_USER'] . ':' . $basicPass);
+                $basicPass                     = $server['PHP_AUTH_PW'] ?? '';
+                $headers['HTTP_AUTHORIZATION'] = 'Basic ' . base64_encode($server['PHP_AUTH_USER'] . ':' . $basicPass);
             } elseif (isset($server['PHP_AUTH_DIGEST'])) {
-                $headers['Authorization'] = $server['PHP_AUTH_DIGEST'];
+                $headers['HTTP_AUTHORIZATION'] = $server['PHP_AUTH_DIGEST'];
             }
         }
 

From c68a0ac37698077b8214f52c8c4b3545563be7cf Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Tue, 9 May 2017 14:16:38 +0200
Subject: [PATCH 37/99] fix kernel test

---
 .../Foundation/Tests/Http/KernelTest.php      | 21 ++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php
index 12ec3041c..ebf07d695 100644
--- a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php
+++ b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php
@@ -6,6 +6,7 @@
 use Mockery as Mock;
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
 use Psr\Http\Message\ResponseInterface;
+use Viserio\Component\Contracts\Routing\Dispatcher as DispatcherContract;
 use Psr\Http\Message\ServerRequestInterface;
 use Viserio\Component\Contracts\Container\Container as ContainerContract;
 use Viserio\Component\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
@@ -114,10 +115,11 @@ public function testHandle()
             ->once()
             ->with(Mock::type(ServerRequestInterface::class))
             ->andReturn($this->mock(ResponseInterface::class));
-        $router->shouldReceive('setCachePath')
+        $dispatcher = $this->mock(DispatcherContract::class);
+        $dispatcher->shouldReceive('setCachePath')
             ->once()
             ->with('/storage/framework/routes.cache.php');
-        $router->shouldReceive('refreshCache')
+        $dispatcher->shouldReceive('refreshCache')
             ->once()
             ->with(true);
 
@@ -125,6 +127,10 @@ public function testHandle()
             ->once()
             ->with(RouterContract::class)
             ->andReturn($router);
+        $container->shouldReceive('get')
+            ->once()
+            ->with(DispatcherContract::class)
+            ->andReturn($dispatcher);
 
         $kernel = $this->getKernel($container);
 
@@ -144,13 +150,14 @@ public function testHandleWithException()
             ->with('X-Php-Ob-Level', (string) ob_get_level())
             ->andReturn($serverRequest);
 
-        $router = $this->mock(RouterContract::class);
-        $router->shouldReceive('setCachePath')
+        $dispatcher = $this->mock(DispatcherContract::class);
+        $dispatcher->shouldReceive('setCachePath')
             ->once()
             ->with('/storage/framework/routes.cache.php');
-        $router->shouldReceive('refreshCache')
+        $dispatcher->shouldReceive('refreshCache')
             ->once()
             ->with(true);
+        $router = $this->mock(RouterContract::class);
         $router->shouldReceive('dispatch')
             ->once()
             ->with($serverRequest)
@@ -173,6 +180,10 @@ public function testHandleWithException()
             ->twice()
             ->with(ExceptionHandlerContract::class)
             ->andReturn($handler);
+        $container->shouldReceive('get')
+            ->once()
+            ->with(DispatcherContract::class)
+            ->andReturn($dispatcher);
 
         $events = $this->mock(EventManagerContract::class);
         $events->shouldReceive('trigger')

From db4149d8e51166680a34de43a4fe49b7ad4c66d2 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Tue, 9 May 2017 12:16:47 +0000
Subject: [PATCH 38/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Foundation/Tests/Http/KernelTest.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php
index ebf07d695..72fea1a9d 100644
--- a/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php
+++ b/src/Viserio/Component/Foundation/Tests/Http/KernelTest.php
@@ -6,11 +6,11 @@
 use Mockery as Mock;
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
 use Psr\Http\Message\ResponseInterface;
-use Viserio\Component\Contracts\Routing\Dispatcher as DispatcherContract;
 use Psr\Http\Message\ServerRequestInterface;
 use Viserio\Component\Contracts\Container\Container as ContainerContract;
 use Viserio\Component\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
 use Viserio\Component\Contracts\Events\EventManager as EventManagerContract;
+use Viserio\Component\Contracts\Routing\Dispatcher as DispatcherContract;
 use Viserio\Component\Contracts\Routing\Router as  RouterContract;
 use Viserio\Component\Events\Providers\EventsServiceProvider;
 use Viserio\Component\Foundation\Bootstrap\LoadServiceProvider;

From ed8e7e17e0e70ab76673120bc94093a5078b578b Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Mon, 15 May 2017 15:18:18 +0200
Subject: [PATCH 39/99] added response time (in miliseconds)

---
 .../Component/Profiler/Middleware/ProfilerMiddleware.php      | 4 ++++
 .../Profiler/Tests/Middleware/ProfilerMiddlewareTest.php      | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php
index 81be9ab2c..fa089263b 100644
--- a/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php
+++ b/src/Viserio/Component/Profiler/Middleware/ProfilerMiddleware.php
@@ -39,7 +39,11 @@ public function __construct(ContainerInterface $container)
      */
     public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface
     {
+        $server    = $request->getServerParams();
+        $startTime = $server['REQUEST_TIME_FLOAT'] ?? microtime(true);
+
         $response = $delegate->process($request);
+        $response = $response->withHeader('X-Response-Time', sprintf('%2.3fms', (microtime(true) - $startTime) * 1000));
 
         if ($this->profiler === null) {
             return $response;
diff --git a/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php b/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php
index 758d49373..639e68115 100644
--- a/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php
+++ b/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php
@@ -30,6 +30,7 @@ public function testProcess()
 
         $server                = $_SERVER;
         $server['SERVER_ADDR'] = '127.0.0.1';
+
         unset($server['PHP_SELF']);
 
         $renderedContent = $assets->render() . $template->render();
@@ -44,6 +45,7 @@ public function testProcess()
             $this->removeId($renderedContent),
             $this->removeId((string) $response->getBody())
         );
+        self::assertRegexp('/^\d{1,4}\.\d{3}ms$/', $response->getHeaderLine('X-Response-Time'));
     }
 
     private function removeId(string $html): string

From 5aaa9591203b3a6eae780e03b75674aaae68d978 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Tue, 16 May 2017 01:16:43 +0200
Subject: [PATCH 40/99] Working on session middleware

---
 src/Viserio/Component/Cookie/Cookie.php       |  8 ++---
 .../Component/Cookie/RequestCookies.php       |  3 +-
 .../ViserioHttpDataCollector.php              | 31 +++++++++---------
 .../Component/Foundation/Http/Kernel.php      | 15 ++++-----
 src/Viserio/Component/Profiler/Profile.php    |  4 +--
 .../Middleware/StartSessionMiddleware.php     | 22 ++++++++-----
 .../Middleware/VerifyCsrfTokenMiddleware.php  |  5 +--
 .../Providers/SessionServiceProvider.php      | 32 ++++++++++++++++++-
 .../Component/Session/SessionManager.php      |  2 +-
 9 files changed, 78 insertions(+), 44 deletions(-)

diff --git a/src/Viserio/Component/Cookie/Cookie.php b/src/Viserio/Component/Cookie/Cookie.php
index 667543593..e5237c25c 100644
--- a/src/Viserio/Component/Cookie/Cookie.php
+++ b/src/Viserio/Component/Cookie/Cookie.php
@@ -43,7 +43,7 @@ public function __construct(string $name, ?string $value = null)
      */
     public function __toString()
     {
-        $name = urlencode($this->name) . '=';
+        $name  = urlencode($this->name) . '=';
 
         return $name . urlencode($this->getValue());
     }
@@ -78,10 +78,10 @@ public function withValue(?string $value = null): Cookie
     /**
      * Returns the value.
      *
-     * @return string|null
+     * @return string
      */
-    public function getValue(): ?string
+    public function getValue(): string
     {
-        return $this->value;
+        return (string) $this->value;
     }
 }
diff --git a/src/Viserio/Component/Cookie/RequestCookies.php b/src/Viserio/Component/Cookie/RequestCookies.php
index 46bfce25e..560fa993f 100644
--- a/src/Viserio/Component/Cookie/RequestCookies.php
+++ b/src/Viserio/Component/Cookie/RequestCookies.php
@@ -50,8 +50,7 @@ public static function fromRequest(ServerRequestInterface $request): self
     public function renderIntoCookieHeader(ServerRequestInterface $request): ServerRequestInterface
     {
         $cookieString = implode('; ', $this->cookies);
-
-        $request = $request->withHeader('Cookie', $cookieString);
+        $request      = $request->withHeader('Cookie', $cookieString);
 
         return $request;
     }
diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
index 4a775ac3b..b77843f49 100644
--- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
+++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
@@ -202,25 +202,22 @@ public function getPanel(): string
                 'name'    => 'Response',
                 'content' => $this->createTable(
                     $response->getHeaders(),
-                    [
-                        'name'    => 'Response Headers',
-                        'headers' => [
-                            'key' => 'Header',
-                        ],
-                    ]
+                    ['name'    => 'Response Headers']
                 ),
             ],
             [
                 'name'    => 'Cookies',
                 'content' => $this->createTable(
-                    $this->splitOnAttributeDelimiter($request->getHeaderLine('Cookie')),
+                    array_map(function ($cookieString) {
+                        return self::fromStringCookie($cookieString);
+                    }, self::splitOnAttributeDelimiter($request->getHeaderLine('Cookie'))),
                     [
                         'name'       => 'Request Cookies',
                         'empty_text' => 'No request cookies',
                     ]
                 ) . $this->createTable(
                     array_map(function ($setCookieString) {
-                        return $this->fromStringCookie($setCookieString);
+                        return self::fromStringCookie($setCookieString);
                     }, $response->getHeader('Set-Cookie')),
                     [
                         'name'       => 'Response Cookies',
@@ -247,7 +244,7 @@ public function getPanel(): string
             [
                 'name'    => 'Flashes',
                 'content' => $this->createTable(
-                    $session !== null ? $session->get('_flash') : [],
+                    $session !== null && $session->has('_flash') ? $session->get('_flash') : [],
                     [
                         'name'       => 'Flashes',
                         'empty_text' => 'No flash messages were created',
@@ -315,13 +312,13 @@ protected function getRouteInformation(RouteContract $route): array
     }
 
     /**
-     * spplit string on attributes delimiter to array.
+     * Split string on attributes delimiter to array.
      *
      * @param string $string
      *
      * @return array
      */
-    protected function splitOnAttributeDelimiter(string $string): array
+    protected static function splitOnAttributeDelimiter(string $string): array
     {
         return array_filter(preg_split('@\s*[;]\s*@', $string));
     }
@@ -333,7 +330,7 @@ protected function splitOnAttributeDelimiter(string $string): array
      *
      * @return array
      */
-    protected function splitCookiePair(string $string): array
+    protected static function splitCookiePair(string $string): array
     {
         $pairParts = explode('=', $string, 2);
 
@@ -355,13 +352,13 @@ protected function splitCookiePair(string $string): array
      *
      * @param string $string
      *
-     * @return \Viserio\Component\Contracts\Cookie\Cookie
+     * @return array
      */
-    protected static function fromStringCookie(string $string): CookieContract
+    protected static function fromStringCookie(string $string): array
     {
-        $rawAttributes = $this->splitOnAttributeDelimiter($string);
+        $rawAttributes = self::splitOnAttributeDelimiter($string);
 
-        list($cookieName, $cookieValue) = $this->splitCookiePair(array_shift($rawAttributes));
+        return self::splitCookiePair(array_shift($rawAttributes));
     }
 
     /**
@@ -385,6 +382,8 @@ protected function prepareRequestAttributes(array $attributes): array
                 }
 
                 $preparedAttributes[$key] = $value;
+            } elseif ($value instanceof StoreContract) {
+                $preparedAttributes[$key] = $value->getId();
             } else {
                 $preparedAttributes[$key] = $value;
             }
diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php
index d2a7e858b..27a143080 100644
--- a/src/Viserio/Component/Foundation/Http/Kernel.php
+++ b/src/Viserio/Component/Foundation/Http/Kernel.php
@@ -81,14 +81,13 @@ class Kernel extends AbstractKernel implements HttpKernelContract, TerminableCon
      */
     public function getDefaultOptions(): iterable
     {
-        return array_merge(
-            parent::getDefaultOptions(),
-            [
-                'app' => [
-                    'skip_middlewares' => false,
-                ],
-            ]
-        );
+        $options = [
+            'app' => [
+                'skip_middlewares' => false,
+            ],
+        ];
+
+        return array_merge(parent::getDefaultOptions(), $options);
     }
 
     /**
diff --git a/src/Viserio/Component/Profiler/Profile.php b/src/Viserio/Component/Profiler/Profile.php
index cb6cfe8e4..9408931b1 100644
--- a/src/Viserio/Component/Profiler/Profile.php
+++ b/src/Viserio/Component/Profiler/Profile.php
@@ -231,7 +231,7 @@ public function setDate(string $date): void
     }
 
     /**
-     * Set the responce status code.
+     * Set the response status code.
      *
      * @param int $statusCode
      *
@@ -290,7 +290,7 @@ public function getCollectors(): array
     public function setCollectors(array $collectors): void
     {
         foreach ($collectors as $collector) {
-            $this->addCollector($collector);
+            $this->addCollector($collector['collector']);
         }
     }
 
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 747307062..a507564da 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -75,11 +75,11 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
         // so that the attributes may be persisted to some storage medium. We will also
         // add the session identifier cookie to the application response headers now.
         if ($this->isSessionConfigured()) {
-            $this->storeCurrentUrl($request, $session);
+            $session = $this->storeCurrentUrl($request, $session);
 
             $response = $this->addCookieToResponse($request, $response, $session);
 
-            $session->save();
+            // $session->save();
         }
 
         return $response;
@@ -114,10 +114,11 @@ protected function startSession(ServerRequestInterface $request): StoreContract
      */
     protected function getSession(ServerRequestInterface $request): StoreContract
     {
-        $session = $this->manager->getDriver();
-        $cookies = RequestCookies::fromRequest($request);
+        $session    = $this->manager->getDriver();
+        $cookies    = RequestCookies::fromRequest($request);
+        $hasCookie  = $cookies->has($session->getName());
 
-        $session->setId($cookies->get($session->getName()) ?? '');
+        $session->setId($hasCookie ? $cookies->get($session->getName())->getName() : '');
 
         $session->addFingerprintGenerator(new ClientIpGenerator($request));
         $session->addFingerprintGenerator(new UserAgentGenerator());
@@ -130,8 +131,10 @@ protected function getSession(ServerRequestInterface $request): StoreContract
      *
      * @param \Psr\Http\Message\ServerRequestInterface   $request
      * @param \Viserio\Component\Contracts\Session\Store $session
+     *
+     * @return \Viserio\Component\Contracts\Session\Store
      */
-    protected function storeCurrentUrl(ServerRequestInterface $request, StoreContract $session)
+    protected function storeCurrentUrl(ServerRequestInterface $request, StoreContract $session): StoreContract
     {
         if ($request->getMethod() === 'GET' &&
             $request->getAttribute('route') &&
@@ -139,6 +142,8 @@ protected function storeCurrentUrl(ServerRequestInterface $request, StoreContrac
         ) {
             $session->setPreviousUrl((string) $request->getUri());
         }
+
+        return $session;
     }
 
     /**
@@ -177,14 +182,15 @@ protected function addCookieToResponse(ServerRequestInterface $request, Response
         }
 
         $config = $this->config;
+        $uri    = $request->getUri();
 
         $setCookie = new SetCookie(
             $session->getName(),
             $session->getId(),
             $this->getCookieExpirationDate($config),
             $config['path'] ?? '/',
-            $config['domain'] ?? null,
-            $config['secure'] ?? ($request->getUri()->getScheme() === 'https'),
+            $config['domain'] ?? $uri->getHost(),
+            $config['secure'] ?? ($uri->getScheme() === 'https'),
             $config['http_only'] ?? false,
             $config['same_site'] ?? false
         );
diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index 483b8b2ed..e4f2ad8e1 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -119,14 +119,15 @@ protected function addCookieToResponse(
         ResponseInterface $response
     ): ResponseInterface {
         $config = $this->config;
+        $uri    = $request->getUri();
 
         $setCookie = new SetCookie(
             'XSRF-TOKEN',
             $request->getAttribute('session')->getToken(),
             $config['csrf.livetime'] ?? Chronos::now()->getTimestamp() + 60 * 120,
             $config['path'],
-            $config['domain'],
-            $config['secure'] ?? false,
+            $config['domain'] ?? $uri->getHost(),
+            $config['secure'] ?? ($uri->getScheme() === 'https'),
             false,
             $config['csrf.samesite'] ?? false
         );
diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index 71e8ec054..c9d30fa36 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -5,8 +5,12 @@
 use Interop\Container\ContainerInterface;
 use Interop\Container\ServiceProvider;
 use Viserio\Component\Contracts\Encryption\Encrypter;
+use Viserio\Component\Contracts\Events\Event as EventContract;
+use Viserio\Component\Contracts\Events\EventManager as EventManagerContract;
+use Viserio\Component\Contracts\Foundation\Terminable as TerminableContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Session\Handler\CookieSessionHandler;
 
 class SessionServiceProvider implements ServiceProvider
 {
@@ -20,10 +24,36 @@ public function getServices()
             'session'             => function (ContainerInterface $container) {
                 return $container->get(SessionManager::class);
             },
-            'session.store' => [self::class, 'createSessionStore'],
+            'session.store'             => [self::class, 'createSessionStore'],
+            EventManagerContract::class => [self::class, 'extendEventManager'],
         ];
     }
 
+    /**
+     * Extend viserio events with data collector.
+     *
+     * @param \Interop\Container\ContainerInterface $container
+     * @param null|callable                         $getPrevious
+     *
+     * @return null|\Viserio\Component\Contracts\Events\EventManager
+     */
+    public static function extendEventManager(ContainerInterface $container, ?callable $getPrevious = null): ?EventManagerContract
+    {
+        $eventManager = $getPrevious();
+
+        if ($eventManager !== null) {
+            $eventManager->attach(TerminableContract::TERMINATE, function (EventContract $event) {
+                $driver = $event->getTarget()->getContainer()->get(SessionManager::class)->getDriver();
+
+                if ($driver instanceof CookieSessionHandler) {
+                    $driver->save();
+                }
+            });
+        }
+
+        return $eventManager;
+    }
+
     public static function createSessionManager(ContainerInterface $container): SessionManager
     {
         return new SessionManager(
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index c7b64e9b8..0a0aa4ab4 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -235,7 +235,7 @@ protected function createCacheBased($driver, array $options = []): StoreContract
     protected function buildSession(SessionHandlerInterface $handler): StoreContract
     {
         return new Store(
-            $this->options['cookie'] ?? '',
+            $this->options['cookie'] ?? '_ns_attributes',
             $handler,
             $this->getEncrypter()
         );

From 59d1b10979e512e2089700a1d4718c4eba84434c Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Mon, 15 May 2017 23:16:55 +0000
Subject: [PATCH 41/99] Apply fixes from StyleCI

---
 .../Component/Session/Providers/SessionServiceProvider.php      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index c9d30fa36..2e55981c4 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -9,8 +9,8 @@
 use Viserio\Component\Contracts\Events\EventManager as EventManagerContract;
 use Viserio\Component\Contracts\Foundation\Terminable as TerminableContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
-use Viserio\Component\Session\SessionManager;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
+use Viserio\Component\Session\SessionManager;
 
 class SessionServiceProvider implements ServiceProvider
 {

From ffe3ed3580999b233fbacf3e9b608419b6fc25f3 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Tue, 16 May 2017 23:35:03 +0200
Subject: [PATCH 42/99] working on session

---
 .../Component/Session/Middleware/StartSessionMiddleware.php     | 2 --
 .../Component/Session/Providers/SessionServiceProvider.php      | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index a507564da..20ddbcb01 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -78,8 +78,6 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
             $session = $this->storeCurrentUrl($request, $session);
 
             $response = $this->addCookieToResponse($request, $response, $session);
-
-            // $session->save();
         }
 
         return $response;
diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index 2e55981c4..6736641db 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -45,7 +45,7 @@ public static function extendEventManager(ContainerInterface $container, ?callab
             $eventManager->attach(TerminableContract::TERMINATE, function (EventContract $event) {
                 $driver = $event->getTarget()->getContainer()->get(SessionManager::class)->getDriver();
 
-                if ($driver instanceof CookieSessionHandler) {
+                if ($driver->getHandler() instanceof CookieSessionHandler) {
                     $driver->save();
                 }
             });

From 42e566ba73f624409c10d1478d200b5f30795c12 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Tue, 16 May 2017 23:38:41 +0200
Subject: [PATCH 43/99] working on session

---
 src/Viserio/Component/Cookie/Cookie.php       |  8 ++---
 .../Component/Cookie/RequestCookies.php       |  3 +-
 .../Component/Foundation/Http/Kernel.php      | 15 ++++-----
 .../Middleware/StartSessionMiddleware.php     | 22 +++++++------
 .../Middleware/VerifyCsrfTokenMiddleware.php  |  5 +--
 .../Providers/SessionServiceProvider.php      | 32 ++++++++++++++++++-
 .../Component/Session/SessionManager.php      |  2 +-
 src/Viserio/Component/WebProfiler/Profile.php |  4 +--
 8 files changed, 62 insertions(+), 29 deletions(-)

diff --git a/src/Viserio/Component/Cookie/Cookie.php b/src/Viserio/Component/Cookie/Cookie.php
index 667543593..e5237c25c 100644
--- a/src/Viserio/Component/Cookie/Cookie.php
+++ b/src/Viserio/Component/Cookie/Cookie.php
@@ -43,7 +43,7 @@ public function __construct(string $name, ?string $value = null)
      */
     public function __toString()
     {
-        $name = urlencode($this->name) . '=';
+        $name  = urlencode($this->name) . '=';
 
         return $name . urlencode($this->getValue());
     }
@@ -78,10 +78,10 @@ public function withValue(?string $value = null): Cookie
     /**
      * Returns the value.
      *
-     * @return string|null
+     * @return string
      */
-    public function getValue(): ?string
+    public function getValue(): string
     {
-        return $this->value;
+        return (string) $this->value;
     }
 }
diff --git a/src/Viserio/Component/Cookie/RequestCookies.php b/src/Viserio/Component/Cookie/RequestCookies.php
index 46bfce25e..560fa993f 100644
--- a/src/Viserio/Component/Cookie/RequestCookies.php
+++ b/src/Viserio/Component/Cookie/RequestCookies.php
@@ -50,8 +50,7 @@ public static function fromRequest(ServerRequestInterface $request): self
     public function renderIntoCookieHeader(ServerRequestInterface $request): ServerRequestInterface
     {
         $cookieString = implode('; ', $this->cookies);
-
-        $request = $request->withHeader('Cookie', $cookieString);
+        $request      = $request->withHeader('Cookie', $cookieString);
 
         return $request;
     }
diff --git a/src/Viserio/Component/Foundation/Http/Kernel.php b/src/Viserio/Component/Foundation/Http/Kernel.php
index 74b96a236..d471182df 100644
--- a/src/Viserio/Component/Foundation/Http/Kernel.php
+++ b/src/Viserio/Component/Foundation/Http/Kernel.php
@@ -79,14 +79,13 @@ class Kernel extends AbstractKernel implements HttpKernelContract, TerminableCon
      */
     public function getDefaultOptions(): iterable
     {
-        return array_merge(
-            parent::getDefaultOptions(),
-            [
-                'app' => [
-                    'skip_middlewares' => false,
-                ],
-            ]
-        );
+        $options = [
+            'app' => [
+                'skip_middlewares' => false,
+            ],
+        ];
+
+        return array_merge(parent::getDefaultOptions(), $options);
     }
 
     /**
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 747307062..20ddbcb01 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -75,11 +75,9 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
         // so that the attributes may be persisted to some storage medium. We will also
         // add the session identifier cookie to the application response headers now.
         if ($this->isSessionConfigured()) {
-            $this->storeCurrentUrl($request, $session);
+            $session = $this->storeCurrentUrl($request, $session);
 
             $response = $this->addCookieToResponse($request, $response, $session);
-
-            $session->save();
         }
 
         return $response;
@@ -114,10 +112,11 @@ protected function startSession(ServerRequestInterface $request): StoreContract
      */
     protected function getSession(ServerRequestInterface $request): StoreContract
     {
-        $session = $this->manager->getDriver();
-        $cookies = RequestCookies::fromRequest($request);
+        $session    = $this->manager->getDriver();
+        $cookies    = RequestCookies::fromRequest($request);
+        $hasCookie  = $cookies->has($session->getName());
 
-        $session->setId($cookies->get($session->getName()) ?? '');
+        $session->setId($hasCookie ? $cookies->get($session->getName())->getName() : '');
 
         $session->addFingerprintGenerator(new ClientIpGenerator($request));
         $session->addFingerprintGenerator(new UserAgentGenerator());
@@ -130,8 +129,10 @@ protected function getSession(ServerRequestInterface $request): StoreContract
      *
      * @param \Psr\Http\Message\ServerRequestInterface   $request
      * @param \Viserio\Component\Contracts\Session\Store $session
+     *
+     * @return \Viserio\Component\Contracts\Session\Store
      */
-    protected function storeCurrentUrl(ServerRequestInterface $request, StoreContract $session)
+    protected function storeCurrentUrl(ServerRequestInterface $request, StoreContract $session): StoreContract
     {
         if ($request->getMethod() === 'GET' &&
             $request->getAttribute('route') &&
@@ -139,6 +140,8 @@ protected function storeCurrentUrl(ServerRequestInterface $request, StoreContrac
         ) {
             $session->setPreviousUrl((string) $request->getUri());
         }
+
+        return $session;
     }
 
     /**
@@ -177,14 +180,15 @@ protected function addCookieToResponse(ServerRequestInterface $request, Response
         }
 
         $config = $this->config;
+        $uri    = $request->getUri();
 
         $setCookie = new SetCookie(
             $session->getName(),
             $session->getId(),
             $this->getCookieExpirationDate($config),
             $config['path'] ?? '/',
-            $config['domain'] ?? null,
-            $config['secure'] ?? ($request->getUri()->getScheme() === 'https'),
+            $config['domain'] ?? $uri->getHost(),
+            $config['secure'] ?? ($uri->getScheme() === 'https'),
             $config['http_only'] ?? false,
             $config['same_site'] ?? false
         );
diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index 483b8b2ed..e4f2ad8e1 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -119,14 +119,15 @@ protected function addCookieToResponse(
         ResponseInterface $response
     ): ResponseInterface {
         $config = $this->config;
+        $uri    = $request->getUri();
 
         $setCookie = new SetCookie(
             'XSRF-TOKEN',
             $request->getAttribute('session')->getToken(),
             $config['csrf.livetime'] ?? Chronos::now()->getTimestamp() + 60 * 120,
             $config['path'],
-            $config['domain'],
-            $config['secure'] ?? false,
+            $config['domain'] ?? $uri->getHost(),
+            $config['secure'] ?? ($uri->getScheme() === 'https'),
             false,
             $config['csrf.samesite'] ?? false
         );
diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index 71e8ec054..6736641db 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -5,7 +5,11 @@
 use Interop\Container\ContainerInterface;
 use Interop\Container\ServiceProvider;
 use Viserio\Component\Contracts\Encryption\Encrypter;
+use Viserio\Component\Contracts\Events\Event as EventContract;
+use Viserio\Component\Contracts\Events\EventManager as EventManagerContract;
+use Viserio\Component\Contracts\Foundation\Terminable as TerminableContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
+use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Session\SessionManager;
 
 class SessionServiceProvider implements ServiceProvider
@@ -20,10 +24,36 @@ public function getServices()
             'session'             => function (ContainerInterface $container) {
                 return $container->get(SessionManager::class);
             },
-            'session.store' => [self::class, 'createSessionStore'],
+            'session.store'             => [self::class, 'createSessionStore'],
+            EventManagerContract::class => [self::class, 'extendEventManager'],
         ];
     }
 
+    /**
+     * Extend viserio events with data collector.
+     *
+     * @param \Interop\Container\ContainerInterface $container
+     * @param null|callable                         $getPrevious
+     *
+     * @return null|\Viserio\Component\Contracts\Events\EventManager
+     */
+    public static function extendEventManager(ContainerInterface $container, ?callable $getPrevious = null): ?EventManagerContract
+    {
+        $eventManager = $getPrevious();
+
+        if ($eventManager !== null) {
+            $eventManager->attach(TerminableContract::TERMINATE, function (EventContract $event) {
+                $driver = $event->getTarget()->getContainer()->get(SessionManager::class)->getDriver();
+
+                if ($driver->getHandler() instanceof CookieSessionHandler) {
+                    $driver->save();
+                }
+            });
+        }
+
+        return $eventManager;
+    }
+
     public static function createSessionManager(ContainerInterface $container): SessionManager
     {
         return new SessionManager(
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index c7b64e9b8..0a0aa4ab4 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -235,7 +235,7 @@ protected function createCacheBased($driver, array $options = []): StoreContract
     protected function buildSession(SessionHandlerInterface $handler): StoreContract
     {
         return new Store(
-            $this->options['cookie'] ?? '',
+            $this->options['cookie'] ?? '_ns_attributes',
             $handler,
             $this->getEncrypter()
         );
diff --git a/src/Viserio/Component/WebProfiler/Profile.php b/src/Viserio/Component/WebProfiler/Profile.php
index 8d16a2ee0..a67247970 100644
--- a/src/Viserio/Component/WebProfiler/Profile.php
+++ b/src/Viserio/Component/WebProfiler/Profile.php
@@ -231,7 +231,7 @@ public function setDate(string $date): void
     }
 
     /**
-     * Set the responce status code.
+     * Set the response status code.
      *
      * @param int $statusCode
      *
@@ -290,7 +290,7 @@ public function getCollectors(): array
     public function setCollectors(array $collectors): void
     {
         foreach ($collectors as $collector) {
-            $this->addCollector($collector);
+            $this->addCollector($collector['collector']);
         }
     }
 

From 577bcf348c42d82dc4df29d6025b859a2a9ee7fd Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 00:19:12 +0200
Subject: [PATCH 44/99] working on session can cookie tab

---
 .../ViserioHttpDataCollector.php              | 107 ++++++------------
 .../Middleware/StartSessionMiddleware.php     |   6 +-
 .../Providers/SessionServiceProvider.php      |   2 +-
 .../Component/Session/SessionManager.php      |  31 ++---
 4 files changed, 51 insertions(+), 95 deletions(-)

diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
index b77843f49..fd9d4082b 100644
--- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
+++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
@@ -7,6 +7,8 @@
 use Psr\Http\Message\ServerRequestInterface;
 use ReflectionFunction;
 use ReflectionMethod;
+use Viserio\Component\Cookie\ResponseCookies;
+use Viserio\Component\Cookie\RequestCookies;
 use Viserio\Component\Contracts\Config\Repository as RepositoryContract;
 use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract;
 use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract;
@@ -205,26 +207,7 @@ public function getPanel(): string
                     ['name'    => 'Response Headers']
                 ),
             ],
-            [
-                'name'    => 'Cookies',
-                'content' => $this->createTable(
-                    array_map(function ($cookieString) {
-                        return self::fromStringCookie($cookieString);
-                    }, self::splitOnAttributeDelimiter($request->getHeaderLine('Cookie'))),
-                    [
-                        'name'       => 'Request Cookies',
-                        'empty_text' => 'No request cookies',
-                    ]
-                ) . $this->createTable(
-                    array_map(function ($setCookieString) {
-                        return self::fromStringCookie($setCookieString);
-                    }, $response->getHeader('Set-Cookie')),
-                    [
-                        'name'       => 'Response Cookies',
-                        'empty_text' => 'No response cookies',
-                    ]
-                ),
-            ],
+            $this->createCookieTab($request, $response),
             [
                 'name'    => 'Session',
                 'content' => $this->createTable(
@@ -266,6 +249,40 @@ public function getAssets(): array
         ];
     }
 
+    protected function createCookieTab(ServerRequestInterface $serverRequest, ResponseInterface $response): ?array
+    {
+        if (! (class_exists(RequestCookies::class) && class_exists(ResponseCookies::class))) {
+            return null;
+        }
+
+        $requestCookies = $responseCookies = [];
+
+        foreach (RequestCookies::fromRequest($serverRequest)->getAll() as $cookie) {
+            $requestCookies[$cookie->getName()] = $cookie->getValue();
+        }
+
+        foreach (ResponseCookies::fromResponse($response)->getAll() as $cookie) {
+            $responseCookies[$cookie->getName()] = $cookie->getValue();
+        }
+
+        return [
+            'name'    => 'Cookies',
+            'content' => $this->createTable(
+                $requestCookies,
+                [
+                    'name'       => 'Request Cookies',
+                    'empty_text' => 'No request cookies',
+                ]
+            ) . $this->createTable(
+                $responseCookies,
+                [
+                    'name'       => 'Response Cookies',
+                    'empty_text' => 'No response cookies',
+                ]
+            ),
+        ];
+    }
+
     /**
      * Get the route information for a given route.
      *
@@ -311,56 +328,6 @@ protected function getRouteInformation(RouteContract $route): array
         return $result;
     }
 
-    /**
-     * Split string on attributes delimiter to array.
-     *
-     * @param string $string
-     *
-     * @return array
-     */
-    protected static function splitOnAttributeDelimiter(string $string): array
-    {
-        return array_filter(preg_split('@\s*[;]\s*@', $string));
-    }
-
-    /**
-     * Split a string to array.
-     *
-     * @param string $string
-     *
-     * @return array
-     */
-    protected static function splitCookiePair(string $string): array
-    {
-        $pairParts = explode('=', $string, 2);
-
-        if (count($pairParts) === 1) {
-            $pairParts[1] = '';
-        }
-
-        return array_map(function ($part) {
-            if ($part === null) {
-                return '';
-            }
-
-            return urldecode($part);
-        }, $pairParts);
-    }
-
-    /**
-     * Creates a Cookie instance from a Set-Cookie header value.
-     *
-     * @param string $string
-     *
-     * @return array
-     */
-    protected static function fromStringCookie(string $string): array
-    {
-        $rawAttributes = self::splitOnAttributeDelimiter($string);
-
-        return self::splitCookiePair(array_shift($rawAttributes));
-    }
-
     /**
      * Prepare request attributes, check of route object.
      *
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 20ddbcb01..30c0fc40a 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -135,8 +135,8 @@ protected function getSession(ServerRequestInterface $request): StoreContract
     protected function storeCurrentUrl(ServerRequestInterface $request, StoreContract $session): StoreContract
     {
         if ($request->getMethod() === 'GET' &&
-            $request->getAttribute('route') &&
-            ! $request->getHeaderLine('HTTP_X_REQUESTED_WITH') == 'xmlhttprequest'
+            $request->getAttribute('_route') &&
+            $request->getHeaderLine('X-Requested-With') !== 'XMLHttpRequest'
         ) {
             $session->setPreviousUrl((string) $request->getUri());
         }
@@ -189,7 +189,7 @@ protected function addCookieToResponse(ServerRequestInterface $request, Response
             $config['path'] ?? '/',
             $config['domain'] ?? $uri->getHost(),
             $config['secure'] ?? ($uri->getScheme() === 'https'),
-            $config['http_only'] ?? false,
+            $config['http_only'] ?? true,
             $config['same_site'] ?? false
         );
 
diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index 6736641db..eedd1f8cd 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -45,7 +45,7 @@ public static function extendEventManager(ContainerInterface $container, ?callab
             $eventManager->attach(TerminableContract::TERMINATE, function (EventContract $event) {
                 $driver = $event->getTarget()->getContainer()->get(SessionManager::class)->getDriver();
 
-                if ($driver->getHandler() instanceof CookieSessionHandler) {
+                if (! $driver->getHandler() instanceof CookieSessionHandler) {
                     $driver->save();
                 }
             });
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index 0a0aa4ab4..123d771ea 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -42,7 +42,9 @@ public function __construct(
     public function getDefaultOptions(): iterable
     {
         return [
-            'default' => 'array',
+            'default'  => 'array',
+            'cookie'   => 'narrowsparksession',
+            'lifetime' => 120
         ];
     }
 
@@ -112,10 +114,7 @@ protected function createMemcacheDriver(): StoreContract
      */
     protected function createMongodbDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'mongodb',
-            $this->options['mongodb']
-        );
+        return $this->createCacheBased('mongodb');
     }
 
     /**
@@ -127,10 +126,7 @@ protected function createMongodbDriver(): StoreContract
      */
     protected function createPredisDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'predis',
-            $this->options['predis']
-        );
+        return $this->createCacheBased('predis');
     }
 
     /**
@@ -142,10 +138,7 @@ protected function createPredisDriver(): StoreContract
      */
     protected function createRedisDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'redis',
-            $this->options['redis']
-        );
+        return $this->createCacheBased('redis');
     }
 
     /**
@@ -157,10 +150,7 @@ protected function createRedisDriver(): StoreContract
      */
     protected function createFilesystemDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'filesystem',
-            $this->options['flysystem']
-        );
+        return $this->createCacheBased('filesystem');
     }
 
     /**
@@ -211,15 +201,14 @@ protected function callCustomCreator(string $driver, array $options = [])
      * Create the cache based session handler instance.
      *
      * @param string $driver
-     * @param array  $options
      *
      * @return \Viserio\Component\Contracts\Session\Store
      */
-    protected function createCacheBased($driver, array $options = []): StoreContract
+    protected function createCacheBased($driver): StoreContract
     {
         return $this->buildSession(
             new CacheBasedSessionHandler(
-                clone $this->container->get(CacheManagerContract::class)->getDriver($driver, $options),
+                clone $this->container->get(CacheManagerContract::class)->getDriver($driver),
                 $this->options['lifetime']
             )
         );
@@ -235,7 +224,7 @@ protected function createCacheBased($driver, array $options = []): StoreContract
     protected function buildSession(SessionHandlerInterface $handler): StoreContract
     {
         return new Store(
-            $this->options['cookie'] ?? '_ns_attributes',
+            $this->options['cookie'],
             $handler,
             $this->getEncrypter()
         );

From 80b77a9977ce476fc3d6b43bef8f112293443ea8 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Wed, 17 May 2017 22:19:29 +0000
Subject: [PATCH 45/99] Apply fixes from StyleCI

---
 .../Foundation/DataCollectors/ViserioHttpDataCollector.php    | 4 ++--
 src/Viserio/Component/Session/SessionManager.php              | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
index fd9d4082b..8eb828b50 100644
--- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
+++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
@@ -7,8 +7,6 @@
 use Psr\Http\Message\ServerRequestInterface;
 use ReflectionFunction;
 use ReflectionMethod;
-use Viserio\Component\Cookie\ResponseCookies;
-use Viserio\Component\Cookie\RequestCookies;
 use Viserio\Component\Contracts\Config\Repository as RepositoryContract;
 use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract;
 use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract;
@@ -16,6 +14,8 @@
 use Viserio\Component\Contracts\Routing\Route as RouteContract;
 use Viserio\Component\Contracts\Routing\Router as RouterContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
+use Viserio\Component\Cookie\RequestCookies;
+use Viserio\Component\Cookie\ResponseCookies;
 use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector;
 
 class ViserioHttpDataCollector extends AbstractDataCollector implements
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index 123d771ea..a0801669c 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -44,7 +44,7 @@ public function getDefaultOptions(): iterable
         return [
             'default'  => 'array',
             'cookie'   => 'narrowsparksession',
-            'lifetime' => 120
+            'lifetime' => 120,
         ];
     }
 

From 1bb5ad9d1b3819d0353e4b589d32bf3794a497d5 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 21:03:59 +0200
Subject: [PATCH 46/99] fixed session bug

---
 .../Component/Contracts/Session/Store.php     |  6 ++--
 .../Middleware/StartSessionMiddleware.php     | 34 ++++++-------------
 .../Component/Session/SessionManager.php      |  2 +-
 src/Viserio/Component/Session/Store.php       | 28 ++++++++-------
 src/Viserio/Component/Session/composer.json   |  2 +-
 5 files changed, 31 insertions(+), 41 deletions(-)

diff --git a/src/Viserio/Component/Contracts/Session/Store.php b/src/Viserio/Component/Contracts/Session/Store.php
index 598c29839..1a4e1fac6 100644
--- a/src/Viserio/Component/Contracts/Session/Store.php
+++ b/src/Viserio/Component/Contracts/Session/Store.php
@@ -14,7 +14,7 @@ interface Store extends JsonSerializable
     /**
      * Starts the session storage.
      * It should be called only once at the beginning. If called for existing
-     * session it ovewrites it (clears all values etc).
+     * session it overwrites it (clears all values etc).
      *
      * @return bool true if session started
      */
@@ -41,9 +41,9 @@ public function setId(string $id): void;
     /**
      * Returns the session ID.
      *
-     * @return string the session ID
+     * @return string|null the session ID
      */
-    public function getId(): string;
+    public function getId(): ?string;
 
     /**
      * Sets the session name.
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 30c0fc40a..4a3150c57 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -91,36 +91,26 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
      * @return \Viserio\Component\Contracts\Session\Store
      */
     protected function startSession(ServerRequestInterface $request): StoreContract
-    {
-        $session = $this->getSession($request);
-
-        if ($session->handlerNeedsRequest()) {
-            $session->setRequestOnHandler($request);
-        }
-
-        $session->start();
-
-        return $session;
-    }
-
-    /**
-     * Get the session implementation from the manager.
-     *
-     * @param \Psr\Http\Message\ServerRequestInterface $request
-     *
-     * @return \Viserio\Component\Contracts\Session\Store
-     */
-    protected function getSession(ServerRequestInterface $request): StoreContract
     {
         $session    = $this->manager->getDriver();
         $cookies    = RequestCookies::fromRequest($request);
         $hasCookie  = $cookies->has($session->getName());
 
-        $session->setId($hasCookie ? $cookies->get($session->getName())->getName() : '');
+        $session->setId($hasCookie ? $cookies->get($session->getName())->getValue() : '');
 
         $session->addFingerprintGenerator(new ClientIpGenerator($request));
         $session->addFingerprintGenerator(new UserAgentGenerator());
 
+        if ($session->handlerNeedsRequest()) {
+            $session->setRequestOnHandler($request);
+        }
+
+        if ($hasCookie) {
+            $session->open();
+        } else {
+            $session->start();
+        }
+
         return $session;
     }
 
@@ -175,8 +165,6 @@ protected function addCookieToResponse(ServerRequestInterface $request, Response
     {
         if ($session->getHandler() instanceof CookieSessionHandler) {
             $session->save();
-
-            return $response;
         }
 
         $config = $this->config;
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index a0801669c..f167a0dad 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -43,7 +43,7 @@ public function getDefaultOptions(): iterable
     {
         return [
             'default'  => 'array',
-            'cookie'   => 'narrowsparksession',
+            'cookie'   => 'NSSESSID',
             'lifetime' => 120,
         ];
     }
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 9a4862550..8219707fb 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -21,7 +21,7 @@ class Store implements StoreContract
     /**
      * The session ID.
      *
-     * @var string
+     * @var string|null
      */
     protected $id;
 
@@ -161,7 +161,7 @@ public function start(): bool
     public function open(): bool
     {
         if (! $this->started) {
-            if ($this->id) {
+            if ($this->id !== null) {
                 $this->loadSession();
 
                 $this->started = true;
@@ -187,7 +187,7 @@ public function setId(string $id): void
     /**
      * {@inheritdoc}
      */
-    public function getId(): string
+    public function getId(): ?string
     {
         return $this->id;
     }
@@ -239,18 +239,20 @@ public function getName(): string
      */
     public function save(): void
     {
-        if ($this->started) {
-            if ($this->shouldRegenerateId()) {
-                $this->migrate(true);
-            }
-
-            $this->updateLastTrace();
-            $this->ageFlashData();
-            $this->writeToHandler();
+        if (!$this->started) {
+            return;
+        }
 
-            $this->values  = [];
-            $this->started = false;
+        if ($this->shouldRegenerateId()) {
+            $this->migrate(true);
         }
+
+        $this->updateLastTrace();
+        $this->ageFlashData();
+        $this->writeToHandler();
+
+        $this->values  = [];
+        $this->started = false;
     }
 
     /**
diff --git a/src/Viserio/Component/Session/composer.json b/src/Viserio/Component/Session/composer.json
index 16e059de6..a02e3e451 100644
--- a/src/Viserio/Component/Session/composer.json
+++ b/src/Viserio/Component/Session/composer.json
@@ -64,7 +64,7 @@
         "container-interop/service-provider"                 : "Required to use service-provider (^0.3).",
         "cache/session-handler"                              : "Required to use the CacheBasedSessionHandler (^0.2).",
         "http-interop/http-middleware"                       : "Required to use middleware (^0.4).",
-        "viserio/cookie"                                     : "Required to use the CookieSessionHandler (self.version).",
+        "viserio/cookie"                                     : "Required to use the CookieSessionHandler and StartSessionMiddleware (self.version).",
         "viserio/filesystem"                                 : "Required to use the FileSessionHandler (self.version).",
         "viserio/statical-proxy"                             : "Required to use the proxy instances (self.version)."
     },

From 4f38e932969ee6c5401651be0b1f17a3f6154142 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 21:05:08 +0200
Subject: [PATCH 47/99] fixed session bug

---
 .../Component/Contracts/Session/Store.php     |  6 ++--
 .../Middleware/StartSessionMiddleware.php     | 34 ++++++-------------
 .../Component/Session/SessionManager.php      | 31 ++++++-----------
 src/Viserio/Component/Session/Store.php       | 28 ++++++++-------
 src/Viserio/Component/Session/composer.json   |  2 +-
 5 files changed, 40 insertions(+), 61 deletions(-)

diff --git a/src/Viserio/Component/Contracts/Session/Store.php b/src/Viserio/Component/Contracts/Session/Store.php
index 598c29839..1a4e1fac6 100644
--- a/src/Viserio/Component/Contracts/Session/Store.php
+++ b/src/Viserio/Component/Contracts/Session/Store.php
@@ -14,7 +14,7 @@ interface Store extends JsonSerializable
     /**
      * Starts the session storage.
      * It should be called only once at the beginning. If called for existing
-     * session it ovewrites it (clears all values etc).
+     * session it overwrites it (clears all values etc).
      *
      * @return bool true if session started
      */
@@ -41,9 +41,9 @@ public function setId(string $id): void;
     /**
      * Returns the session ID.
      *
-     * @return string the session ID
+     * @return string|null the session ID
      */
-    public function getId(): string;
+    public function getId(): ?string;
 
     /**
      * Sets the session name.
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 20ddbcb01..667584700 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -91,36 +91,26 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
      * @return \Viserio\Component\Contracts\Session\Store
      */
     protected function startSession(ServerRequestInterface $request): StoreContract
-    {
-        $session = $this->getSession($request);
-
-        if ($session->handlerNeedsRequest()) {
-            $session->setRequestOnHandler($request);
-        }
-
-        $session->start();
-
-        return $session;
-    }
-
-    /**
-     * Get the session implementation from the manager.
-     *
-     * @param \Psr\Http\Message\ServerRequestInterface $request
-     *
-     * @return \Viserio\Component\Contracts\Session\Store
-     */
-    protected function getSession(ServerRequestInterface $request): StoreContract
     {
         $session    = $this->manager->getDriver();
         $cookies    = RequestCookies::fromRequest($request);
         $hasCookie  = $cookies->has($session->getName());
 
-        $session->setId($hasCookie ? $cookies->get($session->getName())->getName() : '');
+        $session->setId($hasCookie ? $cookies->get($session->getName())->getValue() : '');
 
         $session->addFingerprintGenerator(new ClientIpGenerator($request));
         $session->addFingerprintGenerator(new UserAgentGenerator());
 
+        if ($session->handlerNeedsRequest()) {
+            $session->setRequestOnHandler($request);
+        }
+
+        if ($hasCookie) {
+            $session->open();
+        } else {
+            $session->start();
+        }
+
         return $session;
     }
 
@@ -175,8 +165,6 @@ protected function addCookieToResponse(ServerRequestInterface $request, Response
     {
         if ($session->getHandler() instanceof CookieSessionHandler) {
             $session->save();
-
-            return $response;
         }
 
         $config = $this->config;
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index 0a0aa4ab4..f167a0dad 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -42,7 +42,9 @@ public function __construct(
     public function getDefaultOptions(): iterable
     {
         return [
-            'default' => 'array',
+            'default'  => 'array',
+            'cookie'   => 'NSSESSID',
+            'lifetime' => 120,
         ];
     }
 
@@ -112,10 +114,7 @@ protected function createMemcacheDriver(): StoreContract
      */
     protected function createMongodbDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'mongodb',
-            $this->options['mongodb']
-        );
+        return $this->createCacheBased('mongodb');
     }
 
     /**
@@ -127,10 +126,7 @@ protected function createMongodbDriver(): StoreContract
      */
     protected function createPredisDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'predis',
-            $this->options['predis']
-        );
+        return $this->createCacheBased('predis');
     }
 
     /**
@@ -142,10 +138,7 @@ protected function createPredisDriver(): StoreContract
      */
     protected function createRedisDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'redis',
-            $this->options['redis']
-        );
+        return $this->createCacheBased('redis');
     }
 
     /**
@@ -157,10 +150,7 @@ protected function createRedisDriver(): StoreContract
      */
     protected function createFilesystemDriver(): StoreContract
     {
-        return $this->createCacheBased(
-            'filesystem',
-            $this->options['flysystem']
-        );
+        return $this->createCacheBased('filesystem');
     }
 
     /**
@@ -211,15 +201,14 @@ protected function callCustomCreator(string $driver, array $options = [])
      * Create the cache based session handler instance.
      *
      * @param string $driver
-     * @param array  $options
      *
      * @return \Viserio\Component\Contracts\Session\Store
      */
-    protected function createCacheBased($driver, array $options = []): StoreContract
+    protected function createCacheBased($driver): StoreContract
     {
         return $this->buildSession(
             new CacheBasedSessionHandler(
-                clone $this->container->get(CacheManagerContract::class)->getDriver($driver, $options),
+                clone $this->container->get(CacheManagerContract::class)->getDriver($driver),
                 $this->options['lifetime']
             )
         );
@@ -235,7 +224,7 @@ protected function createCacheBased($driver, array $options = []): StoreContract
     protected function buildSession(SessionHandlerInterface $handler): StoreContract
     {
         return new Store(
-            $this->options['cookie'] ?? '_ns_attributes',
+            $this->options['cookie'],
             $handler,
             $this->getEncrypter()
         );
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 9a4862550..8219707fb 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -21,7 +21,7 @@ class Store implements StoreContract
     /**
      * The session ID.
      *
-     * @var string
+     * @var string|null
      */
     protected $id;
 
@@ -161,7 +161,7 @@ public function start(): bool
     public function open(): bool
     {
         if (! $this->started) {
-            if ($this->id) {
+            if ($this->id !== null) {
                 $this->loadSession();
 
                 $this->started = true;
@@ -187,7 +187,7 @@ public function setId(string $id): void
     /**
      * {@inheritdoc}
      */
-    public function getId(): string
+    public function getId(): ?string
     {
         return $this->id;
     }
@@ -239,18 +239,20 @@ public function getName(): string
      */
     public function save(): void
     {
-        if ($this->started) {
-            if ($this->shouldRegenerateId()) {
-                $this->migrate(true);
-            }
-
-            $this->updateLastTrace();
-            $this->ageFlashData();
-            $this->writeToHandler();
+        if (!$this->started) {
+            return;
+        }
 
-            $this->values  = [];
-            $this->started = false;
+        if ($this->shouldRegenerateId()) {
+            $this->migrate(true);
         }
+
+        $this->updateLastTrace();
+        $this->ageFlashData();
+        $this->writeToHandler();
+
+        $this->values  = [];
+        $this->started = false;
     }
 
     /**
diff --git a/src/Viserio/Component/Session/composer.json b/src/Viserio/Component/Session/composer.json
index 16e059de6..a02e3e451 100644
--- a/src/Viserio/Component/Session/composer.json
+++ b/src/Viserio/Component/Session/composer.json
@@ -64,7 +64,7 @@
         "container-interop/service-provider"                 : "Required to use service-provider (^0.3).",
         "cache/session-handler"                              : "Required to use the CacheBasedSessionHandler (^0.2).",
         "http-interop/http-middleware"                       : "Required to use middleware (^0.4).",
-        "viserio/cookie"                                     : "Required to use the CookieSessionHandler (self.version).",
+        "viserio/cookie"                                     : "Required to use the CookieSessionHandler and StartSessionMiddleware (self.version).",
         "viserio/filesystem"                                 : "Required to use the FileSessionHandler (self.version).",
         "viserio/statical-proxy"                             : "Required to use the proxy instances (self.version)."
     },

From 7ee451cbb4eeb4e4e84dd32a04405afbd5842f20 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 19:05:17 +0000
Subject: [PATCH 48/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Session/Store.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 8219707fb..86392031e 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -239,7 +239,7 @@ public function getName(): string
      */
     public function save(): void
     {
-        if (!$this->started) {
+        if (! $this->started) {
             return;
         }
 

From 5cd99374c21b43195070a256f1e40df66856170c Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 19:05:26 +0000
Subject: [PATCH 49/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Session/Store.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 8219707fb..86392031e 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -239,7 +239,7 @@ public function getName(): string
      */
     public function save(): void
     {
-        if (!$this->started) {
+        if (! $this->started) {
             return;
         }
 

From f777ec54a8987f6609a54b228294a9e8f9228309 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:07:56 +0200
Subject: [PATCH 50/99] fixed some session bugs

---
 .../SuspiciousOperationException.php          | 13 +++
 .../Component/Contracts/Session/Store.php     | 28 ++++--
 .../Session/Fingerprint/ClientIpGenerator.php |  6 +-
 .../Fingerprint/UserAgentGenerator.php        | 16 ++--
 .../Middleware/StartSessionMiddleware.php     | 15 +++-
 src/Viserio/Component/Session/Store.php       | 55 +++++++++---
 .../Fingerprint/ClientIpGeneratorTest.php     | 53 +----------
 .../Fingerprint/UserAgentGeneratorTest.php    | 20 +++--
 .../Component/Session/Tests/StoreTest.php     | 33 ++++---
 .../Component/Support/Http/ClientIp.php       | 87 +++++++++++--------
 10 files changed, 190 insertions(+), 136 deletions(-)
 create mode 100644 src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php

diff --git a/src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php b/src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php
new file mode 100644
index 000000000..fb82b562a
--- /dev/null
+++ b/src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php
@@ -0,0 +1,13 @@
+getIpAddress();
-
-        $this->clientIp = random_bytes(32) . $ip;
+        $this->clientIp = (new ClientIp($serverRequest))->getIpAddress();
     }
 
     /**
-     * {@inhertiddoc}.
+     * {@inheritdoc}.
      */
     public function generate(): string
     {
diff --git a/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php b/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php
index facbffa92..6caf7c68c 100644
--- a/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php
+++ b/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php
@@ -2,6 +2,7 @@
 declare(strict_types=1);
 namespace Viserio\Component\Session\Fingerprint;
 
+use Psr\Http\Message\ServerRequestInterface;
 use Viserio\Component\Contracts\Session\Fingerprint as FingerprintContract;
 
 class UserAgentGenerator implements FingerprintContract
@@ -16,19 +17,22 @@ class UserAgentGenerator implements FingerprintContract
     /**
      * Create a new UserAgentGenerator instance.
      *
-     * @param string|null $userAgent
+     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest
      */
-    public function __construct(string $userAgent = null)
+    public function __construct(ServerRequestInterface $serverRequest)
     {
-        if ($userAgent !== null) {
-            $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
+        $userAgent    = '';
+        $serverParams = $serverRequest->getServerParams();
+
+        if (isset($serverParams['REMOTE_ADDR'])) {
+            $userAgent = $serverParams['REMOTE_ADDR'];
         }
 
-        $this->userAgent = random_bytes(32) . $userAgent;
+        $this->userAgent = $userAgent;
     }
 
     /**
-     * {@inhertiddoc}.
+     * {@inheritdoc}.
      */
     public function generate(): string
     {
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 4a3150c57..773ff4d3a 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -38,6 +38,16 @@ class StartSessionMiddleware implements MiddlewareInterface
      */
     protected $config = [];
 
+    /**
+     * List of fingerprint generators.
+     *
+     * @var array
+     */
+    private $fingerprintGenerators = [
+        ClientIpGenerator::class,
+        UserAgentGenerator::class
+    ];
+
     /**
      * Create a new session middleware.
      *
@@ -98,8 +108,9 @@ protected function startSession(ServerRequestInterface $request): StoreContract
 
         $session->setId($hasCookie ? $cookies->get($session->getName())->getValue() : '');
 
-        $session->addFingerprintGenerator(new ClientIpGenerator($request));
-        $session->addFingerprintGenerator(new UserAgentGenerator());
+        foreach ($this->fingerprintGenerators as $fingerprintGenerator) {
+            $session->addFingerprintGenerator(new $fingerprintGenerator($request));
+        }
 
         if ($session->handlerNeedsRequest()) {
             $session->setRequestOnHandler($request);
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 86392031e..c2beb08b7 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -13,6 +13,7 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
+use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
@@ -61,7 +62,7 @@ class Store implements StoreContract
     private $idRequestsLimit = null;
 
     /**
-     * Time after id is regenerated.
+     * Time after session is regenerated.
      *
      * @var int
      */
@@ -70,21 +71,21 @@ class Store implements StoreContract
     /**
      * Last (id) regeneration timestamp.
      *
-     * @var int
+     * @var int|null
      */
     private $regenerationTrace;
 
     /**
      * First trace (timestamp), time when session was created.
      *
-     * @var int
+     * @var int|null
      */
     private $firstTrace;
 
     /**
      * Last trace (Unix timestamp).
      *
-     * @var int
+     * @var int|null
      */
     private $lastTrace;
 
@@ -161,11 +162,17 @@ public function start(): bool
     public function open(): bool
     {
         if (! $this->started) {
-            if ($this->id !== null) {
+            if ($this->getId() !== null) {
                 $this->loadSession();
 
-                $this->started = true;
-                $this->requestsCount += 1;
+                if ($this->getFirstTrace() === null) {
+                    return false;
+                } elseif ($this->generateFingerprint() !== $this->getFingerprint()) {
+                    throw new SuspiciousOperationException();
+                } else {
+                    $this->started = true;
+                    $this->requestsCount += 1;
+                }
             }
         }
 
@@ -192,6 +199,28 @@ public function getId(): ?string
         return $this->id;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getTtl(): int
+    {
+        return $this->idTtl;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function isExpired(): bool
+    {
+        $lastTrace = $this->getLastTrace();
+
+        if ($lastTrace === null) {
+            return true;
+        }
+
+        return ($lastTrace + $this->getTtl() < time());
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -211,9 +240,9 @@ public function migrate(bool $destroy = false): bool
             $this->handler->destroy($this->id);
         }
 
-        $this->id = $this->generateSessionId();
-
+        $this->id                = $this->generateSessionId();
         $this->regenerationTrace = $this->getTimestamp();
+        $this->requestsCount     = 0;
 
         return true;
     }
@@ -360,7 +389,7 @@ public function setIdLiveTime(int $ttl): void
     /**
      * {@inheritdoc}
      */
-    public function getLastTrace(): int
+    public function getLastTrace(): ?int
     {
         return $this->lastTrace;
     }
@@ -368,7 +397,7 @@ public function getLastTrace(): int
     /**
      * {@inheritdoc}
      */
-    public function getFirstTrace(): int
+    public function getFirstTrace(): ?int
     {
         return $this->firstTrace;
     }
@@ -376,7 +405,7 @@ public function getFirstTrace(): int
     /**
      * {@inheritdoc}
      */
-    public function getRegenerationTrace(): int
+    public function getRegenerationTrace(): ?int
     {
         return $this->regenerationTrace;
     }
@@ -600,7 +629,7 @@ private function removeFromOldFlashData(array $keys): void
     }
 
     /**
-     * Determine if session id should be regenerated? (based on request_counter or regenerationTrace).
+     * Determine if session id should be regenerated? (based on requestsCount or regenerationTrace).
      *
      * @return bool
      */
diff --git a/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php b/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
index 898c8582a..4f8589c05 100644
--- a/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
+++ b/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
@@ -11,60 +11,11 @@ class ClientIpGeneratorTest extends MockeryTestCase
     public function testGenerate()
     {
         $request = $this->mock(ServerRequestInterface::class);
-        $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->once()
-            ->andReturn(false);
-        $request->shouldReceive('hasHeader')
-            ->with('REMOTE_ADDR')
-            ->once()
-            ->andReturn(false);
+        $request->shouldReceive('getServerParams')
+            ->andReturn(['REMOTE_ADDR' => '127.0.0.1']);
 
         $generator = new ClientIpGenerator($request);
 
-        self::assertInternalType('string', $generator->generate());
-        self::assertSame(40, mb_strlen($generator->generate()));
-    }
-
-    public function testGenerateWithProxyIp()
-    {
-        $request = $this->mock(ServerRequestInterface::class);
-        $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->once()
-            ->andReturn(true);
-        $request->shouldReceive('getHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->andReturn('111.111.111.111,123.45.67.178');
-
-        $generator = new ClientIpGenerator($request);
-
-        self::assertInternalType('string', $generator->generate());
-        self::assertSame(40, mb_strlen($generator->generate()));
-    }
-
-    public function testGenerateWithIp()
-    {
-        $request = $this->mock(ServerRequestInterface::class);
-        $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->once()
-            ->andReturn(false);
-        $request->shouldReceive('hasHeader')
-            ->with('REMOTE_ADDR')
-            ->once()
-            ->andReturn(true);
-        $request->shouldReceive('getHeader')
-            ->with('REMOTE_ADDR')
-            ->andReturn('100.8.116.127');
-
-        $generator = new ClientIpGenerator($request);
-
-        self::assertInternalType('string', $generator->generate());
-        self::assertSame(40, mb_strlen($generator->generate()));
-
-        // return empty ip string
-        self::assertInternalType('string', $generator->generate());
         self::assertSame(40, mb_strlen($generator->generate()));
     }
 }
diff --git a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
index 9a26ba9d9..9fd2ea25a 100644
--- a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
+++ b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
@@ -2,21 +2,29 @@
 declare(strict_types=1);
 namespace Viserio\Component\Session\Tests;
 
-use PHPUnit\Framework\TestCase;
+use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
+use Psr\Http\Message\ServerRequestInterface;
 
-class UserAgentGeneratorTest extends TestCase
+class UserAgentGeneratorTest extends MockeryTestCase
 {
     public function testGenerate()
     {
-        $generator = new UserAgentGenerator('test');
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => 'test']);
+        $generator = new UserAgentGenerator($request);
 
-        self::assertInternalType('string', $generator->generate());
         self::assertSame(40, mb_strlen($generator->generate()));
 
-        $generator = new UserAgentGenerator();
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn([]);
+
+        $generator = new UserAgentGenerator($request);
 
-        self::assertInternalType('string', $generator->generate());
         self::assertSame(40, mb_strlen($generator->generate()));
     }
 }
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index a12438066..960ea6636 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -11,6 +11,7 @@
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
+use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {
@@ -45,7 +46,7 @@ public function setUp()
                         'lastTrace'         => 0,
                         'regenerationTrace' => 1,
                         'requestsCount'     => 0,
-                        'fingerprint'       => 0,
+                        'fingerprint'       => '',
                     ],
                 ],
                 \JSON_PRESERVE_ZERO_FRACTION
@@ -66,7 +67,7 @@ public function testSessionIsLoadedFromHandler()
                         'lastTrace'         => 0,
                         'regenerationTrace' => 0,
                         'requestsCount'     => 0,
-                        'fingerprint'       => 0,
+                        'fingerprint'       => '',
                     ],
                 ],
                 \JSON_PRESERVE_ZERO_FRACTION
@@ -217,10 +218,14 @@ public function testStartMethodResetsIdRegenerationTrace()
     public function testStartMethodGeneratesFingerprint()
     {
         $session = $this->session;
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => 'test']);
 
         $oldFingerprint = $session->getFingerprint();
 
-        $session->addFingerprintGenerator(new UserAgentGenerator('test'));
+        $session->addFingerprintGenerator(new UserAgentGenerator($request));
 
         $session->start();
 
@@ -264,38 +269,38 @@ public function testSessionIdShouldBeRegeneratedIfIdRequestsLimitReached()
     {
         $session = $this->session;
         $session->setIdRequestsLimit(3);
-        $session->setId(self::SESSION_ID);
         $session->getHandler()
             ->shouldReceive('read')
-            ->times(4);
+            ->times(3);
         $session->getHandler()
             ->shouldReceive('write')
             ->times(3);
         $session->getHandler()
             ->shouldReceive('destroy')
-            ->times(1);
+            ->once();
 
+        $session->start();
         $session->open();
+
         self::assertSame(1, $session->getRequestsCount());
-        self::assertSame(self::SESSION_ID, $session->getId());
 
         $session->save();
-        $session->open();
+
+        self::assertTrue($session->open());
 
         self::assertSame(2, $session->getRequestsCount());
-        self::assertSame(self::SESSION_ID, $session->getId());
 
         $session->save();
-        $session->open();
+
+        self::assertTrue($session->open());
 
         self::assertSame(3, $session->getRequestsCount());
-        self::assertSame(self::SESSION_ID, $session->getId());
 
         $session->save();
-        $session->open();
+        // Session should migrate to a new one
+        self::assertTrue($session->open());
 
-        self::assertSame(4, $session->getRequestsCount());
-        self::assertNotSame(self::SESSION_ID, $session->getId());
+        self::assertSame(1, $session->getRequestsCount());
     }
 
     public function testSessionIdShouldBeRegeneratedIfIdTtlLimitReached()
diff --git a/src/Viserio/Component/Support/Http/ClientIp.php b/src/Viserio/Component/Support/Http/ClientIp.php
index 83f9e4c86..bbf8b4999 100644
--- a/src/Viserio/Component/Support/Http/ClientIp.php
+++ b/src/Viserio/Component/Support/Http/ClientIp.php
@@ -13,6 +13,19 @@ class ClientIp
      */
     protected $serverRequest;
 
+    /**
+     * List of proxy headers inspected for the client IP address.
+     *
+     * @var array
+     */
+    protected $headersToInspect = [
+        'Forwarded',
+        'X-Forwarded-For',
+        'X-Forwarded',
+        'X-Cluster-Client-Ip',
+        'Client-Ip',
+    ];
+
     /**
      * Create ClientIp instance.
      *
@@ -30,20 +43,20 @@ public function __construct(ServerRequestInterface $serverRequest)
      */
     public function getIpAddress(): string
     {
-        if (($ip = $this->getIpAddressFromProxy()) !== null) {
-            return $ip;
-        }
+        $serverParams = $this->serverRequest->getServerParams();
 
         // direct IP address
-        if ($this->serverRequest->hasHeader('REMOTE_ADDR')) {
-            $ip = filter_var(
-                $this->serverRequest->getHeader('REMOTE_ADDR'),
-                FILTER_VALIDATE_IP,
-                FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
-            );
+        if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
+            return $serverParams['REMOTE_ADDR'];
+        }
+
+        foreach ($this->headersToInspect as $header) {
+            if ($this->serverRequest->hasHeader($header)) {
+                $ip = $this->getFirstIpAddressFromHeader($request, $header);
 
-            if ($ip !== false) {
-                return $ip;
+                if ($this->isValidIpAddress($ip)) {
+                    return $ip;
+                }
             }
         }
 
@@ -51,38 +64,44 @@ public function getIpAddress(): string
     }
 
     /**
-     * Attempt to get the IP address for a proxied client.
+     * Check that a given string is a valid IP address.
      *
-     * @link http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10#section-5.2
+     * @param string $ip
      *
-     * @return string|null
+     * @return bool
      */
-    private function getIpAddressFromProxy(): ?string
+    private function isValidIpAddress(string $ip): bool
     {
-        if (! $this->serverRequest->hasHeader('HTTP_X_FORWARDED_FOR')) {
-            return null;
+        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === false) {
+            return false;
         }
 
-        // Extract IPs
-        $ips = explode(',', $this->serverRequest->getHeader('HTTP_X_FORWARDED_FOR'));
-        $ips = array_map('trim', $ips);
+        return true;
+    }
 
-        // @codeCoverageIgnoreStart
-        if (count($ips) === 0) {
-            return null;
-        }
-        // @codeCoverageIgnoreEnd
+    /**
+     * Find out the client's IP address from the headers available to us.
+     *
+     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest
+     * @param string                                   $header        Header name
+     *
+     * @return string
+     */
+    private function getFirstIpAddressFromHeader(ServerRequestInterface $serverRequest, string $header): string
+    {
+        $items       = explode(',', $request->getHeaderLine($header));
+        $headerValue = trim(reset($items));
 
-        // The right-most address represents the first IP we do not know about
-        // -- i.e., we do not know if it is a proxy server, or a client. As such,
-        // we treat it as the originating IP.
-        // @see http://en.wikipedia.org/wiki/X-Forwarded-For
-        if ($ip = filter_var($ips[0], FILTER_VALIDATE_IP)) {
-            return $ip;
+        if (ucfirst($header) == 'Forwarded') {
+            foreach (explode(';', $headerValue) as $headerPart) {
+                if (strtolower(substr($headerPart, 0, 4)) == 'for=') {
+                    $for         = explode(']', $headerPart);
+                    $headerValue = trim(substr(reset($for), 4), " \t\n\r\0\x0B" . "\"[]");
+                    break;
+                }
+            }
         }
 
-        // @codeCoverageIgnoreStart
-        return null;
-        // @codeCoverageIgnoreEnd
+        return $headerValue;
     }
 }

From 4ed8ee0a3406e0e73bfca35e90829aea00341b1d Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:08:34 +0200
Subject: [PATCH 51/99] fixed some session bugs

---
 .../SuspiciousOperationException.php          | 13 +++
 .../Component/Contracts/Session/Store.php     | 28 ++++--
 .../Session/Fingerprint/ClientIpGenerator.php |  6 +-
 .../Fingerprint/UserAgentGenerator.php        | 16 ++--
 .../Middleware/StartSessionMiddleware.php     | 15 +++-
 src/Viserio/Component/Session/Store.php       | 55 +++++++++---
 .../Fingerprint/ClientIpGeneratorTest.php     | 53 +----------
 .../Fingerprint/UserAgentGeneratorTest.php    | 20 +++--
 .../Component/Session/Tests/StoreTest.php     | 33 ++++---
 .../Component/Support/Http/ClientIp.php       | 87 +++++++++++--------
 10 files changed, 190 insertions(+), 136 deletions(-)
 create mode 100644 src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php

diff --git a/src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php b/src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php
new file mode 100644
index 000000000..fb82b562a
--- /dev/null
+++ b/src/Viserio/Component/Contracts/Session/Exceptions/SuspiciousOperationException.php
@@ -0,0 +1,13 @@
+getIpAddress();
-
-        $this->clientIp = random_bytes(32) . $ip;
+        $this->clientIp = (new ClientIp($serverRequest))->getIpAddress();
     }
 
     /**
-     * {@inhertiddoc}.
+     * {@inheritdoc}.
      */
     public function generate(): string
     {
diff --git a/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php b/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php
index facbffa92..6caf7c68c 100644
--- a/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php
+++ b/src/Viserio/Component/Session/Fingerprint/UserAgentGenerator.php
@@ -2,6 +2,7 @@
 declare(strict_types=1);
 namespace Viserio\Component\Session\Fingerprint;
 
+use Psr\Http\Message\ServerRequestInterface;
 use Viserio\Component\Contracts\Session\Fingerprint as FingerprintContract;
 
 class UserAgentGenerator implements FingerprintContract
@@ -16,19 +17,22 @@ class UserAgentGenerator implements FingerprintContract
     /**
      * Create a new UserAgentGenerator instance.
      *
-     * @param string|null $userAgent
+     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest
      */
-    public function __construct(string $userAgent = null)
+    public function __construct(ServerRequestInterface $serverRequest)
     {
-        if ($userAgent !== null) {
-            $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
+        $userAgent    = '';
+        $serverParams = $serverRequest->getServerParams();
+
+        if (isset($serverParams['REMOTE_ADDR'])) {
+            $userAgent = $serverParams['REMOTE_ADDR'];
         }
 
-        $this->userAgent = random_bytes(32) . $userAgent;
+        $this->userAgent = $userAgent;
     }
 
     /**
-     * {@inhertiddoc}.
+     * {@inheritdoc}.
      */
     public function generate(): string
     {
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 667584700..71e97f7af 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -38,6 +38,16 @@ class StartSessionMiddleware implements MiddlewareInterface
      */
     protected $config = [];
 
+    /**
+     * List of fingerprint generators.
+     *
+     * @var array
+     */
+    private $fingerprintGenerators = [
+        ClientIpGenerator::class,
+        UserAgentGenerator::class
+    ];
+
     /**
      * Create a new session middleware.
      *
@@ -98,8 +108,9 @@ protected function startSession(ServerRequestInterface $request): StoreContract
 
         $session->setId($hasCookie ? $cookies->get($session->getName())->getValue() : '');
 
-        $session->addFingerprintGenerator(new ClientIpGenerator($request));
-        $session->addFingerprintGenerator(new UserAgentGenerator());
+        foreach ($this->fingerprintGenerators as $fingerprintGenerator) {
+            $session->addFingerprintGenerator(new $fingerprintGenerator($request));
+        }
 
         if ($session->handlerNeedsRequest()) {
             $session->setRequestOnHandler($request);
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 86392031e..c2beb08b7 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -13,6 +13,7 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
+use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
@@ -61,7 +62,7 @@ class Store implements StoreContract
     private $idRequestsLimit = null;
 
     /**
-     * Time after id is regenerated.
+     * Time after session is regenerated.
      *
      * @var int
      */
@@ -70,21 +71,21 @@ class Store implements StoreContract
     /**
      * Last (id) regeneration timestamp.
      *
-     * @var int
+     * @var int|null
      */
     private $regenerationTrace;
 
     /**
      * First trace (timestamp), time when session was created.
      *
-     * @var int
+     * @var int|null
      */
     private $firstTrace;
 
     /**
      * Last trace (Unix timestamp).
      *
-     * @var int
+     * @var int|null
      */
     private $lastTrace;
 
@@ -161,11 +162,17 @@ public function start(): bool
     public function open(): bool
     {
         if (! $this->started) {
-            if ($this->id !== null) {
+            if ($this->getId() !== null) {
                 $this->loadSession();
 
-                $this->started = true;
-                $this->requestsCount += 1;
+                if ($this->getFirstTrace() === null) {
+                    return false;
+                } elseif ($this->generateFingerprint() !== $this->getFingerprint()) {
+                    throw new SuspiciousOperationException();
+                } else {
+                    $this->started = true;
+                    $this->requestsCount += 1;
+                }
             }
         }
 
@@ -192,6 +199,28 @@ public function getId(): ?string
         return $this->id;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getTtl(): int
+    {
+        return $this->idTtl;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function isExpired(): bool
+    {
+        $lastTrace = $this->getLastTrace();
+
+        if ($lastTrace === null) {
+            return true;
+        }
+
+        return ($lastTrace + $this->getTtl() < time());
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -211,9 +240,9 @@ public function migrate(bool $destroy = false): bool
             $this->handler->destroy($this->id);
         }
 
-        $this->id = $this->generateSessionId();
-
+        $this->id                = $this->generateSessionId();
         $this->regenerationTrace = $this->getTimestamp();
+        $this->requestsCount     = 0;
 
         return true;
     }
@@ -360,7 +389,7 @@ public function setIdLiveTime(int $ttl): void
     /**
      * {@inheritdoc}
      */
-    public function getLastTrace(): int
+    public function getLastTrace(): ?int
     {
         return $this->lastTrace;
     }
@@ -368,7 +397,7 @@ public function getLastTrace(): int
     /**
      * {@inheritdoc}
      */
-    public function getFirstTrace(): int
+    public function getFirstTrace(): ?int
     {
         return $this->firstTrace;
     }
@@ -376,7 +405,7 @@ public function getFirstTrace(): int
     /**
      * {@inheritdoc}
      */
-    public function getRegenerationTrace(): int
+    public function getRegenerationTrace(): ?int
     {
         return $this->regenerationTrace;
     }
@@ -600,7 +629,7 @@ private function removeFromOldFlashData(array $keys): void
     }
 
     /**
-     * Determine if session id should be regenerated? (based on request_counter or regenerationTrace).
+     * Determine if session id should be regenerated? (based on requestsCount or regenerationTrace).
      *
      * @return bool
      */
diff --git a/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php b/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
index 898c8582a..4f8589c05 100644
--- a/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
+++ b/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
@@ -11,60 +11,11 @@ class ClientIpGeneratorTest extends MockeryTestCase
     public function testGenerate()
     {
         $request = $this->mock(ServerRequestInterface::class);
-        $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->once()
-            ->andReturn(false);
-        $request->shouldReceive('hasHeader')
-            ->with('REMOTE_ADDR')
-            ->once()
-            ->andReturn(false);
+        $request->shouldReceive('getServerParams')
+            ->andReturn(['REMOTE_ADDR' => '127.0.0.1']);
 
         $generator = new ClientIpGenerator($request);
 
-        self::assertInternalType('string', $generator->generate());
-        self::assertSame(40, mb_strlen($generator->generate()));
-    }
-
-    public function testGenerateWithProxyIp()
-    {
-        $request = $this->mock(ServerRequestInterface::class);
-        $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->once()
-            ->andReturn(true);
-        $request->shouldReceive('getHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->andReturn('111.111.111.111,123.45.67.178');
-
-        $generator = new ClientIpGenerator($request);
-
-        self::assertInternalType('string', $generator->generate());
-        self::assertSame(40, mb_strlen($generator->generate()));
-    }
-
-    public function testGenerateWithIp()
-    {
-        $request = $this->mock(ServerRequestInterface::class);
-        $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->once()
-            ->andReturn(false);
-        $request->shouldReceive('hasHeader')
-            ->with('REMOTE_ADDR')
-            ->once()
-            ->andReturn(true);
-        $request->shouldReceive('getHeader')
-            ->with('REMOTE_ADDR')
-            ->andReturn('100.8.116.127');
-
-        $generator = new ClientIpGenerator($request);
-
-        self::assertInternalType('string', $generator->generate());
-        self::assertSame(40, mb_strlen($generator->generate()));
-
-        // return empty ip string
-        self::assertInternalType('string', $generator->generate());
         self::assertSame(40, mb_strlen($generator->generate()));
     }
 }
diff --git a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
index 9a26ba9d9..9fd2ea25a 100644
--- a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
+++ b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
@@ -2,21 +2,29 @@
 declare(strict_types=1);
 namespace Viserio\Component\Session\Tests;
 
-use PHPUnit\Framework\TestCase;
+use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
+use Psr\Http\Message\ServerRequestInterface;
 
-class UserAgentGeneratorTest extends TestCase
+class UserAgentGeneratorTest extends MockeryTestCase
 {
     public function testGenerate()
     {
-        $generator = new UserAgentGenerator('test');
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => 'test']);
+        $generator = new UserAgentGenerator($request);
 
-        self::assertInternalType('string', $generator->generate());
         self::assertSame(40, mb_strlen($generator->generate()));
 
-        $generator = new UserAgentGenerator();
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn([]);
+
+        $generator = new UserAgentGenerator($request);
 
-        self::assertInternalType('string', $generator->generate());
         self::assertSame(40, mb_strlen($generator->generate()));
     }
 }
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index a12438066..960ea6636 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -11,6 +11,7 @@
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
+use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {
@@ -45,7 +46,7 @@ public function setUp()
                         'lastTrace'         => 0,
                         'regenerationTrace' => 1,
                         'requestsCount'     => 0,
-                        'fingerprint'       => 0,
+                        'fingerprint'       => '',
                     ],
                 ],
                 \JSON_PRESERVE_ZERO_FRACTION
@@ -66,7 +67,7 @@ public function testSessionIsLoadedFromHandler()
                         'lastTrace'         => 0,
                         'regenerationTrace' => 0,
                         'requestsCount'     => 0,
-                        'fingerprint'       => 0,
+                        'fingerprint'       => '',
                     ],
                 ],
                 \JSON_PRESERVE_ZERO_FRACTION
@@ -217,10 +218,14 @@ public function testStartMethodResetsIdRegenerationTrace()
     public function testStartMethodGeneratesFingerprint()
     {
         $session = $this->session;
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => 'test']);
 
         $oldFingerprint = $session->getFingerprint();
 
-        $session->addFingerprintGenerator(new UserAgentGenerator('test'));
+        $session->addFingerprintGenerator(new UserAgentGenerator($request));
 
         $session->start();
 
@@ -264,38 +269,38 @@ public function testSessionIdShouldBeRegeneratedIfIdRequestsLimitReached()
     {
         $session = $this->session;
         $session->setIdRequestsLimit(3);
-        $session->setId(self::SESSION_ID);
         $session->getHandler()
             ->shouldReceive('read')
-            ->times(4);
+            ->times(3);
         $session->getHandler()
             ->shouldReceive('write')
             ->times(3);
         $session->getHandler()
             ->shouldReceive('destroy')
-            ->times(1);
+            ->once();
 
+        $session->start();
         $session->open();
+
         self::assertSame(1, $session->getRequestsCount());
-        self::assertSame(self::SESSION_ID, $session->getId());
 
         $session->save();
-        $session->open();
+
+        self::assertTrue($session->open());
 
         self::assertSame(2, $session->getRequestsCount());
-        self::assertSame(self::SESSION_ID, $session->getId());
 
         $session->save();
-        $session->open();
+
+        self::assertTrue($session->open());
 
         self::assertSame(3, $session->getRequestsCount());
-        self::assertSame(self::SESSION_ID, $session->getId());
 
         $session->save();
-        $session->open();
+        // Session should migrate to a new one
+        self::assertTrue($session->open());
 
-        self::assertSame(4, $session->getRequestsCount());
-        self::assertNotSame(self::SESSION_ID, $session->getId());
+        self::assertSame(1, $session->getRequestsCount());
     }
 
     public function testSessionIdShouldBeRegeneratedIfIdTtlLimitReached()
diff --git a/src/Viserio/Component/Support/Http/ClientIp.php b/src/Viserio/Component/Support/Http/ClientIp.php
index 83f9e4c86..bbf8b4999 100644
--- a/src/Viserio/Component/Support/Http/ClientIp.php
+++ b/src/Viserio/Component/Support/Http/ClientIp.php
@@ -13,6 +13,19 @@ class ClientIp
      */
     protected $serverRequest;
 
+    /**
+     * List of proxy headers inspected for the client IP address.
+     *
+     * @var array
+     */
+    protected $headersToInspect = [
+        'Forwarded',
+        'X-Forwarded-For',
+        'X-Forwarded',
+        'X-Cluster-Client-Ip',
+        'Client-Ip',
+    ];
+
     /**
      * Create ClientIp instance.
      *
@@ -30,20 +43,20 @@ public function __construct(ServerRequestInterface $serverRequest)
      */
     public function getIpAddress(): string
     {
-        if (($ip = $this->getIpAddressFromProxy()) !== null) {
-            return $ip;
-        }
+        $serverParams = $this->serverRequest->getServerParams();
 
         // direct IP address
-        if ($this->serverRequest->hasHeader('REMOTE_ADDR')) {
-            $ip = filter_var(
-                $this->serverRequest->getHeader('REMOTE_ADDR'),
-                FILTER_VALIDATE_IP,
-                FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
-            );
+        if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
+            return $serverParams['REMOTE_ADDR'];
+        }
+
+        foreach ($this->headersToInspect as $header) {
+            if ($this->serverRequest->hasHeader($header)) {
+                $ip = $this->getFirstIpAddressFromHeader($request, $header);
 
-            if ($ip !== false) {
-                return $ip;
+                if ($this->isValidIpAddress($ip)) {
+                    return $ip;
+                }
             }
         }
 
@@ -51,38 +64,44 @@ public function getIpAddress(): string
     }
 
     /**
-     * Attempt to get the IP address for a proxied client.
+     * Check that a given string is a valid IP address.
      *
-     * @link http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10#section-5.2
+     * @param string $ip
      *
-     * @return string|null
+     * @return bool
      */
-    private function getIpAddressFromProxy(): ?string
+    private function isValidIpAddress(string $ip): bool
     {
-        if (! $this->serverRequest->hasHeader('HTTP_X_FORWARDED_FOR')) {
-            return null;
+        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === false) {
+            return false;
         }
 
-        // Extract IPs
-        $ips = explode(',', $this->serverRequest->getHeader('HTTP_X_FORWARDED_FOR'));
-        $ips = array_map('trim', $ips);
+        return true;
+    }
 
-        // @codeCoverageIgnoreStart
-        if (count($ips) === 0) {
-            return null;
-        }
-        // @codeCoverageIgnoreEnd
+    /**
+     * Find out the client's IP address from the headers available to us.
+     *
+     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest
+     * @param string                                   $header        Header name
+     *
+     * @return string
+     */
+    private function getFirstIpAddressFromHeader(ServerRequestInterface $serverRequest, string $header): string
+    {
+        $items       = explode(',', $request->getHeaderLine($header));
+        $headerValue = trim(reset($items));
 
-        // The right-most address represents the first IP we do not know about
-        // -- i.e., we do not know if it is a proxy server, or a client. As such,
-        // we treat it as the originating IP.
-        // @see http://en.wikipedia.org/wiki/X-Forwarded-For
-        if ($ip = filter_var($ips[0], FILTER_VALIDATE_IP)) {
-            return $ip;
+        if (ucfirst($header) == 'Forwarded') {
+            foreach (explode(';', $headerValue) as $headerPart) {
+                if (strtolower(substr($headerPart, 0, 4)) == 'for=') {
+                    $for         = explode(']', $headerPart);
+                    $headerValue = trim(substr(reset($for), 4), " \t\n\r\0\x0B" . "\"[]");
+                    break;
+                }
+            }
         }
 
-        // @codeCoverageIgnoreStart
-        return null;
-        // @codeCoverageIgnoreEnd
+        return $headerValue;
     }
 }

From 219d68bc7efb8bfe0ca0fa0ad6b02775a0cb1584 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 22:08:43 +0000
Subject: [PATCH 52/99] Apply fixes from StyleCI

---
 .../Session/Middleware/StartSessionMiddleware.php        | 2 +-
 src/Viserio/Component/Session/Store.php                  | 9 ++++-----
 .../Session/Tests/Fingerprint/UserAgentGeneratorTest.php | 2 +-
 src/Viserio/Component/Session/Tests/StoreTest.php        | 2 +-
 src/Viserio/Component/Support/Http/ClientIp.php          | 4 ++--
 5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 71e97f7af..d846723f1 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -45,7 +45,7 @@ class StartSessionMiddleware implements MiddlewareInterface
      */
     private $fingerprintGenerators = [
         ClientIpGenerator::class,
-        UserAgentGenerator::class
+        UserAgentGenerator::class,
     ];
 
     /**
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index c2beb08b7..d2d6ff13c 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -9,11 +9,11 @@
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 use Viserio\Component\Contracts\Encryption\Traits\EncrypterAwareTrait;
 use Viserio\Component\Contracts\Session\Exceptions\SessionNotStartedException;
+use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 use Viserio\Component\Contracts\Session\Fingerprint as FingerprintContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
-use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
@@ -169,10 +169,9 @@ public function open(): bool
                     return false;
                 } elseif ($this->generateFingerprint() !== $this->getFingerprint()) {
                     throw new SuspiciousOperationException();
-                } else {
-                    $this->started = true;
-                    $this->requestsCount += 1;
                 }
+                $this->started = true;
+                $this->requestsCount += 1;
             }
         }
 
@@ -218,7 +217,7 @@ public function isExpired(): bool
             return true;
         }
 
-        return ($lastTrace + $this->getTtl() < time());
+        return $lastTrace + $this->getTtl() < time();
     }
 
     /**
diff --git a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
index 9fd2ea25a..2f9611634 100644
--- a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
+++ b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
@@ -3,8 +3,8 @@
 namespace Viserio\Component\Session\Tests;
 
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
-use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Psr\Http\Message\ServerRequestInterface;
+use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 
 class UserAgentGeneratorTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index 960ea6636..906d74e48 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -5,13 +5,13 @@
 use Cake\Chronos\Chronos;
 use Defuse\Crypto\Key;
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
+use Psr\Http\Message\ServerRequestInterface;
 use ReflectionClass;
 use SessionHandlerInterface as SessionHandlerContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
-use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Support/Http/ClientIp.php b/src/Viserio/Component/Support/Http/ClientIp.php
index bbf8b4999..da111712d 100644
--- a/src/Viserio/Component/Support/Http/ClientIp.php
+++ b/src/Viserio/Component/Support/Http/ClientIp.php
@@ -94,9 +94,9 @@ private function getFirstIpAddressFromHeader(ServerRequestInterface $serverReque
 
         if (ucfirst($header) == 'Forwarded') {
             foreach (explode(';', $headerValue) as $headerPart) {
-                if (strtolower(substr($headerPart, 0, 4)) == 'for=') {
+                if (mb_strtolower(mb_substr($headerPart, 0, 4)) == 'for=') {
                     $for         = explode(']', $headerPart);
-                    $headerValue = trim(substr(reset($for), 4), " \t\n\r\0\x0B" . "\"[]");
+                    $headerValue = trim(mb_substr(reset($for), 4), " \t\n\r\0\x0B" . '"[]');
                     break;
                 }
             }

From 0bfb9c477e7d4066e24746272a54ff448ba6e9e0 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 22:08:49 +0000
Subject: [PATCH 53/99] Apply fixes from StyleCI

---
 .../Session/Middleware/StartSessionMiddleware.php        | 2 +-
 src/Viserio/Component/Session/Store.php                  | 9 ++++-----
 .../Session/Tests/Fingerprint/UserAgentGeneratorTest.php | 2 +-
 src/Viserio/Component/Session/Tests/StoreTest.php        | 2 +-
 src/Viserio/Component/Support/Http/ClientIp.php          | 4 ++--
 5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 773ff4d3a..18ebe690a 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -45,7 +45,7 @@ class StartSessionMiddleware implements MiddlewareInterface
      */
     private $fingerprintGenerators = [
         ClientIpGenerator::class,
-        UserAgentGenerator::class
+        UserAgentGenerator::class,
     ];
 
     /**
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index c2beb08b7..d2d6ff13c 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -9,11 +9,11 @@
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 use Viserio\Component\Contracts\Encryption\Traits\EncrypterAwareTrait;
 use Viserio\Component\Contracts\Session\Exceptions\SessionNotStartedException;
+use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 use Viserio\Component\Contracts\Session\Fingerprint as FingerprintContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
-use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
@@ -169,10 +169,9 @@ public function open(): bool
                     return false;
                 } elseif ($this->generateFingerprint() !== $this->getFingerprint()) {
                     throw new SuspiciousOperationException();
-                } else {
-                    $this->started = true;
-                    $this->requestsCount += 1;
                 }
+                $this->started = true;
+                $this->requestsCount += 1;
             }
         }
 
@@ -218,7 +217,7 @@ public function isExpired(): bool
             return true;
         }
 
-        return ($lastTrace + $this->getTtl() < time());
+        return $lastTrace + $this->getTtl() < time();
     }
 
     /**
diff --git a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
index 9fd2ea25a..2f9611634 100644
--- a/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
+++ b/src/Viserio/Component/Session/Tests/Fingerprint/UserAgentGeneratorTest.php
@@ -3,8 +3,8 @@
 namespace Viserio\Component\Session\Tests;
 
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
-use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Psr\Http\Message\ServerRequestInterface;
+use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 
 class UserAgentGeneratorTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index 960ea6636..906d74e48 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -5,13 +5,13 @@
 use Cake\Chronos\Chronos;
 use Defuse\Crypto\Key;
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
+use Psr\Http\Message\ServerRequestInterface;
 use ReflectionClass;
 use SessionHandlerInterface as SessionHandlerContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
-use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Support/Http/ClientIp.php b/src/Viserio/Component/Support/Http/ClientIp.php
index bbf8b4999..da111712d 100644
--- a/src/Viserio/Component/Support/Http/ClientIp.php
+++ b/src/Viserio/Component/Support/Http/ClientIp.php
@@ -94,9 +94,9 @@ private function getFirstIpAddressFromHeader(ServerRequestInterface $serverReque
 
         if (ucfirst($header) == 'Forwarded') {
             foreach (explode(';', $headerValue) as $headerPart) {
-                if (strtolower(substr($headerPart, 0, 4)) == 'for=') {
+                if (mb_strtolower(mb_substr($headerPart, 0, 4)) == 'for=') {
                     $for         = explode(']', $headerPart);
-                    $headerValue = trim(substr(reset($for), 4), " \t\n\r\0\x0B" . "\"[]");
+                    $headerValue = trim(mb_substr(reset($for), 4), " \t\n\r\0\x0B" . '"[]');
                     break;
                 }
             }

From 6d324a85da31273b46c5f0e152ff0b623e29f90e Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:25:03 +0200
Subject: [PATCH 54/99] some changes on http panel

---
 .../ViserioHttpDataCollector.php               | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
index 8eb828b50..cc653e33d 100644
--- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
+++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
@@ -166,9 +166,9 @@ public function getPanel(): string
 
         if ($session !== null) {
             $sessionMeta = [
-                'firstTrace'        => $session->getFirstTrace(),
-                'lastTrace'         => $session->getLastTrace(),
-                'regenerationTrace' => $session->getRegenerationTrace(),
+                'Created'           => date(DATE_RFC2822, $session->getFirstTrace()),
+                'Last used'         => date(DATE_RFC2822, $session->getLastTrace()),
+                'Last regeneration' => date(DATE_RFC2822, $session->getRegenerationTrace()),
                 'requestsCount'     => $session->getRequestsCount(),
                 'fingerprint'       => $session->getFingerprint(),
             ];
@@ -249,10 +249,18 @@ public function getAssets(): array
         ];
     }
 
-    protected function createCookieTab(ServerRequestInterface $serverRequest, ResponseInterface $response): ?array
+    /**
+     * Prepare request and response cookie infos and create a cookie tab.
+     *
+     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest
+     * @param \Psr\Http\Message\ResponseInterface      $response
+     *
+     * @return array
+     */
+    protected function createCookieTab(ServerRequestInterface $serverRequest, ResponseInterface $response): array
     {
         if (! (class_exists(RequestCookies::class) && class_exists(ResponseCookies::class))) {
-            return null;
+            return [];
         }
 
         $requestCookies = $responseCookies = [];

From 63223f811db280598417a956d2dd9d85c8e9fb1d Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:25:21 +0200
Subject: [PATCH 55/99] cs fix

---
 src/Viserio/Component/Session/Store.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index d2d6ff13c..5508cbd02 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -55,7 +55,7 @@ class Store implements StoreContract
     protected $encrypter;
 
     /**
-     * Number of requests after which id is regeneratd.
+     * Number of requests after which id is regenerated.
      *
      * @var int|null
      */

From 10912b2083c1bfcea02b05a35888f33b8a0ac552 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:25:21 +0200
Subject: [PATCH 56/99] cs fix

---
 src/Viserio/Component/Session/Store.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index d2d6ff13c..5508cbd02 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -55,7 +55,7 @@ class Store implements StoreContract
     protected $encrypter;
 
     /**
-     * Number of requests after which id is regeneratd.
+     * Number of requests after which id is regenerated.
      *
      * @var int|null
      */

From 2b323934f1c28f34defd5a178e8ecc1c8026799d Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 11:51:01 +0200
Subject: [PATCH 57/99] and more session work

---
 composer.json                                    |  1 +
 src/Viserio/Component/Cache/composer.json        |  2 +-
 .../Session/Handler/CacheBasedSessionHandler.php |  8 +-------
 .../Session/Handler/CookieSessionHandler.php     | 10 +++++-----
 .../Session/Handler/FileSessionHandler.php       |  8 ++++----
 src/Viserio/Component/Session/SessionManager.php |  2 +-
 src/Viserio/Component/Session/Store.php          | 11 ++++++-----
 .../Middleware/StartSessionMiddlewareTest.php    |  4 ++--
 .../Middleware/VerifyCsrfTokenMiddlewareTest.php | 16 ++++++++--------
 .../Providers/SessionServiceProviderTest.php     |  4 ++--
 src/Viserio/Component/Session/composer.json      |  1 -
 11 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/composer.json b/composer.json
index 843a05740..35bfbf75f 100644
--- a/composer.json
+++ b/composer.json
@@ -33,6 +33,7 @@
         "ext-fileinfo"                                       : "*",
         "ext-openssl"                                        : "*",
         "cache/array-adapter"                                : "^0.4",
+        "cache/void-adapter"                                 : "^0.4",
         "cakephp/chronos"                                    : "^1.0",
         "container-interop/container-interop"                : "^1.1",
         "container-interop/service-provider"                 : "^0.3",
diff --git a/src/Viserio/Component/Cache/composer.json b/src/Viserio/Component/Cache/composer.json
index a617b5844..af596e8e5 100644
--- a/src/Viserio/Component/Cache/composer.json
+++ b/src/Viserio/Component/Cache/composer.json
@@ -40,6 +40,7 @@
     "require": {
         "php"                                 : "^7.1",
         "cache/array-adapter"                 : "^0.4",
+        "cache/void-adapter"                  : "^0.4",
         "container-interop/container-interop" : "^1.1",
         "viserio/cotracts"                    : "self.version",
         "viserio/options-resolver"            : "self.version",
@@ -88,7 +89,6 @@
         "cache/namespaced-adapter"            : "Required to use the Namespaced cache (^0.1).",
         "cache/mongodb-adapter"               : "Required to use the Mongodb cache (^0.2).",
         "cache/predis-adapter"                : "Required to use the Predis cache (^0.4).",
-        "cache/void-adapter"                  : "Required to use the Void cache (^0.3).",
         "container-interop/service-provider"  : "Required to use service-provider (^0.3).",
         "viserio/statical-proxy"              : "Required to use the proxy instances (self.version)."
     },
diff --git a/src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php b/src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php
index 46d4896ce..06d0ed062 100644
--- a/src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php
+++ b/src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php
@@ -23,7 +23,7 @@ class CacheBasedSessionHandler implements SessionHandlerInterface
      */
     public function __construct(CacheItemPoolInterface $cache, int $lifetime)
     {
-        $this->psr6cache = new Psr6SessionHandler($cache, ['ttl' => $lifetime]);
+        $this->psr6cache = new Psr6SessionHandler($cache, ['ttl' => $lifetime, 'prefix' => 'ns_ses_']);
     }
 
     /**
@@ -44,8 +44,6 @@ public function close()
 
     /**
      * {@inheritdoc}
-     *
-     * // @codeCoverageIgnore
      */
     public function read($sessionId)
     {
@@ -54,8 +52,6 @@ public function read($sessionId)
 
     /**
      * {@inheritdoc}
-     *
-     * // @codeCoverageIgnore
      */
     public function write($sessionId, $data)
     {
@@ -64,8 +60,6 @@ public function write($sessionId, $data)
 
     /**
      * {@inheritdoc}
-     *
-     * // @codeCoverageIgnore
      */
     public function destroy($sessionId)
     {
diff --git a/src/Viserio/Component/Session/Handler/CookieSessionHandler.php b/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
index 93749d9dd..669f7f925 100644
--- a/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
+++ b/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
@@ -12,14 +12,14 @@ class CookieSessionHandler implements SessionHandlerInterface
     /**
      * The cookie jar instance.
      *
-     * @var JarContract
+     * @var \Viserio\Component\Contracts\Cookie\QueueingFactory
      */
     protected $cookie;
 
     /**
      * The request instance.
      *
-     * @var ServerRequestInterface
+     * @var \Psr\Http\Message\ServerRequestInterface
      */
     protected $request;
 
@@ -33,8 +33,8 @@ class CookieSessionHandler implements SessionHandlerInterface
     /**
      * Create a new cookie driven handler instance.
      *
-     * @param JarContract $cookie
-     * @param int         $lifetime
+     * @param \Viserio\Component\Contracts\Cookie\QueueingFactory $cookie
+     * @param int                                                 $lifetime
      */
     public function __construct(JarContract $cookie, int $lifetime)
     {
@@ -119,7 +119,7 @@ public function gc($lifetime)
     /**
      * Set the request instance.
      *
-     * @param ServerRequestInterface $request
+     * @param \Psr\Http\Message\ServerRequestInterface $request
      */
     public function setRequest(ServerRequestInterface $request)
     {
diff --git a/src/Viserio/Component/Session/Handler/FileSessionHandler.php b/src/Viserio/Component/Session/Handler/FileSessionHandler.php
index 9dff10cb7..fbea2d7c1 100644
--- a/src/Viserio/Component/Session/Handler/FileSessionHandler.php
+++ b/src/Viserio/Component/Session/Handler/FileSessionHandler.php
@@ -12,7 +12,7 @@ class FileSessionHandler implements SessionHandlerInterface
     /**
      * The filesystem instance.
      *
-     * @var FilesystemContract
+     * @var \Viserio\Component\Contracts\Filesystem\Filesystem
      */
     protected $files;
 
@@ -33,9 +33,9 @@ class FileSessionHandler implements SessionHandlerInterface
     /**
      * Create a new file driven handler instance.
      *
-     * @param FilesystemContract $files
-     * @param string             $path
-     * @param int                $lifetime The session lifetime in minutes
+     * @param \Viserio\Component\Contracts\Filesystem\Filesystem $files
+     * @param string                                             $path
+     * @param int                                                $lifetime The session lifetime in minutes
      */
     public function __construct(FilesystemContract $files, string $path, int $lifetime)
     {
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index f167a0dad..9dc5dcb67 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -55,7 +55,7 @@ public function getDefaultOptions(): iterable
      *
      * @return \Viserio\Component\Contracts\Session\Store
      */
-    protected function createLocalDriver(array $config): StoreContract
+    protected function createFileDriver(array $config): StoreContract
     {
         return $this->buildSession(
             new FileSessionHandler(
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 5508cbd02..c50ea3e99 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -3,7 +3,6 @@
 namespace Viserio\Component\Session;
 
 use DateTimeImmutable;
-use Narrowspark\Arr\Arr;
 use Psr\Http\Message\ServerRequestInterface;
 use SessionHandlerInterface as SessionHandlerContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
@@ -290,7 +289,7 @@ public function has(string $name): bool
     {
         $this->checkIfSessionHasStarted();
 
-        return Arr::has($this->values, $name);
+        return isset($this->values[$name]);
     }
 
     /**
@@ -300,7 +299,7 @@ public function get(string $name, $default = null)
     {
         $this->checkIfSessionHasStarted();
 
-        return Arr::get($this->values, $name, $default);
+        return $this->has($name) ? $this->values[$name] : $default;
     }
 
     /**
@@ -310,7 +309,7 @@ public function set(string $name, $value): void
     {
         $this->checkIfSessionHasStarted();
 
-        $this->values = Arr::set($this->values, $name, $value);
+        $this->values[$name] = $value;
     }
 
     /**
@@ -332,7 +331,9 @@ public function remove(string $name)
     {
         $value = $this->get($name);
 
-        Arr::forget($this->values, $name);
+        if ($this->has($name)) {
+            unset($this->values[$name]);
+        }
 
         return $value;
     }
diff --git a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
index c52f95c51..965fae9fa 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
@@ -53,9 +53,9 @@ public function testAddSessionToResponse()
             ->with('viserio')
             ->andReturn([
                 'session' => [
-                    'default' => 'local',
+                    'default' => 'file',
                     'drivers' => [
-                        'local' => [
+                        'file' => [
                             'path' => __DIR__ . '/stubs',
                         ],
                     ],
diff --git a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
index c09677d32..c90cd3c73 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
@@ -60,9 +60,9 @@ public function testSessionCsrfMiddlewareSetCookie()
             ->with('viserio')
             ->andReturn([
                 'session' => [
-                    'default' => 'local',
+                    'default' => 'file',
                     'drivers' => [
-                        'local' => [
+                        'file' => [
                             'path' => __DIR__ . '/stubs',
                         ],
                     ],
@@ -121,9 +121,9 @@ public function testSessionCsrfMiddlewareReadsXCSRFTOKEN()
             ->with('viserio')
             ->andReturn([
                 'session' => [
-                    'default' => 'local',
+                    'default' => 'file',
                     'drivers' => [
-                        'local' => [
+                        'file' => [
                             'path' => __DIR__ . '/stubs',
                         ],
                     ],
@@ -182,9 +182,9 @@ public function testSessionCsrfMiddlewareReadsXXSRFTOKEN()
             ->with('viserio')
             ->andReturn([
                 'session' => [
-                    'default' => 'local',
+                    'default' => 'file',
                     'drivers' => [
-                        'local' => [
+                        'file' => [
                             'path' => __DIR__ . '/stubs',
                         ],
                     ],
@@ -249,9 +249,9 @@ public function testSessionCsrfMiddlewareToThrowException()
             ->with('viserio')
             ->andReturn([
                 'session' => [
-                    'default' => 'local',
+                    'default' => 'file',
                     'drivers' => [
-                        'local' => [
+                        'file' => [
                             'path' => __DIR__ . '/stubs',
                         ],
                     ],
diff --git a/src/Viserio/Component/Session/Tests/Providers/SessionServiceProviderTest.php b/src/Viserio/Component/Session/Tests/Providers/SessionServiceProviderTest.php
index 6e2f4e976..f42295a5a 100644
--- a/src/Viserio/Component/Session/Tests/Providers/SessionServiceProviderTest.php
+++ b/src/Viserio/Component/Session/Tests/Providers/SessionServiceProviderTest.php
@@ -27,9 +27,9 @@ public function testProvider()
         $container->instance('config', [
             'viserio' => [
                 'session' => [
-                    'default'  => 'local',
+                    'default'  => 'file',
                     'drivers'  => [
-                        'local' => [
+                        'file' => [
                             'path' => '',
                         ],
                     ],
diff --git a/src/Viserio/Component/Session/composer.json b/src/Viserio/Component/Session/composer.json
index a02e3e451..5dc5ce1a6 100644
--- a/src/Viserio/Component/Session/composer.json
+++ b/src/Viserio/Component/Session/composer.json
@@ -21,7 +21,6 @@
         "php"                                                : "^7.1",
         "container-interop/container-interop"                : "^1.1",
         "cakephp/chronos"                                    : "^1.0",
-        "narrowspark/arr"                                    : "^1.0",
         "psr/http-message"                                   : "^1.0",
         "viserio/cotracts"                                   : "self.version",
         "viserio/encrypter"                                  : "self.version",

From 9146679b2668ff69394088931ce081143eae72b7 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 15:17:20 +0200
Subject: [PATCH 58/99] and more session work

---
 .../Component/Contracts/Session/Store.php     |  2 +-
 .../Providers/SessionServiceProvider.php      | 23 ++++++++++----
 .../Component/Session/SessionManager.php      | 14 ++++-----
 src/Viserio/Component/Session/Store.php       | 30 ++++++++++---------
 .../Middleware/StartSessionMiddlewareTest.php |  9 +++---
 .../VerifyCsrfTokenMiddlewareTest.php         |  5 ++--
 .../Session/Tests/SessionManagerTest.php      | 14 ++-------
 src/Viserio/Component/Session/composer.json   |  2 ++
 8 files changed, 53 insertions(+), 46 deletions(-)

diff --git a/src/Viserio/Component/Contracts/Session/Store.php b/src/Viserio/Component/Contracts/Session/Store.php
index dc63a5304..6f206653f 100644
--- a/src/Viserio/Component/Contracts/Session/Store.php
+++ b/src/Viserio/Component/Contracts/Session/Store.php
@@ -64,7 +64,7 @@ public function setName(string $name): void;
     public function getName(): string;
 
     /**
-     * Time after session is regenerated.
+     * Time after session is regenerated (in seconds).
      *
      * @return int
      */
diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index 6736641db..a9ea803dd 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -20,8 +20,8 @@ class SessionServiceProvider implements ServiceProvider
     public function getServices()
     {
         return [
-            SessionManager::class => [self::class, 'createSessionManager'],
-            'session'             => function (ContainerInterface $container) {
+            SessionManager::class       => [self::class, 'createSessionManager'],
+            'session'                   => function (ContainerInterface $container) {
                 return $container->get(SessionManager::class);
             },
             'session.store'             => [self::class, 'createSessionStore'],
@@ -54,14 +54,25 @@ public static function extendEventManager(ContainerInterface $container, ?callab
         return $eventManager;
     }
 
+    /**
+     * Create new session manager instance.
+     *
+     * @param \Interop\Container\ContainerInterface $container
+     *
+     * @return \Viserio\Component\Session\SessionManager
+     */
     public static function createSessionManager(ContainerInterface $container): SessionManager
     {
-        return new SessionManager(
-            $container,
-            $container->get(Encrypter::class)
-        );
+        return new SessionManager($container);
     }
 
+    /**
+     * Create session store from default driver.
+     *
+     * @param \Interop\Container\ContainerInterface $container
+     *
+     * @return \Viserio\Component\Contracts\Session\Store
+     */
     public static function createSessionStore(ContainerInterface $container): StoreContract
     {
         return $container->get(SessionManager::class)->getDriver();
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index 9dc5dcb67..4fc95df94 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -23,17 +23,15 @@ class SessionManager extends AbstractManager implements ProvidesDefaultOptionsCo
     /**
      * Create a new session manager instance.
      *
-     * @param \Interop\Container\ContainerInterface             $container
-     * @param \Viserio\Component\Contracts\Encryption\Encrypter $encrypter
+     * @param \Interop\Container\ContainerInterface $container
      */
-    public function __construct(
-        ContainerInteropInterface $container,
-        EncrypterContract $encrypter
-    ) {
+    public function __construct(ContainerInteropInterface $container)
+    {
         parent::__construct($container);
 
         $this->container = $container;
-        $this->encrypter = $encrypter;
+
+        $this->setEncrypter($container->get(EncrypterContract::class));
     }
 
     /**
@@ -44,7 +42,7 @@ public function getDefaultOptions(): iterable
         return [
             'default'  => 'array',
             'cookie'   => 'NSSESSID',
-            'lifetime' => 120,
+            'lifetime' => 86400,
         ];
     }
 
diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index c50ea3e99..eec65dad7 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -2,7 +2,7 @@
 declare(strict_types=1);
 namespace Viserio\Component\Session;
 
-use DateTimeImmutable;
+use Cake\Chronos\Chronos;
 use Psr\Http\Message\ServerRequestInterface;
 use SessionHandlerInterface as SessionHandlerContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
@@ -61,21 +61,21 @@ class Store implements StoreContract
     private $idRequestsLimit = null;
 
     /**
-     * Time after session is regenerated.
+     * The number of seconds the session should be valid.
      *
      * @var int
      */
     private $idTtl = 86400;
 
     /**
-     * Last (id) regeneration timestamp.
+     * Last (id) regeneration (Unix timestamp).
      *
      * @var int|null
      */
     private $regenerationTrace;
 
     /**
-     * First trace (timestamp), time when session was created.
+     * First trace (Unix timestamp), time when session was created.
      *
      * @var int|null
      */
@@ -197,14 +197,6 @@ public function getId(): ?string
         return $this->id;
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getTtl(): int
-    {
-        return $this->idTtl;
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -386,6 +378,14 @@ public function setIdLiveTime(int $ttl): void
         $this->idTtl = $ttl;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getTtl(): int
+    {
+        return $this->idTtl;
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -640,7 +640,9 @@ private function shouldRegenerateId(): bool
         }
 
         if ($this->idTtl && $this->regenerationTrace) {
-            return $this->regenerationTrace + $this->idTtl < $this->getTimestamp();
+            $expires = Chronos::createFromTimestamp($this->regenerationTrace)->addSeconds($this->getTtl())->getTimestamp();
+
+            return $expires < $this->getTimestamp();
         }
 
         return false;
@@ -734,6 +736,6 @@ private function generateFingerprint(): string
      */
     private function getTimestamp(): int
     {
-        return (new DateTimeImmutable())->getTimestamp();
+        return Chronos::now()->toMutable()->getTimestamp();
     }
 }
diff --git a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
index 965fae9fa..4b95bb5b6 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
@@ -16,6 +16,7 @@
 use Viserio\Component\HttpFactory\ServerRequestFactory;
 use Viserio\Component\Session\Middleware\StartSessionMiddleware;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class StartSessionMiddlewareTest extends MockeryTestCase
 {
@@ -74,8 +75,8 @@ public function testAddSessionToResponse()
                 RepositoryContract::class => $config,
                 FilesystemContract::class => $this->files,
                 JarContract::class        => $this->mock(JarContract::class),
-            ]),
-            new Encrypter(Key::createNewRandomKey()->saveToAsciiSafeString())
+                EncrypterContract::class  => new Encrypter(Key::createNewRandomKey()->saveToAsciiSafeString()),
+            ])
         );
 
         $middleware = new StartSessionMiddleware($manager);
@@ -128,8 +129,8 @@ public function testAddSessionToCookie()
                 RepositoryContract::class => $config,
                 FilesystemContract::class => $this->files,
                 JarContract::class        => $jar,
-            ]),
-            new Encrypter(Key::createNewRandomKey()->saveToAsciiSafeString())
+                EncrypterContract::class  => new Encrypter(Key::createNewRandomKey()->saveToAsciiSafeString()),
+            ])
         );
 
         $middleware = new StartSessionMiddleware($manager);
diff --git a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
index c90cd3c73..50e41941c 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
@@ -17,6 +17,7 @@
 use Viserio\Component\Session\Middleware\StartSessionMiddleware;
 use Viserio\Component\Session\Middleware\VerifyCsrfTokenMiddleware;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class VerifyCsrfTokenMiddlewareTest extends MockeryTestCase
 {
@@ -299,8 +300,8 @@ private function getSessionManager($config)
             new ArrayContainer([
                 RepositoryContract::class => $config,
                 FilesystemContract::class => $this->files,
-            ]),
-            $this->encrypter
+                EncrypterContract::class  => $this->encrypter,
+            ])
         );
     }
 }
diff --git a/src/Viserio/Component/Session/Tests/SessionManagerTest.php b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
index 005df1021..8fc847b3d 100644
--- a/src/Viserio/Component/Session/Tests/SessionManagerTest.php
+++ b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
@@ -13,18 +13,10 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class SessionManagerTest extends MockeryTestCase
 {
-    private $manager;
-
-    public function tearDown()
-    {
-        $this->manager = null;
-
-        parent::tearDown();
-    }
-
     public function testCookieStore()
     {
         $config = $this->mock(RepositoryContract::class);
@@ -93,8 +85,8 @@ private function getSessionManager($config)
                 CacheManagerContract::class => new CacheManager(new ArrayContainer([
                     RepositoryContract::class   => $config,
                 ])),
-            ]),
-            new Encrypter(Key::createNewRandomKey()->saveToAsciiSafeString())
+                EncrypterContract::class => new Encrypter(Key::createNewRandomKey()->saveToAsciiSafeString()),
+            ])
         );
     }
 }
diff --git a/src/Viserio/Component/Session/composer.json b/src/Viserio/Component/Session/composer.json
index 5dc5ce1a6..e1f87d957 100644
--- a/src/Viserio/Component/Session/composer.json
+++ b/src/Viserio/Component/Session/composer.json
@@ -63,6 +63,8 @@
         "container-interop/service-provider"                 : "Required to use service-provider (^0.3).",
         "cache/session-handler"                              : "Required to use the CacheBasedSessionHandler (^0.2).",
         "http-interop/http-middleware"                       : "Required to use middleware (^0.4).",
+        "psr/container"                                      : "A container instance is required to use the SessionManager.",
+        "viserio/cache"                                      : "Required to use the CookieSessionHandler (self.version).",
         "viserio/cookie"                                     : "Required to use the CookieSessionHandler and StartSessionMiddleware (self.version).",
         "viserio/filesystem"                                 : "Required to use the FileSessionHandler (self.version).",
         "viserio/statical-proxy"                             : "Required to use the proxy instances (self.version)."

From 6e1bee85798a69793ce283a6339c6495fb629009 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 13:17:33 +0000
Subject: [PATCH 59/99] Apply fixes from StyleCI

---
 .../Component/Session/Providers/SessionServiceProvider.php      | 1 -
 .../Session/Tests/Middleware/StartSessionMiddlewareTest.php     | 2 +-
 .../Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php  | 2 +-
 src/Viserio/Component/Session/Tests/SessionManagerTest.php      | 2 +-
 4 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index a9ea803dd..17f38a3d7 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -4,7 +4,6 @@
 
 use Interop\Container\ContainerInterface;
 use Interop\Container\ServiceProvider;
-use Viserio\Component\Contracts\Encryption\Encrypter;
 use Viserio\Component\Contracts\Events\Event as EventContract;
 use Viserio\Component\Contracts\Events\EventManager as EventManagerContract;
 use Viserio\Component\Contracts\Foundation\Terminable as TerminableContract;
diff --git a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
index 4b95bb5b6..dd4979fd6 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
@@ -8,6 +8,7 @@
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
 use Viserio\Component\Contracts\Config\Repository as RepositoryContract;
 use Viserio\Component\Contracts\Cookie\QueueingFactory as JarContract;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 use Viserio\Component\Contracts\Filesystem\Filesystem as FilesystemContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Encryption\Encrypter;
@@ -16,7 +17,6 @@
 use Viserio\Component\HttpFactory\ServerRequestFactory;
 use Viserio\Component\Session\Middleware\StartSessionMiddleware;
 use Viserio\Component\Session\SessionManager;
-use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class StartSessionMiddlewareTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
index 50e41941c..6a1637520 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
@@ -9,6 +9,7 @@
 use Narrowspark\TestingHelper\Middleware\Dispatcher;
 use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
 use Viserio\Component\Contracts\Config\Repository as RepositoryContract;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 use Viserio\Component\Contracts\Filesystem\Filesystem as FilesystemContract;
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Filesystem\Filesystem;
@@ -17,7 +18,6 @@
 use Viserio\Component\Session\Middleware\StartSessionMiddleware;
 use Viserio\Component\Session\Middleware\VerifyCsrfTokenMiddleware;
 use Viserio\Component\Session\SessionManager;
-use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class VerifyCsrfTokenMiddlewareTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Session/Tests/SessionManagerTest.php b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
index 8fc847b3d..daf15d2af 100644
--- a/src/Viserio/Component/Session/Tests/SessionManagerTest.php
+++ b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
@@ -10,10 +10,10 @@
 use Viserio\Component\Contracts\Cache\Manager as CacheManagerContract;
 use Viserio\Component\Contracts\Config\Repository as RepositoryContract;
 use Viserio\Component\Contracts\Cookie\QueueingFactory as JarContract;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\SessionManager;
-use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class SessionManagerTest extends MockeryTestCase
 {

From 21d22c5fa72c673f5590535a1c87a7a6f95bd236 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 15:35:46 +0200
Subject: [PATCH 60/99] small cookie changes

---
 src/Viserio/Component/Cookie/Tests/CookieTest.php | 15 +++++++++++++--
 .../Cookie/Traits/CookieValidatorTrait.php        |  5 ++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/Viserio/Component/Cookie/Tests/CookieTest.php b/src/Viserio/Component/Cookie/Tests/CookieTest.php
index d01650d8b..7536c60fd 100644
--- a/src/Viserio/Component/Cookie/Tests/CookieTest.php
+++ b/src/Viserio/Component/Cookie/Tests/CookieTest.php
@@ -2,6 +2,7 @@
 declare(strict_types=1);
 namespace Viserio\Component\Cookie\Tests;
 
+use InvalidArgumentException;
 use PHPUnit\Framework\TestCase;
 use Viserio\Component\Cookie\Cookie;
 
@@ -10,7 +11,6 @@ class CookieTest extends TestCase
     public function invalidNames()
     {
         return [
-            [''],
             [',MyName'],
             [';MyName'],
             [' MyName'],
@@ -23,13 +23,24 @@ public function invalidNames()
     }
 
     /**
-     * @dataProvider invalidNames
      * @expectedException \InvalidArgumentException
+     * @expectExceptionMessage The name cannot be empty.
+     */
+    public function testInstantiationThrowsExceptionIfCookieNameIsEmpty()
+    {
+        new Cookie('');
+    }
+
+    /**
+     * @dataProvider invalidNames
      *
      * @param mixed $name
      */
     public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidCharacters($name)
     {
+        self::expectException(InvalidArgumentException::class);
+        self::expectExceptionMessage('Cookie name ['.$name.'] must not contain invalid characters: ASCII Control characters (0-31;127), space, tab and the following characters: ()<>@,;:\"/[]?={}');
+
         new Cookie($name);
     }
 
diff --git a/src/Viserio/Component/Cookie/Traits/CookieValidatorTrait.php b/src/Viserio/Component/Cookie/Traits/CookieValidatorTrait.php
index 22ae4e058..e98cc3d11 100644
--- a/src/Viserio/Component/Cookie/Traits/CookieValidatorTrait.php
+++ b/src/Viserio/Component/Cookie/Traits/CookieValidatorTrait.php
@@ -25,7 +25,10 @@ protected function validateName(string $name): void
 
         // Name attribute is a token as per spec in RFC 2616
         if (preg_match('/[\x00-\x20\x22\x28-\x29\x2c\x2f\x3a-\x40\x5b-\x5d\x7b\x7d\x7f]/', $name)) {
-            throw new InvalidArgumentException(sprintf('The cookie name [%s] contains invalid characters.', $name));
+            throw new InvalidArgumentException(sprintf(
+                'Cookie name [%s] must not contain invalid characters: ASCII Control characters (0-31;127), space, tab and the following characters: ()<>@,;:\"/[]?={}',
+                $name
+            ));
         }
     }
 

From ae947cac20444db0782531a5482e23491f82fd22 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 13:35:57 +0000
Subject: [PATCH 61/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Cookie/Tests/CookieTest.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Cookie/Tests/CookieTest.php b/src/Viserio/Component/Cookie/Tests/CookieTest.php
index 7536c60fd..c6da0be3c 100644
--- a/src/Viserio/Component/Cookie/Tests/CookieTest.php
+++ b/src/Viserio/Component/Cookie/Tests/CookieTest.php
@@ -39,7 +39,7 @@ public function testInstantiationThrowsExceptionIfCookieNameIsEmpty()
     public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidCharacters($name)
     {
         self::expectException(InvalidArgumentException::class);
-        self::expectExceptionMessage('Cookie name ['.$name.'] must not contain invalid characters: ASCII Control characters (0-31;127), space, tab and the following characters: ()<>@,;:\"/[]?={}');
+        self::expectExceptionMessage('Cookie name [' . $name . '] must not contain invalid characters: ASCII Control characters (0-31;127), space, tab and the following characters: ()<>@,;:\"/[]?={}');
 
         new Cookie($name);
     }

From 0fc434c3bcdeface07f8ebf0b9358d28bba56e27 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 20:02:00 +0200
Subject: [PATCH 62/99] Added tests for client ip

---
 src/Viserio/Component/Session/Store.php       |   2 -
 .../Fingerprint/ClientIpGeneratorTest.php     |  15 ++
 .../Component/Support/Http/ClientIp.php       |  19 +-
 .../Support/Tests/Http/ClientIpTest.php       | 225 +++++++++++++++++-
 src/Viserio/Component/WebProfiler/Profile.php |   2 +-
 5 files changed, 240 insertions(+), 23 deletions(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index eec65dad7..8348500ff 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -512,8 +512,6 @@ public function getFingerprint(): string
 
     /**
      * {@inheritdoc}
-     *
-     * @codeCoverageIgnore
      */
     public function jsonSerialize()
     {
diff --git a/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php b/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
index 4f8589c05..d0c2aef36 100644
--- a/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
+++ b/src/Viserio/Component/Session/Tests/Fingerprint/ClientIpGeneratorTest.php
@@ -13,6 +13,21 @@ public function testGenerate()
         $request = $this->mock(ServerRequestInterface::class);
         $request->shouldReceive('getServerParams')
             ->andReturn(['REMOTE_ADDR' => '127.0.0.1']);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('Client-Ip')
+            ->andReturn(false);
 
         $generator = new ClientIpGenerator($request);
 
diff --git a/src/Viserio/Component/Support/Http/ClientIp.php b/src/Viserio/Component/Support/Http/ClientIp.php
index da111712d..2d484d7ee 100644
--- a/src/Viserio/Component/Support/Http/ClientIp.php
+++ b/src/Viserio/Component/Support/Http/ClientIp.php
@@ -39,28 +39,31 @@ public function __construct(ServerRequestInterface $serverRequest)
     /**
      * Returns client IP address.
      *
-     * @return string
+     * @return string|null
      */
-    public function getIpAddress(): string
+    public function getIpAddress(): ?string
     {
-        $serverParams = $this->serverRequest->getServerParams();
+        $ipAddress    = null;
+        $request      = $this->serverRequest;
+        $serverParams = $request->getServerParams();
 
         // direct IP address
         if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
-            return $serverParams['REMOTE_ADDR'];
+            $ipAddress = $serverParams['REMOTE_ADDR'];
         }
 
         foreach ($this->headersToInspect as $header) {
-            if ($this->serverRequest->hasHeader($header)) {
+            if ($request->hasHeader($header)) {
                 $ip = $this->getFirstIpAddressFromHeader($request, $header);
 
                 if ($this->isValidIpAddress($ip)) {
-                    return $ip;
+                    $ipAddress = $ip;
+                    break;
                 }
             }
         }
 
-        return '';
+        return $ipAddress;
     }
 
     /**
@@ -89,7 +92,7 @@ private function isValidIpAddress(string $ip): bool
      */
     private function getFirstIpAddressFromHeader(ServerRequestInterface $serverRequest, string $header): string
     {
-        $items       = explode(',', $request->getHeaderLine($header));
+        $items       = explode(',', $serverRequest->getHeaderLine($header));
         $headerValue = trim(reset($items));
 
         if (ucfirst($header) == 'Forwarded') {
diff --git a/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php b/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php
index 256f57b2b..f58484b33 100644
--- a/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php
+++ b/src/Viserio/Component/Support/Tests/Http/ClientIpTest.php
@@ -8,36 +8,237 @@
 
 class ClientIpTest extends MockeryTestCase
 {
-    public function testGetIpAddress()
+    public function testGetIpAddressByRemoteAddr()
     {
         $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => '192.168.1.1']);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
         $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
+            ->with('Client-Ip')
+            ->andReturn(false);
+
+        $clientIp = new ClientIp($request);
+
+        static::assertSame('192.168.1.1', $clientIp->getIpAddress());
+    }
+
+    public function testGetIpIsNullIfMissing()
+    {
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn([]);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('Client-Ip')
+            ->andReturn(false);
+
+        $clientIp = new ClientIp($request);
+
+        static::assertNull($clientIp->getIpAddress());
+    }
+
+    public function testGetIpByXForwardedFor()
+    {
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
             ->once()
+            ->andReturn(['REMOTE_ADDR' => '192.168.1.1']);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
             ->andReturn(true);
-        $request->shouldReceive('getHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
-            ->andReturn('111.111.111.111,123.45.67.178');
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('getHeaderLine')
+            ->with('X-Forwarded-For')
+            ->andReturn('192.168.1.3, 192.168.1.2, 192.168.1.1');
 
         $clientIp = new ClientIp($request);
 
-        static::assertSame('111.111.111.111', $clientIp->getIpAddress());
+        static::assertSame('192.168.1.3', $clientIp->getIpAddress());
+    }
 
+    public function testGetIpByHttpClientIp()
+    {
         $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => '192.168.1.1']);
         $request->shouldReceive('hasHeader')
-            ->with('HTTP_X_FORWARDED_FOR')
+            ->with('Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('Client-Ip')
+            ->andReturn(true);
+        $request->shouldReceive('getHeaderLine')
+            ->with('Client-Ip')
+            ->andReturn('192.168.1.3');
+
+        $clientIp = new ClientIp($request);
+
+        static::assertSame('192.168.1.3', $clientIp->getIpAddress());
+    }
+
+    public function testGetIpByXForwardedForIpV6()
+    {
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
             ->once()
+            ->andReturn(['REMOTE_ADDR' => '192.168.1.1']);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(true);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
             ->andReturn(false);
         $request->shouldReceive('hasHeader')
-            ->with('REMOTE_ADDR')
+            ->with('Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('getHeaderLine')
+            ->with('X-Forwarded-For')
+            ->andReturn('001:DB8::21f:5bff:febf:ce22:8a2e');
+
+        $clientIp = new ClientIp($request);
+
+        static::assertSame('001:DB8::21f:5bff:febf:ce22:8a2e', $clientIp->getIpAddress());
+    }
+
+    public function testGetIpByForwardedWithMultipleFor()
+    {
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
             ->once()
+            ->andReturn(['REMOTE_ADDR' => '192.168.1.1']);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
             ->andReturn(true);
-        $request->shouldReceive('getHeader')
-            ->with('REMOTE_ADDR')
-            ->andReturn('100.8.116.127');
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('getHeaderLine')
+            ->with('Forwarded')
+            ->andReturn('for=192.0.2.43, for=198.51.100.17;by=203.0.113.60;proto=http;host=example.com');
+
+        $clientIp = new ClientIp($request);
+
+        static::assertSame('192.0.2.43', $clientIp->getIpAddress());
+    }
+
+    public function testGetIpByForwardedhWithIpV6()
+    {
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => '192.168.1.1']);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
+            ->andReturn(true);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('getHeaderLine')
+            ->with('Forwarded')
+            ->andReturn('For="[2001:db8:cafe::17]:4711", for=_internalProxy');
+
+        $clientIp = new ClientIp($request);
+
+        static::assertSame('2001:db8:cafe::17', $clientIp->getIpAddress());
+    }
+
+    public function testGetIpByXForwardedForWithInvalidIp()
+    {
+        $request = $this->mock(ServerRequestInterface::class);
+        $request->shouldReceive('getServerParams')
+            ->once()
+            ->andReturn(['REMOTE_ADDR' => '192.168.1.1']);
+        $request->shouldReceive('hasHeader')
+            ->with('Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded-For')
+            ->andReturn(true);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Forwarded')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('X-Cluster-Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('hasHeader')
+            ->with('Client-Ip')
+            ->andReturn(false);
+        $request->shouldReceive('getHeaderLine')
+            ->with('X-Forwarded-For')
+            ->andReturn('For');
 
         $clientIp = new ClientIp($request);
 
-        static::assertSame('100.8.116.127', $clientIp->getIpAddress());
+        static::assertSame('192.168.1.1', $clientIp->getIpAddress());
     }
 }
diff --git a/src/Viserio/Component/WebProfiler/Profile.php b/src/Viserio/Component/WebProfiler/Profile.php
index a67247970..6d5d0db9d 100644
--- a/src/Viserio/Component/WebProfiler/Profile.php
+++ b/src/Viserio/Component/WebProfiler/Profile.php
@@ -290,7 +290,7 @@ public function getCollectors(): array
     public function setCollectors(array $collectors): void
     {
         foreach ($collectors as $collector) {
-            $this->addCollector($collector['collector']);
+            $this->addCollector($collector);
         }
     }
 

From 75846190fb8403d1be6a03b78f85a351af868108 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 22:28:11 +0200
Subject: [PATCH 63/99] and more work

---
 .../Session/Fingerprint/ClientIpGenerator.php |  2 +-
 .../Handler/CacheBasedSessionHandler.php      | 76 -------------------
 .../Session/Handler/CookieSessionHandler.php  |  8 +-
 .../Middleware/StartSessionMiddleware.php     |  6 +-
 .../Middleware/VerifyCsrfTokenMiddleware.php  | 25 +++---
 .../Component/Session/SessionManager.php      | 12 +--
 .../Handler/CacheBasedSessionHandlerTest.php  | 46 -----------
 .../Middleware/StartSessionMiddlewareTest.php |  9 +--
 .../Component/Session/Tests/StoreTest.php     | 68 +++++++++++++++++
 9 files changed, 96 insertions(+), 156 deletions(-)
 delete mode 100644 src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php
 delete mode 100644 src/Viserio/Component/Session/Tests/Handler/CacheBasedSessionHandlerTest.php

diff --git a/src/Viserio/Component/Session/Fingerprint/ClientIpGenerator.php b/src/Viserio/Component/Session/Fingerprint/ClientIpGenerator.php
index 2c0e530d1..6d39fee86 100644
--- a/src/Viserio/Component/Session/Fingerprint/ClientIpGenerator.php
+++ b/src/Viserio/Component/Session/Fingerprint/ClientIpGenerator.php
@@ -30,6 +30,6 @@ public function __construct(ServerRequestInterface $serverRequest)
      */
     public function generate(): string
     {
-        return hash('ripemd160', $this->clientIp);
+        return hash('ripemd160', $this->clientIp ?? '');
     }
 }
diff --git a/src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php b/src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php
deleted file mode 100644
index 06d0ed062..000000000
--- a/src/Viserio/Component/Session/Handler/CacheBasedSessionHandler.php
+++ /dev/null
@@ -1,76 +0,0 @@
-psr6cache = new Psr6SessionHandler($cache, ['ttl' => $lifetime, 'prefix' => 'ns_ses_']);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function open($savePath, $sessionName)
-    {
-        return true;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function close()
-    {
-        return true;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function read($sessionId)
-    {
-        return $this->psr6cache->read($sessionId);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function write($sessionId, $data)
-    {
-        $this->psr6cache->write($sessionId, $data);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function destroy($sessionId)
-    {
-        $this->psr6cache->destroy($sessionId);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function gc($lifetime)
-    {
-        return true;
-    }
-}
diff --git a/src/Viserio/Component/Session/Handler/CookieSessionHandler.php b/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
index 669f7f925..932ff6b9b 100644
--- a/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
+++ b/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
@@ -61,7 +61,7 @@ public function close()
     /**
      * {@inheritdoc}
      */
-    public function read($sessionId)
+    public function read($sessionId): string
     {
         $cookies = $this->request->getCookieParams();
 
@@ -81,7 +81,7 @@ public function read($sessionId)
     /**
      * {@inheritdoc}
      */
-    public function write($sessionId, $data)
+    public function write($sessionId, $data): bool
     {
         $this->cookie->queue(
             $sessionId,
@@ -101,7 +101,7 @@ public function write($sessionId, $data)
     /**
      * {@inheritdoc}
      */
-    public function destroy($sessionId)
+    public function destroy($sessionId): bool
     {
         $this->cookie->queue($this->cookie->delete($sessionId));
 
@@ -111,7 +111,7 @@ public function destroy($sessionId)
     /**
      * {@inheritdoc}
      */
-    public function gc($lifetime)
+    public function gc($lifetime): bool
     {
         return true;
     }
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index d846723f1..3472832b9 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -203,9 +203,9 @@ protected function addCookieToResponse(ServerRequestInterface $request, Response
     protected function getSessionLifetimeInSeconds(): int
     {
         // Default 1 day
-        $lifetime = $this->config['lifetime'] ?? 1440;
+        $lifetime = $this->config['lifetime'] ?? 86400;
 
-        return Chronos::now()->subMinutes($lifetime)->getTimestamp();
+        return Chronos::now()->subSeconds($lifetime)->getTimestamp();
     }
 
     /**
@@ -219,7 +219,7 @@ protected function getCookieExpirationDate(array $config)
     {
         return ($config['expire_on_close'] ?? false) ?
             0 :
-            Chronos::now()->addMinutes($config['lifetime']);
+            Chronos::now()->addSeconds($config['lifetime']);
     }
 
     /**
diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index e4f2ad8e1..acfe7a250 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -34,23 +34,14 @@ class VerifyCsrfTokenMiddleware implements MiddlewareInterface
      */
     protected $config = [];
 
-    /**
-     * Environment.
-     *
-     * @var string
-     */
-    protected $env;
-
     /**
      * Create a new session middleware.
      *
      * @param \Viserio\Component\Session\SessionManager $manager
-     * @param string                                    $env
      */
-    public function __construct(SessionManager $manager, string $env = 'production')
+    public function __construct(SessionManager $manager)
     {
         $this->manager      = $manager;
-        $this->env          = $env;
         $this->driverConfig = $manager->getDriverConfig($manager->getDefaultDriver());
         $this->config       = $manager->getConfig();
     }
@@ -79,7 +70,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
      */
     protected function runningUnitTests(): bool
     {
-        return php_sapi_name() == 'cli' && $this->env === 'testing';
+        return php_sapi_name() == 'cli' && ($this->config['env'] ?? 'production') === 'testing';
     }
 
     /**
@@ -91,8 +82,9 @@ protected function runningUnitTests(): bool
      */
     protected function tokensMatch(ServerRequestInterface $request): bool
     {
-        $sessionToken = $request->getAttribute('session')->getToken();
-        $data         = $request->getParsedBody();
+        $session      = $request->getAttribute('session');
+        $sessionToken = $session ?? $session->getToken();
+        $data         = is_array($request->getParsedBody());
         $token        = $data['_token'] ?? $request->getHeaderLine('X-CSRF-TOKEN');
 
         if (! $token && $header = $request->getHeaderLine('X-XSRF-TOKEN')) {
@@ -118,12 +110,13 @@ protected function addCookieToResponse(
         ServerRequestInterface $request,
         ResponseInterface $response
     ): ResponseInterface {
-        $config = $this->config;
-        $uri    = $request->getUri();
+        $config  = $this->config;
+        $uri     = $request->getUri();
+        $session = $request->getAttribute('session');
 
         $setCookie = new SetCookie(
             'XSRF-TOKEN',
-            $request->getAttribute('session')->getToken(),
+            $session ?? $session->getToken(),
             $config['csrf.livetime'] ?? Chronos::now()->getTimestamp() + 60 * 120,
             $config['path'],
             $config['domain'] ?? $uri->getHost(),
diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index 4fc95df94..f07deb2f0 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -4,6 +4,7 @@
 
 use Interop\Container\ContainerInterface as ContainerInteropInterface;
 use SessionHandlerInterface;
+use Cache\SessionHandler\Psr6SessionHandler;
 use Viserio\Component\Contracts\Cache\Manager as CacheManagerContract;
 use Viserio\Component\Contracts\Cookie\QueueingFactory as JarContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
@@ -40,9 +41,10 @@ public function __construct(ContainerInteropInterface $container)
     public function getDefaultOptions(): iterable
     {
         return [
-            'default'  => 'array',
-            'cookie'   => 'NSSESSID',
-            'lifetime' => 86400,
+            'default'         => 'array',
+            'cookie'          => 'NSSESSID',
+            'lifetime'        => 86400,
+            'expire_on_close' => false,
         ];
     }
 
@@ -205,9 +207,9 @@ protected function callCustomCreator(string $driver, array $options = [])
     protected function createCacheBased($driver): StoreContract
     {
         return $this->buildSession(
-            new CacheBasedSessionHandler(
+            new Psr6SessionHandler(
                 clone $this->container->get(CacheManagerContract::class)->getDriver($driver),
-                $this->options['lifetime']
+                ['ttl' => $this->options['lifetime'], 'prefix' => 'ns_ses_']
             )
         );
     }
diff --git a/src/Viserio/Component/Session/Tests/Handler/CacheBasedSessionHandlerTest.php b/src/Viserio/Component/Session/Tests/Handler/CacheBasedSessionHandlerTest.php
deleted file mode 100644
index de2187d4e..000000000
--- a/src/Viserio/Component/Session/Tests/Handler/CacheBasedSessionHandlerTest.php
+++ /dev/null
@@ -1,46 +0,0 @@
-handler = new CacheBasedSessionHandler(
-            $this->mock(CacheItemPoolInterface::class),
-            5
-        );
-    }
-
-    public function testOpenReturnsTrue()
-    {
-        $handler = $this->handler;
-
-        self::assertTrue($handler->open('test', 'temp'));
-    }
-
-    public function testCloseReturnsTrue()
-    {
-        $handler = $this->handler;
-
-        self::assertTrue($handler->close());
-    }
-
-    public function testGcSuccessfullyReturnsTrue()
-    {
-        $handler = $this->handler;
-
-        self::assertTrue($handler->gc(2));
-    }
-}
diff --git a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
index dd4979fd6..a7ad780fc 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
@@ -74,7 +74,6 @@ public function testAddSessionToResponse()
             new ArrayContainer([
                 RepositoryContract::class => $config,
                 FilesystemContract::class => $this->files,
-                JarContract::class        => $this->mock(JarContract::class),
                 EncrypterContract::class  => new Encrypter(Key::createNewRandomKey()->saveToAsciiSafeString()),
             ])
         );
@@ -85,9 +84,9 @@ public function testAddSessionToResponse()
         $server['SERVER_ADDR'] = '127.0.0.1';
         unset($server['PHP_SELF']);
 
-        $request    = (new ServerRequestFactory())->createServerRequestFromArray($server);
-
+        $request  = (new ServerRequestFactory())->createServerRequestFromArray($server);
         $response = $middleware->process($request, new DelegateMiddleware(function ($request) {
+
             return (new ResponseFactory())->createResponse(200);
         }));
 
@@ -139,9 +138,9 @@ public function testAddSessionToCookie()
         $server['SERVER_ADDR'] = '127.0.0.1';
         unset($server['PHP_SELF']);
 
-        $request    = (new ServerRequestFactory())->createServerRequestFromArray($server);
+        $request  = (new ServerRequestFactory())->createServerRequestFromArray($server);
 
-        $response = $middleware->process($request, new DelegateMiddleware(function ($request) {
+        $middleware->process($request, new DelegateMiddleware(function ($request) {
             self::assertInstanceOf(StoreContract::class, $request->getAttribute('session'));
 
             return (new ResponseFactory())->createResponse(200);
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index 906d74e48..c9511af17 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -78,6 +78,7 @@ public function testSessionIsLoadedFromHandler()
             ->once()
             ->andReturn($encryptString);
         $session->setId(self::SESSION_ID);
+
         $session->open();
 
         self::assertEquals('bar', $session->get('foo'));
@@ -93,6 +94,62 @@ public function testSessionIsLoadedFromHandler()
         self::assertFalse($session->isStarted());
     }
 
+    public function testSaveDontSaveIfSessionIsNotStarted()
+    {
+        $session = $this->session;
+
+        self::assertFalse($session->isStarted());
+
+        // save dont work if no session is started.
+        $session->save();
+
+        $session->getHandler()
+            ->shouldReceive('write')
+            ->never();
+    }
+
+    /**
+     * @expectedException \Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException
+     */
+    public function testSessionHasSuspiciousFingerPrint()
+    {
+        $session       = $this->session;
+        $encryptString = $this->encrypter->encrypt(
+            json_encode(
+                [
+                    'foo'          => 'bar',
+                    'bagged'       => ['name' => 'viserio'],
+                    '__metadata__' => [
+                        'firstTrace'        => 0,
+                        'lastTrace'         => 0,
+                        'regenerationTrace' => 0,
+                        'requestsCount'     => 0,
+                        'fingerprint'       => 'foo',
+                    ],
+                ],
+                \JSON_PRESERVE_ZERO_FRACTION
+            )
+        );
+        $session->getHandler()
+            ->shouldReceive('read')
+            ->once()
+            ->andReturn($encryptString);
+        $session->setId(self::SESSION_ID);
+        $session->open();
+    }
+
+    public function testSessionReturnsFalseOnFirstTraceNull()
+    {
+        $session       = $this->session;
+        $session->getHandler()
+            ->shouldReceive('read')
+            ->once()
+            ->andReturn([]);
+        $session->setId(self::SESSION_ID);
+
+        self::assertFalse($session->open());
+    }
+
     public function testName()
     {
         $session = $this->session;
@@ -183,6 +240,9 @@ public function testSetAndGetPreviousUrl()
     public function testStartMethodResetsLastTraceAndFirstTrace()
     {
         $session = $this->encryptedSession();
+
+        self::assertTrue($session->isExpired());
+
         $session->open();
 
         $lastTrace  = $session->getLastTrace();
@@ -190,6 +250,7 @@ public function testStartMethodResetsLastTraceAndFirstTrace()
 
         $session->start();
 
+        self::assertFalse($session->isExpired());
         self::assertNotEquals($lastTrace, $session->getLastTrace());
         self::assertNotEquals($firstTrace, $session->getFirstTrace());
     }
@@ -413,6 +474,13 @@ public function testReflashWithNow()
         self::assertFalse(array_search('foo', $session->get('_flash.old')));
     }
 
+    public function testIfSessionCanBeJsonSerialized()
+    {
+        $session = $this->session;
+
+        self::assertSame([], $session->jsonSerialize());
+    }
+
     private function encryptedSession()
     {
         $session = $this->session;

From 805fe127479e0cdc6a7fd5e66a132bf3e9177ec6 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 20:28:22 +0000
Subject: [PATCH 64/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Session/SessionManager.php               | 3 +--
 .../Session/Tests/Middleware/StartSessionMiddlewareTest.php    | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index f07deb2f0..5903b499c 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -2,9 +2,9 @@
 declare(strict_types=1);
 namespace Viserio\Component\Session;
 
+use Cache\SessionHandler\Psr6SessionHandler;
 use Interop\Container\ContainerInterface as ContainerInteropInterface;
 use SessionHandlerInterface;
-use Cache\SessionHandler\Psr6SessionHandler;
 use Viserio\Component\Contracts\Cache\Manager as CacheManagerContract;
 use Viserio\Component\Contracts\Cookie\QueueingFactory as JarContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
@@ -12,7 +12,6 @@
 use Viserio\Component\Contracts\Filesystem\Filesystem as FilesystemContract;
 use Viserio\Component\Contracts\OptionsResolver\ProvidesDefaultOptions as ProvidesDefaultOptionsContract;
 use Viserio\Component\Contracts\Session\Store as StoreContract;
-use Viserio\Component\Session\Handler\CacheBasedSessionHandler;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Session\Handler\FileSessionHandler;
 use Viserio\Component\Support\AbstractManager;
diff --git a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
index a7ad780fc..3d772ebf7 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
@@ -86,7 +86,6 @@ public function testAddSessionToResponse()
 
         $request  = (new ServerRequestFactory())->createServerRequestFromArray($server);
         $response = $middleware->process($request, new DelegateMiddleware(function ($request) {
-
             return (new ResponseFactory())->createResponse(200);
         }));
 

From fa571a58e0851134df8fc1ba6b6af87bc2a30453 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 22:31:07 +0200
Subject: [PATCH 65/99] fix composer

---
 composer.json                             | 2 +-
 src/Viserio/Component/Cache/composer.json | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/composer.json b/composer.json
index 35bfbf75f..769d4e2ac 100644
--- a/composer.json
+++ b/composer.json
@@ -33,7 +33,7 @@
         "ext-fileinfo"                                       : "*",
         "ext-openssl"                                        : "*",
         "cache/array-adapter"                                : "^0.4",
-        "cache/void-adapter"                                 : "^0.4",
+        "cache/void-adapter"                                 : "^0.3",
         "cakephp/chronos"                                    : "^1.0",
         "container-interop/container-interop"                : "^1.1",
         "container-interop/service-provider"                 : "^0.3",
diff --git a/src/Viserio/Component/Cache/composer.json b/src/Viserio/Component/Cache/composer.json
index af596e8e5..cc4bbc6bf 100644
--- a/src/Viserio/Component/Cache/composer.json
+++ b/src/Viserio/Component/Cache/composer.json
@@ -40,7 +40,7 @@
     "require": {
         "php"                                 : "^7.1",
         "cache/array-adapter"                 : "^0.4",
-        "cache/void-adapter"                  : "^0.4",
+        "cache/void-adapter"                  : "^0.3",
         "container-interop/container-interop" : "^1.1",
         "viserio/cotracts"                    : "self.version",
         "viserio/options-resolver"            : "self.version",

From b6890ab6117be112bcc9e9af64b02d3f3684b5f6 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 23:00:54 +0200
Subject: [PATCH 66/99] some sessions changes

---
 .../Session/Handler/CookieSessionHandler.php       |  6 +++---
 .../Session/Handler/FileSessionHandler.php         | 10 +++++-----
 .../Session/Middleware/StartSessionMiddleware.php  |  2 +-
 .../Middleware/VerifyCsrfTokenMiddleware.php       | 14 ++++++++------
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/Viserio/Component/Session/Handler/CookieSessionHandler.php b/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
index 932ff6b9b..698f2ac9f 100644
--- a/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
+++ b/src/Viserio/Component/Session/Handler/CookieSessionHandler.php
@@ -24,7 +24,7 @@ class CookieSessionHandler implements SessionHandlerInterface
     protected $request;
 
     /**
-     * The number of minutes the session should be valid.
+     * The number of seconds the session should be valid.
      *
      * @var int
      */
@@ -34,7 +34,7 @@ class CookieSessionHandler implements SessionHandlerInterface
      * Create a new cookie driven handler instance.
      *
      * @param \Viserio\Component\Contracts\Cookie\QueueingFactory $cookie
-     * @param int                                                 $lifetime
+     * @param int                                                 $lifetime The session lifetime in seconds
      */
     public function __construct(JarContract $cookie, int $lifetime)
     {
@@ -88,7 +88,7 @@ public function write($sessionId, $data): bool
             json_encode(
                 [
                     'data'    => $data,
-                    'expires' => Chronos::now()->addMinutes($this->lifetime)->getTimestamp(),
+                    'expires' => Chronos::now()->addSeconds($this->lifetime)->getTimestamp(),
                 ],
                 \JSON_PRESERVE_ZERO_FRACTION
             ),
diff --git a/src/Viserio/Component/Session/Handler/FileSessionHandler.php b/src/Viserio/Component/Session/Handler/FileSessionHandler.php
index fbea2d7c1..ac942edd7 100644
--- a/src/Viserio/Component/Session/Handler/FileSessionHandler.php
+++ b/src/Viserio/Component/Session/Handler/FileSessionHandler.php
@@ -24,7 +24,7 @@ class FileSessionHandler implements SessionHandlerInterface
     protected $path;
 
     /**
-     * The number of minutes the session should be valid.
+     * The number of seconds the session should be valid.
      *
      * @var int
      */
@@ -35,7 +35,7 @@ class FileSessionHandler implements SessionHandlerInterface
      *
      * @param \Viserio\Component\Contracts\Filesystem\Filesystem $files
      * @param string                                             $path
-     * @param int                                                $lifetime The session lifetime in minutes
+     * @param int                                                $lifetime The session lifetime in seconds
      */
     public function __construct(FilesystemContract $files, string $path, int $lifetime)
     {
@@ -68,9 +68,9 @@ public function read($sessionId): string
         $path = $this->path . '/' . $sessionId;
 
         if ($this->files->has($path)) {
-            if (strtotime($this->files->getTimestamp($path)) >=
-                Chronos::now()->subMinutes($this->lifetime)->getTimestamp()
-            ) {
+            $chronos = Chronos::now()->subSeconds($this->lifetime);
+
+            if (strtotime($this->files->getTimestamp($path)) >= $chronos->getTimestamp()) {
                 return (string) $this->files->read($path);
             }
         }
diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 342581199..b50e2b981 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -174,7 +174,7 @@ protected function collectGarbage(StoreContract $session)
      */
     protected function addCookieToResponse(ServerRequestInterface $request, ResponseInterface $response, StoreContract $session): ResponseInterface
     {
-        if ($session->getHandler() instanceof CookieSessionHandler) {
+        if (! $session->getHandler() instanceof CookieSessionHandler) {
             $session->save();
         }
 
diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index acfe7a250..b5c892ea7 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -10,6 +10,7 @@
 use Viserio\Component\Contracts\Session\Exceptions\TokenMismatchException;
 use Viserio\Component\Cookie\SetCookie;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Contracts\Session\Exceptions\SessionNotStartedException;
 
 class VerifyCsrfTokenMiddleware implements MiddlewareInterface
 {
@@ -51,6 +52,10 @@ public function __construct(SessionManager $manager)
      */
     public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface
     {
+        if ($request->getAttribute('session') === null) {
+            throw new SessionNotStartedException('The session is not started.');
+        }
+
         $response = $delegate->process($request);
 
         if ($this->isReading($request) ||
@@ -82,10 +87,8 @@ protected function runningUnitTests(): bool
      */
     protected function tokensMatch(ServerRequestInterface $request): bool
     {
-        $session      = $request->getAttribute('session');
-        $sessionToken = $session ?? $session->getToken();
-        $data         = is_array($request->getParsedBody());
-        $token        = $data['_token'] ?? $request->getHeaderLine('X-CSRF-TOKEN');
+        $sessionToken = $request->getAttribute('session')->getToken();
+        $token        = $request->getHeaderLine('X-CSRF-TOKEN');
 
         if (! $token && $header = $request->getHeaderLine('X-XSRF-TOKEN')) {
             $token = $this->manager->getEncrypter()->decrypt($header);
@@ -112,11 +115,10 @@ protected function addCookieToResponse(
     ): ResponseInterface {
         $config  = $this->config;
         $uri     = $request->getUri();
-        $session = $request->getAttribute('session');
 
         $setCookie = new SetCookie(
             'XSRF-TOKEN',
-            $session ?? $session->getToken(),
+            $request->getAttribute('session')->getToken(),
             $config['csrf.livetime'] ?? Chronos::now()->getTimestamp() + 60 * 120,
             $config['path'],
             $config['domain'] ?? $uri->getHost(),

From b808c4ac3c64d3a7a387f0c3c5716a582a459892 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 21:01:55 +0000
Subject: [PATCH 67/99] Apply fixes from StyleCI

some sessions changes

Apply fixes from StyleCI

fix first tests

fix cookie handling

working on session (#540)

Refactor some old session code

check if session is open and use http_only with true as default
---
 .../Middleware/StartSessionMiddleware.php     |  6 ++----
 .../Middleware/VerifyCsrfTokenMiddleware.php  |  7 ++++---
 .../Providers/SessionServiceProvider.php      |  2 +-
 .../Handler/CookieSessionHandlerTest.php      | 12 +++++------
 .../Tests/Handler/FileSessionHandlerTest.php  |  6 +++---
 .../VerifyCsrfTokenMiddlewareTest.php         | 20 +++++++++----------
 6 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index b50e2b981..40bd6d348 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -116,9 +116,7 @@ protected function startSession(ServerRequestInterface $request): StoreContract
             $session->setRequestOnHandler($request);
         }
 
-        if ($hasCookie) {
-            $session->open();
-        } else {
+        if (! $session->open()) {
             $session->start();
         }
 
@@ -174,7 +172,7 @@ protected function collectGarbage(StoreContract $session)
      */
     protected function addCookieToResponse(ServerRequestInterface $request, ResponseInterface $response, StoreContract $session): ResponseInterface
     {
-        if (! $session->getHandler() instanceof CookieSessionHandler) {
+        if ($session->getHandler() instanceof CookieSessionHandler) {
             $session->save();
         }
 
diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index b5c892ea7..824201a4e 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -7,10 +7,11 @@
 use Interop\Http\ServerMiddleware\MiddlewareInterface;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
+use Viserio\Component\Contracts\Session\Exceptions\SessionNotStartedException;
 use Viserio\Component\Contracts\Session\Exceptions\TokenMismatchException;
+use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Cookie\SetCookie;
 use Viserio\Component\Session\SessionManager;
-use Viserio\Component\Contracts\Session\Exceptions\SessionNotStartedException;
 
 class VerifyCsrfTokenMiddleware implements MiddlewareInterface
 {
@@ -52,7 +53,7 @@ public function __construct(SessionManager $manager)
      */
     public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface
     {
-        if ($request->getAttribute('session') === null) {
+        if (! $request->getAttribute('session') instanceof StoreContract) {
             throw new SessionNotStartedException('The session is not started.');
         }
 
@@ -88,7 +89,7 @@ protected function runningUnitTests(): bool
     protected function tokensMatch(ServerRequestInterface $request): bool
     {
         $sessionToken = $request->getAttribute('session')->getToken();
-        $token        = $request->getHeaderLine('X-CSRF-TOKEN');
+        $token        = $request->getAttribute('_token') ?? $request->getHeaderLine('X-CSRF-TOKEN');
 
         if (! $token && $header = $request->getHeaderLine('X-XSRF-TOKEN')) {
             $token = $this->manager->getEncrypter()->decrypt($header);
diff --git a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
index 17f38a3d7..d06440015 100644
--- a/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
+++ b/src/Viserio/Component/Session/Providers/SessionServiceProvider.php
@@ -44,7 +44,7 @@ public static function extendEventManager(ContainerInterface $container, ?callab
             $eventManager->attach(TerminableContract::TERMINATE, function (EventContract $event) {
                 $driver = $event->getTarget()->getContainer()->get(SessionManager::class)->getDriver();
 
-                if ($driver->getHandler() instanceof CookieSessionHandler) {
+                if (! $driver->getHandler() instanceof CookieSessionHandler) {
                     $driver->save();
                 }
             });
diff --git a/src/Viserio/Component/Session/Tests/Handler/CookieSessionHandlerTest.php b/src/Viserio/Component/Session/Tests/Handler/CookieSessionHandlerTest.php
index 6a97ec30f..9b23814f7 100644
--- a/src/Viserio/Component/Session/Tests/Handler/CookieSessionHandlerTest.php
+++ b/src/Viserio/Component/Session/Tests/Handler/CookieSessionHandlerTest.php
@@ -21,7 +21,7 @@ public function setUp()
 
         $this->handler = new CookieSessionHandler(
             $this->mock(JarContract::class),
-            5
+            300
         );
     }
 
@@ -47,7 +47,7 @@ public function testReadExistingSessionReturnsTheData()
             ->once()
             ->andReturn('{
                 "temp": {
-                    "expires": "' . Chronos::now()->addMinutes(6)->getTimestamp() . '",
+                    "expires": "' . Chronos::now()->addSeconds(350)->getTimestamp() . '",
                     "data": "Foo Bar"
                 }
             }');
@@ -80,15 +80,15 @@ public function testWriteSuccessfullyReturnsTrue()
                 json_encode(
                     [
                         'data'    => ['user_id' => 1],
-                        'expires' => Chronos::now()->addMinutes(5)->getTimestamp(),
+                        'expires' => Chronos::now()->addSeconds(300)->getTimestamp(),
                     ],
                     \JSON_PRESERVE_ZERO_FRACTION
                 ),
-                5
+                300
             );
         $handler = new CookieSessionHandler(
             $jar,
-            5
+            300
         );
 
         self::assertTrue($handler->write('write.sess', ['user_id' => 1]));
@@ -115,7 +115,7 @@ public function testDestroySuccessfullReturnsTrue()
 
         $handler = new CookieSessionHandler(
             $jar,
-            5
+            300
         );
 
         self::assertTrue($handler->destroy('cookie.sess'));
diff --git a/src/Viserio/Component/Session/Tests/Handler/FileSessionHandlerTest.php b/src/Viserio/Component/Session/Tests/Handler/FileSessionHandlerTest.php
index cad5855d6..6cc76c7d4 100644
--- a/src/Viserio/Component/Session/Tests/Handler/FileSessionHandlerTest.php
+++ b/src/Viserio/Component/Session/Tests/Handler/FileSessionHandlerTest.php
@@ -31,7 +31,7 @@ public function setUp()
         $this->handler = new FileSessionHandler(
             $this->files,
             $this->root->url(),
-            1
+            60
         );
 
         $this->files->createDirectory(__DIR__ . '/stubs');
@@ -81,7 +81,7 @@ public function testWriteSuccessfullyReturnsTrue()
         $handler = new FileSessionHandler(
             $this->files,
             __DIR__ . '/stubs',
-            2
+            120
         );
 
         self::assertTrue($handler->write('write.sess', json_encode(['user_id' => 1])));
@@ -96,7 +96,7 @@ public function testGcSuccessfullyReturnsTrue()
         $handler = new FileSessionHandler(
             $this->files,
             __DIR__ . '/stubs',
-            2
+            120
         );
         $handler->write('temp.sess', json_encode(['user_id' => 1]));
 
diff --git a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
index 6a1637520..3395adccd 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
@@ -68,16 +68,16 @@ public function testSessionCsrfMiddlewareSetCookie()
                         ],
                     ],
                     'cookie'          => 'session',
-                    'path'            => __DIR__ . '/stubs',
+                    'path'            => '/',
                     'expire_on_close' => false,
                     'lottery'         => [2, 100],
                     'lifetime'        => 1440,
-                    'domain'          => '/',
+                    'domain'          => 'test.com',
                     'http_only'       => false,
                     'secure'          => false,
                     'csrf'            => [
                         'samesite' => false,
-                        'livetime' => Chronos::now()->getTimestamp() + 60 * 120,
+                        'livetime' => Chronos::now()->getTimestamp() + 60 * 1200,
                     ],
                 ],
             ]);
@@ -94,7 +94,7 @@ public function testSessionCsrfMiddlewareSetCookie()
             [
                 new StartSessionMiddleware($manager),
                 new CallableMiddleware(function ($request, $delegate) {
-                    $request = $request->withParsedBody(['_token' => $request->getAttribute('session')->getToken()]);
+                    $request = $request->withAttribute('_token', $request->getAttribute('session')->getToken());
 
                     return $delegate->process($request);
                 }),
@@ -129,11 +129,11 @@ public function testSessionCsrfMiddlewareReadsXCSRFTOKEN()
                         ],
                     ],
                     'cookie'          => 'session',
-                    'path'            => __DIR__ . '/stubs',
+                    'path'            => '/',
                     'expire_on_close' => false,
                     'lottery'         => [2, 100],
                     'lifetime'        => 1440,
-                    'domain'          => '/',
+                    'domain'          => 'test.com',
                     'http_only'       => false,
                     'secure'          => false,
                     'csrf'            => [
@@ -190,11 +190,11 @@ public function testSessionCsrfMiddlewareReadsXXSRFTOKEN()
                         ],
                     ],
                     'cookie'          => 'session',
-                    'path'            => __DIR__ . '/stubs',
+                    'path'            => '/',
                     'expire_on_close' => false,
                     'lottery'         => [2, 100],
                     'lifetime'        => 1440,
-                    'domain'          => '/',
+                    'domain'          => 'test.com',
                     'http_only'       => false,
                     'secure'          => false,
                     'csrf'            => [
@@ -257,11 +257,11 @@ public function testSessionCsrfMiddlewareToThrowException()
                         ],
                     ],
                     'cookie'          => 'session',
-                    'path'            => __DIR__ . '/stubs',
+                    'path'            => '/',
                     'expire_on_close' => false,
                     'lottery'         => [2, 100],
                     'lifetime'        => 1440,
-                    'domain'          => '/',
+                    'domain'          => 'test.com',
                     'http_only'       => false,
                     'secure'          => false,
                     'csrf'            => [

From 644f351635b6da5bb4eb42aa6ac6af3dabd3bdc0 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 00:19:12 +0200
Subject: [PATCH 68/99] working on session can cookie tab

---
 .../ViserioHttpDataCollector.php              | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
index cc653e33d..2c9b42fd4 100644
--- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
+++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
@@ -7,6 +7,8 @@
 use Psr\Http\Message\ServerRequestInterface;
 use ReflectionFunction;
 use ReflectionMethod;
+use Viserio\Component\Cookie\ResponseCookies;
+use Viserio\Component\Cookie\RequestCookies;
 use Viserio\Component\Contracts\Config\Repository as RepositoryContract;
 use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract;
 use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract;
@@ -249,6 +251,40 @@ public function getAssets(): array
         ];
     }
 
+    protected function createCookieTab(ServerRequestInterface $serverRequest, ResponseInterface $response): ?array
+    {
+        if (! (class_exists(RequestCookies::class) && class_exists(ResponseCookies::class))) {
+            return null;
+        }
+
+        $requestCookies = $responseCookies = [];
+
+        foreach (RequestCookies::fromRequest($serverRequest)->getAll() as $cookie) {
+            $requestCookies[$cookie->getName()] = $cookie->getValue();
+        }
+
+        foreach (ResponseCookies::fromResponse($response)->getAll() as $cookie) {
+            $responseCookies[$cookie->getName()] = $cookie->getValue();
+        }
+
+        return [
+            'name'    => 'Cookies',
+            'content' => $this->createTable(
+                $requestCookies,
+                [
+                    'name'       => 'Request Cookies',
+                    'empty_text' => 'No request cookies',
+                ]
+            ) . $this->createTable(
+                $responseCookies,
+                [
+                    'name'       => 'Response Cookies',
+                    'empty_text' => 'No response cookies',
+                ]
+            ),
+        ];
+    }
+
     /**
      * Prepare request and response cookie infos and create a cookie tab.
      *

From 40a48620889d0c27d48c466622c3d59ec11929ae Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Wed, 17 May 2017 22:19:29 +0000
Subject: [PATCH 69/99] Apply fixes from StyleCI

	modified:   src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
---
 .../Foundation/DataCollectors/ViserioHttpDataCollector.php      | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
index 2c9b42fd4..563e8d17b 100644
--- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
+++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
@@ -7,8 +7,6 @@
 use Psr\Http\Message\ServerRequestInterface;
 use ReflectionFunction;
 use ReflectionMethod;
-use Viserio\Component\Cookie\ResponseCookies;
-use Viserio\Component\Cookie\RequestCookies;
 use Viserio\Component\Contracts\Config\Repository as RepositoryContract;
 use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract;
 use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract;

From 99f7127805e2cfa111c62b69b70de9033f30d2c6 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 19:05:26 +0000
Subject: [PATCH 70/99] Apply fixes from StyleCI


From 591a58e9e70c7fe71110b5a5c9e3358466ffc199 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:07:56 +0200
Subject: [PATCH 71/99] fixed some session bugs

	modified:   src/Viserio/Component/Session/Store.php
	modified:   src/Viserio/Component/Session/Tests/StoreTest.php
	modified:   src/Viserio/Component/Support/Http/ClientIp.php
---
 src/Viserio/Component/Session/Store.php       |  1 +
 .../Component/Session/Tests/StoreTest.php     |  1 +
 .../Component/Support/Http/ClientIp.php       | 23 ++++++++-----------
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 8348500ff..c77b05a37 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -13,6 +13,7 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
+use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index c9511af17..b19b75b59 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -12,6 +12,7 @@
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
+use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Support/Http/ClientIp.php b/src/Viserio/Component/Support/Http/ClientIp.php
index 2d484d7ee..bbf8b4999 100644
--- a/src/Viserio/Component/Support/Http/ClientIp.php
+++ b/src/Viserio/Component/Support/Http/ClientIp.php
@@ -39,31 +39,28 @@ public function __construct(ServerRequestInterface $serverRequest)
     /**
      * Returns client IP address.
      *
-     * @return string|null
+     * @return string
      */
-    public function getIpAddress(): ?string
+    public function getIpAddress(): string
     {
-        $ipAddress    = null;
-        $request      = $this->serverRequest;
-        $serverParams = $request->getServerParams();
+        $serverParams = $this->serverRequest->getServerParams();
 
         // direct IP address
         if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
-            $ipAddress = $serverParams['REMOTE_ADDR'];
+            return $serverParams['REMOTE_ADDR'];
         }
 
         foreach ($this->headersToInspect as $header) {
-            if ($request->hasHeader($header)) {
+            if ($this->serverRequest->hasHeader($header)) {
                 $ip = $this->getFirstIpAddressFromHeader($request, $header);
 
                 if ($this->isValidIpAddress($ip)) {
-                    $ipAddress = $ip;
-                    break;
+                    return $ip;
                 }
             }
         }
 
-        return $ipAddress;
+        return '';
     }
 
     /**
@@ -92,14 +89,14 @@ private function isValidIpAddress(string $ip): bool
      */
     private function getFirstIpAddressFromHeader(ServerRequestInterface $serverRequest, string $header): string
     {
-        $items       = explode(',', $serverRequest->getHeaderLine($header));
+        $items       = explode(',', $request->getHeaderLine($header));
         $headerValue = trim(reset($items));
 
         if (ucfirst($header) == 'Forwarded') {
             foreach (explode(';', $headerValue) as $headerPart) {
-                if (mb_strtolower(mb_substr($headerPart, 0, 4)) == 'for=') {
+                if (strtolower(substr($headerPart, 0, 4)) == 'for=') {
                     $for         = explode(']', $headerPart);
-                    $headerValue = trim(mb_substr(reset($for), 4), " \t\n\r\0\x0B" . '"[]');
+                    $headerValue = trim(substr(reset($for), 4), " \t\n\r\0\x0B" . "\"[]");
                     break;
                 }
             }

From c420073b19b25cfd8492d3f27504b1f8d1d7c1c9 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 22:08:49 +0000
Subject: [PATCH 72/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Session/Store.php           | 1 -
 src/Viserio/Component/Session/Tests/StoreTest.php | 1 -
 src/Viserio/Component/Support/Http/ClientIp.php   | 4 ++--
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index c77b05a37..8348500ff 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -13,7 +13,6 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
-use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index b19b75b59..c9511af17 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -12,7 +12,6 @@
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
-use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Support/Http/ClientIp.php b/src/Viserio/Component/Support/Http/ClientIp.php
index bbf8b4999..da111712d 100644
--- a/src/Viserio/Component/Support/Http/ClientIp.php
+++ b/src/Viserio/Component/Support/Http/ClientIp.php
@@ -94,9 +94,9 @@ private function getFirstIpAddressFromHeader(ServerRequestInterface $serverReque
 
         if (ucfirst($header) == 'Forwarded') {
             foreach (explode(';', $headerValue) as $headerPart) {
-                if (strtolower(substr($headerPart, 0, 4)) == 'for=') {
+                if (mb_strtolower(mb_substr($headerPart, 0, 4)) == 'for=') {
                     $for         = explode(']', $headerPart);
-                    $headerValue = trim(substr(reset($for), 4), " \t\n\r\0\x0B" . "\"[]");
+                    $headerValue = trim(mb_substr(reset($for), 4), " \t\n\r\0\x0B" . '"[]');
                     break;
                 }
             }

From 79c75e1de86395f4e284c8fb2fe311852d9fdd11 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:25:03 +0200
Subject: [PATCH 73/99] some changes on http panel

---
 .../DataCollectors/ViserioHttpDataCollector.php      | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
index 563e8d17b..49ade4371 100644
--- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
+++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php
@@ -249,10 +249,18 @@ public function getAssets(): array
         ];
     }
 
-    protected function createCookieTab(ServerRequestInterface $serverRequest, ResponseInterface $response): ?array
+    /**
+     * Prepare request and response cookie infos and create a cookie tab.
+     *
+     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest
+     * @param \Psr\Http\Message\ResponseInterface      $response
+     *
+     * @return array
+     */
+    protected function createCookieTab(ServerRequestInterface $serverRequest, ResponseInterface $response): array
     {
         if (! (class_exists(RequestCookies::class) && class_exists(ResponseCookies::class))) {
-            return null;
+            return [];
         }
 
         $requestCookies = $responseCookies = [];

From f0e4a6e48c8c58330395eaac2d5863bc46130a0d Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:25:21 +0200
Subject: [PATCH 74/99] cs fix


From d67bc03fa312163dd61ba5375c25a4741d821cc1 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Tue, 16 May 2017 23:38:41 +0200
Subject: [PATCH 75/99] working on session

	modified:   src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
	modified:   src/Viserio/Component/WebProfiler/Profile.php
---
 .../Session/Middleware/VerifyCsrfTokenMiddleware.php          | 4 ++--
 src/Viserio/Component/WebProfiler/Profile.php                 | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index 824201a4e..4e2e47ad1 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -114,8 +114,8 @@ protected function addCookieToResponse(
         ServerRequestInterface $request,
         ResponseInterface $response
     ): ResponseInterface {
-        $config  = $this->config;
-        $uri     = $request->getUri();
+        $config = $this->config;
+        $uri    = $request->getUri();
 
         $setCookie = new SetCookie(
             'XSRF-TOKEN',
diff --git a/src/Viserio/Component/WebProfiler/Profile.php b/src/Viserio/Component/WebProfiler/Profile.php
index 6d5d0db9d..a67247970 100644
--- a/src/Viserio/Component/WebProfiler/Profile.php
+++ b/src/Viserio/Component/WebProfiler/Profile.php
@@ -290,7 +290,7 @@ public function getCollectors(): array
     public function setCollectors(array $collectors): void
     {
         foreach ($collectors as $collector) {
-            $this->addCollector($collector);
+            $this->addCollector($collector['collector']);
         }
     }
 

From 05a9eb1aec4b963fdb1fc0f5c049b2b525942ec5 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Sat, 20 May 2017 02:34:13 +0200
Subject: [PATCH 76/99] fixed session bug


From 0537020876009993f8efb2335c3d0db56e99811d Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 19:05:17 +0000
Subject: [PATCH 77/99] Apply fixes from StyleCI


From 7514d7f2ec2b519acef191e7922c2738d93ccadc Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:08:34 +0200
Subject: [PATCH 78/99] fixed some session bugs

	modified:   src/Viserio/Component/Session/Store.php
	modified:   src/Viserio/Component/Session/Tests/StoreTest.php
---
 src/Viserio/Component/Session/Store.php           | 1 +
 src/Viserio/Component/Session/Tests/StoreTest.php | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index 8348500ff..c77b05a37 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -13,6 +13,7 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
+use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index c9511af17..b19b75b59 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -12,6 +12,7 @@
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
+use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {

From fc9a2cad87c14014f5a2643d07b197a53627eded Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Thu, 18 May 2017 22:08:43 +0000
Subject: [PATCH 79/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Session/Store.php           | 1 -
 src/Viserio/Component/Session/Tests/StoreTest.php | 1 -
 2 files changed, 2 deletions(-)

diff --git a/src/Viserio/Component/Session/Store.php b/src/Viserio/Component/Session/Store.php
index c77b05a37..8348500ff 100644
--- a/src/Viserio/Component/Session/Store.php
+++ b/src/Viserio/Component/Session/Store.php
@@ -13,7 +13,6 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Session\Handler\CookieSessionHandler;
 use Viserio\Component\Support\Str;
-use Viserio\Component\Contracts\Session\Exceptions\SuspiciousOperationException;
 
 class Store implements StoreContract
 {
diff --git a/src/Viserio/Component/Session/Tests/StoreTest.php b/src/Viserio/Component/Session/Tests/StoreTest.php
index b19b75b59..c9511af17 100644
--- a/src/Viserio/Component/Session/Tests/StoreTest.php
+++ b/src/Viserio/Component/Session/Tests/StoreTest.php
@@ -12,7 +12,6 @@
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\Fingerprint\UserAgentGenerator;
 use Viserio\Component\Session\Store;
-use Psr\Http\Message\ServerRequestInterface;
 
 class StoreTest extends MockeryTestCase
 {

From e19e95e81b342d553f6dd63293e787f71a056902 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 00:25:21 +0200
Subject: [PATCH 80/99] cs fix


From 5517c0ca54301212534b5eb54ec7f283c066619e Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 15:17:20 +0200
Subject: [PATCH 81/99] and more session work

	modified:   src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
	modified:   src/Viserio/Component/Session/Tests/SessionManagerTest.php
---
 .../Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php   | 1 +
 src/Viserio/Component/Session/Tests/SessionManagerTest.php       | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
index 3395adccd..37a5a3e5a 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
@@ -18,6 +18,7 @@
 use Viserio\Component\Session\Middleware\StartSessionMiddleware;
 use Viserio\Component\Session\Middleware\VerifyCsrfTokenMiddleware;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class VerifyCsrfTokenMiddlewareTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Session/Tests/SessionManagerTest.php b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
index daf15d2af..93e226d85 100644
--- a/src/Viserio/Component/Session/Tests/SessionManagerTest.php
+++ b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
@@ -14,6 +14,7 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class SessionManagerTest extends MockeryTestCase
 {

From 30b6f23a8807b743f7f3d1f9e00d2b4dbd74b153 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 13:17:33 +0000
Subject: [PATCH 82/99] Apply fixes from StyleCI

---
 .../Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php   | 1 -
 src/Viserio/Component/Session/Tests/SessionManagerTest.php       | 1 -
 2 files changed, 2 deletions(-)

diff --git a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
index 37a5a3e5a..3395adccd 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php
@@ -18,7 +18,6 @@
 use Viserio\Component\Session\Middleware\StartSessionMiddleware;
 use Viserio\Component\Session\Middleware\VerifyCsrfTokenMiddleware;
 use Viserio\Component\Session\SessionManager;
-use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class VerifyCsrfTokenMiddlewareTest extends MockeryTestCase
 {
diff --git a/src/Viserio/Component/Session/Tests/SessionManagerTest.php b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
index 93e226d85..daf15d2af 100644
--- a/src/Viserio/Component/Session/Tests/SessionManagerTest.php
+++ b/src/Viserio/Component/Session/Tests/SessionManagerTest.php
@@ -14,7 +14,6 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Encryption\Encrypter;
 use Viserio\Component\Session\SessionManager;
-use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
 
 class SessionManagerTest extends MockeryTestCase
 {

From 2cfbcb4adc656a3292081d82efa143116a851c73 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 13:35:57 +0000
Subject: [PATCH 83/99] Apply fixes from StyleCI


From 8e58f5175d4f54d4fd0bb8f7b0e50caaf5c2c868 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 20:02:00 +0200
Subject: [PATCH 84/99] Added tests for client ip

---
 src/Viserio/Component/WebProfiler/Profile.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Viserio/Component/WebProfiler/Profile.php b/src/Viserio/Component/WebProfiler/Profile.php
index a67247970..6d5d0db9d 100644
--- a/src/Viserio/Component/WebProfiler/Profile.php
+++ b/src/Viserio/Component/WebProfiler/Profile.php
@@ -290,7 +290,7 @@ public function getCollectors(): array
     public function setCollectors(array $collectors): void
     {
         foreach ($collectors as $collector) {
-            $this->addCollector($collector['collector']);
+            $this->addCollector($collector);
         }
     }
 

From ed292e04c9939ded75e8affaf0820adf3ed12286 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 22:28:11 +0200
Subject: [PATCH 85/99] and more work

	modified:   src/Viserio/Component/Session/SessionManager.php
	modified:   src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
---
 src/Viserio/Component/Session/SessionManager.php                 | 1 +
 .../Session/Tests/Middleware/StartSessionMiddlewareTest.php      | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index 5903b499c..2023d6bd9 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -5,6 +5,7 @@
 use Cache\SessionHandler\Psr6SessionHandler;
 use Interop\Container\ContainerInterface as ContainerInteropInterface;
 use SessionHandlerInterface;
+use Cache\SessionHandler\Psr6SessionHandler;
 use Viserio\Component\Contracts\Cache\Manager as CacheManagerContract;
 use Viserio\Component\Contracts\Cookie\QueueingFactory as JarContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
diff --git a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
index 3d772ebf7..a7ad780fc 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
@@ -86,6 +86,7 @@ public function testAddSessionToResponse()
 
         $request  = (new ServerRequestFactory())->createServerRequestFromArray($server);
         $response = $middleware->process($request, new DelegateMiddleware(function ($request) {
+
             return (new ResponseFactory())->createResponse(200);
         }));
 

From 30e5f64270c3c59a788bf495e70da404507bb83c Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 20:28:22 +0000
Subject: [PATCH 86/99] Apply fixes from StyleCI

---
 src/Viserio/Component/Session/SessionManager.php                 | 1 -
 .../Session/Tests/Middleware/StartSessionMiddlewareTest.php      | 1 -
 2 files changed, 2 deletions(-)

diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php
index 2023d6bd9..5903b499c 100644
--- a/src/Viserio/Component/Session/SessionManager.php
+++ b/src/Viserio/Component/Session/SessionManager.php
@@ -5,7 +5,6 @@
 use Cache\SessionHandler\Psr6SessionHandler;
 use Interop\Container\ContainerInterface as ContainerInteropInterface;
 use SessionHandlerInterface;
-use Cache\SessionHandler\Psr6SessionHandler;
 use Viserio\Component\Contracts\Cache\Manager as CacheManagerContract;
 use Viserio\Component\Contracts\Cookie\QueueingFactory as JarContract;
 use Viserio\Component\Contracts\Encryption\Encrypter as EncrypterContract;
diff --git a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
index a7ad780fc..3d772ebf7 100644
--- a/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
+++ b/src/Viserio/Component/Session/Tests/Middleware/StartSessionMiddlewareTest.php
@@ -86,7 +86,6 @@ public function testAddSessionToResponse()
 
         $request  = (new ServerRequestFactory())->createServerRequestFromArray($server);
         $response = $middleware->process($request, new DelegateMiddleware(function ($request) {
-
             return (new ResponseFactory())->createResponse(200);
         }));
 

From 5e5d85adb374d9e61f8db9b9cf9627980a91f066 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 22:31:07 +0200
Subject: [PATCH 87/99] fix composer


From 6f53c0aa38bfe4f868b72bf79832789b83ce0522 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 23:00:54 +0200
Subject: [PATCH 88/99] some sessions changes

	modified:   src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
	modified:   src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
---
 .../Component/Session/Middleware/StartSessionMiddleware.php     | 2 +-
 .../Component/Session/Middleware/VerifyCsrfTokenMiddleware.php  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 40bd6d348..901e9c7b2 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -172,7 +172,7 @@ protected function collectGarbage(StoreContract $session)
      */
     protected function addCookieToResponse(ServerRequestInterface $request, ResponseInterface $response, StoreContract $session): ResponseInterface
     {
-        if ($session->getHandler() instanceof CookieSessionHandler) {
+        if (! $session->getHandler() instanceof CookieSessionHandler) {
             $session->save();
         }
 
diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index 4e2e47ad1..107ee95f4 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -12,6 +12,7 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Cookie\SetCookie;
 use Viserio\Component\Session\SessionManager;
+use Viserio\Component\Contracts\Session\Exceptions\SessionNotStartedException;
 
 class VerifyCsrfTokenMiddleware implements MiddlewareInterface
 {

From dd01bb6e9a4cc86f4cc9fedbf81061d8df087d0e Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Fri, 19 May 2017 21:01:55 +0000
Subject: [PATCH 89/99] Apply fixes from StyleCI

some sessions changes

Apply fixes from StyleCI

fix first tests

fix cookie handling

working on session (#540)

Refactor some old session code

check if session is open and use http_only with true as default

	modified:   src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
	modified:   src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
---
 .../Component/Session/Middleware/StartSessionMiddleware.php     | 2 +-
 .../Component/Session/Middleware/VerifyCsrfTokenMiddleware.php  | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
index 901e9c7b2..40bd6d348 100644
--- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php
@@ -172,7 +172,7 @@ protected function collectGarbage(StoreContract $session)
      */
     protected function addCookieToResponse(ServerRequestInterface $request, ResponseInterface $response, StoreContract $session): ResponseInterface
     {
-        if (! $session->getHandler() instanceof CookieSessionHandler) {
+        if ($session->getHandler() instanceof CookieSessionHandler) {
             $session->save();
         }
 
diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
index 107ee95f4..4e2e47ad1 100644
--- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
+++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php
@@ -12,7 +12,6 @@
 use Viserio\Component\Contracts\Session\Store as StoreContract;
 use Viserio\Component\Cookie\SetCookie;
 use Viserio\Component\Session\SessionManager;
-use Viserio\Component\Contracts\Session\Exceptions\SessionNotStartedException;
 
 class VerifyCsrfTokenMiddleware implements MiddlewareInterface
 {

From e5ba2d157d12c6b26f0d44d340dd3b0a2cc0ca34 Mon Sep 17 00:00:00 2001
From: Daniel Bannert 
Date: Sat, 20 May 2017 20:50:32 +0200
Subject: [PATCH 90/99] fixed some tests

---
 composer.json                                 |  2 -
 .../DataCollector/TwigDataCollectorTest.php   | 22 -----
 src/Viserio/Component/Cache/CacheManager.php  | 32 +------
 src/Viserio/Component/Cache/composer.json     |  2 -
 .../Fixture/SimpleFixtureServiceProvider.php  |  2 +-
 .../Container/Tests/ServiceProviderTest.php   |  4 +-
 .../Component/Cookie/AbstractCookie.php       |  4 +-
 .../Bootstrap/SetRequestForConsole.php        |  2 +-
 .../ViserioHttpDataCollector.php              | 43 +--------
 .../ConsoleCommandsServiceProvider.php        |  9 +-
 ...FoundationDataCollectorServiceProvider.php |  5 +-
 .../Bootstrap/SetRequestForConsoleTest.php    |  2 +
 .../FilesLoadedCollectorTest.php              | 11 ---
 .../ViserioHttpDataCollectorTest.php          |  1 +
 .../Component/Foundation/composer.json        |  3 +-
 ...lerMonologDataCollectorServiceProvider.php |  2 +-
 .../Profiler/Resources/css/profiler.css       | 19 ++--
 .../Component/Profiler/TemplateManager.php    |  2 +-
 .../Profiler/Tests/AssetsRendererTest.php     |  7 +-
 .../Cache/Psr6CacheDataCollectorTest.php      | 10 --
 .../Bridge/SwiftMailDataCollectorTest.php     | 10 --
 .../DataCollectors/DataCollectorTest.php      |  2 +-
 .../DataCollectors/LogsDataCollectorTest.php  | 91 -------------------
 .../Tests/Fixture/View/array_table.html       |  2 +-
 .../Tests/Fixture/View/default_table.html     |  2 +-
 .../Profiler/Tests/Fixture/View/profile.html  |  2 +-
 .../View/profilewithajaxcollector.html.php    |  2 +-
 .../View/profilewithcollector.html.php        |  2 +-
 .../View/profilewithpanelcollector.html.php   |  2 +-
 .../Middleware/ProfilerMiddlewareTest.php     |  4 +-
 .../Component/Profiler/Tests/ProfileTest.php  |  4 +-
 ...onologDataCollectorServiceProviderTest.php |  2 +
 .../Profiler/Tests/TemplateManagerTest.php    | 18 +++-
 .../RoutingDataCollectorTest.php              | 19 ----
 ...outingDataCollectorServiceProviderTest.php |  2 +-
 .../Middleware/StartSessionMiddleware.php     |  2 +-
 .../Middleware/VerifyCsrfTokenMiddleware.php  |  4 +-
 .../Component/Session/SessionManager.php      |  2 +-
 .../VerifyCsrfTokenMiddlewareTest.php         | 24 ++---
 .../Tests/Traits/MacroableTraitTest.php       |  2 +-
 .../ViserioTranslationDataCollectorTest.php   | 63 -------------
 ...lationDataCollectorServiceProviderTest.php | 10 +-
 42 files changed, 85 insertions(+), 370 deletions(-)
 delete mode 100644 src/Viserio/Component/Profiler/Tests/DataCollectors/LogsDataCollectorTest.php

diff --git a/composer.json b/composer.json
index 769d4e2ac..a3562a2ba 100644
--- a/composer.json
+++ b/composer.json
@@ -160,8 +160,6 @@
     "suggest": {
         "alcaeus/mongo-php-adapter"                          : "Required to use the ext-mongo interface on ext-mongodb interface (^1.0).",
         "aws/aws-sdk-php"                                    : "Required to use the SQS queue driver and SES mail driver (^3.18).",
-        "cache/apc-adapter"                                  : "Required to use the Apc cache (^0.3).",
-        "cache/apcu-adapter"                                 : "Required to use the Apcu cache (^0.3).",
         "cache/array-adapter"                                : "Required to use the Array cache (^0.2)",
         "cache/filesystem-adapter"                           : "Required to use the Filesystem cache (^0.3).",
         "cache/memcache-adapter"                             : "Required to use the Memcache cache (^0.3).",
diff --git a/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php b/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php
index b67d3df63..c5f3b5660 100644
--- a/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php
+++ b/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php
@@ -39,28 +39,6 @@ public function testGetTooltip()
         self::assertSame('
Template calls1
Block calls0
Macro calls0
', $collect->getTooltip()); } - public function testGetPanel() - { - $profile = new Twig_Profiler_Profile(); - $env = new Twig_Environment( - new Twig_Loader_Array(['test.twig' => 'test']) - ); - $env->addExtension(new Twig_Extension_Profiler($profile)); - - $template = $env->load('test.twig'); - $template->render([]); - - $collect = new TwigDataCollector($profile, $env); - $collect->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - $expect = preg_replace('/(\r\n|\n\r|\r)/', "\n", '

Twig Metrics

  • ' . $this->formatDuration($collect->getTime()) . 'Render time
  • 1Template calls
  • 0Block calls
  • 0Macro calls

Rendered Templates

Template NameRender Count
test.twig1

Rendering Call Graph

' . $collect->getHtmlCallGraph() . '
Extension
Twig_Extension_Core
Twig_Extension_Escaper
Twig_Extension_Optimizer
Twig_Extension_Profiler
'); - - self::assertSame($this->removeTabId($expect), $this->removeTabId(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collect->getPanel()))); - } - public function testGetProfile() { $collect = $this->getTwigDataCollector(); diff --git a/src/Viserio/Component/Cache/CacheManager.php b/src/Viserio/Component/Cache/CacheManager.php index 5e43a0b7e..4542e57ea 100644 --- a/src/Viserio/Component/Cache/CacheManager.php +++ b/src/Viserio/Component/Cache/CacheManager.php @@ -2,8 +2,6 @@ declare(strict_types=1); namespace Viserio\Component\Cache; -use Cache\Adapter\Apc\ApcCachePool; -use Cache\Adapter\Apcu\ApcuCachePool; use Cache\Adapter\Filesystem\FilesystemCachePool; use Cache\Adapter\Memcache\MemcacheCachePool; use Cache\Adapter\Memcached\MemcachedCachePool; @@ -76,35 +74,7 @@ public function createDriver(array $config) } /** - * Create an instance of the Apc cache driver. - * - * @param array $config - * - * @return \Cache\Adapter\Apc\ApcCachePool - * - * @codeCoverageIgnore - */ - protected function createApcDriver(array $config): ApcCachePool - { - return new ApcCachePool(); - } - - /** - * Create an instance of the Apcu cache driver. - * - * @param array $config - * - * @return \Cache\Adapter\Apcu\ApcuCachePool - * - * @codeCoverageIgnore - */ - protected function createApcuDriver(array $config): ApcuCachePool - { - return new ApcuCachePool(); - } - - /** - * Create an instance of the Apcu cache driver. + * Create an instance of the Array cache driver. * * @param array $config * diff --git a/src/Viserio/Component/Cache/composer.json b/src/Viserio/Component/Cache/composer.json index cc4bbc6bf..4f6948a16 100644 --- a/src/Viserio/Component/Cache/composer.json +++ b/src/Viserio/Component/Cache/composer.json @@ -79,8 +79,6 @@ } }, "suggest": { - "cache/apc-adapter" : "Required to use the Apc cache (^0.3).", - "cache/apcu-adapter" : "Required to use the Apcu cache (^0.3).", "cache/array-adapter" : "Required to use the Array cache (^0.4)", "cache/encryption-cache" : "Required to use the Encryption cache (^0.1)", "cache/filesystem-adapter" : "Required to use the Filesystem cache (^0.3).", diff --git a/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php b/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php index 78461e43e..9b367f139 100644 --- a/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php +++ b/src/Viserio/Component/Container/Tests/Fixture/SimpleFixtureServiceProvider.php @@ -25,6 +25,6 @@ public static function getParam() public static function getPrevious(ContainerInterface $container, callable $getPrevious = null) { - return $getPrevious . 'bar'; + return is_callable($getPrevious) ? $getPrevious() : $getPrevious; } } diff --git a/src/Viserio/Component/Container/Tests/ServiceProviderTest.php b/src/Viserio/Component/Container/Tests/ServiceProviderTest.php index 53c617e70..dd3cbd422 100644 --- a/src/Viserio/Component/Container/Tests/ServiceProviderTest.php +++ b/src/Viserio/Component/Container/Tests/ServiceProviderTest.php @@ -36,9 +36,7 @@ public function testExtendingValue() $container->instance('previous', 'foo'); $container->register(new SimpleFixtureServiceProvider()); - $getPrevious = $container->get('previous'); - - self::assertEquals('foo', $getPrevious()); + self::assertEquals('foo', $container->get('previous')); } public function testExtendingNothing() diff --git a/src/Viserio/Component/Cookie/AbstractCookie.php b/src/Viserio/Component/Cookie/AbstractCookie.php index 6612fd4f3..06b1fc360 100644 --- a/src/Viserio/Component/Cookie/AbstractCookie.php +++ b/src/Viserio/Component/Cookie/AbstractCookie.php @@ -323,7 +323,7 @@ protected function normalizeExpires($expiration = null): int $expires = null; if (is_int($expiration)) { - $expires = (new Chronos(sprintf('%d seconds', $expiration)))->toCookieString(); + $expires = Chronos::now()->addSeconds($expiration)->toCookieString(); } elseif ($expiration instanceof DateTimeInterface) { $expires = $expiration->format(DateTime::COOKIE); } @@ -335,7 +335,7 @@ protected function normalizeExpires($expiration = null): int // if $tsExpires is invalid and PHP is compiled as 32bit. Check if it fail reason is the 2038 bug if (! is_int($tsExpires) && PHP_INT_SIZE === 4) { - $dateTime = new DateTime($expires); + $dateTime = new Chronos($expires); if ($dateTime->format('Y') > 2038) { $tsExpires = PHP_INT_MAX; diff --git a/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php b/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php index cf79d6624..0eec44813 100644 --- a/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php +++ b/src/Viserio/Component/Foundation/Bootstrap/SetRequestForConsole.php @@ -57,7 +57,7 @@ public static function createRequest(ContainerInterface $container): ServerReque { return $container->get(ServerRequestFactoryInterface::class)->createServerRequest( 'GET', - self::$config['app']['url'] + self::$config['console']['url'] ); } }); diff --git a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 49ade4371..afa7ec657 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -215,6 +215,7 @@ public function getPanel(): string [ 'name' => 'Session Metadata', 'empty_text' => 'No session metadata', + 'vardumper' => false, ] ) . $this->createTable( $session !== null ? $session->getAll() : [], @@ -291,48 +292,6 @@ protected function createCookieTab(ServerRequestInterface $serverRequest, Respon ]; } - /** - * Prepare request and response cookie infos and create a cookie tab. - * - * @param \Psr\Http\Message\ServerRequestInterface $serverRequest - * @param \Psr\Http\Message\ResponseInterface $response - * - * @return array - */ - protected function createCookieTab(ServerRequestInterface $serverRequest, ResponseInterface $response): array - { - if (! (class_exists(RequestCookies::class) && class_exists(ResponseCookies::class))) { - return []; - } - - $requestCookies = $responseCookies = []; - - foreach (RequestCookies::fromRequest($serverRequest)->getAll() as $cookie) { - $requestCookies[$cookie->getName()] = $cookie->getValue(); - } - - foreach (ResponseCookies::fromResponse($response)->getAll() as $cookie) { - $responseCookies[$cookie->getName()] = $cookie->getValue(); - } - - return [ - 'name' => 'Cookies', - 'content' => $this->createTable( - $requestCookies, - [ - 'name' => 'Request Cookies', - 'empty_text' => 'No request cookies', - ] - ) . $this->createTable( - $responseCookies, - [ - 'name' => 'Response Cookies', - 'empty_text' => 'No response cookies', - ] - ), - ]; - } - /** * Get the route information for a given route. * diff --git a/src/Viserio/Component/Foundation/Providers/ConsoleCommandsServiceProvider.php b/src/Viserio/Component/Foundation/Providers/ConsoleCommandsServiceProvider.php index 24759a20f..9c5012d66 100644 --- a/src/Viserio/Component/Foundation/Providers/ConsoleCommandsServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/ConsoleCommandsServiceProvider.php @@ -31,9 +31,9 @@ public function getServices() */ public static function createConsoleCommands(ContainerInterface $container, ?callable $getPrevious = null): ?Application { - if ($getPrevious !== null) { - $console = $getPrevious(); + $console = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + if ($console !== null) { $console->addCommands([ new DownCommand(), new UpCommand(), @@ -42,8 +42,7 @@ public static function createConsoleCommands(ContainerInterface $container, ?cal return $console; } - // @codeCoverageIgnoreStart - return null; - // @codeCoverageIgnoreEnd + + return $console; } } diff --git a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php index 4d9745dac..57fc19808 100644 --- a/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Foundation/Providers/FoundationDataCollectorServiceProvider.php @@ -80,7 +80,7 @@ public function getDefaultOptions(): iterable */ public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract { - $profiler = $getPrevious(); + $profiler = is_callable($getPrevious) ? $getPrevious() : $getPrevious; if ($profiler !== null) { self::resolveOptions($container); @@ -99,9 +99,8 @@ public static function createProfiler(ContainerInterface $container, ?callable $ return $profiler; } - // @codeCoverageIgnoreStart + return $profiler; - // @codeCoverageIgnoreEnd } private static function createNarrowsparkDataCollector(): NarrowsparkDataCollector diff --git a/src/Viserio/Component/Foundation/Tests/Bootstrap/SetRequestForConsoleTest.php b/src/Viserio/Component/Foundation/Tests/Bootstrap/SetRequestForConsoleTest.php index e01d9013c..4b3dd6472 100644 --- a/src/Viserio/Component/Foundation/Tests/Bootstrap/SetRequestForConsoleTest.php +++ b/src/Viserio/Component/Foundation/Tests/Bootstrap/SetRequestForConsoleTest.php @@ -30,6 +30,8 @@ protected function registerBaseServiceProviders(): void 'viserio' => [ 'app' => [ 'env' => 'prod', + ], + 'console' => [ 'url' => 'http://localhost', ], ], diff --git a/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php b/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php index be76fd16e..d6bf3fbc2 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php @@ -22,15 +22,4 @@ public function testGetMenu() $collector->getMenu() ); } - - public function testGetPanel() - { - $collector = new FilesLoadedCollector(__DIR__); - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - self::assertTrue(is_string($collector->getPanel())); - } } diff --git a/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php b/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php index 0263de7cf..edbb836a4 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php @@ -44,6 +44,7 @@ public function testGetMenuAndPosition() self::assertSame( [ 'label' => '@', + 'class' => 'response-status-green', 'value' => 'Home', ], $collect->getMenu() diff --git a/src/Viserio/Component/Foundation/composer.json b/src/Viserio/Component/Foundation/composer.json index 42b4ef803..f784b75bf 100644 --- a/src/Viserio/Component/Foundation/composer.json +++ b/src/Viserio/Component/Foundation/composer.json @@ -41,7 +41,8 @@ "viserio/exception" : "self.version", "viserio/options-resolver" : "self.version", "viserio/pipeline" : "self.version", - "viserio/routing" : "self.version" + "viserio/routing" : "self.version", + "viserio/support" : "self.version" }, "require-dev": { "cakephp/chronos" : "^1.0", diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php index e8fc29f1f..23789888f 100644 --- a/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php @@ -89,7 +89,7 @@ public static function extendProfiler(ContainerInterface $container, ?callable $ if ($profiler !== null) { self::resolveOptions($container); - if (self::$options['collector']['logs']) { + if (self::$options['collector']['logs'] === true && $container->has(Logger::class)) { $profiler->addCollector(new MonologLoggerDataCollector($container->get(Logger::class))); } diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler.css b/src/Viserio/Component/Profiler/Resources/css/profiler.css index 2f4e3c104..f7096ef84 100644 --- a/src/Viserio/Component/Profiler/Resources/css/profiler.css +++ b/src/Viserio/Component/Profiler/Resources/css/profiler.css @@ -12,7 +12,8 @@ --profiler-tab-active-font-color: #2b2a28; --profiler-tab-counter-color: #424242; --profiler-table-head-background-color: #424242; - --profiler-table-body-background-color: #fff; + --profiler-table-body-background-color-even: #eee; + --profiler-table-body-background-color-odd: #fff; } .profiler { @@ -372,7 +373,6 @@ } .profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label ~ .profiler-tabs-tab-content { z-index: 1; - opacity: 1; } @@ -380,22 +380,23 @@ margin-top: 0; } +.profiler .profiler-body .profiler-panel table tr:nth-child(even) { + background: var(--profiler-table-body-background-color-even); +} +.profiler .profiler-body .profiler-panel table tr:nth-child(odd) { + background: var(--profiler-table-body-background-color-odd); +} .profiler .profiler-body .profiler-panel table, .profiler .profiler-body .profiler-panel tr, .profiler .profiler-body .profiler-panel th, .profiler .profiler-body .profiler-panel td { line-height: 1.5; - border-collapse: collapse; - vertical-align: top; - - background: var(--profiler-table-body-background-color); } .profiler .profiler-body .profiler-panel table { width: 100%; margin: 0; - box-shadow: 0 0 1px rgba(128, 128, 128, .2); } .profiler .profiler-body .profiler-panel table:last-child { @@ -428,7 +429,7 @@ font-size-adjust: .5; color: #2b2a28; - border: 1px solid var(--profiler-table-body-background-color); + border: 1px solid var(--profiler-table-body-background-color-odd); border-width: 1px 0; } .profiler .profiler-body .profiler-panel table tbody td { @@ -455,7 +456,7 @@ text-align: center; color: #fff; - border: 4px dashed var(--profiler-table-body-background-color); + border: 4px dashed var(--profiler-table-body-background-color-odd); } .profiler .profiler-body .profiler-panel .metrics { diff --git a/src/Viserio/Component/Profiler/TemplateManager.php b/src/Viserio/Component/Profiler/TemplateManager.php index ca7910222..8ddefb23b 100644 --- a/src/Viserio/Component/Profiler/TemplateManager.php +++ b/src/Viserio/Component/Profiler/TemplateManager.php @@ -148,7 +148,7 @@ public function getSortedData(): array $class = ' profiler-body-has-selector'; } elseif (mb_strpos($panel, '