Skip to content

Commit

Permalink
Implement compatibility with ZF3
Browse files Browse the repository at this point in the history
  • Loading branch information
neeckeloo committed Jul 26, 2016
1 parent d37bcb2 commit e3702d5
Show file tree
Hide file tree
Showing 21 changed files with 248 additions and 202 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/nbproject
/vendor
composer.lock
.idea
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

matrix:
allow_failures:
- php: 7.0
- php: hhvm

before_script:
Expand All @@ -18,7 +15,7 @@ before_script:

script:
- mkdir -p build/logs
- phpunit -c phpunit.xml.dist
- vendor/bin/phpunit -c phpunit.xml.dist

after_script:
- php vendor/bin/coveralls
26 changes: 0 additions & 26 deletions Module.php

This file was deleted.

20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MonologModule
=============

Monolog integration into Zend Framework 2
Monolog integration into Zend Framework

[![Build Status](https://img.shields.io/travis/neeckeloo/MonologModule.svg?style=flat)](http://travis-ci.org/neeckeloo/MonologModule)
[![Latest Stable Version](http://img.shields.io/packagist/v/neeckeloo/monolog-module.svg?style=flat)](https://packagist.org/packages/neeckeloo/monolog-module)
Expand All @@ -12,9 +12,9 @@ Monolog integration into Zend Framework 2
Requirements
------------

* PHP 5.4 or higher
* PHP ^5.6 || ^7.0
* [Monolog 1.11 or higher](http://www.github.com/Seldaek/monolog)
* [Zend Framework 2.3 or higher](http://www.github.com/zendframework/zf2)
* [Zend Framework ^2.7.5 || ^3.0.3](http://www.github.com/zendframework/zf2)

Installation
------------
Expand Down Expand Up @@ -68,14 +68,14 @@ return [
'name' => 'default',
'handlers' => [
'stream' => [
'name' => 'Monolog\Handler\StreamHandler',
'name' => StreamHandler::class,
'options' => [
'path' => 'data/log/application.log',
'level' => \Monolog\Logger::DEBUG,
'level' => Logger::DEBUG,
],
],
'fire_php' => [
'name' => 'Monolog\Handler\FirePHPHandler',
'name' => FirePHPHandler::class,
],
],
],
Expand All @@ -96,16 +96,16 @@ return [
'name' => 'default',
'handlers' => [
'default' => [
'name' => 'Monolog\Handler\StreamHandler',
'name' => StreamHandler::class,
'options' => [
'path' => 'data/log/application.log',
'level' => \Monolog\Logger::DEBUG,
'level' => Logger::DEBUG,
],
],
],
'processors' => [
'Monolog\Processor\UidProcessor',
'Monolog\Processor\WebProcessor',
UidProcessor::class,
WebProcessor::class,
],
],
],
Expand Down
6 changes: 0 additions & 6 deletions circle.yml

This file was deleted.

16 changes: 6 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neeckeloo/monolog-module",
"description": "Monolog integration into Zend Framework 2",
"description": "Monolog integration into Zend Framework",
"type": "library",
"keywords": [
"zf2", "monolog", "logger", "log"
Expand All @@ -14,23 +14,19 @@
}
],
"require": {
"php": ">=5.4",
"php": "^5.6 || ^7.0",
"monolog/monolog": "~1.11",
"zendframework/zend-servicemanager": "~2.3"
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3"
},
"require-dev": {
"graylog2/gelf-php": "~1.1",
"phpunit/phpunit": "~4.3",
"satooshi/php-coveralls": "dev-master",
"zendframework/zendframework": "~2.3"
"phpunit/phpunit": "~5.4",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"psr-4": {
"MonologModule\\": "src/"
},
"classmap": [
"Module.php"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
21 changes: 12 additions & 9 deletions src/Factory/FormatterPluginManagerFactory.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
namespace MonologModule\Factory;

use Interop\Container\ContainerInterface;
use MonologModule\Formatter\FormatterPluginManager;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class FormatterPluginManagerFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return FormatterPluginManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $serviceLocator->get('Config');
$configInstance = new Config($config['monolog']['formatter_plugin_manager']);
$config = $container->get('Config');

return new FormatterPluginManager(
$container,
$config['monolog']['formatter_plugin_manager']
);
}

return new FormatterPluginManager($configInstance);
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, FormatterPluginManager::class);
}
}
21 changes: 12 additions & 9 deletions src/Factory/HandlerPluginManagerFactory.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
namespace MonologModule\Factory;

use Interop\Container\ContainerInterface;
use MonologModule\Handler\HandlerPluginManager;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class HandlerPluginManagerFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return HandlerPluginManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $serviceLocator->get('Config');
$configInstance = new Config($config['monolog']['handler_plugin_manager']);
$config = $container->get('Config');

return new HandlerPluginManager(
$container,
$config['monolog']['handler_plugin_manager']
);
}

return new HandlerPluginManager($configInstance);
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, HandlerPluginManager::class);
}
}
29 changes: 23 additions & 6 deletions src/Factory/LoggerAbstractFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace MonologModule\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand All @@ -9,9 +10,9 @@ class LoggerAbstractFactory implements AbstractFactoryInterface
/**
* {@inheritdoc}
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
public function canCreate(ContainerInterface $container, $requestedName)
{
$config = $serviceLocator->get('Config');
$config = $container->get('Config');
$loggerConfig = $this->getLoggerConfig($config['monolog'], $requestedName);

return !empty($loggerConfig);
Expand All @@ -20,17 +21,33 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator
/**
* {@inheritdoc}
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this->canCreate($serviceLocator, $requestedName);
}

/**
* {@inheritdoc}
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $serviceLocator->get('Config');
$config = $container->get('Config');
$loggerConfig = $this->getLoggerConfig($config['monolog'], $requestedName);

$factory = $serviceLocator->get('MonologModule\Factory\LoggerFactory');
$factory->setServiceLocator($serviceLocator);
$factory = $container->get(LoggerFactory::class);
$factory->setContainer($container);

return $factory->create($loggerConfig);
}

/**
* {@inheritdoc}
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this->__invoke($serviceLocator, $requestedName);
}

/**
* @param array $config
* @param string $requestedName
Expand Down
24 changes: 17 additions & 7 deletions src/Factory/LoggerFactory.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<?php
namespace MonologModule\Factory;

use Interop\Container\ContainerInterface;
use Monolog\Formatter\FormatterInterface;
use Monolog\Handler\HandlerInterface;
use Monolog\Logger;
use MonologModule\Formatter\FormatterPluginManager;
use MonologModule\Handler\HandlerPluginManager;
use MonologModule\Exception;
use ReflectionClass;
use Zend\ServiceManager\ServiceLocatorAwareTrait;

class LoggerFactory
{
use ServiceLocatorAwareTrait;
/**
* @var ContainerInterface
*/
protected $container;

public function setContainer(ContainerInterface $container)
{
$this->container = $container;
}

/**
* @param array $config
Expand Down Expand Up @@ -54,7 +64,7 @@ private function createHandler($handler)
));
}

$handlerPluginManager = $this->getPluginManager('MonologModule\Handler\HandlerPluginManager');
$handlerPluginManager = $this->getPluginManager(HandlerPluginManager::class);
$instance = $this->createInstanceFromParams($handler, $handlerPluginManager);

if (isset($handler['formatter'])) {
Expand All @@ -81,7 +91,7 @@ private function createFormatter($formatter)
));
}

$formatterPluginManager = $this->getPluginManager('MonologModule\Formatter\FormatterPluginManager');
$formatterPluginManager = $this->getPluginManager(FormatterPluginManager::class);

return $this->createInstanceFromParams($formatter, $formatterPluginManager);
}
Expand Down Expand Up @@ -115,7 +125,7 @@ private function createInstanceFromParams($params, $pluginManager = null)

/**
* @param mixed $processor
* @return Callable
* @return callable
*/
private function createProcessor($processor)
{
Expand All @@ -138,10 +148,10 @@ private function createProcessor($processor)
*/
protected function getPluginManager($name)
{
if (!$this->serviceLocator || !$this->serviceLocator->has($name)) {
if (!$this->container || !$this->container->has($name)) {
return null;
}

return $this->serviceLocator->get($name);
return $this->container->get($name);
}
}
Loading

0 comments on commit e3702d5

Please sign in to comment.