/** * @param string|Name $aName * @param array|EventsDefinition $anEventsDefinition * @param null|array|Arguments $anArguments * @param null|array|StructureDefinition $aStructureDefinition * @return ActionDescription */ public static function asCommand($aName, $anEventsDefinition, $anArguments = null, $aStructureDefinition = null) { if (is_string($aName)) { $aName = new Name($aName); } if (!$anEventsDefinition instanceof EventsDefinition) { $anEventsDefinition = EventsDefinition::fromEventDescriptionDefinitions($anEventsDefinition); } if (is_null($anArguments)) { $anArguments = new Arguments(array()); } if (!$anArguments instanceof Arguments) { $anArguments = new Arguments($anArguments); } if (is_array($aStructureDefinition)) { $aStructureDefinition = StructureDefinition::fromPathValueTypeList($aStructureDefinition); } return new static($aName, new Type(Type::COMMAND), $anArguments, $aStructureDefinition, $anEventsDefinition); }
/** * @test */ public function is_not_same_value_as_when_only_other_has_structure_description() { $eventsDefinition = EventsDefinition::fromEventDescriptionDefinitions(array('CommandTriggered' => array('success' => 'boolean'))); $actionDescription = ActionDescription::asCommand(new Name('Testaction'), $eventsDefinition, new Arguments(array('foo' => 'bar'))); $otherActionDescription = ActionDescription::asCommand(new Name('Testaction'), $eventsDefinition, new Arguments(array('foo' => 'bar')), StructureDefinition::fromPathValueTypeList(array('a' => StructureDefinition::STRING))); $this->assertFalse($actionDescription->sameValueAs($otherActionDescription)); }
/** * @test */ public function is_not_same_value_as() { $eventsDefinition = EventsDefinition::fromEventDescriptionDefinitions(array('Testevent' => array('property1' => 'string'))); $otherEventsDefinition = EventsDefinition::fromEventDescriptionDefinitions(array('SomeEvent' => array('property1' => 'string'))); $this->assertFalse($eventsDefinition->sameValueAs($otherEventsDefinition)); }
/** * @param array $anActionDescriptionDefinition * @return ActionDescription */ public static function actionDescriptionFromDefinition(array $anActionDescriptionDefinition) { Assertion::keyExists($anActionDescriptionDefinition, 'name', sprintf("Missing name property in ActionDescriptionDefinition: %s", json_encode($anActionDescriptionDefinition))); Assertion::keyExists($anActionDescriptionDefinition, 'type', sprintf("Missing type property in ActionDescriptionDefinition: %s", json_encode($anActionDescriptionDefinition))); if ($anActionDescriptionDefinition['type'] === Type::COMMAND) { Assertion::keyExists($anActionDescriptionDefinition, 'events', sprintf("Missing events property in ActionDescriptionDefinition: %s", json_encode($anActionDescriptionDefinition))); $eventsDefinition = EventsDefinition::fromEventDescriptionDefinitions($anActionDescriptionDefinition['events']); } else { $eventsDefinition = null; } if (isset($anActionDescriptionDefinition['arguments'])) { Assertion::isArray($anActionDescriptionDefinition['arguments'], sprintf("The arguments property of ActionDescriptionDefinition must be an array: %s given in %s", Util::getType($anActionDescriptionDefinition['arguments']), json_encode($anActionDescriptionDefinition))); $arguments = new Arguments($anActionDescriptionDefinition['arguments']); } else { $arguments = new Arguments(array()); } if (isset($anActionDescriptionDefinition['structure'])) { Assertion::isArray($anActionDescriptionDefinition['structure'], sprintf("The structure property of ActionDescriptionDefinition must be an array: %s given in %s", Util::getType($anActionDescriptionDefinition['structure']), json_encode($anActionDescriptionDefinition))); $structureDefinition = StructureDefinition::fromPathValueTypeList($anActionDescriptionDefinition['structure']); } else { $structureDefinition = null; } if ($anActionDescriptionDefinition['type'] === Type::COMMAND) { return ActionDescription::asCommand(new Name($anActionDescriptionDefinition['name']), $eventsDefinition, $arguments, $structureDefinition); } else { return ActionDescription::asQuery(new Name($anActionDescriptionDefinition['name']), $arguments, $structureDefinition); } }