Reorganized collector classes.
This commit is contained in:
1 parent
fb144ebe01
commit
961019ef74
16 files changed
+46
-34
No files matched your search
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
### Changed
|
||||
- required PHP version to 7.1
|
||||
- organization and names for Record classes
|
||||
|
||||
### Deprecated
|
||||
- old format of hook events
|
||||
|
||||
+3
-3
@@ -26,17 +26,17 @@
|
||||
<MixedArgument>
|
||||
<errorLevel type="suppress">
|
||||
<file name="src/Provider/Record_Provider.php" />
|
||||
<file name="src/Record/Hook_Record_Collector.php" />
|
||||
<file name="src/Record/Collector/Hook_Collector.php" />
|
||||
</errorLevel>
|
||||
</MixedArgument>
|
||||
<MissingClosureParamType>
|
||||
<errorLevel type="suppress">
|
||||
<file name="src/Record/Hook_Record_Collector.php" />
|
||||
<file name="src/Record/Collector/Hook_Collector.php" />
|
||||
</errorLevel>
|
||||
</MissingClosureParamType>
|
||||
<MissingClosureReturnType>
|
||||
<errorLevel type="suppress">
|
||||
<file name="src/Record/Hook_Record_Collector.php" />
|
||||
<file name="src/Record/Collector/Hook_Collector.php" />
|
||||
</errorLevel>
|
||||
</MissingClosureReturnType>
|
||||
</issueHandlers>
|
||||
|
||||
@@ -3,13 +3,15 @@ declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Event;
|
||||
|
||||
use Rarst\Laps\Record\Collector\Hook_Collector;
|
||||
|
||||
/**
|
||||
* Interface to retrieve configuration array of hook events to track.
|
||||
*/
|
||||
interface Hook_Event_Config_Interface {
|
||||
|
||||
/**
|
||||
* @see Hook_Record_Collector::add_event()
|
||||
* @see Hook_Collector::add_event()
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,7 @@ class Hook_Formatter {
|
||||
$closure = new \ReflectionFunction( $callback );
|
||||
$callback = 'closure from ' . $closure->getFileName() . '::' . $closure->getStartLine();
|
||||
|
||||
if ( false !== strpos( $callback, 'Hook_Record_Collector' ) ) {
|
||||
if ( false !== strpos( $callback, 'Hook_Collector' ) ) {
|
||||
continue;
|
||||
}
|
||||
} elseif ( is_object( $callback ) ) {
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace Rarst\Laps\Provider;
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Plugin;
|
||||
use Rarst\Laps\Record\Core_Load_Collector;
|
||||
use Rarst\Laps\Record\Hook_Record_Collector;
|
||||
use Rarst\Laps\Record\Http_Record_Collector;
|
||||
use Rarst\Laps\Record\Record_Collector_Interface;
|
||||
use Rarst\Laps\Record\Sql_Record_Collector;
|
||||
use Rarst\Laps\Record\Collector\Core_Load_Collector;
|
||||
use Rarst\Laps\Record\Collector\Hook_Collector;
|
||||
use Rarst\Laps\Record\Collector\Http_Collector;
|
||||
use Rarst\Laps\Record\Collector\Record_Collector_Interface;
|
||||
use Rarst\Laps\Record\Collector\Sql_Collector;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
/**
|
||||
@@ -30,9 +30,9 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
|
||||
$pimple['collectors'] = function ( Plugin $laps ): array {
|
||||
return [
|
||||
'core' => new Core_Load_Collector(),
|
||||
'hook' => new Hook_Record_Collector( $laps['stopwatch'], $laps['hook.events'] ),
|
||||
'http' => new Http_Record_Collector( $laps['stopwatch'] ),
|
||||
'sql' => new Sql_Record_Collector(),
|
||||
'hook' => new Hook_Collector( $laps['stopwatch'], $laps['hook.events'] ),
|
||||
'http' => new Http_Collector( $laps['stopwatch'] ),
|
||||
'sql' => new Sql_Collector(),
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
namespace Rarst\Laps\Record\Collector;
|
||||
|
||||
use Rarst\Laps\Record\Record;
|
||||
use Rarst\Laps\Record\Record_Interface;
|
||||
|
||||
/**
|
||||
* Covers pre–plugin load time from available data.
|
||||
@@ -1,17 +1,18 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
namespace Rarst\Laps\Record\Collector;
|
||||
|
||||
use Rarst\Laps\Event\Hook_Event_Config_Interface;
|
||||
use Rarst\Laps\Formatter\Hook_Formatter;
|
||||
use Rarst\Laps\Record\Stopwatch_Record;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
|
||||
/**
|
||||
* Processes events based on hooked starts and stops.
|
||||
*/
|
||||
class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
class Hook_Collector extends Stopwatch_Collector {
|
||||
|
||||
/** @var Hook_Event_Config_Interface[] $event_configs */
|
||||
protected $event_configs = [];
|
||||
@@ -1,16 +1,17 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
namespace Rarst\Laps\Record\Collector;
|
||||
|
||||
use Rarst\Laps\Formatter\Backtrace_Formatter;
|
||||
use Rarst\Laps\Record\Stopwatch_Record;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
|
||||
/**
|
||||
* Captures time of network requests made with HTTP API.
|
||||
*/
|
||||
class Http_Record_Collector extends Stopwatch_Record_Collector {
|
||||
class Http_Collector extends Stopwatch_Collector {
|
||||
|
||||
/** @var Backtrace_Formatter */
|
||||
private $formatter;
|
||||
+3
-1
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
namespace Rarst\Laps\Record\Collector;
|
||||
|
||||
use Rarst\Laps\Record\Record_Interface;
|
||||
|
||||
/**
|
||||
* Interface to retrieve a set of records form collector.
|
||||
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
namespace Rarst\Laps\Record\Collector;
|
||||
|
||||
use Rarst\Laps\Formatter\Backtrace_Formatter;
|
||||
use Rarst\Laps\Record\Record;
|
||||
|
||||
/**
|
||||
* Processes SQL events from data logged by wpdb.
|
||||
*/
|
||||
class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
class Sql_Collector implements Record_Collector_Interface {
|
||||
|
||||
/** @var array $query_starts Log of query start times. */
|
||||
protected $query_starts = [];
|
||||
+3
-2
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
namespace Rarst\Laps\Record\Collector;
|
||||
|
||||
use Rarst\Laps\Record\Stopwatch_Record;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
|
||||
/**
|
||||
* Generic Stopwatch–based collector. Can be used by itself or extended.
|
||||
*/
|
||||
class Stopwatch_Record_Collector implements Record_Collector_Interface {
|
||||
class Stopwatch_Collector implements Record_Collector_Interface {
|
||||
|
||||
/** @var Stopwatch $stopwatch */
|
||||
protected $stopwatch;
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Rarst\Laps\Tests\Record;
|
||||
|
||||
use Rarst\Laps\Record\Core_Load_Collector;
|
||||
use Rarst\Laps\Record\Collector\Core_Load_Collector;
|
||||
use Rarst\Laps\Record\Record_Interface;
|
||||
use Rarst\Laps\Tests\LapsTestCase;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ declare( strict_types=1 );
|
||||
namespace Rarst\Laps\Tests\Record;
|
||||
|
||||
use Rarst\Laps\Event\Core_Events;
|
||||
use Rarst\Laps\Record\Hook_Record_Collector;
|
||||
use Rarst\Laps\Record\Collector\Hook_Collector;
|
||||
use Rarst\Laps\Tests\LapsTestCase;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
@@ -13,7 +13,7 @@ class HookTest extends LapsTestCase {
|
||||
public function testCollector() {
|
||||
|
||||
$stopwatch = new Stopwatch();
|
||||
$collector = new Hook_Record_Collector( $stopwatch, [ 'core' => new Core_Events() ] );
|
||||
$collector = new Hook_Collector( $stopwatch, [ 'core' => new Core_Events() ] );
|
||||
|
||||
$this->assertTrue( $stopwatch->isStarted( 'Plugins Load' ) );
|
||||
$this->assertTrue( has_action( 'after_setup_theme', [ $collector, 'after_setup_theme' ] ) );
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Rarst\Laps\Tests\Record;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use Rarst\Laps\Record\Http_Record_Collector;
|
||||
use Rarst\Laps\Record\Collector\Http_Collector;
|
||||
use Rarst\Laps\Tests\LapsTestCase;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
@@ -16,7 +16,7 @@ class HttpTest extends LapsTestCase {
|
||||
|
||||
$stopwatch = new Stopwatch();
|
||||
$url = 'https://example.com/';
|
||||
$collector = new Http_Record_Collector( $stopwatch );
|
||||
$collector = new Http_Collector( $stopwatch );
|
||||
|
||||
$this->assertTrue( has_action( 'pre_http_request', [ $collector, 'pre_http_request' ] ) );
|
||||
$this->assertTrue( has_action( 'http_api_debug', [ $collector, 'http_api_debug' ] ) );
|
||||
|
||||
@@ -4,13 +4,13 @@ namespace Rarst\Laps\Tests\Record;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use Rarst\Laps\Record\Record;
|
||||
use Rarst\Laps\Record\Sql_Record_Collector;
|
||||
use Rarst\Laps\Record\Collector\Sql_Collector;
|
||||
use Rarst\Laps\Tests\LapsTestCase;
|
||||
|
||||
class SqlTest extends LapsTestCase {
|
||||
|
||||
/**
|
||||
* @covers \Rarst\Laps\Record\Sql_Record_Collector
|
||||
* @covers \Rarst\Laps\Record\Collector\Sql_Collector
|
||||
*/
|
||||
public function testCollector() {
|
||||
|
||||
@@ -22,7 +22,7 @@ class SqlTest extends LapsTestCase {
|
||||
}
|
||||
Functions\expect( 'wp_normalize_path' )->zeroOrMoreTimes()->andReturnFirstArg();
|
||||
|
||||
$collector = new Sql_Record_Collector();
|
||||
$collector = new Sql_Collector();
|
||||
|
||||
$this->assertTrue( has_filter( 'query', [ $collector, 'query' ] ) );
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Rarst\Laps\Tests\Record;
|
||||
|
||||
use Rarst\Laps\Record\Stopwatch_Record;
|
||||
use Rarst\Laps\Record\Stopwatch_Record_Collector;
|
||||
use Rarst\Laps\Record\Collector\Stopwatch_Collector;
|
||||
use Rarst\Laps\Tests\LapsTestCase;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
@@ -11,11 +11,11 @@ use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
class StopwatchTest extends LapsTestCase {
|
||||
|
||||
/**
|
||||
* @covers \Rarst\Laps\Record\Stopwatch_Record_Collector
|
||||
* @covers \Rarst\Laps\Record\Collector\Stopwatch_Collector
|
||||
*/
|
||||
public function testCollector() {
|
||||
|
||||
$collector = new Stopwatch_Record_Collector( new Stopwatch() );
|
||||
$collector = new Stopwatch_Collector( new Stopwatch() );
|
||||
|
||||
$collector->start( 'Event', 'info' );
|
||||
$collector->start( 'Not stopped', 'info' );
|
||||
|
||||
Reference in new issue
Block a user