/** * @return string */ private static function nextIdentity() { if (self::$identityGenerator === null) { self::$identityGenerator = ShortId::create(); } return self::$identityGenerator->generate(); }
/** * @inheritdoc */ public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null) { $client = Client::findByKey($clientId); if ($client === null) { throw new ClientNotFound(); } $session = new Session(['clientId' => $client->getKey(), 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'clientRedirectUri' => $clientRedirectUri]); $session->setId(ShortId::create()->generate()); $session->save(); return $session->getKey(); }
/** * Run the command. */ public function handle() { $client = new Client(['key' => env('OAUTH2_CLIENT_ID'), 'name' => env('OAUTH2_CLIENT_NAME')]); // We need to manually generate the id for the client. $client->setId(ShortId::create()->generate()); // The secret is guarded, so set it manually here. $client->setAttribute('secret', env('OAUTH2_CLIENT_SECRET')); if ($client->save()) { $this->info('Client created.'); } else { $this->error('Could not save client'); } }
/** * @inheritdoc */ public function generate() { return $this->generator->generate(); }
/** * @param array $myModel * @param array $myDoc * * @return array */ public static function setModelDefaults($myModel, $myDoc) { $myKeys = array_keys($myModel); $newDoc = []; foreach ($myKeys as $key) { $item_keys = array_keys($myModel[$key]); // If one of the keys of $myModel[$key] is _type this is a definition, not a defined key if (in_array("_type", $item_keys)) { // If array does not have this key, set the default value . if (!isset($myDoc[$key])) { if (isset($myModel[$key]['_input_type'])) { switch ($myModel[$key]['_input_type']) { case 'uid': $shortid = ShortId::create(); $newDoc[$key] = $shortid->generate(); break; case 'date': if ($myModel[$key]['_default'] == 'today') { $newDoc[$key] = date("Y-m-d"); } else { $newDoc[$key] = $myModel[$key]['_default']; } break; case 'timestamp': $model_default = $myModel[$key]['_default']; $model_type = $myModel[$key]['_type']; if ($model_default == "now" && $model_type == "integer") { $newDoc[$key] = time(); } elseif ($model_default == "now" && $model_type == "string") { $newDoc[$key] = date("Y-m-d H:i:s"); } else { $newDoc[$key] = $model_default; } break; default: $newDoc[$key] = $myModel[$key]['_default']; } } else { $newDoc[$key] = $myModel[$key]['_default']; } } else { // If model definition stated this key's default value is not Null // and has a wrong variable type, fix it. if ($myModel[$key]['_default'] !== null) { $key_type = self::getType($myDoc[$key]); if ($key_type != $myModel[$key]['_type'] && $key_type == "array") { $myDoc[$key] = $myModel[$key]['_default']; } settype($myDoc[$key], $myModel[$key]['_type']); } $newDoc[$key] = $myDoc[$key]; } $newDoc[$key] = self::sanitizeDocItem($newDoc[$key], $myModel[$key]); } else { if (!isset($myDoc[$key])) { $myDoc[$key] = ""; } $newDoc[$key] = self::setModelDefaults($myModel[$key], $myDoc[$key]); } } return $newDoc; }
<?php use Crisu83\ShortId\ShortId; require __DIR__ . '/./vendor/autoload.php'; require __DIR__ . '/./config.php'; $shortid = ShortId::create(); if (isset($_GET['shortid'])) { $short_id = $_GET['shortid']; } else { if (!isset($short_id)) { $short_id = $shortid->generate(); } } if (isset($_GET['uri']) && !empty($_GET['uri']) || isset($uri)) { $uri = isset($uri) ? $uri : $_GET['uri']; $short_path = $short_base_path . $short_id . '.php'; if (file_exists($short_path)) { header('Bad Request', true, 403); header('Content-Type: application/json'); echo json_encode(array('error' => 'this shorts is already taken.')); } else { $shorts = fopen($short_path, "w") or die("Unable to open file!"); $file_content = '<?php header("Location: ' . $uri . '");?>'; fwrite($shorts, $file_content); fclose($shorts); header('HTTP/1.1 200 OK'); header('Content-Type: application/json'); echo json_encode(array('short' => $short_id)); die; } } else {