From b502805fae382fdfbc0d8910cbeb6a3c1f63f52f Mon Sep 17 00:00:00 2001 From: Joao Jacome Date: Thu, 20 Sep 2018 14:59:44 +0100 Subject: [PATCH] changed contextualinterface and contextualtrait to accept objects --- ContextualInterface.php | 4 ++-- Helper/ContextualTrait.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ContextualInterface.php b/ContextualInterface.php index 51661b1..9b05e4f 100644 --- a/ContextualInterface.php +++ b/ContextualInterface.php @@ -12,11 +12,11 @@ interface ContextualInterface /** * Set the context for the logger * - * @param array $context + * @param mixed $context * * @return mixed */ - public function setContext(array $context); + public function setContext($context); /** * Retrieve the context of this class diff --git a/Helper/ContextualTrait.php b/Helper/ContextualTrait.php index eff3ce4..a37692f 100644 --- a/Helper/ContextualTrait.php +++ b/Helper/ContextualTrait.php @@ -2,6 +2,9 @@ namespace KoderHut\OnelogBundle\Helper; +use KoderHut\OnelogBundle\ContextualInterface; + + /** * Trait ContextualTrait * @@ -17,8 +20,14 @@ trait ContextualTrait /** * @inheritdoc */ - public function setContext(array $context): self + public function setContext($context): self { + if (is_object($context) && $context instanceof ContextualInterface) { + $context = $context->getContext(); + } else if (is_object($context)) { + throw new \InvalidArgumentException(); + } + $this->contextualData = $context; return $this;