/** * {@inheritdoc} * * @param Uuid|null $value * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (empty($value)) { return null; } if ($value instanceof Uuid) { return $value->getBytes(); } try { $uuid = Uuid::fromString($value); } catch (InvalidArgumentException $e) { throw ConversionException::conversionFailed($value, self::NAME); } return $uuid->getBytes(); }
/** * 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); }
function handlePost($app, $request) { // Timestamp & reverse-timestamp $odt = new DateTime('now', new DateTimeZone("Europe/Amsterdam")); $timestamp = $odt->format("Y-m-d H:i"); $rtimestamp = $odt->format("siHdmY"); try { $uuid1 = Uuid::uuid1(); // Make sure the media file was uploaded without error $file = $request->files->get('mediaFile'); if (!$file instanceof UploadedFile || $file->getError()) { throw new \InvalidArgumentException('The file is not valid.'); } $ofilename = $rtimestamp . '-' . $file->getFilename(); // create a thumbnail $image = $app['imagine']->open($file->getPathname()); $tfilename = $rtimestamp . '-' . $file->getFilename() . '-thumb.jpeg'; $tfilepath = $file->getPath() . '/' . $tfilename; $image->resize(new Box(200, 200))->save($tfilepath); // Upload the original media file to S3 $ores = $app['aws.s3']->upload($app['env.orig'], $ofilename, fopen($file->getPathname(), 'r'), 'public-read'); // upload the thumbnail $tres = $app['aws.s3']->upload($app['env.trans'], $tfilename, fopen($tfilepath, 'r'), 'public-read'); // add file metadata $dynamoDbResult = $app['aws.ddb']->putItem(['TableName' => $app['env.table'], 'Item' => ['owner' => ['S' => 'PHP-User'], 'uid' => ['S' => $uuid1->toString()], 'timestamp' => ['S' => $timestamp], 'description' => ['S' => (string) $request->request->get('caption')], 'name' => ['S' => $file->getClientOriginalName()], 'source' => ['S' => $ofilename], 'thumbnail' => ['S' => $tfilename]]]); return array('type' => 'success', 'message' => 'File uploaded.'); } catch (Exception $e) { // @TODO if something fails, rollback any object uploads return array('type' => 'error', 'message' => "Error uploading your photo:" . $e); } }
public function deserializeUuid(VisitorInterface $visitor, $data, array $type, Context $context) { if (null === $data) { return null; } return Uuid::fromString($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); }
/** * 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; }
/** * 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 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; }
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 testGenerate() { $id = UuidIdentifier::generate(); $this->assertTrue(Uuid::isValid($id)); $uuid = Uuid::fromString($id->toString()); $this->assertTrue($uuid->getVersion() == 4); }
/** * @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); }
/** * @param ExportEventInterface $event * @throws CloseArchiveException * @throws OpenArchiveException * @throws UnavailableArchiveException */ public function onCreateArchive(ExportEventInterface $event) { $archiveName = (string) Uuid::uuid1(); $projectRootDir = realpath($this->projectRootDir); $archivePath = realpath($this->archiveDir) . '/' . $archiveName . '.zip'; $archive = $this->openArchive($archivePath); foreach ($this->exportedCollection as $exportable) { if ($exportable instanceof ExportableInterface) { $exportPath = $projectRootDir . '/' . $exportable->getExportDestination(); if (file_exists($exportPath)) { $exportFile = new \SplFileObject($exportPath); $archive->addFile($exportPath, $exportFile->getFilename()); } else { $this->logger->error(sprintf('Could not find export at "%s"', $exportPath)); // TODO Emit ErrorEvent to be handled later on for more robustness continue; } } } $this->closeArchive($archive, $archivePath); if ($event instanceof JobAwareEventInterface) { if (!file_exists($archivePath)) { throw new UnavailableArchiveException(sprintf('Could not find archive at "%s"', $archivePath), UnavailableArchiveException::DEFAULT_CODE); } /** @var \WeavingTheWeb\Bundle\ApiBundle\Entity\Job $job */ $job = $event->getJob(); $archiveFile = new \SplFileObject($archivePath); $filename = str_replace('.zip', '', $archiveFile->getFilename()); $router = $this->router; $getArchiveUrl = $this->router->generate('weaving_the_web_api_get_archive', ['filename' => $filename], $router::ABSOLUTE_PATH); $job->setOutput($getArchiveUrl); } $this->exportedCollection = []; }
/** * {@inheritdoc} * * @return Folder */ public function generate(ResourceInterface $resource = null) { $folder = new Folder(); $folder->setId((string) Uuid::uuid4()); $folder->setName($resource->getShortName()); return $folder; }
/** * {@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; }
/** * 获取税务信息 * @return mixed * @param Request $request * @author AndyLee <*****@*****.**> */ public function getTaxList(Request $request) { $company = Company::find($request->session()->get('customer_id')); $start = new \DateTime($company->created_at); $end = new DateTime(); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start, $interval, $end); $card = []; foreach ($period as $dt) { $map = ['user_id' => $request->session()->get('company_id'), 'company_id' => $request->session()->get('customer_id'), 'flag' => $dt->format("Ym")]; $tax = Tax::where($map)->first(); if (empty($tax)) { $record = new Tax(); $record->user_id = $request->session()->get('company_id'); $record->company_id = $request->session()->get('customer_id'); $record->operator_id = Auth::user()->id; $record->card_name = $dt->format("Ym") . '税务申报单'; $record->finish_time = strtotime($dt->format('Y-m') . '-15'); $record->uuid = Uuid::uuid1(); $record->guoshui_status = 0; $record->dishui_status = 0; $record->flag = $dt->format("Ym"); $record->save(); $card[] = $record->toArray(); } else { $card[] = $tax->toArray(); } } $card = array_reverse($card); return view('customer.tax.index')->with('cards', $card); }
public function __construct(array $state = []) { $this->metadata = []; $this->uuid = Uuid::uuid4()->toString(); parent::__construct($state); $this->guardRequiredState(); }
public function __construct($taskName, $workload, $uuid = null) { $this->uuid = $uuid ?: Uuid::uuid4()->toString(); $this->taskName = $taskName; $this->workload = $workload; $this->executionDate = new \DateTime(); }
/** * 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(); }
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']; }
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]); } } }); }
/** * 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(); }
/** * @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; }
/** * Boot the Uuid trait for the model. * * @return void */ public static function bootUuidForKey() { static::creating(function ($model) { $model->incrementing = false; $model->{$model->getKeyName()} = (string) Uuid::uuid1(); }); }
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 $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; } } }
/** * @test */ public function it_should_create_video_proxy_from_the_video_source() { $videoProxyService = new VideoProxyService($this->entityManager); $this->entityManager->expects($this->once())->method('persist'); $proxyUuid = $videoProxyService->createFromSource("http://video-proxy.com"); $this->assertEquals($proxyUuid, (string) Uuid::fromString($proxyUuid)); }
/** * 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 static function fromString(string $uuid) { if (!Uuid::isValid($uuid)) { throw new \InvalidArgumentException(sprintf('%s is not valid uuid', $uuid)); } return new Id(Uuid::fromString($uuid)->toString()); }
/** * @param string $uuidString * @return \Ramsey\Uuid\UuidInterface */ private function deserializeUuidValue($uuidString) { if (!Uuid::isValid($uuidString)) { throw new \Mhujer\JmsSerializer\Uuid\InvalidUuidException($uuidString); } return Uuid::fromString($uuidString); }
/** * 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; }