Skip to content
Permalink
Browse files

Refactor to use contributte/di

  • Loading branch information...
mabar committed Jun 28, 2019
1 parent 6b259ff commit 7790027c25e1aafc9551ad0959b3cfcaca9c9d1f
Showing with 5 additions and 22 deletions.
  1. +1 −1 composer.json
  2. +4 −21 src/DI/MonologExtension.php
@@ -17,8 +17,8 @@
],
"require": {
"php": "^7.2.0",
"contributte/di": "^0.4.0",
"monolog/monolog": "^1.23.0",
"nette/di": "~3.0.0",
"nette/utils": "~3.0.0"
},
"require-dev": {
@@ -2,6 +2,7 @@
namespace Contributte\Monolog\DI;
use Contributte\DI\Helper\ExtensionDefinitionsHelper;
use Contributte\Monolog\Exception\Logic\InvalidStateException;
use Contributte\Monolog\LoggerHolder;
use Contributte\Monolog\LoggerManager;
@@ -14,7 +15,6 @@
use Nette\PhpGenerator\ClassType;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nette\Utils\Strings;
use stdClass;
use Tracy\Bridges\Psr\PsrToTracyLoggerAdapter;
use Tracy\Bridges\Psr\TracyToPsrLoggerAdapter;
@@ -46,28 +46,11 @@ public function getConfigSchema(): Schema
]);
}
/**
* Used in loadConfiguration phase when definition of service defined in services cannot be get
*
* @param string|mixed[]|Statement $config
* @return Definition|string
*/
private function getDefinitionFromConfig($config, string $preferredPrefix)
{
if (is_string($config) && Strings::startsWith($config, '@')) {
return $config;
}
$prefix = $preferredPrefix;
$this->compiler->loadDefinitionsFromConfig([$prefix => $config]);
return $this->getContainerBuilder()->getDefinition($prefix);
}
public function loadConfiguration(): void
{
$config = $this->config;
$builder = $this->getContainerBuilder();
$definitionsHelper = new ExtensionDefinitionsHelper($this->compiler);
if (!isset($config->channel['default'])) {
throw new InvalidStateException(sprintf('%s.channel.default is required.', $this->name));
@@ -99,7 +82,7 @@ public function loadConfiguration(): void
foreach ($channel->handlers as $handlerName => $handlerConfig) {
$handlerPrefix = $this->prefix('logger.' . $name . '.handler.' . $handlerName);
$handlerDefinition = $this->getDefinitionFromConfig($handlerConfig, $handlerPrefix);
$handlerDefinition = $definitionsHelper->getDefinitionFromConfig($handlerConfig, $handlerPrefix);
if ($handlerDefinition instanceof Definition) {
$handlerDefinition->setAutowired(false);
@@ -113,7 +96,7 @@ public function loadConfiguration(): void
foreach ($channel->processors as $processorName => $processorConfig) {
$processorPrefix = $this->prefix('logger.' . $name . '.processor.' . $processorName);
$processorDefinition = $this->getDefinitionFromConfig($processorConfig, $processorPrefix);
$processorDefinition = $definitionsHelper->getDefinitionFromConfig($processorConfig, $processorPrefix);
if ($processorDefinition instanceof Definition) {
$processorDefinition->setAutowired(false);

0 comments on commit 7790027

Please sign in to comment.
You can’t perform that action at this time.