Skip to content

Instantly share code, notes, and snippets.

@vasildakov-zz
Last active February 23, 2017 14:38
Show Gist options
  • Save vasildakov-zz/c2886fc704c1a26ee591daae847b88eb to your computer and use it in GitHub Desktop.
Save vasildakov-zz/c2886fc704c1a26ee591daae847b88eb to your computer and use it in GitHub Desktop.
Monolog and Handlers
<?php
# generic stream handler
use Monolog\Handler\StreamHandler;
class CustomStreamHandlerFactory
{
public function __invoke(ContainerInterface $container) : StreamHandler
{
$options = $container->get(CustomStreamHandlerOptions::class);
return new StreamHandler(
$options->getPath(),
$options->getLevel(),
$options->getBbubble()
);
}
}
<?php
use Zend\Stdlib\AbstractOptions;
class CustomStreamHandlerOptions extends AbstractOptions
{
/**
* @var string $path
*/
protected $path;
/**
* @var int $level
*/
protected $level;
/**
* @var string $bubble
*/
protected $bubble;
public function setPath($path)
{
$this->path = $path;
}
public function getPath()
{
return $this->path;
}
public function setLevel($level)
{
$this->level = $level;
}
public function getLevel()
{
return $this->level;
}
public function setBubble($bubble)
{
$this->bubble = $bubble;
}
public function getBubble()
{
return $this->bubble;
}
}
<?php
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Exception;
class CustomStreamHandlerOptionsFactory
{
public function __invoke(ContainerInterface $container)
{
$config = $container->get('config');
$config['handler']['custom']['options'];
return new CustomStreamHandlerOptions($config);
}
}
<?php
class ModuleConfig
{
public function __invoke()
{
return [
'dependencies' => [
'invokables' => [],
'factories' => [
CustomStreamHandlerOptions::class => CustomStreamHandlerOptionsFactory::class,
CustomStreamHandler::class => CustomStreamHandlerFactory::class,
],
],
'loggers' => [
CustomLogger::class => [
'handlers' => [
CustomStreamHandler::class
],
]
]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment