Skip to content

Commit

Permalink
Merge pull request #6 from MatthiasKuehneEllerhold/master
Browse files Browse the repository at this point in the history
ZF3 Support, Short array syntax
  • Loading branch information
jhuet authored Jul 28, 2016
2 parents b0f20b4 + 4d339a8 commit 8a021b4
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 167 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.lock
/vendor/
/.idea/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JhuZdtLoggerModule
==================

A ZF2 module to log data using [Zend\Log](http://framework.zend.com/manual/2.1/en/modules/zend.log.overview.html) and write them to [ZendDeveloperTools](https://github.com/zendframework/ZendDeveloperTools) toolbar. If you already have a logger in your application (that is an instance of `Zend\Log\Logger`) it will integrate well with it so you still will only have to use your logger.
A ZF3 module to log data using [Zend\Log](http://framework.zend.com/manual/2.1/en/modules/zend.log.overview.html) and write them to [ZendDeveloperTools](https://github.com/zendframework/ZendDeveloperTools) toolbar. If you already have a logger in your application (that is an instance of `Zend\Log\Logger`) it will integrate well with it so you still will only have to use your logger.
___

Installation
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"name": "jhuet/zdt-logger-module",
"description": "A ZF2 module to log data using Zend_Log and write them to ZendDeveloperTools toolbar.",
"description": "A ZF3 module to log data using Zend\\Log and write them to ZendDeveloperTools toolbar.",
"type": "library",
"license": "MIT",
"keywords": ["zf2", "log", "zdt", "module"],
"keywords": ["zf3", "log", "zdt", "module"],
"homepage": "https://github.com/jhuet/JhuZdtLoggerModule",
"authors": [ {
"name": "Jérémy Huet",
"email": "jeremy.huet@gmail.com",
"homepage": "https://github.com/jhuet/"
} ],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.3",
"zendframework/zend-log": "2.*",
"zendframework/zend-developer-tools": "dev-master"
"zendframework/zend-developer-tools": "^1.1.0",
"zendframework/zend-servicemanager": "3.*"
},
"require-dev": {
"atoum/atoum": "dev-master"
Expand All @@ -24,4 +23,4 @@
"Jhu\\ZdtLoggerModule\\": "src/"
}
}
}
}
12 changes: 6 additions & 6 deletions config/jhu-zdt-logger.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* If you have a ./config/autoload/ directory set up for your project, you can
* drop this config file in it and change the values as you wish.
*/
$settings = array(
$settings = [
/**
* The logger that will be used. This module will only add a writer to it
* so if you already have a logger in your application, you can set it here.
Expand All @@ -14,13 +14,13 @@ $settings = array(
* and be an instance or extend Zend\Log\Logger.
*/
'logger' => 'Zend\Log\Logger'
);
];

/**
* You do not need to edit below this line
*/
return array(
'jhu' => array(
return [
'jhu' => [
'zdt_logger' => $settings
)
);
]
];
40 changes: 20 additions & 20 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?php
return array(
'jhu' => array(
'zdt_logger' => array(
return [
'jhu' => [
'zdt_logger' => [
'logger' => 'Zend\Log\Logger'
),
),
],
],

// zendframework/zend-developer-tools specific settings

'view_manager' => array(
'template_map' => array(
'view_manager' => [
'template_map' => [
'zend-developer-tools/toolbar/jhu-zdt-logger' => __DIR__ . '/../view/zend-developer-tools/toolbar/jhu-zdt-logger.phtml',
),
),
],
],

'zenddevelopertools' => array(
'profiler' => array(
'collectors' => array(
'zenddevelopertools' => [
'profiler' => [
'collectors' => [
'jhu_zdt_logger' => 'Jhu\ZdtLoggerModule\Collector',
),
),
'toolbar' => array(
'entries' => array(
],
],
'toolbar' => [
'entries' => [
'jhu_zdt_logger' => 'zend-developer-tools/toolbar/jhu-zdt-logger',
),
),
),
);
],
],
],
];
10 changes: 4 additions & 6 deletions src/Jhu/ZdtLoggerModule/Collector/ZendWriterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

use ZendDeveloperTools\Collector\CollectorInterface;
use ZendDeveloperTools\Collector\AutoHideInterface;

use Zend\Mvc\MvcEvent;

use Jhu\ZdtLoggerModule\Writer\Stack as StackWriter;

/**
Expand All @@ -24,7 +22,7 @@ class ZendWriterCollector implements CollectorInterface, AutoHideInterface
const PRIORITY = 10;

/**
* @var \Jhu\ZdtLoggerModule\Writer\Stack
* @var StackWriter
*/
protected $zendWriter;

Expand All @@ -34,13 +32,13 @@ class ZendWriterCollector implements CollectorInterface, AutoHideInterface
protected $name;

/**
* @param Jhu\ZdtLoggerModule\Writer\Stack $zendWriter
* @param string $name
* @param StackWriter $zendWriter
* @param string $name
*/
public function __construct(StackWriter $zendWriter, $name)
{
$this->zendWriter = $zendWriter;
$this->name = (string) $name;
$this->name = (string) $name;
}

/**
Expand Down
38 changes: 19 additions & 19 deletions src/Jhu/ZdtLoggerModule/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function init(ModuleManagerInterface $manager)
public function onBootstrap(EventInterface $e)
{
$application = $e->getParam('application');
$config = $application->getServiceManager()->get('Config');
$config = $application->getServiceManager()->get('Config');

// If the default logger is different and ZDT's toolbar is activated,
// we initialize ours to add our functionalities
Expand All @@ -60,16 +60,16 @@ public function onBootstrap(EventInterface $e)
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
return [
'Zend\Loader\ClassMapAutoloader' => [
__DIR__ . '/../../../autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
],
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/../../../src/' . __NAMESPACE__,
),
),
);
],
],
];
}

/**
Expand All @@ -85,21 +85,21 @@ public function getConfig()
*/
public function getServiceConfig()
{
return array(
'invokables' => array(
'Jhu\ZdtLoggerModule\Writer' => 'Jhu\ZdtLoggerModule\Writer\Stack',
'Zend\Log\Logger' => 'Zend\Log\Logger'
),
return [
'invokables' => [
'Jhu\ZdtLoggerModule\Writer' => Writer\Stack::class,
'Zend\Log\Logger' => \Zend\Log\Logger::class,
],

'factories' => array(
'factories' => [
'Jhu\ZdtLoggerModule\Logger' => new ServiceFactory\LoggerFactory(),
'Jhu\ZdtLoggerModule\Collector' => new ServiceFactory\CollectorFactory(),
'Jhu\ZdtLoggerModule\Options' => new ServiceFactory\ModuleOptionsFactory(),
),
],

'aliases' => array(
'aliases' => [
'jhu.zdt_logger' => 'Jhu\ZdtLoggerModule\Logger',
),
);
],
];
}
}
11 changes: 6 additions & 5 deletions src/Jhu/ZdtLoggerModule/ServiceFactory/CollectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Jhu\ZdtLoggerModule\ServiceFactory;

use Interop\Container\ContainerInterface;
use Jhu\ZdtLoggerModule\Collector\ZendWriterCollector;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;
use Jhu\ZdtLoggerModule\Writer\Stack as StackWriter;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* Zdt Collector factory
Expand All @@ -22,10 +23,10 @@ class CollectorFactory implements FactoryInterface
*
* @return \Jhu\ZdtLoggerModule\Collector\ZendWriterCollector
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var $writer \Jhu\ZdtLogger\Writer\Zdt */
$writer = $serviceLocator->get('Jhu\ZdtLoggerModule\Writer');
$writer = $container->get('Jhu\ZdtLoggerModule\Writer');
/* @var $writer StackWriter */

return new ZendWriterCollector($writer, 'jhu_zdt_logger');
}
Expand Down
26 changes: 13 additions & 13 deletions src/Jhu/ZdtLoggerModule/ServiceFactory/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Jhu\ZdtLoggerModule\ServiceFactory;

use Interop\Container\ContainerInterface;
use Zend\Log\Logger;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Factory\FactoryInterface;
use Jhu\ZdtLoggerModule\Writer\Stack as StackWriter;

/**
* Zdt Logger factory
Expand All @@ -20,22 +22,20 @@ class LoggerFactory implements FactoryInterface
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
*
* @return \Zend\Log\Logger
* @return Logger
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$options = $serviceLocator->get('Jhu\ZdtLoggerModule\Options');
/* @var $logger \Zend\Log\Logger */
$logger = $serviceLocator->get($options->getLogger());

$options = $container->get('Jhu\ZdtLoggerModule\Options');
$logger = $container->get($options->getLogger());
if (! $logger instanceof Logger) {
throw new \InvalidArgumentException('`logger` option of JhuZdtLoggerModule has to be an instance or extend Zend\Log\Logger class.');
throw new ServiceNotCreatedException(
'`logger` option of JhuZdtLoggerModule has to be an instance or extend Zend\Log\Logger class.'
);
}

/* @var $writer \Jhu\ZdtLogger\Writer\Zdt */
$writer = $serviceLocator->get('Jhu\ZdtLoggerModule\Writer');
$writer = $container->get('Jhu\ZdtLoggerModule\Writer');
/* @var $writer StackWriter */

$logger->addWriter($writer);

Expand Down
12 changes: 6 additions & 6 deletions src/Jhu/ZdtLoggerModule/ServiceFactory/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Jhu\ZdtLoggerModule\ServiceFactory;

use Interop\Container\ContainerInterface;
use Jhu\ZdtLoggerModule\Options;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* @since 0.1
Expand All @@ -18,12 +18,12 @@ class ModuleOptionsFactory implements FactoryInterface
/**
* {@inheritDoc}
*
* @return \Jhu\ZdtLoggerModule\Options\ModuleOptions
* @return Options\ModuleOptions
*/
public function createService(ServiceLocatorInterface $services)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $services->get('Configuration');
$config = $container->get('Configuration');

return new Options\ModuleOptions(isset($config['jhu']['zdt_logger']) ? $config['jhu']['zdt_logger'] : array());
return new Options\ModuleOptions(isset($config['jhu']['zdt_logger']) ? $config['jhu']['zdt_logger'] : []);
}
}
12 changes: 1 addition & 11 deletions src/Jhu/ZdtLoggerModule/Writer/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ class Stack extends AbstractWriter
*
* @var array
*/
protected $stack;

/**
* Constructor
*/
public function __construct($options = null)
{
parent::__construct($options);

$this->stack = array();
}
protected $stack = [];

/**
* @return array
Expand Down
Loading

0 comments on commit 8a021b4

Please sign in to comment.