/**
  * 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));
 }
Пример #2
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;
 }
 /**
  * @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;
 }
Пример #4
0
 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);
     }
 }
 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());
 }
Пример #6
0
 /**
  * Model boot method, sets guid on create.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->guid = Uuid::uuid1();
     });
 }
 /**
  * @expectedException \OutOfBoundsException
  */
 public function testNextReadBeyondEnd()
 {
     $event1 = new GenericDomainEventMessage(Uuid::uuid1(), 0, new \stdClass(), new MetaData());
     $testSubject = new SimpleDomainEventStream(array($event1));
     $testSubject->next();
     $testSubject->next();
 }
 public function testResolveTarget_WithAnnotatedFields()
 {
     $aggregateIdentifier = Uuid::uuid1();
     $version = 1;
     $actual = $this->testSubject->resolveTarget(GenericCommandMessage::asCommandMessage(new FieldAnnotatedCommand($aggregateIdentifier, $version)));
     $this->assertEquals($aggregateIdentifier, $actual->getIdentifier());
     $this->assertEquals($version, $actual->getVersion());
 }
 public function testRegisterCallbackInvokedWithAllRegisteredEvents()
 {
     $container = new EventContainer(Uuid::uuid1()->toString());
     $container->addEvent(MetaData::emptyInstance(), new Event());
     $this->assertFalse(current($container->getEventList())->getMetaData()->has("key"));
     $container->addEventRegistrationCallback(new TestEventRegistrationCallback());
     $this->assertEquals("value", current($container->getEventList())->getMetadata()->get("key"));
 }
 /**
  * schedule.
  *
  * Schedule $command for later execution
  * Returns a unique identifier for the scheduled execution
  * If an $id was passed it'll overwrite the scheduled execution
  *
  * @since 1.0
  *
  * @param ScheduledCommandInterface $command
  * @param string                    $id      - optional
  *
  * @return string
  */
 public function schedule(ScheduledCommandInterface $command, $id = null)
 {
     $fileName = isset($id) ? $id : Uuid::uuid1()->toString();
     file_put_contents($this->path . DIRECTORY_SEPARATOR . $fileName, serialize($command));
     $this->register[$fileName] = $command->getTimestamp();
     file_put_contents($this->path . DIRECTORY_SEPARATOR . 'register', serialize($this->register));
     return $fileName;
 }
 /**
  * createVoucher function.
  *
  * @access public
  *
  * @param string $campaignUrn
  *
  * @return Voucher
  */
 public function createVoucher($campaignUrn)
 {
     // Check for valid campaign
     if ($campaign = $this->campaignRepo->loadCampaign($campaignUrn)) {
         $voucher = $this->model->create(['campaign_id' => $campaign->id, 'hash' => Uuid::uuid1()->toString()]);
         return $voucher;
     }
     return false;
 }
Пример #12
0
 /**
  * @param mixed $payload
  * @param MetaData $metadata
  * @param string $id
  */
 public function __construct($payload, MetaData $metadata = null, $id = null)
 {
     if (!is_object($payload)) {
         throw new \InvalidArgumentException("Payload needs to be an object.");
     }
     $this->id = isset($id) ? $id : Uuid::uuid1()->toString();
     $this->metadata = isset($metadata) ? $metadata : MetaData::emptyInstance();
     $this->payload = $payload;
 }
Пример #13
0
 /**
  * Set object with Auto document_id
  * @param mixed $object Receive object to store
  * @return string Return string with $document_id
  */
 public function set($object, $document_id = null)
 {
     if (is_null($document_id) || !Uuid::isValid($document_id)) {
         $document_id = strtoupper(Uuid::uuid1());
     }
     $this->resolvePath($this->dataPath);
     file_put_contents($this->dataPath . DIRECTORY_SEPARATOR . $document_id, json_encode($object, JSON_PRETTY_PRINT), LOCK_EX);
     return $document_id;
 }
Пример #14
0
 /**
  * UUID1,基于时间戳
  *
  * @param int|string $node
  * @param int        $clockSeq
  * @return string
  */
 public static function v1($node = null, $clockSeq = null)
 {
     try {
         $uuid1 = VendorUUID::uuid1($node, $clockSeq);
         return $uuid1->toString();
     } catch (UnsatisfiedDependencyException $e) {
         return false;
     }
 }
 public function testCommandReply()
 {
     $commandId1 = Uuid::uuid1()->toString();
     $commandId2 = Uuid::uuid1()->toString();
     $this->testSubject->writeCommandReply($commandId1, $commandId1);
     $data = $this->testSubject->readCommandReply($commandId1);
     $this->assertEquals($commandId1, $data[1]);
     $data = $this->testSubject->readCommandReply($commandId2, 1);
     $this->assertNull($data);
 }
Пример #16
0
 /**
  * @param Request $request
  * @param Closure $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     //Generate the request id
     $requestId = Uuid::uuid1()->toString();
     //Add the request id processor to logger instance
     $this->log->addProcessors([new RequestIdProcessor($requestId)]);
     $response = $next($request);
     $response->headers->set('Request-Id', $requestId, false);
     return $response;
 }
 public function testLoadAggregate_NotFound()
 {
     $aggregateIdentifier = Uuid::uuid1()->toString();
     try {
         $this->testSubject->load($aggregateIdentifier);
         $this->fail("Expected AggregateNotFoundException");
     } catch (AggregateNotFoundException $ex) {
         $this->assertEquals($aggregateIdentifier, $ex->getAggregateId());
     }
 }
Пример #18
0
 /**
  * Create a UUID v1
  *
  */
 public static function v1()
 {
     try {
         $uuid = RhumsaaUuid::uuid1();
         $uuidString = $uuid->toString();
     } catch (UnsatisfiedDependencyException $exc) {
         throw new \Exception(__METHOD__ . ': Some dependency was not met or the method cannot be called on a 32 bit
         system.', $exc);
     }
     return $uuidString;
 }
Пример #19
0
 /**
  * @see Norm\Connection::persist()
  */
 public function persist($collection, array $document)
 {
     if ($collection instanceof Collection) {
         $collection = $collection->getName();
     }
     $this->data[$collection] = isset($this->data[$collection]) ? $this->data[$collection] : array();
     // TODO change this to uuidv4
     $document['id'] = Uuid::uuid1() . '';
     $document = $this->marshall($document);
     $this->data[$collection][] = $document;
     return $this->unmarshall($document);
 }
 public function getToken($user)
 {
     if (!$user) {
         return false;
     }
     $this->setUser($user);
     $attributes = ['user_id' => $this->users->getEntityKey($user)];
     if (!($token = $this->findByAttributes($attributes))) {
         $attributes['token'] = (string) Uuid::uuid1();
         $token = $this->create($attributes);
     }
     return $this->serializeToken($token);
 }
 public function testLockFailsOnConcurrentModification()
 {
     $identifier = Uuid::uuid1()->toString();
     $aggregate1 = new StubAggregate($identifier);
     $aggregate2 = new StubAggregate($identifier);
     $manager = new OptimisticLockManager();
     $manager->obtainLock($aggregate1->getIdentifier());
     $manager->obtainLock($aggregate2->getIdentifier());
     $aggregate1->doSomething();
     $aggregate2->doSomething();
     $this->assertTrue($manager->validateLock($aggregate1));
     $this->assertFalse($manager->validateLock($aggregate2));
 }
 public function testFixtureApi_WhenEventIsPublishedToEventBus()
 {
     $aggregate1 = Uuid::uuid1()->toString();
     $aggregate2 = Uuid::uuid1()->toString();
     $fixture = new AnnotatedSagaTestFixture(StubSaga::class);
     $validator = $fixture->givenAggregate($aggregate1)->published(array(new TriggerSagaStartEvent($aggregate1), new TriggerExistingSagaEvent($aggregate1)))->whenAggregate($aggregate1)->publishes(new TriggerExistingSagaEvent($aggregate1));
     $validator->expectActiveSagas(1);
     $validator->expectAssociationWith("identifier", $aggregate1);
     $validator->expectNoAssociationWith("identifier", $aggregate2);
     //validator.expectScheduledEventMatching(Duration.standardMinutes(10),
     // Matchers.messageWithPayload(CoreMatchers.any(Object.class)));
     $validator->expectDispatchedCommandsEqualTo(array());
     $validator->expectPublishedEventsMatching(Matchers::listWithAnyOf(array(Matchers::messageWithPayload(CoreMatchers::any(SagaWasTriggeredEvent::class)))));
 }
Пример #23
0
 public function persist($collection, array $document)
 {
     if ($collection instanceof Collection) {
         $collection = $collection->getName();
     }
     $id = isset($document['$id']) ? $document['$id'] : Uuid::uuid1() . '';
     $document = $this->marshall($document);
     $document['id'] = $id;
     $collectionDir = $this->option('dataDir') . DIRECTORY_SEPARATOR . $collection . DIRECTORY_SEPARATOR;
     if (!is_dir($collectionDir)) {
         @unlink($collectionDir);
         mkdir($collectionDir, 0755, true);
     }
     file_put_contents($collectionDir . $document['id'] . '.json', json_encode($document, JSON_PRETTY_PRINT));
     return $this->unmarshall($document);
 }
 public function testStreamDomainEventMessage()
 {
     $serializer = new JMSSerializer();
     $writer = new EventMessageWriter($serializer);
     $payload = new StreamPayload("string", 10, 15.5);
     $message = new GenericDomainEventMessage(Uuid::uuid1(), 1, $payload, new MetaData(array("metaKey" => "MetaValue")));
     $data = $writer->writeEventMessage($message);
     $reader = new EventMessageReader($serializer);
     $serializedMessage = $reader->readEventMessage($data);
     $this->assertTrue($serializedMessage instanceof DomainEventMessageInterface);
     $this->assertEquals($message->getIdentifier(), $serializedMessage->getIdentifier());
     $this->assertEquals($message->getPayloadType(), $serializedMessage->getPayloadType());
     $this->assertEquals($message->getTimestamp(), $serializedMessage->getTimestamp());
     $this->assertEquals($message->getMetaData(), $serializedMessage->getMetaData());
     $this->assertEquals($message->getPayload(), $serializedMessage->getPayload());
     $this->assertEquals($message->getAggregateIdentifier(), $serializedMessage->getAggregateIdentifier());
     $this->assertEquals($message->getScn(), $serializedMessage->getScn());
 }
 public function testRead_FileNotReadable()
 {
     $mockEventFileResolver = $this->getMock('Governor\\Framework\\EventStore\\Filesystem\\EventFileResolverInterface');
     $mockFile = $this->getMockBuilder('\\SplFileObject')->setConstructorArgs(array(tempnam(sys_get_temp_dir(), 'governormockfile'), 'ab+'))->getMock();
     $mockEventFileResolver->expects($this->any())->method('eventFileExists')->will($this->returnValue(true));
     $mockEventFileResolver->expects($this->any())->method('openEventFileForReading')->will($this->returnValue($mockFile));
     $exception = new \Exception("Mock Exception");
     $mockFile->expects($this->any())->method('fgetc')->will($this->throwException($exception));
     $eventStore = new FileSystemEventStore($mockEventFileResolver, $this->serializer);
     try {
         $eventStore->readEvents("test", Uuid::uuid1()->toString());
         $this->fail("Expected an exception");
     } catch (EventStoreException $ex) {
         $this->assertSame($exception, $ex->getPrevious());
     }
 }
 public function __construct($identifier = null)
 {
     $this->identifier = null !== $identifier ? $identifier : Uuid::uuid1()->toString();
 }
Пример #27
0
 /**
  * Constructer.
  */
 public function __construct()
 {
     $this->items = new ArrayCollection();
     $this->users = new ArrayCollection();
     $this->setUuid(Uuid::uuid1());
 }
Пример #28
0
 public static function uuid1($node = null, $clockSeq = null)
 {
     return BaseUuid::uuid1($node, $clockSeq);
 }
Пример #29
0
 /**
  * generate time base uuid
  *
  * @return string
  */
 protected function createIdVersion1()
 {
     return Uuid::uuid1()->toString();
 }
Пример #30
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * Check to see if this should run at all
      */
     if (!$this->shouldRun($input->getOption("no-lock"))) {
         $output->writeLn("Error: There appears to be an instance of this script running already.");
         return;
     }
     /**
      * Add lock file if required
      */
     if (!$input->getOption("no-lock")) {
         $this->setLockFile();
     }
     $em = $this->deps["entityManager"];
     $query = $em->createQuery("SELECT j from Iu\\Uits\\Webtech\\Clam\\Model\\Job j where j.state = 'waiting'");
     $jobs = $query->getResult();
     foreach ($jobs as $job) {
         /**
          * Set the job state to running, this may be excessive, but what the
          * heck. We can do it, and it would be good to know anyway.
          */
         $job->state = "running";
         $em->persist($job);
         $em->flush();
         /**
          * Run the actual clam scan
          */
         $process = new Process($this->buildJobCommand($job));
         $process->setTimeout(36000);
         $process->run();
         /**
          * Figure out if the program finished correctly and set the state
          * accordingly.
          * If it's not 0 it screwed up
          */
         if ($process->isSuccessful()) {
             $job->state = "finished";
         } else {
             $job->state = "failed";
         }
         $em->persist($job);
         $em->flush();
         /**
          * Parse the results into something useful
          */
         $results = $this->parseOutput($process->getOutput());
         /**
          * Create and store the results in the database
          */
         $result = new Result();
         $result->id = Uuid::uuid1();
         $result->completedAt = new \DateTime("now", $this->deps["timezone"]);
         $result->scannedDirectories = $results["summary"]["Scanned directories"];
         $result->scannedFiles = $results["summary"]["Scanned files"];
         $result->infectedFiles = $results["summary"]["Infected files"];
         $result->dataScanned = $results["summary"]["Data scanned"];
         $result->dataRead = $results["summary"]["Data read"];
         $result->executionTime = $results["summary"]["Time"];
         $result->fileResults = $results["files"];
         $em->persist($result);
         /**
          * Add the resultId to the job entry
          */
         $job->result = $result->id;
         $em->persist($job);
         $em->flush();
         /**
          * Send an email to the requested report address (if set)
          */
         if (!is_null($job->reportAddress)) {
             $this->sendEmailReport($job, $result);
         }
     }
     /**
      * Delete the lock file if required
      */
     if (!$input->getOption("no-lock")) {
         $this->unsetLockFile();
     }
 }