本文整理汇总了PHP中Rhumsaa\Uuid\Uuid::uuid4方法的典型用法代码示例。如果您正苦于以下问题:PHP Uuid::uuid4方法的具体用法?PHP Uuid::uuid4怎么用?PHP Uuid::uuid4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhumsaa\Uuid\Uuid
的用法示例。
在下文中一共展示了Uuid::uuid4方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
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);
}
示例2: createMessageFromArray
/**
* @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);
}
示例3: createUuid
/**
* 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;
}
示例4: handle
/**
* 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}");
}
示例5: nameNew
public static function nameNew($name)
{
$id = Uuid::uuid4()->toString();
$instance = new self();
$instance->recordThat(UserCreated::occur($id, ['id' => $id, 'name' => $name]));
return $instance;
}
示例6: testSameValueAs
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));
}
示例7: __construct
public function __construct()
{
$this->id = Uuid::uuid4();
$this->displayName = null;
$this->description = null;
$this->permissions = new ArrayCollection();
}
示例8: generateNewKey
public function generateNewKey()
{
$apikey = new ApiKey();
$apikey->key = Uuid::uuid4()->toString();
$apikey->save();
return $apikey;
}
示例9: loadItems
/**
* 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();
}
示例10: create
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);
}
示例11: rootAction
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);
}
示例12: store
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)]);
}
示例13: setUp
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())));
}
示例14: register
public function register(Application $app)
{
$app['uuid'] = $app->share(function () use($app) {
$uuid4 = Uuid::uuid4();
return $uuid4;
});
}
示例15: __construct
/**
* @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;
}