/** * @param Uuid $id */ public function find(Uuid $id) { $teamMember = $this->database->getRecord('SELECT * FROM team_members WHERE id = :id', ['id' => $id->getBytes()]); if (empty($teamMember)) { throw new \Exception('No teammember with id ' . $id->toString() . 'found'); } return TeamMember::fromArray($teamMember); }
/** * @param string $messageName * @param array $messageData * @throws \UnexpectedValueException * @return DomainMessage */ public function createMessageFromArray($messageName, array $messageData) { if (!class_exists($messageName)) { throw new \UnexpectedValueException('Given message name is not a valid class: ' . (string) $messageName); } $ref = new \ReflectionClass($messageName); if (!$ref->isSubclassOf(DomainMessage::class)) { throw new \UnexpectedValueException(sprintf('Message class %s is not a sub class of %s', $messageName, DomainMessage::class)); } if (!isset($messageData['message_name'])) { $messageData['message_name'] = $messageName; } if (!isset($messageData['uuid'])) { $messageData['uuid'] = Uuid::uuid4(); } if (!isset($messageData['version'])) { $messageData['version'] = 1; } if (!isset($messageData['created_at'])) { $messageData['created_at'] = new \DateTimeImmutable(); } if (!isset($messageData['metadata'])) { $messageData['metadata'] = []; } return $messageName::fromArray($messageData); }
public function testSameValueAs() { $sameMetaInformation = new MetaInformation($this->metaInformation->workflowRunId(), $this->metaInformation->actionId(), new Name('TestQuery'), new Arguments(array('foo' => 'bar')), 5); $otherMetaInformation = new MetaInformation(new WorkflowRunId(Uuid::uuid4()), new ActionId(Uuid::uuid4()), new Name('AnotherOuery'), new Arguments(array('foo' => 'bar')), 10); $this->assertTrue($this->metaInformation->sameValueAs($sameMetaInformation)); $this->assertFalse($this->metaInformation->sameValueAs($otherMetaInformation)); }
public function create($title, $author, $isbn) { $bookId = (string) Uuid::uuid4(); $book = array('book_id' => $bookId, 'title' => $title, 'author' => $author, 'isbn' => $isbn); $this->books->insert($book); return new $this->entityClass($book); }
public function create($attributes) { if (!isset($attributes['txid']) and !isset($attributes['request_id'])) { throw new Exception("TXID or request ID is required", 1); } if (!isset($attributes['payment_address_id'])) { throw new Exception("payment_address_id is required", 1); } if (!isset($attributes['user_id'])) { throw new Exception("user_id is required", 1); } if (!isset($attributes['destination']) and !isset($attributes['destinations'])) { throw new Exception("destination is required", 1); } if (!isset($attributes['quantity_sat'])) { throw new Exception("quantity_sat is required", 1); } if (!isset($attributes['asset'])) { throw new Exception("asset is required", 1); } if (!isset($attributes['uuid'])) { $attributes['uuid'] = Uuid::uuid4()->toString(); } return Send::create($attributes); }
public function setUp() { $this->userId = new UserId(Uuid::uuid4()); $this->email = new Email('*****@*****.**'); $this->username = new Username('my_username'); $this->password = new HashedPassword('super_secret_password'); }
public function __construct($name, Email $email, HashedPassword $password) { $this->setId(Uuid::uuid4()); $this->setUserName($name); $this->setEmail($email); $this->setPassword($password); }
public function login() { try { $passwordMatch = false; $userDeviceUpdated = false; $access_token = ''; $input = Request::all(); $user = User::where('email', $input['email'])->first(); if ($user) { if (crypt($input['password'], $user->password) == $user->password) { $passwordMatch = true; } } if ($passwordMatch) { $userDevice = UserDevice::where('device_id', $input['device_id'])->first(); $access_token = Uuid::uuid1()->toString(); if ($userDevice) { $userDeviceUpdated = $userDevice->update(['device_id' => $input['device_id'], 'rest_access_token' => $access_token, 'rest_access_token_expires' => Carbon::now()->addDays(360), 'rest_notification_id' => $input['notification_id'], 'os_type' => $input['os_type'], 'os_version' => $input['os_version'], 'hardware' => $input['hardware'], 'rest_app_version' => $input['app_version'], 'user_id' => $user->id]); } else { $userDeviceUpdated = UserDevice::create(['device_id' => $input['device_id'], 'rest_access_token' => $access_token, 'rest_access_token_expires' => Carbon::now()->addDays(360), 'rest_notification_id' => $input['notification_id'], 'os_type' => $input['os_type'], 'os_version' => $input['os_version'], 'hardware' => $input['hardware'], 'rest_app_version' => $input['app_version'], 'user_id' => $user->id]); } } if ($userDeviceUpdated) { $vendorLocationContact = VendorLocationContact::where('user_id', $user->id)->first(); $vendorLocation = VendorLocation::where('id', $vendorLocationContact->vendor_location_id)->first(); $vendor = Vendor::where('id', $vendorLocation->vendor_id)->first(); return response()->json(['id' => $user->id, 'access_token' => $access_token, 'full_name' => $user->full_name, 'email' => $user->email, 'phone_number' => $user->phone_number, 'role' => $user->role->name, 'vendor_name' => $vendor->name], 200); } else { return response()->json(['action' => 'Check if the email address and password match', 'message' => 'There is an email password mismatch. Please check and try again'], 227); } } catch (\Exception $e) { return response()->json(['message' => 'An application error occured.', 'error' => $e->getMessage()], 500); } }
/** * {@inheritDoc} */ public function generateUniqueId($name = null) { if (empty($name)) { $name = uniqid($name, $moreEnthropy = true); } return RhumsaaUuid::uuid5(RhumsaaUuid::NAMESPACE_OID, $name)->toString(); }
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); }
public function rootAction(Application $app, Request $request) { $data = $this->prepareInput(); if ($data === null) { return new JsonResponse(['error' => 'no json data found'], 400); } $templateName = isset($data['template']) ? $data['template'] : null; $templateData = isset($data['data']) ? $data['data'] : null; if (!$templateName || !$templateData) { return new JsonResponse(['error' => 'template and data must be set'], 400); } $repo = $app->getTemplateRepository(); $template = $repo->getByName($templateName); if (!$template) { return new JsonResponse(['error' => "template {$templateName} not found"], 404); } $twig = new \Twig_Environment(new \Twig_Loader_String()); $html = $twig->render($template->getTemplate(), $templateData); $file = new File(); $file->setId(Uuid::uuid4()->toString()); $file->setCreatedAt(date('Y-m-d H:i:s')); $file->setPath($this->getFilePath($file)); $snappy = new Pdf(); if (substr(php_uname(), 0, 7) == "Windows") { $snappy->setBinary('vendor\\bin\\wkhtmltopdf.exe.bat'); } else { $snappy->setBinary('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'); } $snappy->generateFromHtml($html, $file->getPath()); $repo = $app->getFileRepository(); $repo->add($file); return new JsonResponse(['id' => $file->getId()], 201); }
public static function generate($ver = 4, $node = null, $clockSeq = null, $ns = null, $name = null) { $uuid = null; /* Create a new UUID based on provided data. */ switch ((int) $ver) { case 1: $uuid = Uuid::uuid1($node, $clockSeq); break; case 2: // Version 2 is not supported throw new \RuntimeException('UUID version 2 is unsupported.'); case 3: $uuid = Uuid::uuid3($ns, $name); break; case 4: $uuid = Uuid::uuid4(); break; case 5: $uuid = Uuid::uuid5($ns, $name); break; default: throw new \RuntimeException('Selected UUID version is invalid or unsupported.'); } if (function_exists('gmp_strval')) { return gmp_strval(gmp_init($uuid->getHex(), 16), 62); } return Base62::encode((string) $uuid->getInteger()); }
public function testUuidToBinary() { $uuid = Uuid::uuid5(Uuid::NAMESPACE_OID, 1); $binary = UuidConverter::uuidToBinary($uuid->toString()); $finalUuid = Uuid::fromBytes($binary); $this->assertSame($uuid->toString(), $finalUuid->toString()); }
/** * @inheritdoc */ public static function setUpBeforeClass() { parent::setUpBeforeClass(); foreach (self::$uuids as $i => $uuid) { self::$uuids[$i] = Uuid::fromString($uuid); } }
public function generateNewKey() { $apikey = new ApiKey(); $apikey->key = Uuid::uuid4()->toString(); $apikey->save(); return $apikey; }
/** * Load items * * @param ObjectManager $manager */ public function loadItems($manager) { for ($ind = 1; $ind <= self::COUNT; $ind++) { //create item /** @var $item Item */ $item = new Item(); //string value $item->stringValue = 'item' . $ind . '@mail.com'; $item->integerValue = $ind * 1000; //decimal $item->decimalValue = $ind / 10.0; //float $item->floatValue = $ind / 10.0 + 10; //boolean $item->booleanValue = rand(0, 1) == true; //blob $item->blobValue = "blob-{$ind}"; //array $item->arrayValue = array($ind); //datetime $date = new \DateTime('now', new \DateTimeZone('UTC')); $date->add(new \DateInterval("P{$ind}Y")); $item->datetimeValue = $date; //guid $item->guidValue = Uuid::uuid4(); //object $item->objectValue = new \stdClass(); $manager->persist($item); } $manager->flush(); }
protected function setUp() { $this->queryResultId = new QueryResultId(Uuid::uuid4()); $this->metaInformation = new MetaInformation(new WorkflowRunId(Uuid::uuid4()), new ActionId(Uuid::uuid4()), new Name('TestQuery'), new Arguments(array('foo' => 'bar')), 1); $this->result = new Item('A result item'); $this->queryResultCreated = new QueryResultCreated(array('queryResultId' => $this->queryResultId->toString(), 'metaInformation' => $this->metaInformation->toArray(), 'result' => array('resultClass' => get_class($this->result), 'data' => $this->result->toJSON()))); }
/** * @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); }
public function store(Request $request) { //get the email and password from the input $email = ""; $password = ""; if ($request->get('email') && $request->get('password')) { $password = $request->get('password'); if (Libraries\InputValidator::isEmailValid($request->get('email'))) { $email = $request->get('email'); } else { \App::abort(400, 'The contract of the api was not met'); } } else { \App::abort(400, 'The contract of the api was not met'); } //get the user based on the email $userRepo = new UserRepository(new User()); $user = $userRepo->getUserBasedOnEmail($email)->toArray(); //fill the information of the user //if the user didn't exist $userInfo = []; if ($user == []) { $userInfo = ["email" => $email, "password" => sha1($password), "uuid" => \Rhumsaa\Uuid\Uuid::uuid4()->toString()]; } else { \App::abort(409, 'The email is already in use'); } //update the information of the user $user = $userRepo->updateUserInfo($userInfo); $userRepo->setUserLevel(1); $userRepo->logSignUp(); //send the results back to the user return json_encode(["status" => ["points" => $userRepo->getUserPoints(), "level" => $userRepo->getUserLevel()->id], "user_id" => $user->uuid, "email" => $email, "password" => sha1($password)]); }
/** * {@inheritdoc} * * @return static */ public static function fromString($id) { if (null === $id) { return null; } return new static(Uuid::fromString($id)); }
/** * * @param string $correlationID * * @return string */ private function createCorrelationID($correlationID) { if (!$correlationID) { $correlationID = str_replace('-', '', Uuid::uuid4()); } return $correlationID; }
/** * Initialize the internal members. */ public function __construct() { // create a UUID as prefix for dynamic object properties $this->serial = Uuid::uuid4()->toString(); // initialize the application state $this->applicationState = ApplicationStateKeys::get(ApplicationStateKeys::WAITING_FOR_INITIALIZATION); }
/** * @param string|null $identifier If null is given, a UUIDv4 will be generated */ private function __construct($identifier = null) { if ($identifier === null) { $identifier = (string) Uuid::uuid4(); } $this->identifier = $identifier; }
/** * @param \AGmakonts\DddBricks\Service\ServiceInterface $target * @param array $params */ public function __construct(ServiceInterface $target, array $params = []) { $this->target = $target; $this->occurrenceTime = DateTime::get(); $this->identifier = Text::get(Uuid::uuid4()->toString()); $this->params = $params; }
public function register(Application $app) { $app['uuid'] = $app->share(function () use($app) { $uuid4 = Uuid::uuid4(); return $uuid4; }); }
/** * @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()); }
/** * @test */ public function acceptsUppercase() { $uuid = strtoupper(Uuid::uuid4()->toString()); $resource = new UniversallyIdentifiableObj('xoo', $uuid); $calc = new UniversalLeveledStrategy(); $this->assertInternalType('string', $calc->calculateDirectory($resource)); }
/** * @param mixed $payload * @param MetaData $metaData * @param string|null $id * @param string|null $commandName */ public function __construct($payload, MetaData $metaData = null, $id = null, $commandName = null) { $this->id = null === $id ? Uuid::uuid1()->toString() : $id; $this->commandName = null === $commandName ? get_class($payload) : $commandName; $this->payload = $payload; $this->metaData = null === $metaData ? MetaData::emptyInstance() : $metaData; }
/** * Initialize the saga. If an identifier is provided it will be used, otherwise a random UUID will be generated. * * @param string $identifier */ public function __construct($identifier = null) { $this->identifier = null === $identifier ? Uuid::uuid1()->toString() : $identifier; $this->associationValues = new AssociationValuesImpl(); $this->inspector = new SagaMethodMessageHandlerInspector($this); $this->associationValues->add(new AssociationValue('sagaIdentifier', $this->identifier)); }
/** * Model boot method, sets guid on create. * * @return void */ public static function boot() { parent::boot(); static::creating(function ($model) { $model->guid = Uuid::uuid1(); }); }