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->queryResult = new QueryResult($this->queryResultId, $this->metaInformation, $this->result);
 }
 /**
  * @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);
     }
     if (!is_subclass_of($messageName, 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'] = 0;
     }
     if (!isset($messageData['created_at'])) {
         $time = microtime(true);
         if (false === strpos($time, '.')) {
             $time .= '.0000';
         }
         $messageData['created_at'] = \DateTimeImmutable::createFromFormat('U.u', $time);
     }
     if (!isset($messageData['metadata'])) {
         $messageData['metadata'] = [];
     }
     return $messageName::fromArray($messageData);
 }
Beispiel #3
0
 /**
  * Creates the requested UUID
  *
  * @param int $version
  * @param string $namespace
  * @param string $name
  * @return Uuid
  */
 protected function createUuid($version, $namespace = null, $name = null)
 {
     switch ((int) $version) {
         case 1:
             $uuid = Uuid::uuid1();
             break;
         case 4:
             $uuid = Uuid::uuid4();
             break;
         case 3:
         case 5:
             $ns = $this->validateNamespace($namespace);
             if (empty($name)) {
                 throw new Exception('The name argument is required for version 3 or 5 UUIDs');
             }
             if ($version == 3) {
                 $uuid = Uuid::uuid3($ns, $name);
             } else {
                 $uuid = Uuid::uuid5($ns, $name);
             }
             break;
         default:
             throw new Exception('Invalid UUID version. Supported are version "1", "3", "4", and "5".');
     }
     return $uuid;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user_email = $this->argument('email');
     if (!($system_user = User::where("email", $user_email)->first())) {
         $password = $this->createSystemUser($user_email);
         $system_user = User::where("email", $user_email)->first();
         $this->info(sprintf("New System user with username %s and password %s made", $user_email, $password));
     }
     $reset_password = $this->argument('reset-secret');
     if ($user = OauthClient::where('name', $user_email)->first()) {
         $client_id = $user->id;
         if (!$reset_password) {
             $this->error("User already exists try the update reset-secret switch");
             exit;
         } else {
             $client_secret = $this->getService()->updateClientSecret($user);
             $this->info("Updated Client Secret {$client_secret}");
             $this->info("For Client Id {$client_id}");
             exit;
         }
     }
     $datetime = Carbon::now();
     $client_id = Uuid::uuid4()->toString();
     $client_secret = Str::random();
     $this->getService()->createOauthClient($client_id, $client_secret, $user_email, $datetime, $system_user->id);
     $this->info("Your Client_secret was set to {$client_secret}");
     $this->info("Your Client_id was set to {$client_id}");
     $this->info("Your name is {$user_email}");
 }
 public static function nameNew($name)
 {
     $id = Uuid::uuid4()->toString();
     $instance = new self();
     $instance->recordThat(UserCreated::occur($id, ['id' => $id, 'name' => $name]));
     return $instance;
 }
 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 __construct()
 {
     $this->id = Uuid::uuid4();
     $this->displayName = null;
     $this->description = null;
     $this->permissions = new ArrayCollection();
 }
 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();
 }
 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 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 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)]);
 }
 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())));
 }
 public function register(Application $app)
 {
     $app['uuid'] = $app->share(function () use($app) {
         $uuid4 = Uuid::uuid4();
         return $uuid4;
     });
 }
Beispiel #15
0
 /**
  * @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;
 }
Beispiel #16
0
 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);
 }
Beispiel #17
0
 public function __construct($name, Email $email, HashedPassword $password)
 {
     $this->setId(Uuid::uuid4());
     $this->setUserName($name);
     $this->setEmail($email);
     $this->setPassword($password);
 }
Beispiel #18
0
 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');
 }
 /**
  *
  * @param string $correlationID
  *
  * @return string
  */
 private function createCorrelationID($correlationID)
 {
     if (!$correlationID) {
         $correlationID = str_replace('-', '', Uuid::uuid4());
     }
     return $correlationID;
 }
Beispiel #20
0
 /**
  * @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 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());
 }
 /**
  * @test
  */
 public function acceptsUppercase()
 {
     $uuid = strtoupper(Uuid::uuid4()->toString());
     $resource = new UniversallyIdentifiableObj('xoo', $uuid);
     $calc = new UniversalLeveledStrategy();
     $this->assertInternalType('string', $calc->calculateDirectory($resource));
 }
 /**
  * @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;
 }
 /**
  * {@inheritdoc}
  */
 protected function init()
 {
     if (!isset($this['event_id'])) {
         /**
          * Support the old namespace
          */
         if (class_exists('Rhumsaa\\Uuid\\Uuid')) {
             $uuid = \Rhumsaa\Uuid\Uuid::uuid4();
         } else {
             $uuid = Uuid::uuid4();
         }
         $this['event_id'] = str_replace('-', '', $uuid->toString());
     }
     if (!isset($this['timestamp'])) {
         $this['timestamp'] = new \DateTime();
     }
     if ($this['timestamp'] instanceof \DateTime) {
         $this['timestamp'] = clone $this['timestamp'];
         $this['timestamp']->setTimezone(new \DateTimeZone('UTC'));
         $this['timestamp'] = $this['timestamp']->format('Y-m-d\\TH:i:s');
     }
     $factory = new VisitorFlyweight();
     $factory->addRequestVisitor('json', new JsonVisitor());
     $this->setRequestSerializer(new DefaultRequestSerializer($factory));
 }
Beispiel #25
0
 /**
  * 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);
 }
 /**
  * @test
  */
 public function it_cannot_rehydrate_with_eventstream()
 {
     $uuid = Uuid::uuid4();
     $sample = new SampleAggregateRoot($uuid);
     $eventStream = new EventStream('LiteCQRS\\SampleAggregateRoot', $uuid, array(new SampleCreated(array('foo' => 'bar'))));
     $this->setExpectedException('LiteCQRS\\Exception\\RuntimeException', 'AggregateRoot was already created from event stream and cannot be hydrated again.');
     $sample->loadFromEventStream($eventStream);
 }
 public function __construct()
 {
     $this->id = Uuid::uuid4();
     $this->displayName = null;
     $this->description = null;
     $this->updated = new \DateTime();
     $this->created = new \DateTime();
 }
 public function provideMessageDataWithMissingKey()
 {
     $uuid = Uuid::uuid4()->toString();
     $payload = ['foo' => ['bar' => ['baz' => 100]]];
     $metadata = ['key' => 'value', 'string' => 'scalar'];
     $createdAt = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
     return [['message-data', 'MessageData must be an array'], [['message_name' => 'test-message', 'version' => 1, 'payload' => $payload, 'metadata' => $metadata, 'created_at' => $createdAt], 'MessageData must contain a key uuid'], [['uuid' => $uuid, 'version' => 1, 'payload' => $payload, 'metadata' => $metadata, 'created_at' => $createdAt], 'MessageData must contain a key message_name'], [['uuid' => $uuid, 'message_name' => 'test-message', 'payload' => $payload, 'metadata' => $metadata, 'created_at' => $createdAt], 'MessageData must contain a key version'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 1, 'metadata' => $metadata, 'created_at' => $createdAt], 'MessageData must contain a key payload'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 1, 'payload' => $payload, 'created_at' => $createdAt], 'MessageData must contain a key metadata'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 1, 'payload' => $payload, 'metadata' => $metadata], 'MessageData must contain a key created_at'], [['uuid' => 'invalid', 'message_name' => 'test-message', 'version' => 1, 'payload' => $payload, 'metadata' => $metadata, 'created_at' => $createdAt], 'uuid must be a valid UUID string'], [['uuid' => $uuid, 'message_name' => 'te', 'version' => 1, 'payload' => $payload, 'metadata' => $metadata, 'created_at' => $createdAt], 'message_name must be string with at least 3 chars length'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => -1, 'payload' => $payload, 'metadata' => $metadata, 'created_at' => $createdAt], 'version must be an unsigned integer'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 0, 'payload' => 'string', 'metadata' => $metadata, 'created_at' => $createdAt], 'payload must be an array'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 0, 'payload' => ['sub' => ['key' => new \stdClass()]], 'metadata' => $metadata, 'created_at' => $createdAt], 'payload must only contain arrays and scalar values'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 0, 'payload' => $payload, 'metadata' => 'string', 'created_at' => $createdAt], 'metadata must be an array'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 0, 'payload' => $payload, 'metadata' => ['sub_array' => []], 'created_at' => $createdAt], 'A metadata value must have a scalar type. Got array for sub_array'], [['uuid' => $uuid, 'message_name' => 'test-message', 'version' => 0, 'payload' => $payload, 'metadata' => $metadata, 'created_at' => '2015-08-25 16:30:10'], 'created_at must be of type DateTimeInterface. Got string']];
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $faker = \Faker\Factory::create();
     for ($i = 0; $i < 10; $i++) {
         $createTaskCommand = new CreateTaskCommand(array('id' => (string) Uuid::uuid4(), 'content' => $faker->sentence(8)));
         $this->getCommandBus()->handle($createTaskCommand);
     }
 }
Beispiel #30
0
 public function __construct($id = null, $name = null, array $attributes = [], $createdAt = null)
 {
     $this->id = $id ?: \Rhumsaa\Uuid\Uuid::uuid4();
     $this->name = $name;
     $this->attributes = $attributes;
     $this->createdAt = $createdAt ?: new \DateTime();
     $this->emit(new \Knp\Event\Event\Generic('ProductCreated', ['id' => $this->id, 'name' => $name, 'attributes' => $attributes, 'createdAt' => $this->createdAt]));
 }