forked from enlitepro/enlite-monolog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement factories and aware interfaces
- Loading branch information
1 parent
e43800e
commit 347d8cc
Showing
20 changed files
with
828 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
composer.lock | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
|
||
before_script: | ||
- composer self-update | ||
- composer --dev install | ||
|
||
script: | ||
- vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "enlitepro/enlite-monolog", | ||
"description": "Monolog integration to Zend Framework 2", | ||
"minimum-stability": "dev", | ||
"authors": [ | ||
{ | ||
"name": "Evgeny Shpilevsky", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"keywords": [ | ||
"Zend Framework 2", | ||
"Monolog" | ||
], | ||
"require": { | ||
"monolog/monolog": "~1.6.0", | ||
"zendframework/zendframework": "2.2.4" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~3.7" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"EnliteMonolog": "src" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<phpunit bootstrap="./test/bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>./test/EnliteMonologTest</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* @author Evgeny Shpilevsky <[email protected]> | ||
*/ | ||
|
||
namespace EnliteMonolog; | ||
|
||
|
||
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; | ||
use Zend\ModuleManager\Feature\ConfigProviderInterface; | ||
|
||
class Module implements | ||
AutoloaderProviderInterface, | ||
ConfigProviderInterface | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAutoloaderConfig() | ||
{ | ||
return array( | ||
'Zend\Loader\StandardAutoloader' => array( | ||
'namespaces' => array( | ||
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, | ||
), | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfig() | ||
{ | ||
return include __DIR__ . "/config/module.config.php"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
return array( | ||
'EnliteMonolog' => array( | ||
// Logger name | ||
// 'name' => 'EnliteMonolog', | ||
|
||
// Handlers, it can be service manager alias(string) or config(array) | ||
'handlers' => array( | ||
'default' => array( | ||
'name' => 'Monolog\Handler\StreamHandler', | ||
'args' => array( | ||
'path' => 'data/log/application.log', | ||
'level' => \Monolog\Logger::DEBUG, | ||
'bubble' => true | ||
) | ||
) | ||
) | ||
), | ||
'service_manager' => array( | ||
'factories' => array( | ||
'EnliteMonologService' => 'EnliteMonolog\MonologServiceFactory', | ||
'EnliteMonologOptions' => 'EnliteMonolog\MonologOptionsFactory', | ||
), | ||
'initializers' => array( | ||
'EnliteMonolog\Service\MonologServiceInitializer' | ||
) | ||
) | ||
); |
62 changes: 62 additions & 0 deletions
62
src/EnliteMonolog/src/EnliteMonolog/Service/MonologOptions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* @author Evgeny Shpilevsky <[email protected]> | ||
*/ | ||
|
||
namespace EnliteMonolog\Service; | ||
|
||
|
||
use Zend\Stdlib\AbstractOptions; | ||
|
||
class MonologOptions extends AbstractOptions | ||
{ | ||
|
||
/** | ||
* Logger name | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'EnliteMonolog'; | ||
|
||
/** | ||
* Handlers | ||
* | ||
* @var array | ||
*/ | ||
protected $handlers = array(); | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @param array $handlers | ||
*/ | ||
public function setHandlers(array $handlers) | ||
{ | ||
$this->handlers = $handlers; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHandlers() | ||
{ | ||
return $this->handlers; | ||
} | ||
|
||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/EnliteMonolog/src/EnliteMonolog/Service/MonologOptionsFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* @author Evgeny Shpilevsky <[email protected]> | ||
*/ | ||
|
||
namespace EnliteMonolog\Service; | ||
|
||
|
||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class MonologOptionsFactory implements FactoryInterface | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$config = $serviceLocator->get('config'); | ||
return new MonologOptions(isset($config['EnliteMonolog']) ? $config['EnliteMonolog'] : array()); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/EnliteMonolog/src/EnliteMonolog/Service/MonologServiceAwareInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* @author Evgeny Shpilevsky <[email protected]> | ||
*/ | ||
|
||
namespace EnliteMonolog\Service; | ||
|
||
|
||
use Monolog\Logger; | ||
|
||
interface MonologServiceAwareInterface | ||
{ | ||
|
||
/** | ||
* @param Logger $monologService | ||
* @return void | ||
*/ | ||
public function setMonologService(Logger $monologService); | ||
|
||
/** | ||
* @return Logger | ||
*/ | ||
public function getMonologService(); | ||
} |
52 changes: 52 additions & 0 deletions
52
src/EnliteMonolog/src/EnliteMonolog/Service/MonologServiceAwareTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* @author Evgeny Shpilevsky <[email protected]> | ||
*/ | ||
|
||
namespace EnliteMonolog\Service; | ||
|
||
|
||
use Monolog\Logger; | ||
use RuntimeException; | ||
use Zend\ServiceManager\ServiceLocatorAwareInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
trait MonologServiceAwareTrait | ||
{ | ||
|
||
/** | ||
* @var Logger | ||
*/ | ||
protected $monologService; | ||
|
||
/** | ||
* @param Logger $monologService | ||
*/ | ||
public function setMonologService(Logger $monologService) | ||
{ | ||
$this->monologService = $monologService; | ||
} | ||
|
||
/** | ||
* @throws \RuntimeException | ||
* @return Logger | ||
*/ | ||
public function getMonologService() | ||
{ | ||
if (null === $this->monologService) { | ||
if ($this instanceof ServiceLocatorAwareInterface || method_exists($this, 'getServiceLocator')) { | ||
$this->analyseService = $this->getServiceLocator()->get('EnliteMonologService'); | ||
} else { | ||
if (property_exists($this, 'serviceLocator') | ||
&& $this->monologService instanceof ServiceLocatorInterface | ||
) { | ||
$this->analyseService = $this->serviceLocator->get('EnliteMonologService'); | ||
} else { | ||
throw new RuntimeException('Service locator not found'); | ||
} | ||
} | ||
} | ||
return $this->monologService; | ||
} | ||
|
||
} |
Oops, something went wrong.