diff --git a/composer.json b/composer.json index 769d4e2ac..937aab8df 100644 --- a/composer.json +++ b/composer.json @@ -32,8 +32,8 @@ "php" : "^7.1", "ext-fileinfo" : "*", "ext-openssl" : "*", - "cache/array-adapter" : "^0.4", - "cache/void-adapter" : "^0.3", + "cache/array-adapter" : "^0.5", + "cache/void-adapter" : "^0.4", "cakephp/chronos" : "^1.0", "container-interop/container-interop" : "^1.1", "container-interop/service-provider" : "^0.3", @@ -56,6 +56,9 @@ "opis/closure" : "^2.2", "paragonie/password_lock" : "^3.0", "php-di/invoker" : "^2.0", + "psr/cache" : "^1.0", + "psr/log" : "^1.0", + "psr/simple-cache" : "^1.0", "respect/validation" : "^1.1", "symfony/console" : "^3.2", "symfony/debug" : "^3.2", @@ -106,10 +109,9 @@ }, "require-dev": { "aws/aws-sdk-php" : "^3.18", - "cache/filesystem-adapter" : "^0.3", + "cache/filesystem-adapter" : "^0.4", "cache/namespaced-cache" : "^0.1", "cache/session-handler" : "^0.2", - "cache/void-adapter" : "^0.3", "erusev/parsedown-extra" : "^0.7", "filp/whoops" : "^2.0", "guzzlehttp/guzzle" : "^6.0", @@ -136,9 +138,9 @@ "twig/twig" : "^2.0", "sepia/po-parser" : "^4.2", "spatie/flysystem-dropbox" : "^1.0", - "symfony/routing" : "^3.1", + "symfony/routing" : "^3.2", "symfony/var-dumper" : "^3.2", - "symfony/yaml" : "^3.1", + "symfony/yaml" : "^3.2", "yosymfony/toml" : "^0.3" }, "autoload": { @@ -160,17 +162,13 @@ "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/filesystem-adapter" : "Required to use the Filesystem cache (^0.4).", "cache/memcache-adapter" : "Required to use the Memcache cache (^0.3).", - "cache/memcached-adapter" : "Required to use the Memcached cache (^0.3).", + "cache/memcached-adapter" : "Required to use the Memcached cache (^0.4).", "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/mongodb-adapter" : "Required to use the Mongodb cache (^0.3).", + "cache/predis-adapter" : "Required to use the Predis cache (^0.5).", "cache/session-handler" : "Required to use the Session cache (^0.1).", - "cache/void-adapter" : "Required to use the Void cache (^0.3).", "guzzlehttp/guzzle" : "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (^6.0).", "league/flysystem-aws-s3-v3" : "Required to use the Flysystem S3 adapter (^1.0).", "league/flysystem-cached-adapter" : "Required to use the Flysystem Caching adapter (^1.0.3).", diff --git a/phpstan.neon b/phpstan.neon index 78513abd6..c05f3e037 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -77,6 +77,8 @@ parameters: - '#\$casters of method Symfony\\Component\\VarDumper\\Cloner\\AbstractCloner::addCasters#' - '#Call to function count\(\) with argument type iterable\(mixed\[\]\) will always result in number 1#' - '#Method Viserio\\Component\\Filesystem\\Encryption\\EncryptionWrapper::decryptStream() should return resource but returns mixed|string#' + - '#set\(\) has invalid typehint type Psr\\SimpleCache\\DateInterval#' + - '#setMultiple\(\) has invalid typehint type Psr\\SimpleCache\\DateInterval#' # DUMP_COMMA_SEPARATOR constant only supported from var-dumper v3.3 - "#DUMP_COMMA_SEPARATOR#" @@ -109,7 +111,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/phpunit.xml.dist b/phpunit.xml.dist index e4ec1c29e..988332cbc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -121,8 +121,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..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 @@ -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph { - margin-top: 25px; +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph { + margin: 25px 0; } -.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; + color: var(--profiler-second-font-color); padding: 10px; - background-color: #fff; + background-color: #FFF; } -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-success { - color: #4F805D; +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-success { + color: var(--profiler-status-green-color); } -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-warning { - background-color: #A46A1F; +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-warning { + background-color: var(--profiler-status-yellow-color); color: #FFF; padding: 0px 5px; } -.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-error { - color: #B0413E; +.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-error { + color: var(--profiler-status-red-color); } 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 688cd0d0a..cd983f0f7 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/Bridge/Twig/Providers/TwigBridgeServiceProvider.php b/src/Viserio/Bridge/Twig/Providers/TwigBridgeServiceProvider.php index 35630494d..acf278415 100644 --- a/src/Viserio/Bridge/Twig/Providers/TwigBridgeServiceProvider.php +++ b/src/Viserio/Bridge/Twig/Providers/TwigBridgeServiceProvider.php @@ -4,6 +4,7 @@ use Interop\Container\ContainerInterface; use Interop\Container\ServiceProvider; +use Symfony\Component\VarDumper\Cloner\VarCloner; use Twig_Environment as TwigEnvironment; use Twig_Lexer; use Twig_Loader_Array; @@ -129,7 +130,7 @@ public static function createTwigEnvironment(ContainerInterface $container): Twi $twig->setLexer($container->get(Twig_Lexer::class)); } - if ($options['debug']) { + if ($options['debug'] && class_exists(VarCloner::class)) { $twig->addExtension(new DumpExtension()); } diff --git a/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php b/src/Viserio/Bridge/Twig/Tests/DataCollector/TwigDataCollectorTest.php index d213bf690..c5f3b5660 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,36 +36,14 @@ public function testGetTooltip() $this->mock(ResponseInterface::class) ); - static::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
'); - - static::assertSame($this->removeTabId($expect), $this->removeTabId(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collect->getPanel()))); + self::assertSame('
Template calls1
Block calls0
Macro calls0
', $collect->getTooltip()); } 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 788730eda..3d9a69dc4 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\Profiler\Providers\ProfilerServiceProvider; use Viserio\Component\View\Providers\ViewServiceProvider; -use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider; /** * @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,13 +61,13 @@ public function testGetServices() ], ]); - $profiler = $container->get(WebProfilerContract::class); + $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(WebProfilerContract::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/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": { diff --git a/src/Viserio/Component/Cache/CacheManager.php b/src/Viserio/Component/Cache/CacheManager.php index 5e43a0b7e..c55b6208f 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; @@ -65,7 +63,7 @@ public function createDriver(array $config) $namespace = $this->options['namespace']; if (class_exists(NamespacedCachePool::class) && $namespace && $driver instanceof HierarchicalPoolInterface) { - $driver = $this->namespacedPool($driver, $namespace); + $driver = $this->getNamespacedPool($driver, $namespace); } if ($this->logger !== null) { @@ -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 * @@ -248,7 +218,7 @@ protected function createNullDriver(array $config): VoidCachePool * * @return \Cache\Namespaced\NamespacedCachePool */ - protected function namespacedPool(HierarchicalPoolInterface $hierarchyPool, $namespace): NamespacedCachePool + protected function getNamespacedPool(HierarchicalPoolInterface $hierarchyPool, string $namespace): NamespacedCachePool { return new NamespacedCachePool($hierarchyPool, $namespace); } diff --git a/src/Viserio/Component/Cache/Providers/CacheServiceProvider.php b/src/Viserio/Component/Cache/Providers/CacheServiceProvider.php index a25d3a51f..6fb5d47b6 100644 --- a/src/Viserio/Component/Cache/Providers/CacheServiceProvider.php +++ b/src/Viserio/Component/Cache/Providers/CacheServiceProvider.php @@ -5,6 +5,7 @@ use Interop\Container\ContainerInterface; use Interop\Container\ServiceProvider; use Psr\Cache\CacheItemPoolInterface; +use Psr\SimpleCache\CacheInterface; use Viserio\Component\Cache\CacheManager; use Viserio\Component\Contracts\Cache\Manager as CacheManagerContract; @@ -16,26 +17,31 @@ class CacheServiceProvider implements ServiceProvider public function getServices() { return [ - CacheManagerContract::class => [self::class, 'registerCacheFactory'], - CacheManager::class => function (ContainerInterface $container) { + CacheManagerContract::class => function (ContainerInterface $container): CacheManagerContract { + return new CacheManager($container); + }, + CacheManager::class => function (ContainerInterface $container): CacheManagerContract { return $container->get(CacheManagerContract::class); }, - 'cache' => function (ContainerInterface $container) { + 'cache' => function (ContainerInterface $container): CacheManagerContract { return $container->get(CacheManagerContract::class); }, CacheItemPoolInterface::class => [self::class, 'registerDefaultCache'], + CacheInterface::class => [self::class, 'registerDefaultCache'], 'cache.store' => function (ContainerInterface $container) { return $container->get(CacheItemPoolInterface::class); }, ]; } - public static function registerCacheFactory(ContainerInterface $container): CacheManager - { - return new CacheManager($container); - } - - public static function registerDefaultCache(ContainerInterface $container): CacheItemPoolInterface + /** + * A instance of the default driver. + * + * @param \Interop\Container\ContainerInterface $container + * + * @return \Psr\Cache\CacheItemPoolInterface|\Psr\SimpleCache\CacheInterface + */ + public static function registerDefaultCache(ContainerInterface $container) { return $container->get(CacheManager::class)->getDriver(); } diff --git a/src/Viserio/Component/Cache/Proxies/Cache.php b/src/Viserio/Component/Cache/Proxies/Cache.php index 98a131130..5105b9f15 100644 --- a/src/Viserio/Component/Cache/Proxies/Cache.php +++ b/src/Viserio/Component/Cache/Proxies/Cache.php @@ -2,6 +2,7 @@ declare(strict_types=1); namespace Viserio\Component\Cache\Proxies; +use Psr\Cache\CacheItemPoolInterface; use Viserio\Component\StaticalProxy\StaticalProxy; class Cache extends StaticalProxy @@ -13,6 +14,6 @@ class Cache extends StaticalProxy */ public static function getInstanceIdentifier() { - return 'cache'; + return CacheItemPoolInterface::class; } } diff --git a/src/Viserio/Component/Cache/Proxies/SimpleCache.php b/src/Viserio/Component/Cache/Proxies/SimpleCache.php new file mode 100644 index 000000000..346c3e1c0 --- /dev/null +++ b/src/Viserio/Component/Cache/Proxies/SimpleCache.php @@ -0,0 +1,19 @@ +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)) { - // Extend a previous entry - $this->extend($key, function ($previous) use ($container, $callable) { + $this->extend($key, function ($previous, $container) use ($callable) { + // Extend a previous entry 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..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; + 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/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/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 @@ 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/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/Cookie/AbstractCookieCollector.php b/src/Viserio/Component/Cookie/AbstractCookieCollector.php index 9fd1ddf2a..cd8fae010 100644 --- a/src/Viserio/Component/Cookie/AbstractCookieCollector.php +++ b/src/Viserio/Component/Cookie/AbstractCookieCollector.php @@ -2,7 +2,7 @@ declare(strict_types=1); namespace Viserio\Component\Cookie; -use RuntimeException; +use InvalidArgumentException; abstract class AbstractCookieCollector { @@ -56,7 +56,7 @@ public function getAll(): array * * @param \Viserio\Component\Cookie\Cookie|\Viserio\Component\Contracts\Cookie\Cookie $cookie * - * @throws \RuntimeException + * @throws \InvalidArgumentException * * @return $this */ @@ -69,9 +69,11 @@ public function add($cookie): self return $clone; } - throw new RuntimeException(sprintf( - 'The object [%s] must be an instance of "\Viserio\Component\Cookie\Cookie" or "\Viserio\Component\Contracts\Cookie\Cookie".', - get_class($cookie) + throw new InvalidArgumentException(sprintf( + 'The object [%s] must be an instance of [%s] or [%s].', + get_class($cookie), + Cookie::class, + SetCookie::class )); } diff --git a/src/Viserio/Component/Cookie/RequestCookies.php b/src/Viserio/Component/Cookie/RequestCookies.php index 560fa993f..07d90140b 100644 --- a/src/Viserio/Component/Cookie/RequestCookies.php +++ b/src/Viserio/Component/Cookie/RequestCookies.php @@ -2,8 +2,8 @@ declare(strict_types=1); namespace Viserio\Component\Cookie; +use InvalidArgumentException; use Psr\Http\Message\ServerRequestInterface; -use RuntimeException; class RequestCookies extends AbstractCookieCollector { @@ -12,15 +12,16 @@ class RequestCookies extends AbstractCookieCollector * * @param array $cookies * - * @throws \RuntimeException + * @throws \InvalidArgumentException */ public function __construct(array $cookies = []) { foreach ($cookies as $cookie) { if (! ($cookie instanceof Cookie)) { - throw new RuntimeException(sprintf( - 'The object [%s] must be an instance of [\Viserio\Component\Cookie\Cookie].', - get_class($cookie) + throw new InvalidArgumentException(sprintf( + 'The object [%s] must be an instance of [%s].', + get_class($cookie), + Cookie::class )); } diff --git a/src/Viserio/Component/Cookie/ResponseCookies.php b/src/Viserio/Component/Cookie/ResponseCookies.php index 7e7150563..0eb225f55 100644 --- a/src/Viserio/Component/Cookie/ResponseCookies.php +++ b/src/Viserio/Component/Cookie/ResponseCookies.php @@ -3,8 +3,8 @@ namespace Viserio\Component\Cookie; use Cake\Chronos\Chronos; +use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; -use RuntimeException; use Viserio\Component\Contracts\Cookie\Cookie as CookieContract; class ResponseCookies extends AbstractCookieCollector @@ -14,15 +14,16 @@ class ResponseCookies extends AbstractCookieCollector * * @param array $cookies * - * @throws \RuntimeException + * @throws \InvalidArgumentException */ public function __construct(array $cookies = []) { foreach ($cookies as $cookie) { if (! ($cookie instanceof CookieContract)) { - throw new RuntimeException(sprintf( - 'The object [%s] must implement [Viserio\Component\Contracts\Cookie\Cookie].', - get_class($cookie) + throw new InvalidArgumentException(sprintf( + 'The object [%s] must implement [%s].', + get_class($cookie), + CookieContract::class )); } diff --git a/src/Viserio/Component/Cookie/Tests/RequestCookiesTest.php b/src/Viserio/Component/Cookie/Tests/RequestCookiesTest.php index d321775f9..9ef961c21 100644 --- a/src/Viserio/Component/Cookie/Tests/RequestCookiesTest.php +++ b/src/Viserio/Component/Cookie/Tests/RequestCookiesTest.php @@ -12,8 +12,8 @@ class RequestCookiesTest extends MockeryTestCase { /** - * @expectedException \RuntimeException - * @expectedExceptionMessage The object [Viserio\Component\Cookie\SetCookie] must be an instance of [\Viserio\Component\Cookie\Cookie]. + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The object [Viserio\Component\Cookie\SetCookie] must be an instance of [Viserio\Component\Cookie\Cookie]. */ public function testRequestCookiesToThrowException() { diff --git a/src/Viserio/Component/Cookie/Tests/ResponseCookiesTest.php b/src/Viserio/Component/Cookie/Tests/ResponseCookiesTest.php index 0e44f0044..544039f6b 100644 --- a/src/Viserio/Component/Cookie/Tests/ResponseCookiesTest.php +++ b/src/Viserio/Component/Cookie/Tests/ResponseCookiesTest.php @@ -13,7 +13,7 @@ class ResponseCookiesTest extends MockeryTestCase { /** - * @expectedException \RuntimeException + * @expectedException \InvalidArgumentException * @expectedExceptionMessage The object [Viserio\Component\Cookie\Cookie] must implement [Viserio\Component\Contracts\Cookie\Cookie]. */ public function testRequestCookiesToThrowException() 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/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/AbstractKernel.php b/src/Viserio/Component/Foundation/AbstractKernel.php index c60a000cd..b8aa8a5b4 100644 --- a/src/Viserio/Component/Foundation/AbstractKernel.php +++ b/src/Viserio/Component/Foundation/AbstractKernel.php @@ -347,6 +347,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 e6a436838..f24fb08a1 100644 --- a/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php +++ b/src/Viserio/Component/Foundation/Bootstrap/LoadConfiguration.php @@ -49,9 +49,8 @@ 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) { 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/FilesLoadedCollector.php b/src/Viserio/Component/Foundation/DataCollectors/FilesLoadedCollector.php index f12b719af..44a812db0 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/FilesLoadedCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/FilesLoadedCollector.php @@ -4,8 +4,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -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 FilesLoadedCollector extends AbstractDataCollector implements PanelAwareContract { @@ -49,8 +49,8 @@ public function collect(ServerRequestInterface $serverRequest, ResponseInterface $included = []; foreach (get_included_files() as $file) { - // Skip the files from webprofiler, they are only loaded for Debugging and confuse the output. - if (mb_strpos($file, 'vendor/narrowspark/framework/src/Viserio/WebProfiler') !== false || + // Skip the files from Profiler, they are only loaded for Debugging and confuse the output. + if (mb_strpos($file, 'vendor/narrowspark/framework/src/Viserio/Profiler') !== false || mb_strpos($file, 'vendor/viserio/web-profiler') !== false ) { continue; diff --git a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php index 384eb8025..f679d1cc8 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/NarrowsparkDataCollector.php @@ -4,10 +4,10 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Viserio\Component\Contracts\WebProfiler\TooltipAware as TooltipAwareContract; +use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract; use Viserio\Component\Foundation\AbstractKernel; +use Viserio\Component\Profiler\DataCollectors\PhpInfoDataCollector; use Viserio\Component\Support\Env; -use Viserio\Component\WebProfiler\DataCollectors\PhpInfoDataCollector; class NarrowsparkDataCollector extends PhpInfoDataCollector implements TooltipAwareContract { 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 d4ea3f45a..7b6e5adc7 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css +++ b/src/Viserio/Component/Foundation/DataCollectors/Resources/css/request-response.css @@ -1,20 +1,20 @@ -.webprofiler-menu.webprofiler-menu-viserio-http-data-collector.response-status-green .webprofiler-menu-label, -.webprofiler-menu.webprofiler-menu-viserio-http-data-collector.response-status-yellow .webprofiler-menu-label, -.webprofiler-menu.webprofiler-menu-viserio-http-data-collector.response-status-red .webprofiler-menu-label { +.profiler-menu.profiler-menu-viserio-http-data-collector.response-status-green .profiler-menu-label, +.profiler-menu.profiler-menu-viserio-http-data-collector.response-status-yellow .profiler-menu-label, +.profiler-menu.profiler-menu-viserio-http-data-collector.response-status-red .profiler-menu-label { padding: 0 10px!important; margin-right: 5px; } -.webprofiler-menu.webprofiler-menu-viserio-http-data-collector.response-status-green .webprofiler-menu-label { - background-color: #4F805D; +.profiler-menu.profiler-menu-viserio-http-data-collector.response-status-green .profiler-menu-label { + background-color: var(--profiler-status-green-color); } -.webprofiler-menu.webprofiler-menu-viserio-http-data-collector.response-status-yellow .webprofiler-menu-label { - background-color: #A46A1F; +.profiler-menu.profiler-menu-viserio-http-data-collector.response-status-yellow .profiler-menu-label { + background-color: var(--profiler-status-yellow-color); color: #FFF; } -.webprofiler-menu.webprofiler-menu-viserio-http-data-collector.response-status-red .webprofiler-menu-label { - background-color: #B0413E; +.profiler-menu.profiler-menu-viserio-http-data-collector.response-status-red .profiler-menu-label { + background-color: var(--profiler-status-red-color); } -.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu-position-left.webprofiler-menu-viserio-http-data-collector .webprofiler-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/Foundation/DataCollectors/ViserioHttpDataCollector.php b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php index 98aaba2ed..afa7ec657 100644 --- a/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php +++ b/src/Viserio/Component/Foundation/DataCollectors/ViserioHttpDataCollector.php @@ -8,13 +8,15 @@ use ReflectionFunction; use ReflectionMethod; use Viserio\Component\Contracts\Config\Repository as RepositoryContract; +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\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\Cookie\RequestCookies; +use Viserio\Component\Cookie\ResponseCookies; +use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector; class ViserioHttpDataCollector extends AbstractDataCollector implements TooltipAwareContract, @@ -108,11 +110,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 +123,9 @@ public function getMenu(): array ] ); } elseif ($this->route !== null) { - $tabInfos = array_merge( + return array_merge( $tabInfos, [ - 'class' => $status, 'value' => implode(' | ', $this->route->getMethods()), ] ); @@ -157,14 +159,16 @@ 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) { $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(), ]; @@ -174,55 +178,61 @@ 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(), - [ - 'name' => 'Response Headers', - 'headers' => [ - 'key' => 'Header', - ], - ] - ) . $this->createTable( - $this->serverRequest->getHeader('Set-Cookie'), - ['name' => 'Cookies'] + $response->getHeaders(), + ['name' => 'Response Headers'] ), ], + $this->createCookieTab($request, $response), [ 'name' => 'Session', 'content' => $this->createTable( $sessionMeta, - ['name' => 'Session Metadata'] + [ + 'name' => 'Session Metadata', + 'empty_text' => 'No session metadata', + 'vardumper' => false, + ] ) . $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'] + $session !== null && $session->has('_flash') ? $session->get('_flash') : [], + [ + 'name' => 'Flashes', + 'empty_text' => 'No flash messages were created', + ] ), ], ]); @@ -240,6 +250,48 @@ public function getAssets(): 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 []; + } + + $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. * @@ -279,59 +331,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. - * - * @param string $string - * - * @return array - */ - protected function splitOnAttributeDelimiter(string $string): array - { - return array_filter(preg_split('@\s*[;]\s*@', $string)); - } - /** * Prepare request attributes, check of route object. * @@ -353,6 +358,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/Events/KernelResponseEvent.php b/src/Viserio/Component/Foundation/Http/Events/KernelResponseEvent.php index a9eb159d5..44c9be11c 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 + */ + protected $response; + /** * Create a new kernel response event. * @@ -25,4 +32,26 @@ 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. + * + * @return \Psr\Http\Message\ResponseInterface + */ + 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 d471182df..27a143080 100644 --- a/src/Viserio/Component/Foundation/Http/Kernel.php +++ b/src/Viserio/Component/Foundation/Http/Kernel.php @@ -21,6 +21,7 @@ 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\Dispatchers\MiddlewareBasedDispatcher; use Viserio\Component\Routing\Pipeline; use Viserio\Component\Routing\Router; @@ -61,6 +62,7 @@ class Kernel extends AbstractKernel implements HttpKernelContract, TerminableCon protected $middlewarePriority = [ StartSessionMiddleware::class, ShareErrorsFromSessionMiddleware::class, + 99999 => ProfilerMiddleware::class, ]; /** @@ -204,7 +206,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/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 274a41d51..57fc19808 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\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; 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,11 +76,11 @@ 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 { - $profiler = $getPrevious(); + $profiler = is_callable($getPrevious) ? $getPrevious() : $getPrevious; if ($profiler !== null) { self::resolveOptions($container); @@ -99,9 +99,8 @@ public static function createWebProfiler(ContainerInterface $container, ?callabl 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 317fe848c..ba52a7b76 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/FilesLoadedCollectorTest.php @@ -3,8 +3,6 @@ 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\FilesLoadedCollector; class FilesLoadedCollectorTest extends MockeryTestCase @@ -13,7 +11,7 @@ public function testGetMenu() { $collector = new FilesLoadedCollector(__DIR__); - static::assertSame( + self::assertSame( [ 'icon' => 'ic_insert_drive_file_white_24px.svg', 'label' => '', @@ -22,15 +20,4 @@ public function testGetMenu() $collector->getMenu() ); } - - public function testGetPanel() - { - $collector = new FilesLoadedCollector(__DIR__); - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - static::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..edbb836a4 100644 --- a/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php +++ b/src/Viserio/Component/Foundation/Tests/DataCollectors/ViserioHttpDataCollectorTest.php @@ -41,14 +41,15 @@ public function testGetMenuAndPosition() $collect = new ViserioHttpDataCollector($router, $this->mock(RepositoryContract::class)); $collect->collect($serverRequest, $response); - static::assertSame( + self::assertSame( [ 'label' => '@', + 'class' => 'response-status-green', 'value' => 'Home', ], $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 bff8202f1..494f6f7a5 100644 --- a/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Foundation/Tests/Providers/FoundationDataCollectorServiceProviderTest.php @@ -7,13 +7,13 @@ 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\WebProfiler\WebProfiler as WebProfilerContract; 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 { @@ -33,11 +33,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, @@ -48,15 +48,15 @@ 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); + 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/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/Http/Stream.php b/src/Viserio/Component/Http/Stream.php index e1319c633..abed67b7e 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/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/Log/DataCollectors/LogParser.php b/src/Viserio/Component/Log/DataCollectors/LogParser.php deleted file mode 100644 index b51c1bc10..000000000 --- a/src/Viserio/Component/Log/DataCollectors/LogParser.php +++ /dev/null @@ -1,150 +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 29ccf380c..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/Log/Tests/DataCollectors/LogsDataCollectorTest.php b/src/Viserio/Component/Log/Tests/DataCollectors/LogsDataCollectorTest.php deleted file mode 100644 index 1cdf36ab7..000000000 --- a/src/Viserio/Component/Log/Tests/DataCollectors/LogsDataCollectorTest.php +++ /dev/null @@ -1,91 +0,0 @@ -addMessage('foobar'); - - $msgs = $collector->getMessages(); - - static::assertCount(1, $msgs); - - $collector->addMessage(['hello'], 'notice'); - - static::assertCount(1, $collector->getMessages()); - - $collector->flush(); - - $msgs = $collector->getMessages(); - - static::assertCount(1, $msgs); - } - - public function testCollect() - { - $collector = new LogsDataCollector(new LogParser(), [__DIR__ . '/../Fixture/']); - $collector->addMessage('foo'); - - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - $data = $collector->getData(); - - static::assertEquals(1, $data['counted']); - static::assertEquals(1, $collector->getCountedLogs()); - static::assertEquals($collector->getMessages(), $data['messages']); - } - - public function testGetMenu() - { - $collector = new LogsDataCollector(new LogParser(), [__DIR__ . '/../Fixture/']); - - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - static::assertSame(['label' => 'Logs', 'value' => 1], $collector->getMenu()); - } - - public function testGetPanel() - { - $collector = new LogsDataCollector(new LogParser(), [__DIR__ . '/../Fixture/']); - - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - static::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":{}} []"
-
-
'), - preg_replace('/(\r\n|\n\r|\r)/', "\n", $this->removeSomeValues($collector->getPanel())) - ); - } - - private function removeSomeValues(string $html): string - { - $html = preg_replace('/]*>(.*?)<\/script>/', '', $html); - $html = preg_replace('/]*>(.*?)<\/style>/', '', $html); - $html = preg_replace('/value="content-(.*?)"/', '', $html); - $html = preg_replace('/id="content-(.*?)"/', '', $html); - $html = preg_replace('/id=sf-dump-(?:\d+) /', '', $html); - - return trim(preg_replace('/"id":"(.*?)"/', '', $html)); - } -} 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 72% rename from src/Viserio/Component/WebProfiler/AssetsRenderer.php rename to src/Viserio/Component/Profiler/AssetsRenderer.php index 716314e54..f9d599de7 100644 --- a/src/Viserio/Component/WebProfiler/AssetsRenderer.php +++ b/src/Viserio/Component/Profiler/AssetsRenderer.php @@ -1,13 +1,13 @@ __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', ]; /** - * The webprofiler instance. + * The profiler instance. * - * @var \Viserio\Component\Contracts\WebProfiler\WebProfiler + * @var \Viserio\Component\Contracts\Profiler\Profiler */ - protected $webprofiler; + protected $profiler; /** * Root path to the resources. @@ -73,7 +74,7 @@ class AssetsRenderer implements RenderableContract protected $ignoredCollectors = []; /** - * jQuery is used, remove zapto js. + * If jQuery is used, remove zapto. * * @var bool */ @@ -92,28 +93,19 @@ public function __construct(bool $jqueryIsUsed = false, string $rootPath = null) } /** - * Set the WebProfiler. - * - * @param \Viserio\Component\Contracts\WebProfiler\WebProfiler $webprofiler - * - * @return $this + * {@inheritdoc} */ - public function setWebProfiler(WebProfilerContract $webprofiler): self + public function setProfiler(ProfilerContract $profiler): AssetsRendererContract { - $this->webprofiler = $webprofiler; + $this->profiler = $profiler; return $this; } /** - * 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 +113,7 @@ public function setIcon(string $name, string $path): self } /** - * Get all registered icons. - * - * @return array + * {@inheritdoc} */ public function getIcons(): array { @@ -131,13 +121,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 +131,7 @@ public function setIgnoredCollector(string $name) } /** - * Returns the list of ignored collectors. - * - * @return array + * {@inheritdoc} */ public function getIgnoredCollectors(): array { @@ -159,11 +143,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'), ]); @@ -183,11 +167,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 +182,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 { @@ -228,16 +204,18 @@ function ($js) { $this->jsFiles ); - $additionalAssets = []; - - // finds assets provided by collectors - foreach ($this->webprofiler->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'])) { @@ -259,8 +237,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/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..9c9a5c48c 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 76% rename from src/Viserio/Component/WebProfiler/Controllers/OpenHandlerController.php rename to src/Viserio/Component/Profiler/Controllers/OpenHandlerController.php index f03b5472a..d7798ea4a 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 = $profiler; } /** diff --git a/src/Viserio/Component/WebProfiler/DataCollectors/AbstractDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php similarity index 88% rename from src/Viserio/Component/WebProfiler/DataCollectors/AbstractDataCollector.php rename to src/Viserio/Component/Profiler/DataCollectors/AbstractDataCollector.php index 1fdb10a2b..e2a0a11f9 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 . ''; @@ -198,21 +198,15 @@ 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 .= '
'; + $html .= '
'; $html .= $value['content']; $html .= '
'; } @@ -233,18 +227,19 @@ 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 .= ''; + $html .= ''; } $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 . '' . $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/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/Profiler/DataCollectors/Bridge/Cache/PhpCacheTraceableCacheDecorator.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/PhpCacheTraceableCacheDecorator.php new file mode 100644 index 000000000..1a204c8a1 --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/PhpCacheTraceableCacheDecorator.php @@ -0,0 +1,117 @@ +pool = $pool; + $this->name = get_class($pool); + $this->miss = new stdClass(); + } + + /** + * Get the original class name. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function clear() + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result = $this->pool->clear(); + } finally { + $event->end = microtime(true); + } + } + + /** + * Get a list of calls. + * + * @return array + */ + public function getCalls(): array + { + try { + return $this->calls; + } finally { + $this->calls = []; + } + } + + /** + * Start new event. + * + * @param string $name + * + * @return object + */ + private function start(string $name) + { + $this->calls[] = $event = new class() { + public $name; + public $start; + public $end; + public $result; + public $hits = 0; + public $misses = 0; + }; + + $event->name = $name; + $event->start = microtime(true); + + return $event; + } +} diff --git a/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6Psr16CacheDataCollector.php similarity index 79% rename from src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php rename to src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6Psr16CacheDataCollector.php index 6d63b3536..62bcdd78c 100644 --- a/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/Psr6CacheDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Psr6Psr16CacheDataCollector.php @@ -1,38 +1,57 @@ pools[$cache->getName()] = $cache; + if ($cache instanceof TraceableCacheItemDecorator || + $cache instanceof SimpleTraceableCacheDecorator || + $cache instanceof PhpCacheTraceableCacheDecorator + ) { + $this->pools[$cache->getName()] = $cache; + + return; + } + + throw new InvalidArgumentException(sprintf( + 'The object [%s] must be an instance of [%s] or [%s].', + get_class($cache), + TraceableCacheItemDecorator::class, + SimpleTraceableCacheDecorator::class + )); } /** @@ -105,11 +124,10 @@ public function getPanel(): string $calledCalls = []; foreach ($calls as $i => $call) { - $calledCalls[] =[ + $calledCalls[] = [ + $this->formatDuration($call->end - $call->start), $call->name, - $call->argument, $call->result, - $this->formatDuration($call->end - $call->start), ]; } @@ -117,7 +135,7 @@ public function getPanel(): string $calledCalls, [ 'name' => 'Calls', - 'headers' => ['Method', 'Argument', 'Result', 'Time'], + 'headers' => ['Time', 'Call', 'Hit'], ] ); @@ -134,8 +152,6 @@ public function getPanel(): string * Method returns amount of logged Cache reads: "get" calls. * * @return array - * - * @codeCoverageIgnore */ public function getStatistics(): array { @@ -146,8 +162,6 @@ public function getStatistics(): array * Method returns the statistic totals. * * @return array - * - * @codeCoverageIgnore */ public function getTotals(): array { @@ -158,8 +172,6 @@ public function getTotals(): array * Method returns all logged Cache call objects. * * @return int - * - * @codeCoverageIgnore */ public function getCalls(): int { @@ -217,10 +229,10 @@ private function calculateStatistics(): array $statistics[$name]['time'] = $statistics[$name]['time']; if ($statistics[$name]['reads']) { - $statistics[$name]['hits/reads'] = + $statistics[$name]['hits'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2) . '%'; } else { - $statistics[$name]['hits/reads'] = 'N/A'; + $statistics[$name]['hits'] = 0; } } @@ -249,9 +261,9 @@ private function calculateTotalStatistics(): array } if ($totals['reads']) { - $totals['hits/reads'] = round(100 * $totals['hits'] / $totals['reads'], 2) . '%'; + $totals['hits'] = round(100 * $totals['hits'] / $totals['reads'], 2) . '%'; } else { - $totals['hits/reads'] = 'N/A'; + $totals['hits'] = 0; } return $totals; diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/SimpleTraceableCacheDecorator.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/SimpleTraceableCacheDecorator.php new file mode 100644 index 000000000..5dc55bca5 --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/SimpleTraceableCacheDecorator.php @@ -0,0 +1,119 @@ +pool = $pool; + $this->name = get_class($pool); + $this->miss = new stdClass(); + } + + /** + * Get the original class name. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function clear() + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result = $this->pool->clear(); + } finally { + $event->end = microtime(true); + } + } + + /** + * Get a list of calls. + * + * @return array + */ + public function getCalls(): array + { + try { + return $this->calls; + } finally { + $this->calls = []; + } + } + + /** + * Start new event. + * + * @param string $name + * + * @return object + */ + private function start(string $name) + { + $this->calls[] = $event = new class() { + public $name; + public $start; + public $end; + public $result; + public $hits = 0; + public $misses = 0; + }; + + $event->name = $name; + $event->start = microtime(true); + + return $event; + } +} diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorator.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorator.php new file mode 100644 index 000000000..55a4a0797 --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorator.php @@ -0,0 +1,110 @@ +name = get_class($pool); + $this->pool = $pool; + } + + /** + * Get the original class name. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function clear() + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result = $this->pool->clear(); + } finally { + $event->end = microtime(true); + } + } + + /** + * Get a list of calls. + * + * @return array + */ + public function getCalls(): array + { + try { + return $this->calls; + } finally { + $this->calls = []; + } + } + + /** + * Start new event. + * + * @param string $name + * + * @return object + */ + private function start(string $name) + { + $this->calls[] = $event = new class() { + public $name; + public $start; + public $end; + public $result; + public $hits = 0; + public $misses = 0; + }; + + $event->name = $name; + $event->start = microtime(true); + + return $event; + } +} diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Traits/SimpleTraceableCacheDecoratorTrait.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Traits/SimpleTraceableCacheDecoratorTrait.php new file mode 100644 index 000000000..948816ebc --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Traits/SimpleTraceableCacheDecoratorTrait.php @@ -0,0 +1,152 @@ +miss; + $event = $this->start(__FUNCTION__); + + try { + $value = $this->pool->get($key, $miss); + } finally { + $event->end = microtime(true); + } + + if ($event->result[$key] = $miss !== $value) { + ++$event->hits; + } else { + ++$event->misses; + $value = $default; + } + + return $value; + } + + /** + * {@inheritdoc} + */ + public function has($key) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result[$key] = $this->pool->has($key); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function delete($key) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result[$key] = $this->pool->delete($key); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function set($key, $value, $ttl = null) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result[$key] = $this->pool->set($key, $value, $ttl); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function setMultiple($values, $ttl = null) + { + $event = $this->start(__FUNCTION__); + $event->result['keys'] = []; + + if ($values instanceof Traversable) { + $values = function () use ($values, $event) { + foreach ($values as $k => $v) { + $event->result['keys'][] = $k; + + yield $k => $v; + } + }; + $values = $values(); + } elseif (is_array($values)) { + $event->result['keys'] = array_keys($values); + } + + try { + return $event->result['result'] = $this->pool->setMultiple($values, $ttl); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function getMultiple($keys, $default = null) + { + $miss = null !== $default && is_object($default) ? $default : $this->miss; + $event = $this->start(__FUNCTION__); + + try { + $result = $this->pool->getMultiple($keys, $miss); + } finally { + $event->end = microtime(true); + } + + $f = function () use ($result, $event, $miss, $default) { + $event->result = []; + foreach ($result as $key => $value) { + if ($event->result[$key] = $miss !== $value) { + ++$event->hits; + } else { + ++$event->misses; + $value = $default; + } + yield $key => $value; + } + }; + + return $f(); + } + + /** + * {@inheritdoc} + */ + public function deleteMultiple($keys) + { + $event = $this->start(__FUNCTION__); + + if ($keys instanceof Traversable) { + $keys = $event->result['keys'] = iterator_to_array($keys, false); + } else { + $event->result['keys'] = $keys; + } + + try { + return $event->result['result'] = $this->pool->deleteMultiple($keys); + } finally { + $event->end = microtime(true); + } + } +} diff --git a/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Traits/TraceableCacheItemDecoratorTrait.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Traits/TraceableCacheItemDecoratorTrait.php new file mode 100644 index 000000000..a943820af --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Cache/Traits/TraceableCacheItemDecoratorTrait.php @@ -0,0 +1,144 @@ +start(__FUNCTION__); + + try { + $item = $this->pool->getItem($key); + } finally { + $event->end = microtime(true); + } + + if ($event->result[$key] = $item->isHit()) { + ++$event->hits; + } else { + ++$event->misses; + } + + return $item; + } + + /** + * {@inheritdoc} + */ + public function hasItem($key) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result[$key] = $this->pool->hasItem($key); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function deleteItem($key) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result[$key] = $this->pool->deleteItem($key); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function save(CacheItemInterface $item) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result[$item->getKey()] = $this->pool->save($item); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function saveDeferred(CacheItemInterface $item) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result[$item->getKey()] = $this->pool->saveDeferred($item); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function getItems(array $keys = []) + { + $event = $this->start(__FUNCTION__); + + try { + $result = $this->pool->getItems($keys); + } finally { + $event->end = microtime(true); + } + + $f = function () use ($result, $event) { + $event->result = []; + + foreach ($result as $key => $item) { + if ($event->result[$key] = $item->isHit()) { + ++$event->hits; + } else { + ++$event->misses; + } + + yield $key => $item; + } + }; + + return $f(); + } + + /** + * {@inheritdoc} + */ + public function deleteItems(array $keys) + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result = $this->pool->deleteItems($keys); + } finally { + $event->end = microtime(true); + } + } + + /** + * {@inheritdoc} + */ + public function commit() + { + $event = $this->start(__FUNCTION__); + + try { + return $event->result = $this->pool->commit(); + } finally { + $event->end = microtime(true); + } + } +} 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..27947c480 --- /dev/null +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/Log/MonologLoggerDataCollector.php @@ -0,0 +1,397 @@ +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))); + } + } + + /** + * {@inheritdoc} + */ + 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'], + ]; + } + + /** + * {@inheritdoc} + */ + public function getTooltip(): string + { + $html = $this->createTooltipGroup([ + 'Errors' => $this->getCountedErrors(), + 'Warnings' => $this->getCountedWarnings(), + 'Deprecations' => $this->getCountedDeprecations(), + ]); + + return $html; + } + + /** + * {@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; + } + + /** + * {@inheritdoc} + */ + public function collect(ServerRequestInterface $serverRequest, ResponseInterface $response): void + { + $data = $this->getComputedErrorsCount(); + + $data['logs'] = $this->sanitizeLogs($this->getLogs()); + $data['counted'] = count($data['logs']); + + $this->data = $data; + } + + /** + * Get log error priorities. + * + * @return array + */ + public function getPriorities(): array + { + return $this->data['priorities'] ?? []; + } + + /** + * Get counted errors. + * + * @return int + */ + public function getCountedErrors(): int + { + return $this->data['error_count'] ?? 0; + } + + /** + * Get counted deprecations. + * + * @return int + */ + public function getCountedDeprecations(): int + { + return $this->data['deprecation_count'] ?? 0; + } + + /** + * 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; + } + + /** + * Get counted logs. + * + * @return int + */ + public function getCountedLogs(): int + { + return $this->data['counted'] ?? 0; + } + + /** + * Returns collected logs. + * + * @return array + */ + public function getLogs(): array + { + if ($logger = $this->getDebugLogger()) { + return $logger->getLogs(); + } + + return []; + } + + /** + * 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; + } + + /** + * Undocumented function. + * + * @param array $logs + * + * @return array + */ + private function sanitizeLogs(array $logs): array + { + $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); + } + + /** + * Undocumented function. + * + * @param array $log + * + * @return bool + */ + 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; + } + + /** + * Get computed log error levels. + * + * @return array + */ + private function getComputedErrorsCount(): array + { + $errorCount = 0; + + if ($logger = $this->getDebugLogger()) { + $errorCount = $logger->countErrors(); + } + + $count = [ + 'error_count' => $errorCount, + 'deprecation_count' => 0, + 'warning_count' => 0, + 'scream_count' => 0, + 'priorities' => [], + ]; + + foreach ($this->getLogs() 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; + } + + /** + * 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/WebProfiler/DataCollectors/Bridge/PDO/PDODataCollector.php b/src/Viserio/Component/Profiler/DataCollectors/Bridge/PDO/PDODataCollector.php similarity index 70% rename from src/Viserio/Component/WebProfiler/DataCollectors/Bridge/PDO/PDODataCollector.php rename to src/Viserio/Component/Profiler/DataCollectors/Bridge/PDO/PDODataCollector.php index 908db7715..4ce328f6f 100644 --- a/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/PDO/PDODataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollectors/Bridge/PDO/PDODataCollector.php @@ -1,24 +1,24 @@ has(ProfilerContract::class)) { + $profiler = $container->get(ProfilerContract::class); + } + + $this->profiler = $profiler; + } + + /** + * {@inheritdoc} + */ + 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; + } + + // 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 6d5d0db9d..b628a376f 100644 --- a/src/Viserio/Component/WebProfiler/Profile.php +++ b/src/Viserio/Component/Profiler/Profile.php @@ -1,9 +1,9 @@ addCollector($collector); + $this->addCollector($collector['collector']); } } /** * Adds a Collector. * - * @param \Viserio\Component\Contracts\WebProfiler\DataCollector $collector + * @param \Viserio\Component\Contracts\Profiler\DataCollector $collector * * @return void */ diff --git a/src/Viserio/Component/WebProfiler/WebProfiler.php b/src/Viserio/Component/Profiler/Profiler.php similarity index 86% rename from src/Viserio/Component/WebProfiler/WebProfiler.php rename to src/Viserio/Component/Profiler/Profiler.php index e6fa579ea..489e62446 100644 --- a/src/Viserio/Component/WebProfiler/WebProfiler.php +++ b/src/Viserio/Component/Profiler/Profiler.php @@ -1,6 +1,6 @@ assetsRenderer = $assetsRenderer->setWebProfiler($this); + $this->assetsRenderer = $assetsRenderer->setProfiler($this); } /** @@ -99,7 +100,7 @@ public function enable(): void /** * {@inheritdoc} */ - public function setUrlGenerator(UrlGeneratorContract $urlGenerator): WebProfilerContract + public function setUrlGenerator(UrlGeneratorContract $urlGenerator): ProfilerContract { $this->urlGenerator = $urlGenerator; @@ -115,13 +116,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 +130,7 @@ public function setTemplate(string $path): WebProfilerContract } /** - * Get the webprofiler template path. + * Get the Profiler template path. * * @return string */ @@ -141,7 +142,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,21 +197,21 @@ 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\Contracts\Profiler\AssetsRenderer */ - public function getAssetsRenderer(): AssetsRenderer + public function getAssetsRenderer(): AssetsRendererContract { return $this->assetsRenderer; } @@ -223,9 +224,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); @@ -282,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/Log/Providers/LogsDataCollectorServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php similarity index 50% rename from src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php index c047fd2a3..23789888f 100644 --- a/src/Viserio/Component/Log/Providers/LogsDataCollectorServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerMonologDataCollectorServiceProvider.php @@ -1,22 +1,21 @@ [self::class, 'createLogParser'], - WebProfilerContract::class => [self::class, 'createWebProfiler'], + ProfilerContract::class => [self::class, 'extendProfiler'], + Logger::class => [self::class, 'extendLogger'], ]; } @@ -41,15 +40,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; - } - - /** - * {@inheritdoc} - */ - public function getMandatoryOptions(): iterable - { - return ['logs_storages']; + return ['viserio', 'profiler']; } /** @@ -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\WebProfiler\WebProfiler + * @return null|\Viserio\Component\Contracts\Profiler\Profiler */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract + 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'] - )); + if (self::$options['collector']['logs'] === true && $container->has(Logger::class)) { + $profiler->addCollector(new MonologLoggerDataCollector($container->get(Logger::class))); } return $profiler; } - // @codeCoverageIgnoreStart - return null; - // @codeCoverageIgnoreEnd + + return $profiler; } /** diff --git a/src/Viserio/Component/WebProfiler/Providers/WebProfilerPDOBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php similarity index 62% rename from src/Viserio/Component/WebProfiler/Providers/WebProfilerPDOBridgeServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerPDOBridgeServiceProvider.php index a195a319b..3ccd68c0d 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,17 +31,17 @@ 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 { - if ($getPrevious !== null) { - $pdo = $getPrevious(); + $pdo = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + if ($pdo !== null) { return new TraceablePDODecorater($pdo); } - return null; + return $pdo; } /** @@ -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 { $profiler = $getPrevious(); diff --git a/src/Viserio/Component/Profiler/Providers/ProfilerPsr6Psr16CacheBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6Psr16CacheBridgeServiceProvider.php new file mode 100644 index 000000000..0afed9488 --- /dev/null +++ b/src/Viserio/Component/Profiler/Providers/ProfilerPsr6Psr16CacheBridgeServiceProvider.php @@ -0,0 +1,118 @@ + [self::class, 'createCacheItemPoolDecorator'], + CacheInterface::class => [self::class, 'createSimpleTraceableCacheDecorator'], + ProfilerContract::class => [self::class, 'createProfiler'], + ]; + } + + /** + * Decorate CacheItemPool instances. + * + * @param \Interop\Container\ContainerInterface $container + * @param null|callable $getPrevious + * + * @return null|\Psr\Cache\CacheItemPoolInterface + */ + public static function createCacheItemPoolDecorator(ContainerInterface $container, ?callable $getPrevious = null): ?CacheItemPoolInterface + { + $cache = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + + if ($cache !== null) { + if (self::checkForPhpCacheNamespace($cache)) { + return new PhpCacheTraceableCacheDecorator($cache); + } + + return new TraceableCacheItemDecorator($cache); + } + + return $cache; + } + + /** + * Decorate SimpleTraceableCache instances. + * + * @param \Interop\Container\ContainerInterface $container + * @param null|callable $getPrevious + * + * @return null|\Psr\SimpleCache\CacheInterface + */ + public static function createSimpleTraceableCacheDecorator(ContainerInterface $container, ?callable $getPrevious = null): ?CacheInterface + { + $cache = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + + if ($cache !== null) { + if (self::checkForPhpCacheNamespace($cache)) { + return new PhpCacheTraceableCacheDecorator($cache); + } + + return new SimpleTraceableCacheDecorator($cache); + } + + return $cache; + } + + /** + * 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 + { + $profiler = is_callable($getPrevious) ? $getPrevious() : $getPrevious; + + if ($profiler !== null) { + $collector = new Psr6Psr16CacheDataCollector(); + + if ($container->has(CacheItemPoolInterface::class) || $container->has(CacheInterface::class)) { + if (($cache = $container->get(CacheItemPoolInterface::class)) instanceof TraceableCacheItemDecorator || + ($cache = $container->get(CacheInterface::class)) instanceof SimpleTraceableCacheDecorator || + ($cache = $container->get(CacheInterface::class)) instanceof PhpCacheTraceableCacheDecorator + ) { + $collector->addPool($cache); + } + } + + $profiler->addCollector($collector); + + return $profiler; + } + + return $profiler; + } + + private static function checkForPhpCacheNamespace($class): bool + { + $class = get_class($class); + $pos = mb_strrpos($class, '\\'); + + if ($pos === false) { + return false; + } + + return mb_strpos(mb_substr($class, 0, $pos), 'Cache\Adapter') !== false; + } +} diff --git a/src/Viserio/Component/WebProfiler/Providers/WebProfilerServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php similarity index 55% rename from src/Viserio/Component/WebProfiler/Providers/WebProfilerServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php index 9866c96d4..4631d2623 100644 --- a/src/Viserio/Component/WebProfiler/Providers/WebProfilerServiceProvider.php +++ b/src/Viserio/Component/Profiler/Providers/ProfilerServiceProvider.php @@ -1,6 +1,6 @@ [self::class, 'registerWebProfilerAssetsControllers'], - AssetsRenderer::class => [self::class, 'createAssetsRenderer'], - WebProfilerContract::class => [self::class, 'createWebProfiler'], - WebProfiler::class => function (ContainerInterface $container) { - return $container->get(WebProfilerContract::class); + 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); }, ]; } @@ -55,7 +55,7 @@ public function getServices() */ public function getDimensions(): iterable { - return ['viserio', 'webprofiler']; + return ['viserio', 'profiler']; } /** @@ -82,15 +82,15 @@ public function getDefaultOptions(): iterable ], 'jquery_is_used' => false, 'path' => null, - 'collectors' => null, + 'collectors' => [], ]; } - 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(); @@ -109,13 +109,11 @@ public static function createWebProfiler(ContainerInterface $container): WebProf ); 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 registerWebProfilerAssetsControllers(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\WebProfiler\Controllers', - 'prefix' => 'webprofiler', - ], - function ($router) { - $router->get('assets/stylesheets', [ - 'uses' => 'AssetController@css', - 'as' => 'webprofiler.assets.css', - ]); - $router->get('assets/javascript', [ - 'uses' => 'AssetController@js', - 'as' => 'webprofiler.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, WebProfiler $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, WebP } } - private static function registerCollectorsFromConfig(ContainerInterface $container, WebProfiler $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/WebProfiler/Providers/WebProfilerSwiftMailerBridgeServiceProvider.php b/src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php similarity index 53% rename from src/Viserio/Component/WebProfiler/Providers/WebProfilerSwiftMailerBridgeServiceProvider.php rename to src/Viserio/Component/Profiler/Providers/ProfilerSwiftMailerBridgeServiceProvider.php index c79a4417b..b2aef1233 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,11 +26,11 @@ 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 { - $profiler = $getPrevious(); + $profiler = is_callable($getPrevious) ? $getPrevious() : $getPrevious; if ($profiler !== null) { $profiler->addCollector(new SwiftMailDataCollector( diff --git a/src/Viserio/Component/WebProfiler/Proxies/WebProfiler.php b/src/Viserio/Component/Profiler/Proxies/Profiler.php similarity index 64% rename from src/Viserio/Component/WebProfiler/Proxies/WebProfiler.php rename to src/Viserio/Component/Profiler/Proxies/Profiler.php index 099099bd3..81322d457 100644 --- a/src/Viserio/Component/WebProfiler/Proxies/WebProfiler.php +++ b/src/Viserio/Component/Profiler/Proxies/Profiler.php @@ -1,10 +1,10 @@ Viserio Profiler Component +

+ + + + + +

+ + + +> **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). + +Installation +------------- + +Use [Composer](https://getcomposer.org/) to install this package: + +```sh +composer require viserio/profiler +``` + +Official Documentation +------------- + +Documentation for the framework can be found on the [Narrowspark website](http://narrowspark.com/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 +------------- + +The Narrowspark framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). diff --git a/src/Viserio/Component/WebProfiler/Resources/css/ajax-requests.css b/src/Viserio/Component/Profiler/Resources/css/ajax-requests.css similarity index 53% rename from src/Viserio/Component/WebProfiler/Resources/css/ajax-requests.css rename to src/Viserio/Component/Profiler/Resources/css/ajax-requests.css index 3575f0df3..a85cdac75 100644 --- a/src/Viserio/Component/WebProfiler/Resources/css/ajax-requests.css +++ b/src/Viserio/Component/Profiler/Resources/css/ajax-requests.css @@ -1,50 +1,50 @@ -.webprofiler-menu-ajax-requests-data-collector { +.profiler-menu-ajax-requests-data-collector { display: none; } -.webprofiler-menu-ajax-requests-data-collector.ajax-request { +.profiler-menu-ajax-requests-data-collector.ajax-request { display: inline-block; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-menu-icon svg { +.profiler-menu-ajax-requests-data-collector .profiler-menu-icon svg { transform: rotate(90deg) scaleX(-1); } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests { table-layout: auto; width: 100%; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests td { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests td { background-color: #444; border-bottom: 1px solid #777; color: #F5F5F5; font-size: 12px; padding: 4px; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests tr:last-child td { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests tr:last-child td { border-bottom: 0; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests th { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests th { background-color: #222; border-bottom: 0; color: #AAA; font-size: 11px; padding: 4px; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests .ajax-request-url { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests .ajax-request-url { max-width: 250px; line-height: 9px; overflow: hidden; text-overflow: ellipsis; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests .ajax-request-url a { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests .ajax-request-url a { text-decoration: none; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests .ajax-request-url a:hover { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests .ajax-request-url a:hover { text-decoration: underline; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests .ajax-request-duration { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests .ajax-request-duration { text-align: right; } -.webprofiler-menu-ajax-requests-data-collector .webprofiler-ajax-requests .ajax-request-loading { +.profiler-menu-ajax-requests-data-collector .profiler-ajax-requests .ajax-request-loading { -webkit-animation: ns-blink .5s ease-in-out infinite; -o-animation: ns-blink .5s ease-in-out infinite; -moz-animation: ns-blink .5s ease-in-out infinite; diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler-grid.css b/src/Viserio/Component/Profiler/Resources/css/profiler-grid.css new file mode 100644 index 000000000..8c7c0ccc8 --- /dev/null +++ b/src/Viserio/Component/Profiler/Resources/css/profiler-grid.css @@ -0,0 +1,31 @@ +.profiler * { + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + vertical-align: baseline; +} +.profiler .row:after, +.profiler .col:after, +.profiler .clearfix:after { + content: ""; + display: table; + clear: both; +} +.profiler .row { + display: -webkit-flex; + display: -ms-flexbox; + display: flex; +} +.profiler .col { + -webkit-flex: 1; + -ms-flex: 1; + flex: 1; +} +@media (max-width : 480px) { + .profiler .row { + display: block; + } + .profiler .col { + width: 100%; + } +} diff --git a/src/Viserio/Component/Profiler/Resources/css/profiler.css b/src/Viserio/Component/Profiler/Resources/css/profiler.css new file mode 100644 index 000000000..f7096ef84 --- /dev/null +++ b/src/Viserio/Component/Profiler/Resources/css/profiler.css @@ -0,0 +1,538 @@ +:root { + --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-even: #eee; + --profiler-table-body-background-color-odd: #fff; +} + +.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; + left: 0; + + margin: 0; + padding: 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; +} + + +.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; +} +.profiler .profiler-show-button.active, +.profiler .profiler-body.active, +.profiler .profiler-body .profiler-panel.active, +.profiler .profiler-body .profiler-panel .selected-content.active { + display: block; +} + +.profiler .profiler-header { + position: absolute; + z-index: 9999; + right: 0; + bottom: 0; + left: 0; + + background-color: var(--profiler-profiler-background-color); +} + +.profiler .profiler-show-button { + position: fixed; + z-index: 99999; + right: 0; + bottom: 0; + + display: none; + + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + height: 36px; + padding: 6px; + + cursor: pointer; + + border-top-left-radius: 4px; + background-color: var(--profiler-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 { + display: block; + float: right; + + width: 36px; + height: 36px; + + cursor: pointer; + text-align: center; + + background: var(--profiler-menu-background-active-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 { + 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; + + min-width: 15px; + min-height: 13px; + margin-bottom: 2px; + padding: 3px 6px; + + text-align: center; + vertical-align: middle; + + color: #fff; + 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, +.profiler .profiler-header .profiler-menus .profiler-menu .status-green + .status-green { + border-left: 5px solid #444; +} +.profiler .profiler-header .profiler-menus .profiler-menu .status-green { + background-color: var(--profiler-status-green-color); +} +.profiler .profiler-header .profiler-menus .profiler-menu .status-yellow { + color: #fff; + background-color: var(--profiler-status-yellow-color); +} +.profiler .profiler-header .profiler-menus .profiler-menu .status-red { + 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(--profiler-menu-background-active-color); +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover { + cursor: help; +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-panel:hover { + cursor: pointer; +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip .profiler-menu-tooltip { + display: none; +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-has-tooltip:hover .profiler-menu-tooltip { + position: absolute; + bottom: 36px; + + display: block; + overflow: hidden; + overflow-y: auto; + + max-width: 480px; + max-height: 480px; + padding: 10px; + + word-wrap: break-word; + + 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; + padding-bottom: 4px; + + 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 { + 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 { + 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 { + font-size: 12px; + + display: table-cell; + + 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; +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-position-left.profiler-menu-has-tooltip:hover .profiler-menu-tooltip { + left: 0; +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-position-right.profiler-menu-has-tooltip:hover .profiler-menu-tooltip { + right: 0; +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-position-left { + float: left; +} +.profiler .profiler-header .profiler-menus .profiler-menu.profiler-menu-position-right { + float: right; +} +.profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-content { + line-height: 36px; + + display: block; + + 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 { + padding: 0 7px; +} +.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 { + font-size: 13px; + line-height: 36px; + + display: inline-block; + + padding: 0; + + color: var(--profiler-font-color); +} +.profiler .profiler-header .profiler-menus .profiler-menu .profiler-menu-icon .profiler-menu-value { + margin-left: 4px; +} + +.profiler .profiler-body { + position: relative; + z-index: 9998; + + display: none; + + height: 324px; + margin-bottom: 36px; + + 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; +} +.profiler .profiler-body pre.sf-dump, +.profiler .profiler-body pre.sf-dump .sf-dump-num, +.profiler .profiler-body pre.sf-dump .sf-dump-const, +.profiler .profiler-body pre.sf-dump .sf-dump-str, +.profiler .profiler-body pre.sf-dump .sf-dump-note, +.profiler .profiler-body pre.sf-dump .sf-dump-ref, +.profiler .profiler-body pre.sf-dump .sf-dump-public, +.profiler .profiler-body pre.sf-dump .sf-dump-protected, +.profiler .profiler-body pre.sf-dump .sf-dump-private, +.profiler .profiler-body pre.sf-dump .sf-dump-meta, +.profiler .profiler-body pre.sf-dump .sf-dump-key, +.profiler .profiler-body pre.sf-dump .sf-dump-index { + margin: 0; + padding: 0; + + color: #2b2a28; +} +.profiler .profiler-body .text-muted { + color: #999; +} +.profiler .profiler-body .profiler-panel { + 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-x: hidden; + overflow-y: auto; + + padding: 15px; +} +.profiler .profiler-body .profiler-panel .profiler-tabs { + position: relative; + + min-height: 180px; +} +.profiler .profiler-body .profiler-panel .profiler-tabs-tab label { + display: block; + + margin: 0 0 0 -1px; + padding: 10px 15px; + + cursor: pointer; + text-align: center; + + color: #fff; + border-bottom: 3px solid #fff; + background: var(--profiler-tab-default-color); +} +.profiler .profiler-body .profiler-panel .profiler-tabs-tab label span.counter { + display: inline-block; + + min-width: 15px; + min-height: 13px; + margin-bottom: 2px; + margin-left: 10px; + padding: 2px 6px 3px 6px; + + text-align: center; + vertical-align: middle; + + color: var(--profiler-tab-active-font-color); + background-color: #fff; +} +.profiler .profiler-body .profiler-panel .profiler-tabs-tab [type=radio] { + position: absolute; + + 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; + right: 0; + left: 0; + + overflow-y: auto; + + height: 247px; + padding: 15px 15px 0 15px; + + opacity: 0; +} +.profiler .profiler-body .profiler-panel .profiler-tabs .profiler-tabs-tab [type=radio]:checked ~ label { + z-index: 2; + + 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(--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; + opacity: 1; +} + +.profiler .profiler-body h3:first-child { + 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; +} +.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 { + margin-bottom: 25px; +} +.profiler .profiler-body .profiler-panel table + table { + margin-top: 30px; +} + +.profiler .profiler-body .profiler-panel table th, +.profiler .profiler-body .profiler-panel table td { + padding: 8px 10px; +} +.profiler .profiler-body .profiler-panel table th { + font-weight: bold; + + text-align: left; +} +.profiler .profiler-body .profiler-panel table thead th { + color: #fff; + background-color: var(--profiler-table-head-background-color); +} +.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-size: 13px; + font-size-adjust: .5; + + color: #2b2a28; + border: 1px solid var(--profiler-table-body-background-color-odd); + border-width: 1px 0; +} +.profiler .profiler-body .profiler-panel table tbody td { + word-break: break-all; + -ms-word-break: break-all; + -webkit-hyphens: auto; + -moz-hyphens: auto; + hyphens: auto; +} +.profiler .profiler-body .profiler-panel table tbody div { + margin: .25em 0; +} +.profiler .profiler-body .profiler-panel table tbody ul { + margin: 0; + padding: 0 0 0 1em; +} +.profiler .profiler-body .profiler-panel .empty { + font-size: 16px; + font-weight: bold; + + margin: 1em 0; + padding: .5em 2em; + + text-align: center; + + color: #fff; + border: 4px dashed var(--profiler-table-body-background-color-odd); +} + +.profiler .profiler-body .profiler-panel .metrics { + overflow: auto; + + margin: 0; + padding: 0; + + list-style: none; +} +.profiler .profiler-body .profiler-panel .metrics .metric { + display: inline-block; + + min-width: 100px; + min-height: 65px; + 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 { + font-size: 28px; + + display: block; + + padding: 8px 15px 4px; + + text-align: center; + + color: #2b2a28; +} +.profiler .profiler-body .profiler-panel .metrics .metric .label { + 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; + + border: 0; +} + +.profiler .profiler-body .profiler-body-menu { + height: 24px; + + border-bottom: 1px solid #383838; + 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; +} +.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; + } +} diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/LICENSE b/src/Viserio/Component/Profiler/Resources/icons/LICENSE similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/LICENSE rename to src/Viserio/Component/Profiler/Resources/icons/LICENSE diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_clear_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_clear_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_clear_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_clear_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_insert_drive_file_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_insert_drive_file_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_insert_drive_file_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_insert_drive_file_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_keyboard_arrow_down_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_keyboard_arrow_down_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_keyboard_arrow_down_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_keyboard_arrow_down_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_keyboard_arrow_up_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_keyboard_arrow_up_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_keyboard_arrow_up_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_keyboard_arrow_up_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_layers_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_layers_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_layers_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_layers_white_24px.svg 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 @@ + + + + diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_mail_outline_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_mail_outline_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_mail_outline_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_mail_outline_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_memory_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_memory_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_memory_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_memory_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_message_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_message_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_message_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_message_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_narrowspark_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_narrowspark_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_narrowspark_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_narrowspark_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_repeat_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_repeat_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_repeat_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_repeat_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_schedule_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_schedule_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_schedule_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_schedule_white_24px.svg diff --git a/src/Viserio/Component/WebProfiler/Resources/icons/ic_storage_white_24px.svg b/src/Viserio/Component/Profiler/Resources/icons/ic_storage_white_24px.svg similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/icons/ic_storage_white_24px.svg rename to src/Viserio/Component/Profiler/Resources/icons/ic_storage_white_24px.svg diff --git a/src/Viserio/Component/Profiler/Resources/js/ajaxHandler.js b/src/Viserio/Component/Profiler/Resources/js/ajaxHandler.js new file mode 100644 index 000000000..dfc7d3ad0 --- /dev/null +++ b/src/Viserio/Component/Profiler/Resources/js/ajaxHandler.js @@ -0,0 +1,13 @@ +/** + * AjaxHandler + * + * Extract data from headers of an XMLHttpRequest and adds a new dataset + */ +var AjaxHandler = Profiler.AjaxHandler = function(Profiler, headerName) { + this.profiler = Profiler; + this.headerName = headerName || 'Profiler'; +}; + +Profiler.$.extend(AjaxHandler.prototype, { + +}); diff --git a/src/Viserio/Component/WebProfiler/Resources/js/webprofiler.js b/src/Viserio/Component/Profiler/Resources/js/profiler.js similarity index 61% rename from src/Viserio/Component/WebProfiler/Resources/js/webprofiler.js rename to src/Viserio/Component/Profiler/Resources/js/profiler.js index 2ccdbabd4..ceb23af89 100644 --- a/src/Viserio/Component/WebProfiler/Resources/js/webprofiler.js +++ b/src/Viserio/Component/Profiler/Resources/js/profiler.js @@ -1,8 +1,8 @@ -if (typeof(WebProfiler) == 'undefined') { +if (typeof(Profiler) == 'undefined') { // namespace - var WebProfiler = {}; + var Profiler = {}; - WebProfiler.$ = Zepto; + Profiler.$ = Zepto; } (function($) { @@ -21,10 +21,11 @@ if (typeof(WebProfiler) == 'undefined') { var openPanel = false; // helper vars for long class names - var panelBodyClass = '.webprofiler .webprofiler-body'; - var panelClass = panelBodyClass + ' .webprofiler-panel'; - var menuHasPanel = '.webprofiler .webprofiler-header .webprofiler-menus .webprofiler-menu.webprofiler-menu-has-panel'; - var bodyMenu = panelBodyClass + ' .webprofiler-body-menu'; + var panelBodyClass = '.profiler .profiler-body'; + 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; @@ -41,14 +42,14 @@ if (typeof(WebProfiler) == 'undefined') { }; var resizeBodyAndTabContent = function(panelHeight, tabContentHeight) { $(panelBodyClass).height(panelHeight); - $('.webprofiler-tabs-tab-content').height(tabContentHeight); + $('.profiler-tabs-tab-content').height(tabContentHeight); setPreference('panelHeight', panelHeight); setPreference('tabContentHeight', tabContentHeight); }; // Symfony VarDumper: Close the by default expanded objects - WebProfiler.symfony = function() { + Profiler.symfony = function() { $('.sf-dump-expanded') .removeClass('sf-dump-expanded') .addClass('sf-dump-compact'); @@ -57,7 +58,7 @@ if (typeof(WebProfiler) == 'undefined') { }; // Toggle Panel - WebProfiler.toggle = function() { + Profiler.toggle = function() { $(menuHasPanel).on('click', function(e) { e.preventDefault(); @@ -90,36 +91,36 @@ if (typeof(WebProfiler) == 'undefined') { }); }; - WebProfiler.openCloseHandler = function() { - // close webprofiler-body panel - $(bodyMenu + ' .webprofiler-body-close-panel').on('click', function(e) { + Profiler.openCloseHandler = function() { + // close profiler-body panel + $(bodyMenu + ' .profiler-body-close-panel').on('click', function(e) { $(menuHasPanel + ', ' + panelBodyClass + ', ' + openPanel).removeClass('active'); openPanel = false; }); - // close webprofiler button - $('.webprofiler .webprofiler-header .webprofiler-hide-button').on('click', function(e) { + // close button + $('.profiler .profiler-header .profiler-hide-button').on('click', function(e) { e.preventDefault(); openPanel = false; - $('.webprofiler .webprofiler-body, ' + panelClass).removeClass('active'); - $('.webprofiler .webprofiler-header').addClass('hide'); - $('.webprofiler .webprofiler-show-button').addClass('active'); + $('.profiler .profiler-body, ' + panelClass).removeClass('active'); + $(profilerHeader).addClass('hide'); + $('.profiler .profiler-show-button').addClass('active'); }); // open button - $('.webprofiler .webprofiler-show-button').on('click', function(e) { + $('.profiler .profiler-show-button').on('click', function(e) { e.preventDefault(); - $('.webprofiler .webprofiler-header').removeClass('hide'); - $('.webprofiler .webprofiler-show-button').removeClass('active'); + $(profilerHeader).removeClass('hide'); + $('.profiler .profiler-show-button').removeClass('active'); }); }; // select content - WebProfiler.selectContent = function() { + Profiler.selectContent = function() { var selected = $(panelClass + ' .content-selector option').not(function () { return !this.selected; }); @@ -139,21 +140,22 @@ if (typeof(WebProfiler) == 'undefined') { }); }; - WebProfiler.resize = function() { + Profiler.resize = function() { var resizeIsActive = false; - var panelHeight = $(window).height() - 38; - var tabContentHeight = $(panelBodyClass).height() - 87; - $(bodyMenu + ' .webprofiler-body-resize-panel').on('click', function(e) { + $(bodyMenu + ' .profiler-body-resize-panel').on('click', function (e) { if (resizeIsActive) { resizeIsActive = false; $(panelBodyClass).height(null); - $('.webprofiler-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,19 +163,22 @@ if (typeof(WebProfiler) == '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); } }); }; - WebProfiler.restoreState = function() { + Profiler.restoreState = function() { }; -})(WebProfiler.$); - -WebProfiler.$(function() { - WebProfiler.symfony(); - WebProfiler.toggle(); - WebProfiler.openCloseHandler(); - WebProfiler.selectContent(); - WebProfiler.resize(); +})(Profiler.$); + +Profiler.$(function() { + Profiler.symfony(); + Profiler.toggle(); + Profiler.openCloseHandler(); + Profiler.selectContent(); + Profiler.resize(); }); diff --git a/src/Viserio/Component/WebProfiler/Resources/js/zepto.min.js b/src/Viserio/Component/Profiler/Resources/js/zepto.min.js similarity index 100% rename from src/Viserio/Component/WebProfiler/Resources/js/zepto.min.js rename to src/Viserio/Component/Profiler/Resources/js/zepto.min.js diff --git a/src/Viserio/Component/Profiler/Resources/views/profiler.html.php b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php new file mode 100644 index 000000000..8c20c904c --- /dev/null +++ b/src/Viserio/Component/Profiler/Resources/views/profiler.html.php @@ -0,0 +1,69 @@ + +
+ + + +
+ +
+ + + + $menu): + $tooltip = false; + + if (isset($menu['tooltip'])) { + $tooltip = true; + } + + $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="profiler-menu profiler-menu- profiler-menu-position-"> +
+ + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+
+ + $panel): ?> +
+ +
+ +
+
diff --git a/src/Viserio/Component/WebProfiler/TemplateManager.php b/src/Viserio/Component/Profiler/TemplateManager.php similarity index 85% rename from src/Viserio/Component/WebProfiler/TemplateManager.php rename to src/Viserio/Component/Profiler/TemplateManager.php index 92bbb2828..8ddefb23b 100644 --- a/src/Viserio/Component/WebProfiler/TemplateManager.php +++ b/src/Viserio/Component/Profiler/TemplateManager.php @@ -1,10 +1,10 @@ collectors as $name => $collector) { + $collector = $collector['collector']; + if ($collector instanceof TooltipAwareContract) { $data['menus'][$collector->getName()] = [ 'menu' => $collector->getMenu(), @@ -140,14 +142,14 @@ public function getSortedData(): array $panel = $collector->getPanel(); // @codeCoverageIgnoreStart - if (mb_strpos($panel, '
') !== false) { - $class = ' webprofiler-body-has-table'; + $class = ' profiler-body-has-metrics'; + } elseif (mb_strpos($panel, '') !== false) { + $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 55% rename from src/Viserio/Component/WebProfiler/Tests/AssetsRendererTest.php rename to src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php index e7ae580ab..4987e070f 100644 --- a/src/Viserio/Component/WebProfiler/Tests/AssetsRendererTest.php +++ b/src/Viserio/Component/Profiler/Tests/AssetsRendererTest.php @@ -1,13 +1,13 @@ 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,51 +28,56 @@ public function testSetAndGetIgnoredCollectors() $assets->setIgnoredCollector('test'); - static::assertSame('test', $assets->getIgnoredCollectors()[0]); + self::assertSame('test', $assets->getIgnoredCollectors()[0]); } public function testGetAssets() { - $profiler = $this->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')); - static::assertSame($jsAssets, $assets->getAssets('js')); + self::assertSame($cssAssets, $assets->getAssets('css')); + self::assertSame($jsAssets, $assets->getAssets('js')); } public function testGetAssetsFromCollectors() { - $profiler = $this->mock(WebProfilerContract::class); + $profiler = $this->mock(ProfilerContract::class); $profiler->shouldReceive('getCollectors') ->once() - ->andReturn([new AjaxRequestsDataCollector()]); + ->andReturn([ + 'ajax' => [ + 'collector' => new AjaxRequestsDataCollector(), + 'priority' => 100, + ], + ]); $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', ]; - static::assertSame([$cssAssets, $jsAssets], $assets->getAssets()); + self::assertSame([$cssAssets, $jsAssets], $assets->getAssets()); } public function testRenderWithUrlGenerator() @@ -84,15 +89,15 @@ 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()); + self::assertSame('', $assets->render()); } } diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6Psr16CacheDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6Psr16CacheDataCollectorTest.php new file mode 100644 index 000000000..3b3d97c34 --- /dev/null +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/Psr6Psr16CacheDataCollectorTest.php @@ -0,0 +1,62 @@ +getPsr6CacheDataCollector(); + + self::assertSame( + [ + 'icon' => 'ic_layers_white_24px.svg', + 'label' => '0 in', + 'value' => '0μs', + ], + $collector->getMenu() + ); + } + + public function testGetTooltip() + { + $collector = $this->getPsr6CacheDataCollector(); + + self::assertSame( + '
Cache calls0
Total time0μs
Cache hits0
Cache writes0
', + $collector->getTooltip() + ); + } + + private function removeTabId(string $html): string + { + return trim(preg_replace('/="tab-0(.*?)"/', '', $html)); + } + + private function getPsr6CacheDataCollector() + { + $collector = new Psr6Psr16CacheDataCollector(); + $collector->addPool(new TraceableCacheItemDecorator(new ArrayCachePool())); + $collector->collect( + $this->mock(ServerRequestInterface::class), + $this->mock(ResponseInterface::class) + ); + + return $collector; + } + + private function removeSymfonyVarDumper(string $html): string + { + $html = preg_replace('/]*>(.*?)<\/script>/', '', $html); + $html = preg_replace('/]*>(.*?)<\/style>/', '', $html); + + return $this->removeTabId(preg_replace('/id=sf-dump-(?:\d+) /', '', $html)); + } +} diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/SimpleTraceableCacheDecoratorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/SimpleTraceableCacheDecoratorTest.php new file mode 100644 index 000000000..938cc49d9 --- /dev/null +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/SimpleTraceableCacheDecoratorTest.php @@ -0,0 +1,184 @@ +createSimpleCache(); + $pool->get('k'); + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertSame('get', $call->name); + self::assertSame(['k' => false], $call->result); + self::assertSame(0, $call->hits); + self::assertSame(1, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testGetHitTrace() + { + $pool = $this->createSimpleCache(); + $pool->set('k', 'foo'); + $pool->get('k'); + $calls = $pool->getCalls(); + + self::assertCount(2, $calls); + + $call = $calls[1]; + + self::assertSame(1, $call->hits); + self::assertSame(0, $call->misses); + } + + public function testGetMultipleMissTrace() + { + $pool = $this->createSimpleCache(); + $pool->set('k1', 123); + + $values = $pool->getMultiple(['k0', 'k1']); + + foreach ($values as $value) { + } + + $calls = $pool->getCalls(); + + self::assertCount(2, $calls); + + $call = $calls[1]; + + self::assertSame('getMultiple', $call->name); + self::assertSame(['k0' => false, 'k1' => true], $call->result); + self::assertSame(1, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testHasMissTrace() + { + $pool = $this->createSimpleCache(); + $pool->has('k'); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertSame('has', $call->name); + self::assertSame(['k' => false], $call->result); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testHasHitTrace() + { + $pool = $this->createSimpleCache(); + $pool->set('k', 'foo'); + $pool->has('k'); + + $calls = $pool->getCalls(); + + self::assertCount(2, $calls); + + $call = $calls[1]; + + self::assertSame('has', $call->name); + self::assertSame(['k' => true], $call->result); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testDeleteTrace() + { + $pool = $this->createSimpleCache(); + $pool->delete('k'); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertSame('delete', $call->name); + self::assertSame(['k' => true], $call->result); + self::assertSame(0, $call->hits); + self::assertSame(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testDeleteMultipleTrace() + { + $pool = $this->createSimpleCache(); + $arg = ['k0', 'k1']; + + $pool->deleteMultiple($arg); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertSame('deleteMultiple', $call->name); + self::assertSame(['keys' => $arg, 'result' => true], $call->result); + self::assertSame(0, $call->hits); + self::assertSame(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testTraceSetTrace() + { + $pool = $this->createSimpleCache(); + $pool->set('k', 'foo'); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertSame('set', $call->name); + self::assertSame(['k' => true], $call->result); + self::assertSame(0, $call->hits); + self::assertSame(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testSetMultipleTrace() + { + $pool = $this->createSimpleCache(); + $pool->setMultiple(['k' => 'foo']); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertSame('setMultiple', $call->name); + self::assertSame(['keys' => ['k'], 'result' => true], $call->result); + self::assertSame(0, $call->hits); + self::assertSame(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + private function createSimpleCache() + { + return new SimpleTraceableCacheDecorator(new ArrayCachePool()); + } +} diff --git a/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoratorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoratorTest.php new file mode 100644 index 000000000..5159a4d11 --- /dev/null +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoratorTest.php @@ -0,0 +1,220 @@ +createCachePool(); + $pool->getItem('k'); + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertEquals('getItem', $call->name); + self::assertSame(['k' => false], $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(1, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testGetItemHitTrace() + { + $pool = $this->createCachePool(); + $item = $pool->getItem('k')->set('foo'); + $pool->save($item); + $pool->getItem('k'); + $calls = $pool->getCalls(); + + self::assertCount(3, $calls); + + $call = $calls[2]; + + self::assertEquals(1, $call->hits); + self::assertEquals(0, $call->misses); + } + + public function testGetItemsMissTrace() + { + $pool = $this->createCachePool(); + $arg = ['k0', 'k1']; + $items = $pool->getItems($arg); + + foreach ($items as $item) { + } + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertEquals('getItems', $call->name); + self::assertSame(['k0' => false, 'k1' => false], $call->result); + self::assertEquals(2, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testHasItemMissTrace() + { + $pool = $this->createCachePool(); + $pool->hasItem('k'); + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertEquals('hasItem', $call->name); + self::assertSame(['k' => false], $call->result); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testHasItemHitTrace() + { + $pool = $this->createCachePool(); + $item = $pool->getItem('k')->set('foo'); + $pool->save($item); + $pool->hasItem('k'); + $calls = $pool->getCalls(); + + self::assertCount(3, $calls); + + $call = $calls[2]; + + self::assertEquals('hasItem', $call->name); + self::assertSame(['k' => true], $call->result); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testDeleteItemTrace() + { + $pool = $this->createCachePool(); + $pool->deleteItem('k'); + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertEquals('deleteItem', $call->name); + self::assertSame(['k' => true], $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testDeleteItemsTrace() + { + $pool = $this->createCachePool(); + $arg = ['k0', 'k1']; + + $pool->deleteItems($arg); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertEquals('deleteItems', $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 testSaveTrace() + { + $pool = $this->createCachePool(); + $item = $pool->getItem('k')->set('foo'); + $pool->save($item); + $calls = $pool->getCalls(); + + self::assertCount(2, $calls); + + $call = $calls[1]; + + self::assertEquals('save', $call->name); + self::assertSame(['k' => true], $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testSaveDeferredTrace() + { + $pool = $this->createCachePool(); + $item = $pool->getItem('k')->set('foo'); + $pool->saveDeferred($item); + $calls = $pool->getCalls(); + + self::assertCount(2, $calls); + + $call = $calls[1]; + + self::assertEquals('saveDeferred', $call->name); + self::assertSame(['k' => true], $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + public function testCommitTrace() + { + $pool = $this->createCachePool(); + $pool->commit(); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + 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() + { + $pool = $this->createCachePool(); + $pool->clear(); + + $calls = $pool->getCalls(); + + self::assertCount(1, $calls); + + $call = $calls[0]; + + self::assertEquals('clear', $call->name); + self::assertNull(null, $call->result); + self::assertEquals(0, $call->hits); + self::assertEquals(0, $call->misses); + self::assertNotEmpty($call->start); + self::assertNotEmpty($call->end); + } + + private function createCachePool() + { + return new TraceableCacheItemDecorator(new ArrayCachePool()); + } +} 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/WebProfiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php similarity index 70% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php index 93d17b5e5..27522b71b 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/Bridge/SwiftMailDataCollectorTest.php @@ -1,13 +1,13 @@ getSwiftDataCollector(); - static::assertSame( + self::assertSame( [ 'icon' => 'ic_mail_outline_white_24px.svg', 'label' => 'Mails', @@ -25,16 +25,6 @@ public function testGetMenu() ); } - public function testGetPanel() - { - $collector = $this->getSwiftDataCollector(); - - static::assertSame( - '
Empty
', - $collector->getPanel() - ); - } - private function getSwiftDataCollector() { $collector = new SwiftMailDataCollector( diff --git a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/DataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/DataCollectorTest.php similarity index 66% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/DataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/DataCollectorTest.php index 412559df9..cc1603dfa 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/DataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/DataCollectorTest.php @@ -1,9 +1,9 @@ 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,8 +45,8 @@ public function testCreateTooltipGroupDefault() { $collector = new FixtureDataCollector(); - static::assertSame( - '
testtest
', + self::assertSame( + '
testtest
', $collector->getTooltippGroupDefault() ); } @@ -55,8 +55,8 @@ public function testCreateTooltipGroupDefaultWithLink() { $collector = new FixtureDataCollector(); - static::assertSame( - '', + self::assertSame( + '', $collector->getTooltippGroupDefaultWithLink() ); } @@ -65,8 +65,8 @@ public function testCreateTooltipGroupArray() { $collector = new FixtureDataCollector(); - static::assertSame( - '
testtesttest2
', + self::assertSame( + '
testtesttest2
', $collector->getTooltippGroupArray() ); } @@ -75,8 +75,8 @@ public function testCreateTabs() { $collector = new FixtureDataCollector(); - static::assertSame( - $this->removeTabId('
test
'), + 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/WebProfiler/Tests/DataCollectors/MemoryDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php similarity index 70% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/MemoryDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/MemoryDataCollectorTest.php index 7e5a5ff88..b21ea20bb 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( + self::assertSame( [ 'icon' => 'ic_memory_white_24px.svg', 'label' => $data['memory'] / 1024 / 1024, @@ -41,8 +41,8 @@ public function testGetTooltip() $collect->updateMemoryUsage(); $data = $collect->getData(); - static::assertSame( - '
Peak memory usage' . $data['memory'] / 1024 / 1024 . ' MB
PHP memory limitUnlimited MB
', + self::assertSame( + '
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 69% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/MessagesDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php index 7a08157e9..33eec4cf5 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/MessagesDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/MessagesDataCollectorTest.php @@ -1,11 +1,11 @@ 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/WebProfiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php similarity index 61% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php index 154d44836..3273e8115 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/PhpInfoDataCollectorTest.php @@ -1,11 +1,11 @@ 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/WebProfiler/Tests/DataCollectors/TimeDataCollectorTest.php b/src/Viserio/Component/Profiler/Tests/DataCollectors/TimeDataCollectorTest.php similarity index 82% rename from src/Viserio/Component/WebProfiler/Tests/DataCollectors/TimeDataCollectorTest.php rename to src/Viserio/Component/Profiler/Tests/DataCollectors/TimeDataCollectorTest.php index 9f65541cc..490274072 100644 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/TimeDataCollectorTest.php +++ b/src/Viserio/Component/Profiler/Tests/DataCollectors/TimeDataCollectorTest.php @@ -1,11 +1,11 @@ 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/WebProfiler/Tests/Fixture/FixtureDataCollector.php b/src/Viserio/Component/Profiler/Tests/Fixture/FixtureDataCollector.php similarity index 93% rename from src/Viserio/Component/WebProfiler/Tests/Fixture/FixtureDataCollector.php rename to src/Viserio/Component/Profiler/Tests/Fixture/FixtureDataCollector.php index 3eb411a6d..43549894e 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Fixture/FixtureDataCollector.php +++ b/src/Viserio/Component/Profiler/Tests/Fixture/FixtureDataCollector.php @@ -1,10 +1,10 @@ array
KeyValue
"test value"
+
+
diff --git a/src/Viserio/Component/Profiler/Tests/Fixture/View/default_table.html b/src/Viserio/Component/Profiler/Tests/Fixture/View/default_table.html new file mode 100644 index 000000000..85da53cba --- /dev/null +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/default_table.html @@ -0,0 +1,3 @@ +

test

KeyValue
test key
"test value"
+
+
diff --git a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profile.html b/src/Viserio/Component/Profiler/Tests/Fixture/View/profile.html similarity index 87% rename from src/Viserio/Component/WebProfiler/Tests/Fixture/View/profile.html rename to src/Viserio/Component/Profiler/Tests/Fixture/View/profile.html index 092a4dba6..d30283b57 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/profile.html +++ b/src/Viserio/Component/Profiler/Tests/Fixture/View/profile.html @@ -1,17 +1,17 @@ -
- +
+ -
+
-
-
- +
+
+ - + 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..c0fea912b 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..4eb44302b 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..cd07f94f5 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 62% rename from src/Viserio/Component/WebProfiler/Tests/Middleware/WebProfilerMiddlewareTest.php rename to src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php index 8e1f0265a..0a38473fa 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Middleware/WebProfilerMiddlewareTest.php +++ b/src/Viserio/Component/Profiler/Tests/Middleware/ProfilerMiddlewareTest.php @@ -1,26 +1,28 @@ enable(); - $middleware = new WebProfilerMiddleware($profiler); + $middleware = new ProfilerMiddleware(new ArrayContainer([ProfilerContract::class => $profiler])); $template = new TemplateManager( [], $profiler->getTemplate(), @@ -30,6 +32,7 @@ public function testProcess() $server = $_SERVER; $server['SERVER_ADDR'] = '127.0.0.1'; + unset($server['PHP_SELF']); $renderedContent = $assets->render() . $template->render(); @@ -40,10 +43,11 @@ public function testProcess() return (new ResponseFactory())->createResponse(200); })); - static::assertEquals( + self::assertEquals( $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 @@ -52,7 +56,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 63% rename from src/Viserio/Component/WebProfiler/Tests/ProfileTest.php rename to src/Viserio/Component/Profiler/Tests/ProfileTest.php index 3305bb358..91f9ef0eb 100644 --- a/src/Viserio/Component/WebProfiler/Tests/ProfileTest.php +++ b/src/Viserio/Component/Profiler/Tests/ProfileTest.php @@ -1,10 +1,10 @@ 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() @@ -84,12 +84,14 @@ public function testSetGetHasAllCollectors() $collector = new PhpInfoDataCollector(); $profile->setCollectors([ - $collector, + $collector->getName() => [ + 'collector' => $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/WebProfiler/Tests/WebProfilerTest.php b/src/Viserio/Component/Profiler/Tests/ProfilerTest.php similarity index 76% rename from src/Viserio/Component/WebProfiler/Tests/WebProfilerTest.php rename to src/Viserio/Component/Profiler/Tests/ProfilerTest.php index 65e310e43..d92efe057 100644 --- a/src/Viserio/Component/WebProfiler/Tests/WebProfilerTest.php +++ b/src/Viserio/Component/Profiler/Tests/ProfilerTest.php @@ -1,47 +1,47 @@ getWebProfiler(); + $profiler = $this->getProfiler(); $profiler->setUrlGenerator($this->mock(UrlGeneratorContract::class)); - static::assertInstanceOf(UrlGeneratorContract::class, $profiler->getUrlGenerator()); + self::assertInstanceOf(UrlGeneratorContract::class, $profiler->getUrlGenerator()); } public function testSetAndGetTemplate() { - $profiler = $this->getWebProfiler(); + $profiler = $this->getProfiler(); $profiler->setTemplate(__DIR__); - static::assertSame(__DIR__, $profiler->getTemplate()); + self::assertSame(__DIR__, $profiler->getTemplate()); } public function testAddHasAndGetCollectors() { - $profiler = $this->getWebProfiler(); + $profiler = $this->getProfiler(); $collector = new PhpInfoDataCollector(); $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, @@ -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'; @@ -91,7 +91,7 @@ public function testModifyResponse() $renderedContent = $assets->render() . $template->render(); - static::assertEquals( + self::assertEquals( $this->removeId($renderedContent), $this->removeId((string) $response->getBody()) ); @@ -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( @@ -128,7 +128,7 @@ public function testModifyResponseWithOldContent() $renderedContent = $assets->render() . $template->render(); - static::assertEquals( + self::assertEquals( $this->removeId('' . $renderedContent . ''), $this->removeId((string) $response->getBody()) ); @@ -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'; @@ -151,16 +151,16 @@ public function testDontModifyResponse() $orginalResponse ); - static::assertEquals($response, $orginalResponse); + self::assertEquals($response, $orginalResponse); } 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/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerMonologDataCollectorServiceProviderTest.php similarity index 59% rename from src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php rename to src/Viserio/Component/Profiler/Tests/Providers/ProfilerMonologDataCollectorServiceProviderTest.php index 3a5ed2b30..425492645 100644 --- a/src/Viserio/Component/Log/Tests/Providers/LogsDataCollectorServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerMonologDataCollectorServiceProviderTest.php @@ -1,42 +1,44 @@ register(new OptionsResolverServiceProvider()); $container->instance(ServerRequestInterface::class, $this->getRequest()); + $container->register(new OptionsResolverServiceProvider()); + $container->register(new LoggerServiceProvider()); $container->register(new HttpFactoryServiceProvider()); - $container->register(new WebProfilerServiceProvider()); - $container->register(new LogsDataCollectorServiceProvider()); + $container->register(new ProfilerServiceProvider()); + $container->register(new ProfilerMonologDataCollectorServiceProvider()); $container->instance('config', [ 'viserio' => [ - 'webprofiler' => [ - 'enable' => true, - 'logs_storages' => [__DIR__], - 'collector' => [ + 'log' => [ + 'env' => 'prod', + ], + 'profiler' => [ + 'enable' => true, + 'collector' => [ 'logs' => true, ], ], ], ]); - 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/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..a176baaf3 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/ProfilerPsr6Psr16CacheBridgeServiceProviderTest.php similarity index 58% rename from src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPsr6CacheBridgeServiceProviderTest.php rename to src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6Psr16CacheBridgeServiceProviderTest.php index c5a26942a..a8a1232b7 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Providers/WebProfilerPsr6CacheBridgeServiceProviderTest.php +++ b/src/Viserio/Component/Profiler/Tests/Providers/ProfilerPsr6Psr16CacheBridgeServiceProviderTest.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 ProfilerPsr6Psr16CacheBridgeServiceProvider()); - $container->instance('config', ['viserio' => ['webprofiler' => ['enable' => true]]]); + $container->instance('config', ['viserio' => ['profiler' => ['enable' => true]]]); - self::assertInstanceOf(WebProfilerContract::class, $container->get(WebProfilerContract::class)); - self::assertInstanceOf(TraceableCacheItemDecorater::class, $container->get(CacheItemPoolInterface::class)); + self::assertInstanceOf(ProfilerContract::class, $container->get(ProfilerContract::class)); + self::assertInstanceOf(TraceableCacheItemDecorator::class, $container->get(CacheItemPoolInterface::class)); } private function getRequest() 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..482076e2b 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..e9355b9c3 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 73% rename from src/Viserio/Component/WebProfiler/Tests/TemplateManagerTest.php rename to src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php index 9f938f299..720dd8627 100644 --- a/src/Viserio/Component/WebProfiler/Tests/TemplateManagerTest.php +++ b/src/Viserio/Component/Profiler/Tests/TemplateManagerTest.php @@ -1,17 +1,17 @@ getIcons() ); - static::assertSame( + self::assertSame( $this->removeId(file_get_contents(__DIR__ . '/Fixture/View/profile.html')), $this->removeId($template->render()) ); @@ -64,15 +64,19 @@ public function testRenderWithCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( - ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/webprofiler.html.php', + [ + 'php-info-data-collector' => [ + 'collector' => $collector, + ], + ], + __DIR__ . '/../Resources/views/profiler.html.php', 'fds4f6as', $assets->getIcons() ); require_once __DIR__ . '/Fixture/View/profilewithcollector.html.php'; - static::assertSame( + self::assertSame( $this->removeId($text), $this->removeId($template->render()) ); @@ -88,13 +92,17 @@ public function testRenderWithAjaxRequestsDataCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( - ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/webprofiler.html.php', + [ + 'php-info-data-collector' => [ + 'collector' => $collector, + ], + ], + __DIR__ . '/../Resources/views/profiler.html.php', 'fds4f6as', $assets->getIcons() ); - static::assertSame( + self::assertSame( $this->removeId(file_get_contents(__DIR__ . '/Fixture/View/profilewithajaxcollector.html.php')), $this->removeId($template->render()) ); @@ -112,13 +120,17 @@ public function testRenderWithAPanelCollector() $assets = new AssetsRenderer(); $template = new TemplateManager( - ['php-info-data-collector' => $collector], - __DIR__ . '/../Resources/views/webprofiler.html.php', + [ + 'php-info-data-collector' => [ + 'collector' => $collector, + ], + ], + __DIR__ . '/../Resources/views/profiler.html.php', 'fds4f6as', $assets->getIcons() ); - static::assertSame( + self::assertSame( $this->removeId(file_get_contents(__DIR__ . '/Fixture/View/profilewithpanelcollector.html.php')), $this->removeId($template->render()) ); @@ -128,6 +140,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 70% rename from src/Viserio/Component/WebProfiler/Tests/Util/HtmlDumperOutputTest.php rename to src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php index 9bde43183..a8c937a6e 100644 --- a/src/Viserio/Component/WebProfiler/Tests/Util/HtmlDumperOutputTest.php +++ b/src/Viserio/Component/Profiler/Tests/Util/HtmlDumperOutputTest.php @@ -1,9 +1,9 @@ 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/WebProfiler/Util/HtmlDumperOutput.php b/src/Viserio/Component/Profiler/Util/HtmlDumperOutput.php similarity index 95% rename from src/Viserio/Component/WebProfiler/Util/HtmlDumperOutput.php rename to src/Viserio/Component/Profiler/Util/HtmlDumperOutput.php index b3a47445b..020b16c83 100644 --- a/src/Viserio/Component/WebProfiler/Util/HtmlDumperOutput.php +++ b/src/Viserio/Component/Profiler/Util/HtmlDumperOutput.php @@ -1,6 +1,6 @@ - + ./Tests/ diff --git a/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php b/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php index 1b76dd9f9..2130106fc 100644 --- a/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php +++ b/src/Viserio/Component/Routing/DataCollectors/RoutingDataCollector.php @@ -4,9 +4,9 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract; 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\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 4dc65e397..813d44c94 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\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Routing\Router as RouterContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; 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 { $profiler = $getPrevious(); diff --git a/src/Viserio/Component/Routing/Tests/DataCollectors/RoutingDataCollectorTest.php b/src/Viserio/Component/Routing/Tests/DataCollectors/RoutingDataCollectorTest.php index 5678eeab4..b59dad430 100644 --- a/src/Viserio/Component/Routing/Tests/DataCollectors/RoutingDataCollectorTest.php +++ b/src/Viserio/Component/Routing/Tests/DataCollectors/RoutingDataCollectorTest.php @@ -55,23 +55,4 @@ public function testGetMenu() 'value' => 1, ], $collector->getMenu()); } - - public function testGetPanel() - { - $route = new Route('GET', '/test', ['domain' => 'test.com']); - $routes = $this->mock(RouteCollectionContract::class); - $routes->shouldReceive('getRoutes') - ->twice() - ->andReturn([$route]); - $collector = new RoutingDataCollector($routes); - - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - $data = $collector->getData(); - - self::assertSame('
MethodsPathNameActionWith MiddlewareWithout MiddlewareDomain
GET | HEAD/testClosureDomain
', $collector->getPanel()); - } } diff --git a/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php b/src/Viserio/Component/Routing/Tests/Providers/RoutingDataCollectorServiceProviderTest.php index aad381407..e39df8cbd 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\WebProfiler\WebProfiler as WebProfilerContract; use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider; use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider; +use Viserio\Component\Profiler\Providers\ProfilerServiceProvider; use Viserio\Component\Routing\Providers\RoutingDataCollectorServiceProvider; -use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider; 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,13 +46,13 @@ public function testGetServices() ] ); - $profiler = $container->get(WebProfilerContract::class); + $profiler = $container->get(ProfilerContract::class); - static::assertInstanceOf(WebProfilerContract::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/Session/Middleware/StartSessionMiddleware.php b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php index 40bd6d348..a7596cde1 100644 --- a/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php +++ b/src/Viserio/Component/Session/Middleware/StartSessionMiddleware.php @@ -187,7 +187,7 @@ protected function addCookieToResponse(ServerRequestInterface $request, Response $config['domain'] ?? $uri->getHost(), $config['secure'] ?? ($uri->getScheme() === 'https'), $config['http_only'] ?? true, - $config['same_site'] ?? false + $config['samesite'] ?? false ); return $response->withAddedHeader('Set-Cookie', (string) $setCookie); diff --git a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php index 824201a4e..25a9facee 100644 --- a/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php +++ b/src/Viserio/Component/Session/Middleware/VerifyCsrfTokenMiddleware.php @@ -114,18 +114,18 @@ 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', $request->getAttribute('session')->getToken(), - $config['csrf.livetime'] ?? Chronos::now()->getTimestamp() + 60 * 120, + Chronos::now()->addSeconds($config['lifetime']), $config['path'], $config['domain'] ?? $uri->getHost(), $config['secure'] ?? ($uri->getScheme() === 'https'), false, - $config['csrf.samesite'] ?? false + $config['samesite'] ); return $response->withAddedHeader('Set-Cookie', (string) $setCookie); diff --git a/src/Viserio/Component/Session/SessionManager.php b/src/Viserio/Component/Session/SessionManager.php index 5903b499c..cbae19b9a 100644 --- a/src/Viserio/Component/Session/SessionManager.php +++ b/src/Viserio/Component/Session/SessionManager.php @@ -42,7 +42,7 @@ public function getDefaultOptions(): iterable return [ 'default' => 'array', 'cookie' => 'NSSESSID', - 'lifetime' => 86400, + 'lifetime' => 86400, // 1 day 'expire_on_close' => false, ]; } diff --git a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php index 3395adccd..d2a795201 100644 --- a/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php +++ b/src/Viserio/Component/Session/Tests/Middleware/VerifyCsrfTokenMiddlewareTest.php @@ -75,10 +75,8 @@ public function testSessionCsrfMiddlewareSetCookie() 'domain' => 'test.com', 'http_only' => false, 'secure' => false, - 'csrf' => [ - 'samesite' => false, - 'livetime' => Chronos::now()->getTimestamp() + 60 * 1200, - ], + 'samesite' => false, + 'livetime' => Chronos::now()->getTimestamp() + 60 * 1200, ], ]); $manager = $this->getSessionManager($config); @@ -136,10 +134,8 @@ public function testSessionCsrfMiddlewareReadsXCSRFTOKEN() 'domain' => 'test.com', 'http_only' => false, 'secure' => false, - 'csrf' => [ - 'samesite' => false, - 'livetime' => Chronos::now()->getTimestamp() + 60 * 120, - ], + 'samesite' => false, + 'livetime' => Chronos::now()->getTimestamp() + 60 * 120, ], ]); $manager = $this->getSessionManager($config); @@ -197,10 +193,8 @@ public function testSessionCsrfMiddlewareReadsXXSRFTOKEN() 'domain' => 'test.com', 'http_only' => false, 'secure' => false, - 'csrf' => [ - 'samesite' => false, - 'livetime' => Chronos::now()->getTimestamp() + 60 * 120, - ], + 'samesite' => false, + 'livetime' => Chronos::now()->getTimestamp() + 60 * 120, ], ]); $manager = $this->getSessionManager($config); @@ -264,10 +258,8 @@ public function testSessionCsrfMiddlewareToThrowException() 'domain' => 'test.com', 'http_only' => false, 'secure' => false, - 'csrf' => [ - 'samesite' => false, - 'livetime' => Chronos::now()->getTimestamp() + 60 * 120, - ], + 'samesite' => false, + 'livetime' => Chronos::now()->getTimestamp() + 60 * 120, ], ]); $manager = $this->getSessionManager($config); diff --git a/src/Viserio/Component/Support/Str.php b/src/Viserio/Component/Support/Str.php index 164183f7c..ebbe77e70 100644 --- a/src/Viserio/Component/Support/Str.php +++ b/src/Viserio/Component/Support/Str.php @@ -4,10 +4,16 @@ use BadMethodCallException; use Stringy\StaticStringy; +use Stringy\Stringy; 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/Tests/Traits/MacroableTraitTest.php b/src/Viserio/Component/Support/Tests/Traits/MacroableTraitTest.php index b0c46a54b..6f50fd06d 100644 --- a/src/Viserio/Component/Support/Tests/Traits/MacroableTraitTest.php +++ b/src/Viserio/Component/Support/Tests/Traits/MacroableTraitTest.php @@ -64,7 +64,7 @@ public function testBadFunctionCall() /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method dontExist does not exist. + * @expectedExceptionMessage Method [dontExist] does not exist. */ public function testBadStaticFunctionCall() { diff --git a/src/Viserio/Component/Support/Traits/MacroableTrait.php b/src/Viserio/Component/Support/Traits/MacroableTrait.php index 6ac8ee7f9..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("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)); diff --git a/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php b/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php index 025fe36ac..84b882b6b 100644 --- a/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php +++ b/src/Viserio/Component/Translation/DataCollectors/ViserioTranslationDataCollector.php @@ -4,11 +4,11 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +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\Contracts\WebProfiler\PanelAware as PanelAwareContract; -use Viserio\Component\Contracts\WebProfiler\TooltipAware as TooltipAwareContract; -use Viserio\Component\WebProfiler\DataCollectors\AbstractDataCollector; +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 aaf8bfd56..ec695bf60 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\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; 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 { $profiler = $getPrevious(); diff --git a/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php b/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php index f86284670..1e1df5d95 100644 --- a/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php +++ b/src/Viserio/Component/Translation/Tests/DataCollectors/ViserioTranslationDataCollectorTest.php @@ -3,8 +3,6 @@ namespace Viserio\Component\Translation\Tests\DataCollectors; use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; use Viserio\Component\Translation\DataCollectors\ViserioTranslationDataCollector; use Viserio\Component\Translation\MessageCatalogue; use Viserio\Component\Translation\MessageSelector; @@ -44,7 +42,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,70 +56,7 @@ public function testGetTooltip() { $collector = new ViserioTranslationDataCollector($this->translator); - static::assertSame('
Missing messages
Fallback messages
Defined messages
', $collector->getTooltip()); - } - - public function testGetPanel() - { - $collector = new ViserioTranslationDataCollector($this->translator); - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - 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($collector->getPanel()) - ); - } - - public function testGetPanelWithTranslation() - { - $this->translator->trans('foo'); - $this->translator->trans('foo'); - $this->translator->trans('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pretium nulla non gravida interdum. In pretium eleifend lorem. Morbi porttitor, diam sed rutrum pretium, purus mauris lacinia arcu, nec eleifend metus ex eu nisl. Duis finibus ipsum at arcu iaculis, viverra sagittis erat viverra. In et nulla posuere, molestie turpis id, euismod erat. Suspendisse diam sem, cursus at eros non, venenatis tincidunt nisi. Morbi viverra, risus quis tempor lacinia, purus ligula pretium quam, non ornare turpis orci sit amet ex. Proin. purus ligula pretium quam, non ornare turpis orci sit amet ex.'); - $this->translator->trans('test'); - - $collector = new ViserioTranslationDataCollector($this->translator); - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - static::assertSame( - '

These messages are correctly translated into the given locale.

LocaleDomainTimes usedMessage IDMessage Preview
"en"
-
-
"messages"
-
-
2
-
-
"foo"
-
-
"bar"
-
-

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

LocaleDomainTimes usedMessage IDMessage Preview
"fr"
-
-
"messages"
-
-
1
-
-
"test"
-
-
"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"
-
-
"messages"
-
-
1
-
-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pretium nulla non gravida interdum. In pretium eleifend lorem. Morbi porttitor, diam sed rutrum pretium, purus mauris lacinia arcu, nec eleifend metus ex eu nisl. Duis finibus ipsum at arcu iaculis, viverra sagittis erat viverra. In et nulla posuere, molestie turpis id, euismod erat. Suspendisse diam sem, cursus at eros non, venenatis tincidunt nisi. Morbi viverra, risus quis tempor lacinia, purus ligula pretium quam, non ornare turpis orci sit amet ex. Proin. purus ligula pretium quam, non ornare turpis orci sit amet ex."
-
-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pretium nulla non gravida interdum. In pretium eleifend lorem. Morbi porttitor, diam sed rutrum pretium, purus mauris lacinia arcu, nec eleifend metus ex eu nisl. Duis finibus ipsum at arcu iaculis, viverra sagittis erat viverra. In et nulla posuere, molestie turpis id, euismod erat. Suspendisse diam sem, cursus at eros non, venenatis tincidunt nisi. Morbi viverra, risus quis tempor lacinia, purus ligula pretium quam, non ornare turpis orci sit amet ex. Proin. purus ligula pretium quam, non ornare turpis orci sit amet ex."
-
-
', - $this->removeId($collector->getPanel()) - ); + self::assertSame('
Missing messages
Fallback messages
Defined messages
', $collector->getTooltip()); } private function removeId(string $html): string diff --git a/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php b/src/Viserio/Component/Translation/Tests/Providers/TranslationDataCollectorServiceProviderTest.php index e6ee34bc1..abeacd331 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\Profiler\Profiler as ProfilerContract; use Viserio\Component\Contracts\Translation\Translator as TranslatorContract; -use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract; 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\WebProfiler\Providers\WebProfilerServiceProvider; 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' => [ 'enable' => true, 'collector' => [ 'translation' => true, @@ -57,7 +57,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/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); } } diff --git a/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php b/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php deleted file mode 100644 index 53da0cdb4..000000000 --- a/src/Viserio/Component/WebProfiler/DataCollectors/Bridge/Cache/TraceableCacheItemDecorater.php +++ /dev/null @@ -1,245 +0,0 @@ -name = get_class($pool); - $this->pool = $pool; - } - - /** - * {@inheritdoc} - */ - public function getItem($key) - { - $event = $this->start(__FUNCTION__, $key); - - try { - $item = $this->pool->getItem($key); - } finally { - $event->end = microtime(true); - } - - if ($item->isHit()) { - ++$event->hits; - } else { - ++$event->misses; - } - - $event->result = $item->get(); - - return $item; - } - - /** - * {@inheritdoc} - */ - public function hasItem($key) - { - $event = $this->start(__FUNCTION__, $key); - - try { - return $event->result = $this->pool->hasItem($key); - } finally { - $event->end = microtime(true); - } - } - - /** - * {@inheritdoc} - */ - public function deleteItem($key) - { - $event = $this->start(__FUNCTION__, $key); - - try { - return $event->result = $this->pool->deleteItem($key); - } finally { - $event->end = microtime(true); - } - } - - /** - * {@inheritdoc} - */ - public function save(CacheItemInterface $item) - { - $event = $this->start(__FUNCTION__, $item); - - try { - return $event->result = $this->pool->save($item); - } finally { - $event->end = microtime(true); - } - } - - /** - * {@inheritdoc} - */ - public function saveDeferred(CacheItemInterface $item) - { - $event = $this->start(__FUNCTION__, $item); - - try { - return $event->result = $this->pool->saveDeferred($item); - } finally { - $event->end = microtime(true); - } - } - - /** - * {@inheritdoc} - */ - public function getItems(array $keys = []) - { - $event = $this->start(__FUNCTION__, $keys); - - try { - $result = $this->pool->getItems($keys); - } finally { - $event->end = microtime(true); - } - - $f = function () use ($result, $event) { - $event->result = []; - - foreach ($result as $key => $item) { - if ($item->isHit()) { - ++$event->hits; - } else { - ++$event->misses; - } - - $event->result[$key] = $item->get(); - - yield $key => $item; - } - }; - - return $f(); - } - - /** - * {@inheritdoc} - */ - public function clear() - { - $event = $this->start(__FUNCTION__); - - try { - return $event->result = $this->pool->clear(); - } finally { - $event->end = microtime(true); - } - } - - /** - * {@inheritdoc} - */ - public function deleteItems(array $keys) - { - $event = $this->start(__FUNCTION__, $keys); - - try { - return $event->result = $this->pool->deleteItems($keys); - } finally { - $event->end = microtime(true); - } - } - - /** - * {@inheritdoc} - */ - public function commit() - { - $event = $this->start(__FUNCTION__); - - try { - return $event->result = $this->pool->commit(); - } finally { - $event->end = microtime(true); - } - } - - /** - * Get all calls. - * - * @return array - */ - public function getCalls(): array - { - return $this->calls; - } - - /** - * Get the original class name. - * - * @return string - * - * @codeCoverageIgnore - */ - public function getName(): string - { - return $this->name; - } - - /** - * Start new event. - * - * @param string $name - * @param mixed $argument - * - * @return object - */ - private function start(string $name, $argument = null) - { - $this->calls[] = $event = new class() { - public $name; - public $argument; - public $start; - public $end; - public $result; - public $hits = 0; - public $misses = 0; - }; - - $event->name = $name; - $event->argument = $argument; - $event->start = microtime(true); - - return $event; - } -} 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/Providers/WebProfilerPsr6CacheBridgeServiceProvider.php b/src/Viserio/Component/WebProfiler/Providers/WebProfilerPsr6CacheBridgeServiceProvider.php deleted file mode 100644 index 46188f433..000000000 --- a/src/Viserio/Component/WebProfiler/Providers/WebProfilerPsr6CacheBridgeServiceProvider.php +++ /dev/null @@ -1,56 +0,0 @@ - [self::class, 'createCacheItemPoolDecorater'], - WebProfilerContract::class => [self::class, 'createWebProfiler'], - ]; - } - - public static function createCacheItemPoolDecorater(ContainerInterface $container): TraceableCacheItemDecorater - { - return new TraceableCacheItemDecorater($container->get(CacheItemPoolInterface::class)); - } - - /** - * Extend viserio profiler with data collector. - * - * @param \Interop\Container\ContainerInterface $container - * @param null|callable $getPrevious - * - * @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler - */ - public static function createWebProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract - { - $profiler = $getPrevious(); - - if ($profiler !== null) { - $cache = new Psr6CacheDataCollector(); - - if ($container->has(CacheItemPoolInterface::class)) { - $cache->addPool($container->get(CacheItemPoolInterface::class)); - } - - $profiler->addCollector($cache); - - return $profiler; - } - - return $profiler; - } -} diff --git a/src/Viserio/Component/WebProfiler/README.md b/src/Viserio/Component/WebProfiler/README.md deleted file mode 100644 index 2dca51756..000000000 --- a/src/Viserio/Component/WebProfiler/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Viserio WebProfiler package - -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). - -## 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 - -Use [Composer](https://getcomposer.org/) to install this package: - -```sh -composer require viserio/web-profiler -``` - -## Official Documentation - -Documentation for the framework can be found on the [Narrowspark website](http://narrowspark.de/docs). - -### License - -The Narrowspark framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). 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/Component/WebProfiler/Resources/views/webprofiler.html.php b/src/Viserio/Component/WebProfiler/Resources/views/webprofiler.html.php deleted file mode 100644 index 6e61c05be..000000000 --- a/src/Viserio/Component/WebProfiler/Resources/views/webprofiler.html.php +++ /dev/null @@ -1,69 +0,0 @@ - -
- - - -
- -
- - - - $menu): - $tooltip = false; - - if (isset($menu['tooltip'])) { - $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' : ''; - $cssClasses = isset($menu['menu']['class']) ? ' ' . $menu['menu']['class'] : ''; - ?> -
class="webprofiler-menu webprofiler-menu- webprofiler-menu-position-"> -
- - - - - - - - - - - -
- -
- -
- -
- -
- -
-
- - $panel): ?> -
- -
- -
-
diff --git a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php b/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php deleted file mode 100644 index 1d2b71efc..000000000 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/Psr6CacheDataCollectorTest.php +++ /dev/null @@ -1,72 +0,0 @@ -getPsr6CacheDataCollector(); - - static::assertSame( - [ - 'icon' => 'ic_layers_white_24px.svg', - 'label' => '0 in', - 'value' => '0μs', - ], - $collector->getMenu() - ); - } - - public function testGetTooltip() - { - $collector = $this->getPsr6CacheDataCollector(); - - static::assertSame( - '
Cache calls0
Total time0μs
Cache hits0
Cache writes0
', - $collector->getTooltip() - ); - } - - 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->removeSymfonyVarDumper($collector->getPanel()) - ); - } - - private function removeTabId(string $html): string - { - return trim(preg_replace('/="tab-0(.*?)"/', '', $html)); - } - - private function getPsr6CacheDataCollector() - { - $collector = new Psr6CacheDataCollector(); - $collector->addPool(new TraceableCacheItemDecorater(new ArrayCachePool())); - $collector->collect( - $this->mock(ServerRequestInterface::class), - $this->mock(ResponseInterface::class) - ); - - return $collector; - } - - private function removeSymfonyVarDumper(string $html): string - { - $html = preg_replace('/]*>(.*?)<\/script>/', '', $html); - $html = preg_replace('/]*>(.*?)<\/style>/', '', $html); - - return $this->removeTabId(preg_replace('/id=sf-dump-(?:\d+) /', '', $html)); - } -} diff --git a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php b/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php deleted file mode 100644 index e27a89b0a..000000000 --- a/src/Viserio/Component/WebProfiler/Tests/DataCollectors/Bridge/Cache/TraceableCacheItemDecoraterTest.php +++ /dev/null @@ -1,219 +0,0 @@ -createCachePool(); - $pool->getItem('k'); - $calls = $pool->getCalls(); - - static::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); - } - - public function testGetItemHit() - { - $pool = $this->createCachePool(); - $item = $pool->getItem('k')->set('foo'); - $pool->save($item); - $pool->getItem('k'); - $calls = $pool->getCalls(); - - static::assertCount(3, $calls); - - $call = $calls[2]; - - static::assertEquals(1, $call->hits); - static::assertEquals(0, $call->misses); - } - - public function testGetItemsMiss() - { - $pool = $this->createCachePool(); - $arg = ['k0', 'k1']; - $items = $pool->getItems($arg); - - foreach ($items as $item) { - } - - $calls = $pool->getCalls(); - - static::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); - } - - public function testHasItemMiss() - { - $pool = $this->createCachePool(); - $pool->hasItem('k'); - $calls = $pool->getCalls(); - - static::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); - } - - public function testHasItemHit() - { - $pool = $this->createCachePool(); - $item = $pool->getItem('k')->set('foo'); - $pool->save($item); - $pool->hasItem('k'); - $calls = $pool->getCalls(); - - static::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); - } - - public function testDeleteItem() - { - $pool = $this->createCachePool(); - $pool->deleteItem('k'); - $calls = $pool->getCalls(); - - static::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); - } - - public function testDeleteItems() - { - $pool = $this->createCachePool(); - $arg = ['k0', 'k1']; - $pool->deleteItems($arg); - $calls = $pool->getCalls(); - - static::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); - } - - public function testSave() - { - $pool = $this->createCachePool(); - $item = $pool->getItem('k')->set('foo'); - $pool->save($item); - $calls = $pool->getCalls(); - - static::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); - } - - public function testSaveDeferred() - { - $pool = $this->createCachePool(); - $item = $pool->getItem('k')->set('foo'); - $pool->saveDeferred($item); - $calls = $pool->getCalls(); - - static::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); - } - - public function testCommit() - { - $pool = $this->createCachePool(); - $pool->commit(); - $calls = $pool->getCalls(); - - static::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); - } - - public function testClear() - { - $pool = $this->createCachePool(); - $pool->clear(); - $calls = $pool->getCalls(); - - static::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); - } - - private function createCachePool() - { - return new TraceableCacheItemDecorater(new ArrayCachePool()); - } -} diff --git a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/array_table.html b/src/Viserio/Component/WebProfiler/Tests/Fixture/View/array_table.html deleted file mode 100644 index 6e355f3f1..000000000 --- a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/array_table.html +++ /dev/null @@ -1,3 +0,0 @@ -

array

KeyValue
"test value"
-
-
diff --git a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/default_table.html b/src/Viserio/Component/WebProfiler/Tests/Fixture/View/default_table.html deleted file mode 100644 index 74a02fad9..000000000 --- a/src/Viserio/Component/WebProfiler/Tests/Fixture/View/default_table.html +++ /dev/null @@ -1,3 +0,0 @@ -

test

KeyValue
test key
"test value"
-
-