-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from M6Web/fix/validateLoggerService
Fix logger service validation
- Loading branch information
Showing
3 changed files
with
38 additions
and
28 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/M6Web/Bundle/LogBridgeBundle/DependencyInjection/CompilerPass/LoggerValidationPass.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,35 @@ | ||
<?php | ||
|
||
namespace M6Web\Bundle\LogBridgeBundle\DependencyInjection\CompilerPass; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Validates logger service used by the log request listener. | ||
*/ | ||
class LoggerValidationPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasParameter('m6web_log_bridge.logger.service')) { | ||
return; | ||
} | ||
|
||
$loggerServiceId = $container->getParameter('m6web_log_bridge.logger.service'); | ||
$loggerClass = $container->findDefinition($loggerServiceId)->getClass(); | ||
|
||
// If $loggerClass is not a valid namespace but a container parameter | ||
if (preg_match("/^%[\w\.]+%$/", $loggerClass)) { | ||
$loggerClassParameter = substr($loggerClass, 1, -1); | ||
$loggerClass = $container->getParameter($loggerClassParameter); | ||
} | ||
|
||
if (!in_array('Psr\Log\LoggerInterface', class_implements($loggerClass))) { | ||
throw new \InvalidArgumentException(sprintf('Class "%s" must be implement "Psr\Log\LoggerInterface"', $loggerClass)); | ||
} | ||
} | ||
} |
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