/** * @test */ public function it_should_generate_a_version_4_uuid() { $generator = new Version4Generator(); $uuid = $generator->generate(); $uuidObject = Uuid::fromString($uuid); $this->assertEquals(4, $uuidObject->getVersion()); }
/** * @inheritdoc */ public static function setUpBeforeClass() { parent::setUpBeforeClass(); foreach (self::$uuids as $i => $uuid) { self::$uuids[$i] = Uuid::fromString($uuid); } }
function testParseWithUuidTagHandler() { $expected = [Uuid::fromString('f81d4fae-7dec-11d0-a765-00a0c91e6bf6')]; $edn = '#uuid "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"'; $data = igorw\edn\parse($edn); $this->assertEquals($expected, $data); }
/** * @covers Rhumsaa\Uuid\Doctrine\UuidType::convertToDatabaseValue */ public function testUuidConvertsToDatabaseValue() { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $expected = $uuid->toString(); $actual = $this->type->convertToDatabaseValue($uuid, $this->platform); $this->assertEquals($expected, $actual); }
/** * {@inheritdoc} * * @return static */ public static function fromString($id) { if (null === $id) { return null; } return new static(Uuid::fromString($id)); }
public function testDenormalize() { $obj = Uuid::fromString('6d6f9c73-1f59-4235-ace1-3bccd789315d'); $str = '6d6f9c73-1f59-4235-ace1-3bccd789315d'; self::assertEquals($obj, $this->normalizer->denormalize($str, 'json')); self::assertEquals($obj, $this->normalizer->denormalize($str, 'xml')); }
/** * Get identifier * * @return Uuid */ public function getIdentifier() { if (is_null($this->identifier)) { return Uuid::fromString(Uuid::NIL); } return $this->identifier; }
/** * @inheritdoc */ public function denormalize($data, $class, $format = null, array $context = []) { if ($data === null) { return null; } return Uuid::fromString($data); }
public function execute() { parent::execute(); try { $id = Uuid::fromString($this->getParameter('id', 'string')); $teamMember = $this->get('team_repository')->find($id); } catch (\Exception $e) { return $this->redirect(Model::createURLForAction('Index') . '&error=non-existing'); } $form = new TeamType('edit', $teamMember); if ($form->handle()) { $teamMember = $form->getData(); $this->get('team_repository')->save($teamMember); return $this->redirect(Model::createURLForAction('Index') . '&report=edited' . '&highlight=row-' . $teamMember->getId()); } // assign the detail url to the template if available $url = Model::getURLForBlock($this->URL->getModule(), 'Detail'); if (Model::getURL(404) != $url) { $this->tpl->assign('detailURL', SITE_URL . $url); } $form->parse($this->tpl); $this->tpl->assign('teamMember', $teamMember->toArray()); $this->parse(); $this->display(); }
/** * @param string $id * @return mixed */ public function get($id) { $message = $this->messageLogger->getEntryForMessageId(Uuid::fromString($id)); if (is_null($message)) { return new ApiProblemResponse(new ApiProblem(404, "Message can not be found")); } return ["message" => $message->toArray()]; }
/** * @param string $string * @return static */ public static function fromString($string) { try { return new static(RamseyUuid::fromString($string)); } catch (\InvalidArgumentException $e) { throw InvalidUuid::create($string, $e); } }
function it_is_equal_to_statement_ids_with_equal_value() { $value = '39e24cc4-69af-4b01-a824-1fdc6ea8a3af'; $uuid = Uuid::fromString($value); $this->beConstructedThrough('fromUuid', array($uuid)); $this->equals(StatementId::fromString($value))->shouldReturn(true); $this->equals(StatementId::fromUuid(Uuid::fromString($value)))->shouldReturn(true); $this->equals(StatementId::fromUuid($uuid))->shouldReturn(true); }
/** * @param string */ public final function __construct($uuid) { if (!is_string($uuid)) { throw new InvalidArgumentException('Uuid expected a string.'); } if (!\Rhumsaa\Uuid\Uuid::isValid($uuid)) { throw new InvalidArgumentException('Invalid Uuid format.'); } $this->uuid = \Rhumsaa\Uuid\Uuid::fromString($uuid); }
public function deserializeUuid(VisitorInterface $visitor, $data, array $type, Context $context) { if (null === $data) { return null; } if (!preg_match('/^' . self::UUID_V4_PATTERN . '$/', $data)) { throw new Exception\RuntimeException('Invalid UUID version 4 format'); } $uuid = Uuid::fromString($data); return $uuid; }
/** * @Route("/returns/refund", name="refund_return") * @Method("POST") */ public function refundReturnAction(Request $request) { $returnNumber = new ReturnNumber(Uuid::fromString($request->request->get('return_number'))); if ('credit' == $request->request->get('return_type')) { $command = new RefundForCredit($returnNumber); } else { $command = new RefundForCash($returnNumber); } $this->get('symfony_live.pos.command_bus')->dispatch($command); return $this->redirect($this->generateUrl('outstanding')); }
/** * Converts a value from its database representation to its PHP representation * of this type. * * @param mixed $value The value to convert. * @return mixed The PHP representation of the value. */ public function convertToPHPValue($value) { if (empty($value)) { return null; } if ($value instanceof Uuid) { return $value; } $uuid = Uuid::fromString($value); return $uuid; }
public function replay(Stream $stream) { foreach ($stream->replay() as $event) { switch (get_class($event)) { case CategoryWasCreated::class: $this->id = Uuid::fromString($event->getId()); $this->title = $event->getTitle(); $this->type = $event->getType(); } } return $this; }
public function store($id, $className, $eventData, $nextVersion, $currentVersion) { if ($this->contains($id)) { $streamData = $this->load($id); $streamData->setEventData($eventData); $streamData->setVersion($nextVersion); } else { $streamData = new StreamData(Uuid::fromString($id), $className, $eventData, $nextVersion); } $this->doctrine->getManager()->persist($streamData); $this->doctrine->getManager()->flush(); }
/** * @throws EventStreamNotFoundException * @return EventStream */ public function find(Uuid $uuid) { $streamData = $this->storage->load((string) $uuid); if ($streamData === null) { throw new EventStreamNotFoundException(); } $events = array(); foreach ($streamData->getEventData() as $eventData) { $events[] = $this->serializer->fromArray($eventData); } return new EventStream($streamData->getClassName(), Uuid::fromString($streamData->getId()), $events, $streamData->getVersion()); }
/** * {@inheritdoc} * * @param string|null $value * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform */ public function convertToPHPValue($value, AbstractPlatform $platform) { if (empty($value)) { return null; } try { $uuid = Uuid::fromString($value); } catch (InvalidArgumentException $e) { throw ConversionException::conversionFailed($value, self::NAME); } return $uuid; }
public function execute() { parent::execute(); try { $id = Uuid::fromString($this->getParameter('id', 'string')); $teamMember = $this->get('team_repository')->find($id); } catch (\Exception $e) { return $this->redirect(Model::createURLForAction('Index') . '&error=non-existing'); } $this->get('team_repository')->delete($teamMember); return $this->redirect(Model::createURLForAction('Index') . '&report=deleted'); }
/** * @param $uuid * @param string $object * * @return \Symfony\Component\HttpFoundation\Response * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ private function createResponse($uuid, $object) { $repository = $this->getRepository($this->repository); $entity = $repository->findOneBy(array('uuid' => Uuid::fromString($uuid))); if (null === $entity) { throw $this->createNotFoundException(sprintf('"%s" with id %s does not exist', $object, $uuid)); } if (true === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { return $this->redirect($this->generateUrl($this->route, array('id' => $entity->getId()))); } $template = 'CSBillCoreBundle:View:' . $object . '.html.twig'; return $this->render($template, array($object => $entity, 'title' => $object . ' #' . $entity->getId(), 'template' => $this->template)); }
/** * @param array $aMetaInformationArray * @return MetaInformation */ public static function fromArray(array $aMetaInformationArray) { Assertion::keyExists($aMetaInformationArray, 'workflowRunId'); Assertion::keyExists($aMetaInformationArray, 'actionId'); Assertion::keyExists($aMetaInformationArray, 'actionName'); Assertion::keyExists($aMetaInformationArray, 'actionArguments'); Assertion::keyExists($aMetaInformationArray, 'resultSetCount'); $aWorkflowRunId = new WorkflowRunId(Uuid::fromString($aMetaInformationArray['workflowRunId'])); $anActionId = new ActionId(Uuid::fromString($aMetaInformationArray['actionId'])); $anActionName = new Name($aMetaInformationArray['actionName']); $anActionArguments = new Arguments($aMetaInformationArray['actionArguments']); $aResultSetCount = $aMetaInformationArray['resultSetCount']; return new MetaInformation($aWorkflowRunId, $anActionId, $anActionName, $anActionArguments, $aResultSetCount); }
/** * Creates a new domain message from given array * * @param array $messageData * @return static */ public static function fromArray(array $messageData) { MessageDataAssertion::assert($messageData); $messageRef = new \ReflectionClass(get_called_class()); /** @var $message DomainMessage */ $message = $messageRef->newInstanceWithoutConstructor(); $message->uuid = Uuid::fromString($messageData['uuid']); $message->messageName = $messageData['message_name']; $message->version = $messageData['version']; $message->setPayload($messageData['payload']); $message->metadata = $messageData['metadata']; $message->createdAt = $messageData['created_at']; return $message; }
/** * Create notification type from string * * @param string $string * * @throws InvalidArgumentException * @return $this */ public static function fromString($string = self::DEFAULT_NOTIFICATION_TYPE) { $tuple = explode(':', $string, 2); $token = array_shift($tuple); if (self::UUID_TOKEN === strtolower($token)) { return self::fromUuid(Uuid::fromString($string)); } if (self::URN_TOKEN === strtolower($token)) { return self::fromUrn(Urn::fromString($string)); } $notificationType = new static(); $notificationType->setToken($token); $notificationType->setValue(array_pop($tuple)); return $notificationType; }
/** * @param string $taskListIdStr * @throws \InvalidArgumentException * @return TaskListId */ public static function fromString($taskListIdStr) { if (!is_string($taskListIdStr)) { throw new \InvalidArgumentException("TaskListIdStr must be string"); } $parts = explode(':TASK_LIST_ID:', $taskListIdStr); if (count($parts) != 2) { throw new \InvalidArgumentException(sprintf("Invalid taskLIstIdStr %s provided. Needs to have the format: node-name:PROCESS_ID:process-uuid:TASK_LIST_ID:task-list-uuid", $taskListIdStr)); } $envParts = explode(':PROCESS_ID:', $parts[0]); if (count($envParts) != 2) { throw new \InvalidArgumentException(sprintf("Invalid taskLIstIdStr %s provided. Needs to have the format: node-name:PROCESS_ID:process-uuid:TASK_LIST_ID:task-list-uuid", $taskListIdStr)); } $nodeName = NodeName::fromString($envParts[0]); $processId = ProcessId::fromString($envParts[1]); return new self($nodeName, $processId, Uuid::fromString($parts[1])); }
public function configure(SerializerBuilder $builder) { return $builder->setSerializationVisitor('array', new ArraySerialize(new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy())))->setDeSerializationVisitor('array', new ArrayDeserialize(new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy())))->configureHandlers(function (HandlerRegistry $handlers) { $handlers->registerHandler('serialization', 'Rhumsaa\\Uuid\\Uuid', 'array', function ($visitor, Uuid $id, array $type) { return (string) $id; }); $handlers->registerHandler('deserialization', 'Rhumsaa\\Uuid\\Uuid', 'array', function ($visitor, $id, array $type) { return \Rhumsaa\Uuid\Uuid::fromString($id); }); $handlers->registerHandler('serialization', 'DateTime', 'array', function ($visitor, DateTime $date, array $type) { return $date->format(DateTime::ISO8601); }); $handlers->registerHandler('deserialization', 'DateTime', 'array', function ($visitor, $date, array $type) { return DateTime::createFromFormat(DateTime::ISO8601, $date); }); $handlers->registerSubscribingHandler(new Generic()); })->addDefaultHandlers()->addDefaultListeners(); }
/** * {@inheritDoc} * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { if (!Uuid::isValid($input->getArgument('uuid'))) { throw new Exception('Invalid UUID (' . $input->getArgument('uuid') . ')'); } $uuid = Uuid::fromString($input->getArgument('uuid')); $table = $this->getHelperSet()->get('table'); $table->setLayout(TableHelper::LAYOUT_BORDERLESS); $table->addRows(array(array('encode:', 'STR:', (string) $uuid), array('', 'INT:', (string) $uuid->getInteger()))); if ($uuid->getVariant() != Uuid::RFC_4122) { $table->addRows(array(array('decode:', 'variant:', 'Not an RFC 4122 UUID'))); $table->render($output); return; } switch ($uuid->getVersion()) { case 1: $version = '1 (time and node based)'; break; case 2: $version = '2 (DCE security based)'; break; case 3: $version = '3 (name based, MD5)'; break; case 4: $version = '4 (random data based)'; break; case 5: $version = '5 (name based, SHA-1)'; break; } $table->addRows(array(array('decode:', 'variant:', 'RFC 4122'), array('', 'version:', $version))); if ($uuid->getVersion() == 1) { $table->addRows(array(array('', 'content:', 'time: ' . $uuid->getDateTime()->format('c')), array('', '', 'clock: ' . $uuid->getClockSequence() . ' (usually random)'), array('', '', 'node: ' . substr(chunk_split($uuid->getNodeHex(), 2, ':'), 0, -1)))); } if ($uuid->getVersion() == 4) { $table->addRows(array(array('', 'content:', substr(chunk_split($uuid->getHex(), 2, ':'), 0, -1)), array('', '', '(no semantics: random data only)'))); } if ($uuid->getVersion() == 3 || $uuid->getVersion() == 5) { $table->addRows(array(array('', 'content:', substr(chunk_split($uuid->getHex(), 2, ':'), 0, -1)), array('', '', '(not decipherable: MD5 message digest only)'))); } $table->render($output); }
public function fromArray(array $data) { if ($data['php_class'] === "DateTime") { return DateTime::createFromFormat('Y-m-d H:i:s.u', $data['time'], new DateTimeZone($data['timezone'])); } if ($data['php_class'] === "DateTimeImmutable") { return DateTimeImmutable::createFromFormat('Y-m-d H:i:s.u', $data['time'], new DateTimeZone($data['timezone'])); } if ($data['php_class'] === "Rhumsaa\\Uuid\\Uuid") { return Uuid::fromString($data['uuid']); } $reflClass = $this->getReflectionClass($data['php_class']); $constructor = $reflClass->getConstructor(); $arguments = array(); foreach ($constructor->getParameters() as $parameter) { $parameterClass = $parameter->getClass(); $parameterName = strtolower($parameter->getName()); if ($parameterClass !== null && isset($data[$parameterName])) { $data[$parameterName] = $this->fromArray($data[$parameterName]); } $arguments[] = isset($data[$parameterName]) ? $data[$parameterName] : $parameter->getDefaultValue(); } return $reflClass->newInstanceArgs($arguments); }
/** * Creates a UUID from a byte string. * * @param string $bytes * @return Uuid * @throws InvalidArgumentException If the $bytes string does not contain 16 characters */ public static function fromBytes($bytes) { if (strlen($bytes) !== 16) { throw new InvalidArgumentException('$bytes string should contain 16 characters.'); } $uuid = ''; foreach (range(0, 15) as $step) { $uuid .= sprintf('%02x', ord($bytes[$step])); if (in_array($step, array(3, 5, 7, 9))) { $uuid .= '-'; } } return Uuid::fromString($uuid); }