diff --git a/src/InmailAnalyzerResult.php b/src/InmailAnalyzerResult.php index b3fd1f8..c7a1f5c 100644 --- a/src/InmailAnalyzerResult.php +++ b/src/InmailAnalyzerResult.php @@ -3,6 +3,7 @@ namespace Drupal\inmail; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Plugin\Context\ContextInterface; /** * Contains defaults Inmail analyzer result. @@ -21,6 +22,13 @@ class InmailAnalyzerResult implements AnalyzerResultInterface, InmailAnalyzerRes const TOPIC = 'default'; /** + * An array of collected contexts for this this analyzer result. + * + * @var \Drupal\Component\Plugin\Context\ContextInterface[] + */ + protected $contexts = []; + + /** * The sender. * * @var string @@ -28,7 +36,7 @@ class InmailAnalyzerResult implements AnalyzerResultInterface, InmailAnalyzerRes protected $sender; /** - * The user + * The user. * * @var \Drupal\user\UserInterface */ @@ -56,54 +64,6 @@ class InmailAnalyzerResult implements AnalyzerResultInterface, InmailAnalyzerRes protected $subject; /** - * The detected entity type. - * - * @var string - */ - protected $entity_type; - - /** - * The detected bundle. - * - * @var string - */ - protected $bundle; - - /** - * The PGP signature. - * - * In case the PGP type is "inline", the signature is FALSE. - * - * @var string|bool - */ - protected $signature; - - /** - * The signed text. - * - * @var string - */ - protected $signedText; - - /** - * The PGP type. - * - * Represents the type of the message. Could be "inline" (message text is - * signed and embedded as a plain text into message body) - * or "mime" (message is sent as PGP/MIME type). - * - * @var string - */ - protected $pgpType; - - /** - * A flag that determines whether message is verified. - * - * @var bool - */ - protected $verified; - - /** * The context data. * * It should contain information provided by analyzers that are not part of @@ -228,116 +188,34 @@ class InmailAnalyzerResult implements AnalyzerResultInterface, InmailAnalyzerRes /** * @inheritDoc */ - public function getEntityType() { - return $this->entity_type; - } - - /** - * @inheritDoc - */ - public function setEntityType($entity_type) { - $this->entity_type = $entity_type; - } - - /** - * @inheritDoc - */ - public function getBundle() { - return $this->bundle; - } - - /** - * @inheritDoc - */ - public function setBundle($bundle) { - $this->bundle = $bundle; + public function addContext($name, ContextInterface $context) { + $this->contexts[$name] = $context; } /** * @inheritDoc */ - public function isSigned() { - return (bool) $this->signedText; + public function getContexts() { + return $this->contexts; } /** * @inheritDoc */ - public function getSignature() { - return $this->signature; + public function hasContext($name) { + $contexts = $this->getContexts(); + return isset($contexts[$name]) ? TRUE : FALSE; } /** * @inheritDoc */ - public function setSignature($signature) { - $this->signature = $signature; - } - - /** - * @inheritDoc - */ - public function getSignedText() { - return $this->signedText; - } - - /** - * @inheritDoc - */ - public function setSignedText($signed_text) { - $this->signedText = $signed_text; - } - - /** - * @inheritDoc - */ - public function getPgpType() { - return $this->pgpType; - } - - /** - * @inheritDoc - */ - public function setPgpType($pgp_type) { - $this->pgpType = $pgp_type; - } - - /** - * @inheritDoc - */ - public function setVerified($verified) { - $this->verified = $verified; - } - - /** - * @inheritDoc - */ - public function isVerified() { - return $this->verified; - } - - - /** - * @inheritDoc - */ - public function getContext() { - return $this->context; - } - - - /** - * @inheritDoc - */ - public function setContext(array $context) { - $this->context = $context; - } - - /** - * @inheritDoc - */ - public function getContextItem($key) { - $context = $this->getContext(); - return NestedArray::getValue($context, (array) $key); + public function getContext($name) { + $contexts = $this->getContexts(); + if (isset($contexts[$name])) { + return $contexts[$name]; + } + return NULL; } } diff --git a/src/InmailAnalyzerResultInterface.php b/src/InmailAnalyzerResultInterface.php index 69b5fb1..3bb02e4 100644 --- a/src/InmailAnalyzerResultInterface.php +++ b/src/InmailAnalyzerResultInterface.php @@ -2,6 +2,8 @@ namespace Drupal\inmail; +use Drupal\Core\Plugin\Context\ContextInterface; + /** * A default Inmail analyzer result created to allow collaboration between * analyzers. @@ -99,137 +101,43 @@ interface InmailAnalyzerResultInterface { public function setSubject($subject); /** - * Returns the detected entity type. - * - * @return string|null - * The detected entity type. - */ - public function getEntityType(); - - /** - * Sets the detected entity type. - * - * @param string $entity_type - * The detected entity type. - */ - public function setEntityType($entity_type); - - /** - * Returns the detected bundle. - * - * @return string|null - * The detected bundle. - */ - public function getBundle(); - - /** - * Sets the detected bundle. + * Sets the condition context for a given name. * - * @param string $bundle - * The detected bundle. + * @param string $name + * The name of the context. + * @param \Drupal\Core\Plugin\Context\ContextInterface $context + * The context to add. */ - public function setBundle($bundle); + public function addContext($name, ContextInterface $context); /** - * Returns TRUE if message is signed. Otherwise, FALSE. + * Gets the values for all defined contexts. * - * @return bool - * A flag whether a message is signed or not. + * @return \Drupal\Component\Plugin\Context\ContextInterface[] + * An array of set contexts, keyed by context name. */ - public function isSigned(); + public function getContexts(); /** - * Returns the PGP signature. + * Returns a specific context from available contexts. * - * @return string|bool - * The PGP signature or FALSE if PGP type is "inline". - */ - public function getSignature(); - - /** - * Sets the PGP signature. - * - * @param string $signature - * The PGP signature. - */ - public function setSignature($signature); - - /** - * Returns the signed text. + * @param string $name + * The name of the context to get. * - * @return string - * The signed text. + * @return \Drupal\Core\Plugin\Context\ContextInterface|null $context + * Requested context object or NULL if not found. */ - public function getSignedText(); + public function getContext($name); /** - * Sets the signed text. + * A flag whether given context name exist. * - * @param string $signed_text - * The signed text. - */ - public function setSignedText($signed_text); - - /** - * Returns the PGP type. - * - * @return string - * The PGP type. - */ - public function getPgpType(); - - /** - * Sets the PGP type. - * - * @param string $pgp_type - * The PGP type. - */ - public function setPgpType($pgp_type); - - /** - * A flag whether signed message is verified or not. - * - * @param bool $verified - * The verification status. - * - * @return bool - * TRUE if signed message is verified. Otherwise, FALSE. - */ - public function setVerified($verified); - - /** - * A flag whether a message is verified or not. + * @param string $name + * The name of the context. * * @return bool - * TRUE if signed message is verified. - */ - public function isVerified(); - - /** - * Returns the context for this analyzer result. - * - * @return array - * The context data. - */ - public function getContext(); - - /** - * Replaces the stored context data. - * - * @param array $context - * New context data. - */ - public function setContext(array $context); - - /** - * Returns a specific item from the context data. - * - * @param string|array $key - * The key of the context item to get, or an array of nested keys. - * - * @return mixed - * An item from the context data. + * TRUE if context exists. Otherwise, FALSE. */ - public function getContextItem($key); + public function hasContext($name); }