Skip to content
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

Improvements with zf3, php5.5 and better tests #13

Merged
merged 8 commits into from
Oct 23, 2016
Merged
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
28 changes: 16 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
language: php

matrix:
fast_finish: true
include:
- php: 5.5
- php: 5.6
- php: 7
- php: hhvm
allow_failures:
- php: hhvm
php:
- 5.5
- 5.6
- 7
- hhvm

env:
- DEPS=lowest
- DEPS=latest

install:
before_script:
- composer self-update
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable --no-interaction ; fi
- travis_retry composer install --no-interaction
- composer info -i

script:
- ./vendor/bin/phpunit
- composer test

matrix:
fast_finish: true
3 changes: 0 additions & 3 deletions Module.php

This file was deleted.

41 changes: 22 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,38 @@
}
],
"require": {
"php": ">=5.5 || ^7.0",
"maximebf/debugbar": "1.*",
"zendframework/zend-mvc": "2.* || ^3.0",
"zendframework/zend-log": "2.*",
"zendframework/zend-servicemanager": "~2.6 || ^3.0",
"zendframework/zend-view": "2.*",
"zendframework/zend-eventmanager": "2.* || ^3.0",
"zendframework/zend-http": "2.*",
"zendframework/zend-modulemanager": "2.*"
"php": "^5.5 || ^7.0",
"maximebf/debugbar": "^1.10",
"zendframework/zend-mvc": "^2.4 || ^3.0",
"zendframework/zend-log": "^2.4",
"zendframework/zend-servicemanager": "^2.6 || ^3.0",
"zendframework/zend-view": "^2.4",
"zendframework/zend-eventmanager": "^2.4 || ^3.0",
"zendframework/zend-http": "^2.4",
"zendframework/zend-modulemanager": "^2.4"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"zendframework/zend-test": "2.* || ^3.0",
"zendframework/zend-config": "2.*",
"zendframework/zend-serializer": "2.*",
"zendframework/zend-i18n": "2.*",
"zendframework/zend-db": "2.*"
"phpunit/phpunit": "^4.0 || ^5.0",
"zendframework/zend-test": "^2.4 || ^3.0",
"zendframework/zend-config": "^2.4",
"zendframework/zend-serializer": "^2.4",
"zendframework/zend-i18n": "^2.4",
"zendframework/zend-db": "^2.4"
},
"autoload": {
"psr-0": {
"ZfSnapPhpDebugBar": "src/"
"psr-4": {
"ZfSnapPhpDebugBar\\": "src/"
},
"classmap": [
"./Module.php"
"files": [
"src/Functions.php"
]
},
"autoload-dev": {
"psr-4": {
"ZfSnapPhpDebugBar\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
}
}
19 changes: 19 additions & 0 deletions config/aliases.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* Aliases for ZF3 (it's case sensitive)
*/
return [
'service_manager' => [
'aliases' => [
'DebugBar' => 'debugbar',
'Debugbar' => 'debugbar',
],
],
'view_helpers' => [
'aliases' => [
'DebugBar' => 'debugbar',
'Debugbar' => 'debugbar',
],
],
];
86 changes: 48 additions & 38 deletions config/zfsnapphpdebugbar.config.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,64 @@
<?php

return array(
'php-debug-bar' => array(
'view' => array(
return [
'php-debug-bar' => [
'view' => [
'custom-style-path' => 'zf-snap-php-debug-bar.css',
),
// Enables/disables PHP Debug Bar
],
'enabled' => true,

'auto-append-assets' => true,

'zend-db-adapter-service-name' => 'Zend\Db\Adapter\Adapter',

// ServiceManager keys to inject collectors
'render-on-shutdown' => true,
'zend-db-adapter-service-name' => Zend\Db\Adapter\Adapter::class,
// ServiceManager service keys to inject collectors
// http://phpdebugbar.com/docs/data-collectors.html
'collectors' => array(),

// ServiceManager key to inject storage
'collectors' => [],
// ServiceManager service key to inject storage
// http://phpdebugbar.com/docs/storage.html
'storage' => null,
),
'controllers' => array(
'invokables' => array(
'ZfSnapPhpDebugBar\Controller\Resources' => 'ZfSnapPhpDebugBar\Controller\Resources',
),
),
'router' => array(
'routes' => array(
'phpdebugbar-resource' => array(
],
'service_manager' => [
'invokables' => [
DebugBar\DebugBar::class => DebugBar\StandardDebugBar::class,
],
'factories' => [
'debugbar' => ZfSnapPhpDebugBar\Service\PhpDebugBarFactory::class,
ZfSnapPhpDebugBar\Log\Writer\PhpDebugBar::class => ZfSnapPhpDebugBar\Log\Writer\PhpDebugBarFactory::class,
],
],
'controllers' => [
'invokables' => [
ZfSnapPhpDebugBar\Controller\Resources::class => ZfSnapPhpDebugBar\Controller\Resources::class,
],
],
'view_helpers' => [
'factories' => [
'debugbar' => ZfSnapPhpDebugBar\View\Helper\DebugBarFactory::class,
],
],
'router' => [
'routes' => [
'phpdebugbar-resource' => [
'type' => 'regex',
'options' => array(
'options' => [
'regex' => '/DebugBar/Resources/(?<resource>[a-zA-Z0-9_.\-/]+)',
'spec' => '/DebugBar/Resources/%resource%',
'defaults' => array(
'controller' => 'ZfSnapPhpDebugBar\Controller\Resources',
'defaults' => [
'controller' => ZfSnapPhpDebugBar\Controller\Resources::class,
'action' => 'index',
),
),
),
'phpdebugbar-custom-resource' => array(
],
],
],
'phpdebugbar-custom-resource' => [
'type' => 'regex',
'options' => array(
'options' => [
'regex' => '/ZfSnapPhpDebugBar/Resources/(?<resource>[a-zA-Z0-9_.\-/]+)',
'spec' => '/ZfSnapPhpDebugBar/Resources/%resource%',
'defaults' => array(
'controller' => 'ZfSnapPhpDebugBar\Controller\Resources',
'defaults' => [
'controller' => ZfSnapPhpDebugBar\Controller\Resources::class,
'action' => 'custom',
),
),
),
),
),
);
],
],
],
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
use Zend\Mvc\Controller\AbstractActionController;

/**
* Resources
*
* @author Witold Wasiczko <witold@wasiczko.pl>
*/
class Resources extends AbstractActionController
{
protected $extensionToContentTypeMap = array(
protected $extensionToContentTypeMap = [
'css' => 'text/css; charset=UTF-8',
'js' => 'text/javascript; charset=UTF-8',
);
];

public function indexAction()
{
Expand Down
17 changes: 17 additions & 0 deletions src/Exception/ThrowableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace ZfSnapPhpDebugBar\Exception;

use Exception;

/**
* @author witold
*/
class ThrowableException extends Exception
{

public function __construct(\Throwable $exception)
{
parent::__construct($exception->getMessage(), $exception->getCode(), $exception);
}
}
4 changes: 3 additions & 1 deletion src/ZfSnapPhpDebugBar/Functions.php → src/Functions.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

use ZfSnapPhpDebugBar\Module;

if (!function_exists('debugbar_log')) {
/**
* @param string $message
* @param string $type
*/
function debugbar_log($message, $type = 'debug')
{
\ZfSnapPhpDebugBar\Module::log($message, $type);
Module::log($message, $type);
}
}
40 changes: 40 additions & 0 deletions src/Listener/ExceptionListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace ZfSnapPhpDebugBar\Listener;

use DebugBar\DataCollector\ExceptionsCollector;
use Exception;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManagerInterface;
use ZfSnapPhpDebugBar\Exception\ThrowableException;

/**
* @author witold
*/
final class ExceptionListener extends AbstractListenerAggregate
{

private $exceptionsCollector;

public function __construct(ExceptionsCollector $exceptionsCollector)
{
$this->exceptionsCollector = $exceptionsCollector;
}

public function attach(EventManagerInterface $events, $priority = 1)
{
$this->listeners[] = $events->attach('*', [$this, 'collectException'], $priority);
}

public function collectException(EventInterface $event)
{
$exception = $event->getParam('exception');

if ($exception instanceof Exception || $exception instanceof \Throwable) {
$exception = $exception instanceof \Throwable ? new ThrowableException($exception) : $exception;

$this->exceptionsCollector->addException($exception);
}
}
}
47 changes: 47 additions & 0 deletions src/Listener/MeasureListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace ZfSnapPhpDebugBar\Listener;

use DebugBar\DataCollector\TimeDataCollector;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\View\Model\ModelInterface;
use Zend\View\ViewEvent;

/**
* @author witold
*/
class MeasureListener extends AbstractListenerAggregate
{

private $timeCollector;
private $lastMeasure;

public function __construct(TimeDataCollector $timeCollector)
{
$this->timeCollector = $timeCollector;
}

public function attach(EventManagerInterface $events, $priority = 1)
{
$this->listeners[] = $events->attach('*', [$this, 'mesureToCollector'], $priority);
}

public function mesureToCollector(EventInterface $event)
{
if ($this->lastMeasure !== null && $this->timeCollector->hasStartedMeasure($this->lastMeasure)) {
$this->timeCollector->stopMeasure($this->lastMeasure);
}
$this->lastMeasure = $event->getName();

if ($event instanceof ViewEvent) {
$model = $event->getParam('model');

if ($model instanceof ModelInterface) {
$this->lastMeasure .= ' (' . $model->getTemplate() . ')';
}
}
$this->timeCollector->startMeasure($this->lastMeasure, $this->lastMeasure);
}
}
Loading