diff --git a/composer.json b/composer.json index 42f6a56..2cb5f66 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ "source": "https://github.com/skaut/SkautisNette" }, "require": { - "php": ">=7.1", - "skautis/skautis": "3.0.0-alpha.1", + "php": ">=7.2", + "skautis/skautis": "3.0.0-alpha.4", "nette/di": "^3.0", "nette/http": "^3.0", "nette/utils": "^3.0" diff --git a/src/SessionAdapter.php b/src/SessionAdapter.php index 5e792d4..c29caaf 100644 --- a/src/SessionAdapter.php +++ b/src/SessionAdapter.php @@ -5,7 +5,7 @@ namespace Skautis\Nette; use Nette; -use Skautis\SessionAdapter\AdapterInterface; +use Skaut\Skautis\SessionAdapter\AdapterInterface; class SessionAdapter implements AdapterInterface diff --git a/src/SkautisExtension.php b/src/SkautisExtension.php index 45afda4..d369689 100644 --- a/src/SkautisExtension.php +++ b/src/SkautisExtension.php @@ -6,12 +6,11 @@ use Nette; use Nette\Schema\Expect; -use Skautis\Config; -use Skautis\Wsdl\WebServiceFactory; -use Skautis\Wsdl\WsdlManager; -use Skautis\Nette\SessionAdapter; -use Skautis\User; -use Skautis\Skautis; +use Skaut\Skautis\Config; +use Skaut\Skautis\Wsdl\WebServiceFactory; +use Skaut\Skautis\Wsdl\WsdlManager; +use Skaut\Skautis\User; +use Skaut\Skautis\Skautis; use Skautis\Nette\Tracy\Panel; use Tracy\Debugger; diff --git a/src/Tracy/EventDispatcher.php b/src/Tracy/EventDispatcher.php new file mode 100644 index 0000000..12f11fb --- /dev/null +++ b/src/Tracy/EventDispatcher.php @@ -0,0 +1,46 @@ +queries[] = SkautisQuery::createFromPostEvent($event); + break; + case $event instanceof RequestFailEvent: + $this->queries[] = SkautisQuery::createFromFailEvent($event); + break; + } + + return $event; + } + + /** @return SkautisQuery[] */ + public function getQueries(): array + { + return $this->queries; + } +} \ No newline at end of file diff --git a/src/Tracy/Panel.php b/src/Tracy/Panel.php index 76a5597..545ac14 100644 --- a/src/Tracy/Panel.php +++ b/src/Tracy/Panel.php @@ -5,9 +5,7 @@ namespace Skautis\Nette\Tracy; use Nette; -use Skautis\SkautisQuery; -use Skautis\Wsdl\WebService; -use Skautis\Wsdl\WsdlManager; +use Skaut\Skautis\Wsdl\WsdlManager; use Tracy; use Tracy\Debugger; @@ -19,41 +17,36 @@ */ class Panel implements Tracy\IBarPanel { - use Nette\SmartObject; - /** @var SkautisQuery[] */ - private $queries = []; + /** @var EventDispatcher */ + private $eventDispatcher; + public function __construct() + { + $this->eventDispatcher = new EventDispatcher(); + } - /** + /** * Registers event listener on WebService objects via WsdlManager */ public function register(WsdlManager $wsdlManager): void { - $wsdlManager->addWebServiceListener(WebService::EVENT_SUCCESS, [$this, 'logEvent']); - $wsdlManager->addWebServiceListener(WebService::EVENT_FAILURE, [$this, 'logEvent']); + $wsdlManager->setEventDispatcher($this->eventDispatcher); Debugger::getBar()->addPanel($this); } - - public function logEvent(SkautisQuery $query): void - { - $this->queries[] = $query; - } - - /** * @inheritdoc */ public function getTab(): string { $totalTime = 0; - foreach ($this->queries as $query) { + foreach ($this->eventDispatcher->getQueries() as $query) { $totalTime += $query->time; } return '' - . count($this->queries) . ' queries' + . count($this->eventDispatcher->getQueries()) . ' queries' . ($totalTime ? sprintf(' / %0.1f ms', $totalTime * 1000) : '') . ''; } @@ -66,7 +59,7 @@ public function getPanel(): string { $cnt = 0; $s = ""; - foreach ($this->queries as $query) { + foreach ($this->eventDispatcher->getQueries() as $query) { $rowId = "tracy-debug-Skautis-args-row-$cnt"; $s .= "" . "" . sprintf('%0.2f', $query->time * 1000) . "" @@ -77,7 +70,7 @@ public function getPanel(): string $cnt++; } - return empty($this->queries) ? '' : + return empty($this->eventDispatcher->getQueries()) ? '' : '

Skautis

' . '
' . '' diff --git a/src/Tracy/SkautisQuery.php b/src/Tracy/SkautisQuery.php new file mode 100644 index 0000000..246e5b6 --- /dev/null +++ b/src/Tracy/SkautisQuery.php @@ -0,0 +1,66 @@ + + */ + public $args; + + /** + * Zasobnik volanych funkci. + * @var array> + */ + public $trace; + + /** + * Doba trvani pozadvku. + * @var float + */ + public $time; + + /** + * SOAP response. + * @var mixed + */ + public $result; + + /** + * @param array $args + * @param array> $trace + * @param mixed $result + */ + private function __construct(string $fname, array $args, array $trace, float $time, $result) + { + $this->fname = $fname; + $this->args = $args; + $this->trace = $trace; + $this->time = $time; + $this->result = $result; + } + + public static function createFromPostEvent(RequestPostEvent $event): SkautisQuery { + return new SkautisQuery($event->getFname(), $event->getArgs(), $event->getTrace(), $event->getDuration(), $event->getResult()); + } + + public static function createFromFailEvent(RequestFailEvent $event): SkautisQuery { + return new SkautisQuery($event->getFname(), $event->getArgs(), $event->getTrace(), $event->getDuration(), null); + } +} \ No newline at end of file diff --git a/tests/SkautisNette/SkautisExtension.debug.phpt b/tests/SkautisNette/SkautisExtension.debug.phpt index 8ff09e5..192219c 100644 --- a/tests/SkautisNette/SkautisExtension.debug.phpt +++ b/tests/SkautisNette/SkautisExtension.debug.phpt @@ -23,7 +23,7 @@ else { } Assert::true($container->hasService('skautis.skautis')); -Assert::type('Skautis\Skautis', $container->getService('skautis.skautis')); +Assert::type('Skaut\Skautis\Skautis', $container->getService('skautis.skautis')); if (class_exists('Tracy\Debugger')) { Assert::true($container->isCreated('skautis.panel')); diff --git a/tests/SkautisNette/SkautisExtension.production.phpt b/tests/SkautisNette/SkautisExtension.production.phpt index 8de5c0b..14bed26 100644 --- a/tests/SkautisNette/SkautisExtension.production.phpt +++ b/tests/SkautisNette/SkautisExtension.production.phpt @@ -14,5 +14,5 @@ $configurator->setDebugMode(FALSE); $configurator->addConfig(__DIR__ . '/files/config.neon'); $container = $configurator->createContainer(); -Assert::type('Skautis\Skautis', $container->getService('skautis.skautis')); +Assert::type('Skaut\Skautis\Skautis', $container->getService('skautis.skautis')); Assert::false($container->hasService('skautis.panel')); diff --git a/tests/composer-nette-3.0-without-tracy.json b/tests/composer-nette-3.0-without-tracy.json index 766e9cd..4d7135c 100644 --- a/tests/composer-nette-3.0-without-tracy.json +++ b/tests/composer-nette-3.0-without-tracy.json @@ -17,7 +17,7 @@ }, "require": { "php": ">=7.1", - "skautis/skautis": "3.0.0-alpha.1", + "skautis/skautis": "3.0.0-alpha.4", "nette/di": "^3.0", "nette/http": "^3.0", "nette/utils": "^3.0" diff --git a/tests/composer-nette-3.0.json b/tests/composer-nette-3.0.json index bbb4d74..5af2107 100644 --- a/tests/composer-nette-3.0.json +++ b/tests/composer-nette-3.0.json @@ -17,7 +17,7 @@ }, "require": { "php": ">=7.1", - "skautis/skautis": "3.0.0-alpha.1", + "skautis/skautis": "3.0.0-alpha.4", "nette/di": "^3.0", "nette/http": "^3.0", "nette/utils": "^3.0" diff --git a/tests/composer-nette-3.1-without-tracy.json b/tests/composer-nette-3.1-without-tracy.json index f61d114..8369704 100644 --- a/tests/composer-nette-3.1-without-tracy.json +++ b/tests/composer-nette-3.1-without-tracy.json @@ -17,7 +17,7 @@ }, "require": { "php": ">=7.2", - "skautis/skautis": "3.0.0-alpha.1", + "skautis/skautis": "3.0.0-alpha.4", "nette/di": "^3.0", "nette/http": "^3.1", "nette/utils": "^3.1" diff --git a/tests/composer-nette-3.1.json b/tests/composer-nette-3.1.json index 351890f..a8b6c01 100644 --- a/tests/composer-nette-3.1.json +++ b/tests/composer-nette-3.1.json @@ -17,7 +17,7 @@ }, "require": { "php": ">=7.2", - "skautis/skautis": "3.0.0-alpha.1", + "skautis/skautis": "3.0.0-alpha.4", "nette/di": "^3.0", "nette/http": "^3.1", "nette/utils": "^3.1"