/** * @param Schema $schema * @param Mixin $originalMixin * @param Mixin $duplicateMixin */ public function __construct(Schema $schema, Mixin $originalMixin, Mixin $duplicateMixin) { $this->schema = $schema; $this->originalMixin = $originalMixin; $this->duplicateMixin = $duplicateMixin; parent::__construct(sprintf('Mixin with id [%s] was already added from [%s] to message [%s]. ' . 'You cannot add multiple versions of the same mixin.', $this->duplicateMixin->getId()->toString(), $this->originalMixin->getId()->toString(), $this->schema->getClassName())); }
/** * @param Mixin $mixin * @param Schema[] $schemas */ public function __construct(Mixin $mixin, array $schemas) { $this->mixin = $mixin; $this->schemas = $schemas; $ids = array_map(function (Schema $schema) { return $schema->getId()->toString() . ' => ' . $schema->getClassName(); }, $schemas); parent::__construct(sprintf('MessageResolver returned multiple messages using [%s] when one was expected. ' . 'Messages found:' . PHP_EOL . '%s', $mixin->getId()->getCurieMajor(), implode(PHP_EOL, $ids))); }
/** * @param Mixin $mixin */ public function __construct(Mixin $mixin) { $this->mixin = $mixin; parent::__construct(sprintf('MessageResolver is unable to find any messages using [%s].', $mixin->getId()->getCurieMajor())); }
/** * Returns an array of Schemas expected to be using the provided mixin. * * @param Mixin $mixin * @param string $inPackage * @param string $inCategory * @return Schema[] * * @throws NoMessageForMixin */ public static function findAllUsingMixin(Mixin $mixin, $inPackage = null, $inCategory = null) { $mixinId = $mixin->getId()->getCurieMajor(); $key = sprintf('%s%s%s', $mixinId, $inPackage, $inCategory); if (!isset(self::$resolvedMixins[$key])) { $filtered = !empty($inPackage) || !empty($inCategory); /** @var Message $class */ $schemas = []; foreach (self::$messages as $id => $class) { if ($filtered) { list($vendor, $package, $category, $message) = explode(':', $id); if (!empty($inPackage) && $package != $inPackage) { continue; } if (!empty($inCategory) && $category != $inCategory) { continue; } } $schema = $class::schema(); if ($schema->hasMixin($mixinId)) { $schemas[] = $schema; } } self::$resolvedMixins[$key] = $schemas; } else { $schemas = self::$resolvedMixins[$key]; } if (empty($schemas)) { throw new NoMessageForMixin($mixin); } return $schemas; }
/** * @param Mixin $mixin * @throws MixinAlreadyAdded */ private function addMixin(Mixin $mixin) { $id = $mixin->getId(); $curieStr = $id->getCurie()->toString(); if (isset($this->mixinsByCurie[$curieStr])) { throw new MixinAlreadyAdded($this, $this->mixinsByCurie[$curieStr], $mixin); } $this->mixins[$id->getCurieMajor()] = $mixin; $this->mixinsByCurie[$curieStr] = $mixin; foreach ($mixin->getFields() as $field) { $this->addField($field); } }