-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
merge pomm bridge with pommbundle #104
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/* | ||
* This file is part of the PommProject/PommBundle package. | ||
* | ||
* (c) 2018 Grégoire HUBERT <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PommProject\PommBundle\Configurator; | ||
|
||
use PommProject\Foundation\Pomm; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
|
||
/** | ||
* Data collector for the database profiler. | ||
* | ||
* @package PommBundle | ||
* @copyright 2018 Grégoire HUBERT | ||
* @author Paris Mikael | ||
* @license X11 {@link http://opensource.org/licenses/mit-license.php} | ||
* @see DataCollector | ||
*/ | ||
class DatabaseCollectorConfigurator | ||
{ | ||
protected $datacollector; | ||
|
||
public function __construct(DataCollector $datacollector) | ||
{ | ||
$this->datacollector = $datacollector; | ||
} | ||
|
||
/** | ||
* @param Pomm $pomm | ||
* | ||
* @return null | ||
*/ | ||
public function configure(Pomm $pomm) | ||
{ | ||
$callable = [$this->datacollector, 'execute']; | ||
|
||
foreach ($pomm->getSessionBuilders() as $name => $builder) { | ||
$pomm->addPostConfiguration($name, function ($session) use ($callable) { | ||
$session | ||
->getClientUsingPooler('listener', 'query') | ||
->attachAction($callable) | ||
; | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/* | ||
* This file is part of the PommProject/PommBundle package. | ||
* | ||
* (c) 2018 Grégoire HUBERT <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PommProject\PommBundle\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\HttpKernel\Profiler\Profiler; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
use PommProject\Foundation\Pomm; | ||
|
||
/** | ||
* Controllers for the Pomm profiler extension. | ||
* | ||
* @package PommBundle | ||
* @copyright 2018 Grégoire HUBERT | ||
* @author Grégoire HUBERT | ||
* @license X11 {@link http://opensource.org/licenses/mit-license.php} | ||
*/ | ||
class PommProfilerController | ||
{ | ||
private $generator; | ||
private $profiler; | ||
private $twig; | ||
private $pomm; | ||
|
||
public function __construct( | ||
UrlGeneratorInterface $generator, | ||
Profiler $profiler, | ||
\Twig_Environment $twig, | ||
Pomm $pomm | ||
) { | ||
$this->generator = $generator; | ||
$this->profiler = $profiler; | ||
$this->twig = $twig; | ||
$this->pomm = $pomm; | ||
} | ||
|
||
/** | ||
* Controller to explain a SQL query. | ||
* | ||
* @param $request | ||
* @param string $token | ||
* @param int $index_query | ||
* | ||
* @return Response | ||
*/ | ||
public function explainAction(Request $request, $token, $index_query) | ||
{ | ||
$panel = 'pomm'; | ||
$page = 'home'; | ||
|
||
if (!($profile = $this->profiler->loadProfile($token))) { | ||
return new Response( | ||
$this->twig->render( | ||
'@WebProfiler/Profiler/info.html.twig', | ||
array('about' => 'no_token', 'token' => $token) | ||
), | ||
200, | ||
array('Content-Type' => 'text/html') | ||
); | ||
} | ||
|
||
$this->profiler->disable(); | ||
|
||
if (!$profile->hasCollector($panel)) { | ||
throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token)); | ||
} | ||
|
||
if (!array_key_exists($index_query, $profile->getCollector($panel)->getQueries())) { | ||
throw new \InvalidArgumentException(sprintf("No such query index '%s'.", $index_query)); | ||
} | ||
|
||
$query_data = $profile->getCollector($panel)->getQueries()[$index_query]; | ||
|
||
$explain = $this->pomm[$query_data['session_stamp']] | ||
->getClientUsingPooler('query_manager', null) | ||
->query(sprintf("explain %s", $query_data['sql']), $query_data['parameters']); | ||
|
||
return new Response($this->twig->render('@Pomm/Profiler/explain.html.twig', array( | ||
'token' => $token, | ||
'profile' => $profile, | ||
'collector' => $profile->getCollector($panel), | ||
'panel' => $panel, | ||
'page' => $page, | ||
'request' => $request, | ||
'query_index' => $index_query, | ||
'explain' => $explain, | ||
)), 200, array('Content-Type' => 'text/html')); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
/* | ||
* This file is part of the PommProject/PommBundle package. | ||
* | ||
* (c) 2018 Grégoire HUBERT <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PommProject\PommBundle; | ||
|
||
use PommProject\Foundation\Exception\SqlException; | ||
use PommProject\Foundation\Listener\Listener; | ||
use PommProject\Foundation\Session\Session; | ||
|
||
use Symfony\Component\Stopwatch\Stopwatch; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
|
||
/** | ||
* Data collector for the database profiler. | ||
* | ||
* @package PommBundle | ||
* @copyright 2018 Grégoire HUBERT | ||
* @author Jérôme MACIAS | ||
* @author Grégoire HUBERT | ||
* @license X11 {@link http://opensource.org/licenses/mit-license.php} | ||
* @see DataCollector | ||
*/ | ||
class DatabaseDataCollector extends DataCollector | ||
{ | ||
/** @var Stopwatch */ | ||
private $stopwatch; | ||
|
||
public function __construct($unused = null, Stopwatch $stopwatch = null) | ||
{ | ||
if ($unused !== null) { | ||
trigger_error("The parameter Pomm has been deleted for to delete the high dependency.", E_USER_DEPRECATED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rephrase it to |
||
} | ||
|
||
$this->stopwatch = $stopwatch; | ||
$this->data = [ | ||
'time' => 0, | ||
'queries' => [], | ||
'exception' => null, | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param array $data | ||
* @param $session | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @param Session $session |
||
* | ||
* @return null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. void |
||
*/ | ||
public function execute($name, $data, Session $session) | ||
{ | ||
switch ($name) { | ||
case 'query:post': | ||
$this->data['time'] += $data['time_ms']; | ||
$data += array_pop($this->data['queries']); | ||
/* fall-through */ | ||
case 'query:pre': | ||
$this->data['queries'][] = $data; | ||
break; | ||
} | ||
|
||
$this->watch($name); | ||
} | ||
|
||
private function watch($name) | ||
{ | ||
if ($this->stopwatch !== null) { | ||
switch ($name) { | ||
case 'query:pre': | ||
$this->stopwatch->start('query.pomm', 'pomm'); | ||
break; | ||
case 'query:post': | ||
$this->stopwatch->stop('query.pomm'); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function collect(Request $request, Response $response, \Exception $exception = null) | ||
{ | ||
if ($exception instanceof SqlException) { | ||
$this->data['exception'] = $exception->getMessage(); | ||
} | ||
} | ||
|
||
/** | ||
* Return the list of queries sent. | ||
* | ||
* @return array | ||
*/ | ||
public function getQueries() | ||
{ | ||
return $this->data['queries']; | ||
} | ||
|
||
/** | ||
* Return the number of queries sent. | ||
* | ||
* @return integer | ||
*/ | ||
public function getQuerycount() | ||
{ | ||
return count($this->data['queries']); | ||
} | ||
|
||
/** | ||
* Return queries total time. | ||
* | ||
* @return float | ||
*/ | ||
public function getTime() | ||
{ | ||
return $this->data['time']; | ||
} | ||
|
||
/** | ||
* Return sql exception. | ||
* | ||
* @return \PommProject\Foundation\Exception\SqlException|null | ||
*/ | ||
public function getException() | ||
{ | ||
return $this->data['exception']; | ||
} | ||
|
||
/** | ||
* Return profiler identifier. | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'pomm'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function reset() | ||
{ | ||
$this->stopwatch->reset(); | ||
$this->data = array(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/* | ||
* This file is part of the PommProject/PommBundle package. | ||
* | ||
* (c) 2018 Grégoire HUBERT <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PommProject\PommBundle\PropertyInfo\Extractor; | ||
|
||
use PommProject\Foundation\Pomm; | ||
use PommProject\Foundation\Session; | ||
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; | ||
|
||
/** | ||
* Extract properties list using pomm. | ||
* | ||
* @package PommBundle | ||
* @copyright 2018 Grégoire HUBERT | ||
* @author Nicolas Joseph | ||
* @license X11 {@link http://opensource.org/licenses/mit-license.php} | ||
*/ | ||
class ListExtractor implements PropertyListExtractorInterface | ||
{ | ||
private $pomm; | ||
|
||
public function __construct(Pomm $pomm) | ||
{ | ||
$this->pomm = $pomm; | ||
} | ||
|
||
/** | ||
* @see PropertyListExtractorInterface | ||
*/ | ||
public function getProperties($class, array $context = array()) | ||
{ | ||
if (isset($context['session:name'])) { | ||
$session = $this->pomm->getSession($context['session:name']); | ||
} else { | ||
$session = $this->pomm->getDefaultSession(); | ||
} | ||
|
||
if (isset($context['model:name'])) { | ||
$model_name = $context['model:name']; | ||
} else { | ||
$model_name = "${class}Model"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the $model_name = "{$class}Model"; syntax as it allows the use of sub properties or function calls |
||
} | ||
|
||
if (!class_exists($model_name)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth to move it up a bit. As it doesn't require the session to exit. |
||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would add a warning in the logs could be usefull here ? |
||
} | ||
|
||
return $this->getPropertiesList($session, $model_name); | ||
} | ||
|
||
private function getPropertiesList(Session $session, $model_name) | ||
{ | ||
$model = $session->getModel($model_name); | ||
$structure = $model->getStructure(); | ||
|
||
return $structure->getFieldNames(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return void