Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Page for background-collection #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
overview-page for background requests
  • Loading branch information
Blaimi committed May 3, 2016
commit b136c175b60c010dc460e38c5ecb912edef48c6f
14 changes: 14 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?php
return array(
'router' => array(
'routes' => array(
'zdtBackgroundRequests' => array(
'type' => 'segment',
'options' => array(
'route' => '/zdt-background-requests[/:uuid][/]',
'defaults' => array(
'controller' => 'zenddevelopertools',
'action' => 'background-requests',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'zenddevelopertools' => __DIR__ . '/../view',
Expand Down
12 changes: 12 additions & 0 deletions config/zenddevelopertools.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ return array(
*/
'identifiers' => array()
),
/**
* General Background-Request settings
*/
'backgroundrequests' => array(
/**
* Enables or disables the Background-Requests-Page
*
* Expects: bool
* Default: false
*/
'enabled' => true,
),
/**
* General Toolbar settings
*/
Expand Down
30 changes: 30 additions & 0 deletions src/ZendDeveloperTools/Controller/DeveloperToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,41 @@

use Zend\View\Model\ViewModel;
use Zend\Mvc\Controller\AbstractActionController;
use ZendDeveloperTools\Options;

class DeveloperToolsController extends AbstractActionController
{
/**
* @var Options
*/
protected $options;

public function __construct(Options $options)
{
$this->options = $options;
}

public function indexAction()
{
return new ViewModel();
}

public function backgroundRequestsAction()
{
$this->options->setToolbar(['enabled' => false]);

/*TODO: make this configurable */
$this->options->setBackgroundrequests(['enabled' => false]);

$toolbars = array();
$cacheDir = $this->options->getCacheDir();

foreach (glob($cacheDir . '/ZDT_*.entries') as $entriesFileName) {
$toolbars[] = unserialize(file_get_contents($entriesFileName));
}

$model = new ViewModel(['toolbars' => $toolbars]);
$model->setTerminal(true);
return $model;
}
}
13 changes: 11 additions & 2 deletions src/ZendDeveloperTools/Listener/ToolbarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ public function onCollected(ProfilerEvent $event)
$application = $event->getApplication();
$request = $application->getRequest();

if ($request->isXmlHttpRequest()) {
if ($this->options->isBackgroundrequestsEnabled()) {
$toolbar = array(
'renderedEntries' => $this->renderEntries($event),
'timestamp' => microtime(true),
);
$cacheDir = $this->options->getCacheDir();
file_put_contents($cacheDir . '/ZDT_' . microtime(true) . '.entries', serialize($toolbar));
}

if ($request->isXmlHttpRequest() || !$this->options->isToolbarEnabled()) {
return;
}

Expand Down Expand Up @@ -183,7 +192,7 @@ protected function renderEntries(ProfilerEvent $event)
$report = $event->getReport();

list($isLatest, $latest) = $this->getLatestVersion(Version::VERSION);

if (false === ($pos = strpos(Version::VERSION, 'dev'))) {
$docUri = sprintf(self::DOC_URI_PATTERN, substr(Version::VERSION, 0, 3));
} else { // unreleased dev branch - compare minor part of versions
Expand Down
29 changes: 23 additions & 6 deletions src/ZendDeveloperTools/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendDeveloperTools;

use Zend\EventManager\EventInterface;
Expand All @@ -17,14 +16,17 @@
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
use Zend\ModuleManager\Feature\ViewHelperProviderInterface;
use Zend\ModuleManager\Feature\ControllerProviderInterface;
use BjyProfiler\Db\Adapter\ProfilingAdapter;
use ZendDeveloperTools\Controller\DeveloperToolsController;

class Module implements
InitProviderInterface,
ConfigProviderInterface,
ServiceProviderInterface,
BootstrapListenerInterface,
ViewHelperProviderInterface
ViewHelperProviderInterface,
ControllerProviderInterface
{
/**
* Initialize workflow
Expand Down Expand Up @@ -82,9 +84,10 @@ public function onBootstrap(EventInterface $event)
$sem = $em->getSharedManager();
$sm = $app->getServiceManager();

/* @var $options \ZendDeveloperTools\Options */
$options = $sm->get('ZendDeveloperTools\Config');

if (!$options->isToolbarEnabled()) {
if (!($options->isToolbarEnabled() || $options->isBackgroundrequestsEnabled())) {
return;
}

Expand All @@ -104,9 +107,7 @@ public function onBootstrap(EventInterface $event)

$em->attachAggregate($sm->get('ZendDeveloperTools\ProfilerListener'));

if ($options->isToolbarEnabled()) {
$sem->attach('profiler', $sm->get('ZendDeveloperTools\ToolbarListener'), null);
}
$sem->attach('profiler', $sm->get('ZendDeveloperTools\ToolbarListener'), null);

if ($options->isStrict() && $report->hasErrors()) {
throw new Exception\ProfilerException(implode(' ', $report->getErrors()));
Expand All @@ -132,6 +133,22 @@ public function getViewHelperConfig()
);
}

/**
* @inheritdoc
*/
public function getControllerConfig()
{
return array(
'factories' => array(
'zenddevelopertools' => function ($cm) {
$sm = $cm->getServiceLocator();
$config = $sm->get('ZendDeveloperTools\Config');
return new DeveloperToolsController($config);
},
),
);
}

/**
* @inheritdoc
*/
Expand Down
29 changes: 29 additions & 0 deletions src/ZendDeveloperTools/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class Options extends AbstractOptions
),
);

/**
* @var array
*/
protected $backgroundrequests = array(
'enabled' => false,
);

/**
* Overloading Constructor.
*
Expand Down Expand Up @@ -409,5 +416,27 @@ public function getToolbarEntries()
return $this->toolbar['entries'];
}

/**
* Sets BackgroundRequest options.
*
* @param array $options
*/
public function setBackgroundrequests($options)
{
if (isset($options['enabled'])) {
$this->backgroundrequests['enabled'] = (bool) $options['enabled'];
}
}

/**
* Is the background-request-collection enabled?
*
* @return bool
*/
public function isBackgroundrequestsEnabled()
{
return $this->backgroundrequests['enabled'];
}

// todo: storage and firephp options.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Zend Developer Tools for Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendDeveloperTools for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
?>

<html>
<head>
<?php echo $this->partial('zend-developer-tools/toolbar/style', ['position' => 'stack']); ?>
</head>

<body>
<?php
foreach ($toolbars as $toolbar) {
echo $this->partial(
'zend-developer-tools/toolbar/toolbar',
array(
'entries' => $toolbar['renderedEntries'],
'multitoolbar' => true,
)
);
}

?>
</body>
</html>
26 changes: 25 additions & 1 deletion view/zend-developer-tools/toolbar/style.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?php include __DIR__ . '/toolbar.css'; ?>

<?php if ($this->position === 'top') : ?>
#zend-developer-toolbar {
.zend-developer-toolbar {
top: 0;
bottom: auto;
border-top: 0;
Expand All @@ -23,6 +23,30 @@
border-top: 0;
border-bottom: 10px solid #68B604;
}
<?php elseif ($this->position === 'stack') : ?>
.zend-developer-toolbar {
position: inherit;
display:block;
clear:both;
}

.zdt-toolbar-detail {
top: auto;
bottom: auto;
}

.zdt-toolbar-detail:before,
.zdt-toolbar-detail:after {
left: 14px;
top: -10px;
bottom: auto;
border-top: 0;
border-bottom: 10px solid #68B604;
}

.zdt-toolbar-entry:hover .zdt-toolbar-detail {
box-shadow: rgba(255, 255, 255, 0.75) 0 0 7px;
}
<?php endif; ?>
</style>
<!-- END Zend Developer Toolbar Style -->
16 changes: 8 additions & 8 deletions view/zend-developer-tools/toolbar/toolbar.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#zend-developer-toolbar {
.zend-developer-toolbar {
left: 0;
bottom: 0;
width: 100%;
Expand All @@ -19,12 +19,12 @@
text-align: left;
}

#zend-developer-toolbar a {
.zend-developer-toolbar a {
color: #80dc09;
text-decoration: none;
}

#zend-developer-toolbar a:hover {
.zend-developer-toolbar a:hover {
text-decoration: underline;
}

Expand Down Expand Up @@ -226,7 +226,7 @@
color: #9d9d9d;
}

#zend-developer-toolbar .zdf-toolbar-hide-button {
.zend-developer-toolbar .zdf-toolbar-hide-button {
top: 0;
right: 8px;
color: #bebebe;
Expand All @@ -236,17 +236,17 @@
text-decoration: none;
}

#zend-developer-toolbar .zdf-toolbar-hide-button:hover {
.zend-developer-toolbar .zdf-toolbar-hide-button:hover {
color: #eb4a4a;
text-decoration: none;
}

#zend-developer-toolbar .zdt-toolbar-entry .zdt-toolbar-detail,#zend-developer-toolbar .zdt-toolbar-entry .zdt-toolbar-info {
.zend-developer-toolbar .zdt-toolbar-entry .zdt-toolbar-detail,.zend-developer-toolbar .zdt-toolbar-entry .zdt-toolbar-info {
font-size: 11px;
max-width: 700px;
}

#zend-developer-toolbar .zdt-toolbar-info .zdt-detail-value pre {
.zend-developer-toolbar .zdt-toolbar-info .zdt-detail-value pre {
max-height: 350px;
max-width: 650px;
overflow-y: scroll;
Expand Down Expand Up @@ -289,7 +289,7 @@
}

@media print {
#zend-developer-toolbar {
.zend-developer-toolbar {
display: none;
}
}
6 changes: 5 additions & 1 deletion view/zend-developer-tools/toolbar/toolbar.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<!-- START Zend Developer Toolbar -->
<div id="zend-developer-toolbar">
<?php if (isset($this->multitoolbar) && $this->multitoolbar): ?>
<div class="zend-developer-toolbar">
<?php else: ?>
<div id="zend-developer-toolbar" class="zend-developer-toolbar">
<?php endif; ?>
<?php foreach ($this->entries as $entry): ?>
<?php echo $entry; ?>
<?php endforeach; ?>
Expand Down