/** @test */ public function book_in_reservation_can_be_given_away() { $reservation = new Reservation(Uuid::uuid4(), Uuid::uuid4(), '*****@*****.**'); $reservation->giveAway(new \DateTime('2016-01-01 00:00:00')); $this->assertTrue($reservation->isGivenAway()); $this->assertEquals((new \DateTime('2016-01-01 00:00:00'))->format('Y-m-d H:i:s'), $reservation->givenAwayAt()->format('Y-m-d H:i:s')); }
/** * Initializes a new instance of this class. * * @param string $name * @param string $homepage */ public function __construct($name, $homepage) { $this->clientId = Uuid::uuid4(); $this->createdOn = new DateTimeImmutable('now'); $this->name = $name; $this->homepage = $homepage; }
public function __construct(array $params = null) { //All child class need to have constant UUID_CLASS_PREFIX to create uuid prefix if (!defined(get_class($this) . '::UUID_CLASS_PREFIX')) { throw new \Exception("Class " . get_class($this) . " has missing UUID_CLASS_PREFIX constant."); } //bind array values to class properties if ($params) { foreach ($params as $key => $value) { if (property_exists($this, $key)) { $this->{$key} = $value; } } } //Add uuid if not exists for new created object if (property_exists($this, 'uuid')) { if (!$this->uuid) { $uuid = Uuid::uuid4()->toString(); //Add uuid prefix (defined in UUID_CLASS_PREFIX constant) by replacing first x characters. Where x is prefix length. $prefix_length = strlen($this::UUID_CLASS_PREFIX); $uuid = substr_replace($uuid, $this::UUID_CLASS_PREFIX, 0, $prefix_length); $this->uuid = $uuid; } } }
public function send() { if (!$this->validate()) { throw new SMSMessageException('Could not send message'); } if (empty($this->strId)) { $objUuid = Uuid::uuid4(); $this->strId = $objUuid->toString(); } $arrParams = ['cc' => $this->strUsername, 'ekey' => $this->strPassword, 'message' => $this->strBody, 'title' => $this->strSenderId, 'network' => $this->strNetwork, 'value' => $this->fltValue, 'currency' => $this->strCurrency, 'encoding' => $this->strEncoding, 'number' => $this->strMsisdn, 'id' => $this->strId, 'reply' => $this->intReply]; if ($this->blBinary) { $arrParams['binary'] = (int) $this->blBinary; $arrParams['udh'] = $this->strUdh; } if (!empty($this->shortcode)) { $arrParams['shortcode'] = $this->shortcode; } $this->objLogger->addDebug('Sending the following to txtNation:', $arrParams); $objClient = new Client(['base_uri' => 'http://client.txtnation.com/', 'timeout' => 10.0]); $objResponse = $objClient->get('/gateway.php', [RequestOptions::QUERY => $arrParams, RequestOptions::SYNCHRONOUS => true, RequestOptions::ALLOW_REDIRECTS => true, RequestOptions::HEADERS => ['User-agent' => 'txtNationGatewayLibraryPHP/1.0'], RequestOptions::HTTP_ERRORS => false]); $objResult = new SMSMessageResult($objResponse); $objResult->setCallbackId($this->strId); if (!$objResult->success()) { $this->objLogger->addAlert('Message was not sent. ', ['error' => $objResult->getErrorMessage()]); } return $objResult; }
/** * Boot the Uuid trait for the model. */ protected static function boot() { static::creating(function ($model) { $model->incrementing = false; $model->{$model->getKeyName()} = Uuid::uuid4()->toString(); }); }
public function refresh(Token $token) : Token { $newToken = new Token(Uuid::uuid4(), $this->generatePassCode(), $token->getUserUuid(), $this->generateExpires()); $this->tokenRepository->create($newToken); $this->tokenRepository->delete($token); return $newToken; }
public function __construct(array $state = []) { $this->metadata = []; $this->uuid = Uuid::uuid4()->toString(); parent::__construct($state); $this->guardRequiredState(); }
/** * Register new email change * * @param string $userId * @param string $email * @return void */ public function register($userId, $email) { $emailReset = $this->model->firstOrNew(['user_id' => $userId]); $emailReset->email = $email; $emailReset->token = Uuid::uuid4(); $emailReset->save(); }
public function run($type, callable $runCallback) { static $wrapperPassingRunCallback; if (!isset($wrapperPassingRunCallback)) { $wrapperPassingRunCallback = []; } if (is_null($this->consumerTag)) { $runCallbackWrapper = function (AMQPMessage $amqpMessage) use(&$wrapperPassingRunCallback) { $inputMessage = new InputMessage($amqpMessage->body); $runCallback = $wrapperPassingRunCallback['runCallback']; /** @var OutputMessage $outputMessage */ $outputMessage = $runCallback($inputMessage); $channel = $amqpMessage->delivery_info['channel']; if ($amqpMessage->has('reply_to')) { $replyQueueName = $amqpMessage->get('reply_to'); $id = $amqpMessage->get('correlation_id'); $replyAmqpMessage = new AMQPMessage($outputMessage->getData(), ['correlation_id' => $id]); $channel->basic_publish($replyAmqpMessage, '', $replyQueueName); } $channel->basic_ack($amqpMessage->delivery_info['delivery_tag']); }; $this->consumerTag = 'consumer_' . substr(Uuid::uuid4()->toString(), 0, 8); $this->channel->basic_qos(null, 1, null); $this->channel->basic_consume($this->getQueueName($type), $this->consumerTag, false, false, false, false, $runCallbackWrapper); } $wrapperPassingRunCallback['runCallback'] = $runCallback; $this->channel->wait(); unset($wrapperPassingRunCallback['runCallback']); }
/** * {@inheritdoc} */ public function create($user, array $data) { $creator = array_get($data, 'from'); $notification = Notification::create(['id' => Uuid::uuid4(), 'user_id' => $user->id, 'created_by' => $creator ? $creator->id : null, 'icon' => $data['icon'], 'body' => $data['body'], 'action_text' => array_get($data, 'action_text'), 'action_url' => array_get($data, 'action_url')]); event(new NotificationCreated($notification)); return $notification; }
/** * Generates a universally unique identifier (UUID) according to RFC 4122. * The algorithm used here, might not be completely random. * * If php-uuid was installed it will be used instead to speed up the process. * * @return string The universally unique id * @todo Optionally generate type 1 and type 5 UUIDs. */ public static function generateUUID() { if (is_callable('uuid_create')) { return strtolower(uuid_create(UUID_TYPE_RANDOM)); } return (string) Uuid::uuid4(); }
/** * Initializes a new instance of this class. * * @param AccountInterface $account * @param string $name * @param string|null $value */ public function __construct(AccountInterface $account, $name, $value) { $this->id = Uuid::uuid4(); $this->account = $account; $this->name = $name; $this->value = $value; }
public function let(ConfigTypeInterface $type) { $this->uuid = Uuid::uuid4(); $this->type = $type; $this->beConstructedWith($this->uuid, $type, $this->name); $type->getDefaultItems()->willReturn($this->items); }
/** * @test */ public function it_generates_valid_uuid_with_both_namespaces() { $uuid1 = \Rhumsaa\Uuid\Uuid::uuid4(); $uuid2 = \Ramsey\Uuid\Uuid::uuid4(); $this->assertRegExp(self::UUID_REGEX, $uuid1->toString()); $this->assertRegExp(self::UUID_REGEX, $uuid2->toString()); }
public static function boot() { parent::boot(); // assign a guid for each model static::creating(function ($tournamentQuizmaster) { $tournamentQuizmaster->guid = Uuid::uuid4(); return true; }); // Make sure the user has the quizmaster role // Using a saved event since the user could be assigned // after the initial creation static::saved(function ($tournamentQuizmaster) { $user = $tournamentQuizmaster->user; // if no user is linked, try to find one if (is_null($user)) { $user = User::where('email', $tournamentQuizmaster->email)->first(); } if (!is_null($user)) { // label the user as a quizmaster if ($user->isNotA(Role::QUIZMASTER)) { $role = Role::where('name', Role::QUIZMASTER)->firstOrFail(); $user->assign($role); } // associate the user with the quizmaster if ($tournamentQuizmaster->user_id == null) { $tournamentQuizmaster->update(['user_id' => $user->id]); } } }); }
public static function uuid4() { if (self::$isThrowing) { throw new UnsatisfiedDependencyException('TEST'); } return Uuid::uuid4(); }
/** * Boot the Uuid trait for the model. * * @return void */ public static function bootHasUuid() { static::creating(function ($model) { $model->incrementing = false; $model->{$model->getKeyName()} = (string) Uuid::uuid4(); }); }
/** * Add a uuid to the model before persist to the data base. * * @param array $options */ public function save(array $options = []) { if (!$this->exists) { $this->uuid = Uuid::uuid4(); } parent::save($options); }
/** * Constructor. * * @param string $anEmail The email * @param string $aPlainPassword The plain password * @param array $roles Array which contains the roles * @param string|null $anId User id, it can be null */ public function __construct($anEmail, $aPlainPassword, array $roles, $anId = null) { $this->id = null === $anId ? Uuid::uuid4()->toString() : $anId; $this->email = $anEmail; $this->plainPassword = $aPlainPassword; $this->roles = $roles; }
/** * {@inheritdoc} */ public function new() : IdentityInterface { $class = (string) $this->identities->valueType(); $uuid = new $class((string) Generator::uuid4()); $this->identities = $this->identities->put($uuid->value(), $uuid); return $uuid; }
public function __construct($taskName, $workload, $uuid = null) { $this->uuid = $uuid ?: Uuid::uuid4()->toString(); $this->taskName = $taskName; $this->workload = $workload; $this->executionDate = new \DateTime(); }
/** * {@inheritdoc} * * @return Folder */ public function generate(ResourceInterface $resource = null) { $folder = new Folder(); $folder->setId((string) Uuid::uuid4()); $folder->setName($resource->getShortName()); return $folder; }
function upload_base64($request, $args) { global $config; $bucket_name = $args['bucket']; $sub_folder = $request->getParam('sub_folder', ''); $image_content = $request->getParam('image_content'); $uuid4 = Uuid::uuid4(); $file_name = $uuid4->toString() . '.jpg'; $folder_path = $config['buckets_folder'] . '/' . str_replace('//', '/', $bucket_name . '/' . $sub_folder . '/'); if (!is_dir($folder_path)) { mkdir($folder_path, 0755, true); } $real_file_path = $folder_path . $file_name; list(, $image_content) = explode(';', $image_content); list(, $image_content) = explode(',', $image_content); $image_content = base64_decode($image_content); $fp = fopen($real_file_path, 'wb'); fwrite($fp, $image_content); fclose($fp); if (file_exists($real_file_path)) { $relative_file_name = $file_name; if ($sub_folder != '') { $relative_file_name .= $sub_folder . '/' . $file_name; } $file_info = array('file_name' => $relative_file_name, 'base_url' => $config['cdn_url'] . '/' . $bucket_name, 'valid_options' => json_decode(file_get_contents(dirname($config['buckets_folder']) . '/bucket_configs/' . $bucket_name . '.json'), true)); return ['status' => 200, 'data' => $file_info]; } return ['status' => 500, 'error' => 'INTERNAL_SERVER_ERROR']; }
/** * @param mixed $payload * @param Metadata|array|null $metadata * @param UuidInterface|null $id */ public function __construct($payload, $metadata = null, UuidInterface $id = null) { $this->id = $id ?: Uuid::uuid4(); $this->payloadType = get_class($payload); $this->payload = $payload; $this->metadata = Metadata::from($metadata); }
/** * Initializes a new instance of this class. * * @param string $name The name of the group. */ public function __construct($name) { $this->id = Uuid::uuid4(); $this->name = $name; $this->permissions = []; $this->accounts = new ArrayCollection(); }
private function buildObject(array $data) { $data['PRODID'] = '-//Zource//Zource VObject ' . self::VERSION . '//EN'; $data['UID'] = 'zource-vobject-' . Uuid::uuid4()->toString(); $data['CLASS'] = 'public'; return new VCard($data); }
public function it_should_be_able_to_delete_an_object(\PDOStatement $pdoStatement) { $uuid = Uuid::uuid4(); $this->pdo->prepare(new TypeToken('string'))->willReturn($pdoStatement); $pdoStatement->execute(['uuid' => $uuid->getBytes(), 'type' => 'test'])->shouldBeCalled(); $this->delete('test', $uuid); }
/** * AbstractTransactionEvent constructor. * * @param string $managerName * @param string $actionName */ public function __construct($managerName, $actionName) { $this->managerName = $managerName; $this->actionName = $actionName; $this->commandUuid = Uuid::uuid4()->toString(); parent::__construct(); }
/** * Initializes a new instance of this class. * * @param AccountInterface $account The account to which this entity belongs. * @param string $directory The directory of the identity. * @param string $identity The identity representation. */ public function __construct(AccountInterface $account, $directory, $identity) { $this->id = Uuid::uuid4(); $this->account = $account; $this->directory = $directory; $this->identity = $identity; }
public function testAlphabet() { $alphabet = '01'; $su1 = new ShortUUID($alphabet); $su2 = new ShortUUID(); $this->assertEquals($alphabet, $su1->getAlphabet()); $su1->setAlphabet('01010101010101'); $this->assertEquals($alphabet, $su1->getAlphabet()); $d = array_values(array_unique(str_split($su1->uuid()))); sort($d, SORT_NATURAL); $this->assertEquals($d, str_split('01')); $a = strlen($su1->uuid()); $b = strlen($su2->uuid()); $this->assertTrue($a > 116 && $a < 140); $this->assertTrue($b > 20 && $b < 24); $u = Uuid::uuid4(); $this->assertEquals($u, $su1->decode($su1->encode($u))); $u = $su1->uuid(); $this->assertEquals($u, $su1->encode($su1->decode($u))); try { $su1->setAlphabet('1'); } catch (ValueError $e) { $this->assertTrue(true); } try { $su1->setAlphabet('1111111'); } catch (ValueError $e) { $this->assertTrue(true); } }