Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"link0/profiler": "~1.0"
"link0/profiler": "^1.0.0"
},
"require-dev": {
"symfony/framework-bundle": "~2",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 28 additions & 51 deletions src/Link0/ProfilerBundle/EventListener/ProfilingEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,88 +8,65 @@
namespace Link0\ProfilerBundle\EventListener;

use Link0\Profiler\PersistenceHandler;
use Link0\Profiler\Profiler;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\HttpKernel\TerminableInterface;
use Link0\ProfilerBundle\Service\ProfilingService;

/**
* Class ProfilingEventListener
*
* Hooks into the symfony event system, and starts and stops the profiler on certain events
*
* Start:
* - console.command
* - kernel.request
* Stop:
* - console.terminate
* - kernel.terminate
* You can configure this event listener in your services.yml in the following format
*
* services:
* kernel.listener.link0profilerlistener:
* class: Link0\ProfilerBundle\EventListener\ProfilingEventListener
* param: [@profiling_service]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this documentation needed in here? Since it just duplicates code that's available in your bundle and thus decreases maintainability.

* tags:
* - { name: kernel.event_listener, event: console.command, method: start }
* - { name: kernel.event_listener, event: kernel.request, method: start }
* - { name: kernel.event_listener, event: console.terminate, method: stop }
* - { name: kernel.event_listener, event: kernel.terminate, method: stop }
*
* @package Link0\ProfilerBundle\EventListener
*/
class ProfilingEventListener
final class ProfilingEventListener
{
/**
* @var \Link0\Profiler\Profiler

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the leading backslash here.

*/
private $profiler;

/**
* A persistence handler should be fed, since null will disable persisting profiles
*
* @param PersistenceHandler $handler
*/
public function __construct(PersistenceHandler $handler = null)
{
$this->profiler = new Profiler($handler);
}

/**
* @return Profiler
*/
public function getProfiler()
{
return $this->profiler;
}
private $profilingService;

/**
* @event console.command
* @param ConsoleCommandEvent $event
* @param ProfilingService $profilingService
*/
public function onConsoleCommand(ConsoleCommandEvent $event)
public function __construct(ProfilingService $profilingService)
{
$this->getProfiler()->start();
$this->profilingService = $profilingService;
}

/**
* @event kernel.request
* @param GetResponseEvent $event
* @return ProfilingService
*/
public function onKernelRequest(GetResponseEvent $event)
public function getProfilingService()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this getter necessary? Are the consumers of this class going to need to do anything with the profilingService other than the start() and stop() functions you've provided? If not, it's worth removing it.

{
if (!$event->isMasterRequest()) {
return;
}

$this->getProfiler()->start();
return $this->profilingService;
}

/**
* @event console.terminate
* @param ConsoleTerminateEvent $event
* Starts the profiler
*/
public function onConsoleTerminate(ConsoleTerminateEvent $event)
public function start()
{
$this->getProfiler()->stop();
$this->getProfilingService()->start();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When working with internal variables, I use $this->profilingService in most of the cases, and not the getter, but this could be just my personal preference.

}

/**
* @event kernel.terminate
* @param TerminableInterface $event
* Stops the profiler
*
* @return \Link0\Profiler\Profile
*/
public function onKernelTerminate(TerminableInterface $event)
public function stop()
{
$this->getProfiler()->stop();
return $this->getProfilingService()->stop();
}
}
8 changes: 7 additions & 1 deletion src/Link0/ProfilerBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
services:
kernel.listener.link0profilerlistener:
class: Link0\ProfilerBundle\EventListener\ProfilingEventListener
param: [@profiling_service]
tags:
- { name: kernel.event_listener, event: console.command, method: onConsoleCommand }
- { name: kernel.event_listener, event: console.command, method: start }
- { name: kernel.event_listener, event: kernel.request, method: start }
- { name: kernel.event_listener, event: console.terminate, method: stop }
- { name: kernel.event_listener, event: kernel.terminate, method: stop }
profiling_service:
class: Link0\ProfilerBundle\Service\ProfilingService
52 changes: 52 additions & 0 deletions src/Link0/ProfilerBundle/Service/ProfilingService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* ProfilingEventListener.php
*
* @author Dennis de Greef <github@link0.net>
*/
namespace Link0\ProfilerBundle\Service;

use Link0\Profiler\PersistenceService;

/**
* Class ProfilingService
*
* @package Link0\ProfilerBundle\Service
*/
final class ProfilingService
{
/**
* @var \Link0\Profiler\PersistenceService

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need leading backslash

*/
private $persistenceService;

/**
* @var \Link0\Profiler\Profiler
*/
private $profiler;

/**
* @param PersistenceService $persistenceService
*/
public function __construct(PersistenceService $persistenceService = null)
{
$this->persistenceService = $persistenceService;
}

/**
* Starts the profiler
*/
public function start()
{
$this->profiler->start();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this gives an error? I don't see where this profiler object comes from. Shouldn't it be injected in the constructor?

}

/**
* @return \Link0\Profiler\Profile
*/
public function stop()
{
return $this->profiler->stop();
}
}