本文整理汇总了PHP中UUID::TryParse方法的典型用法代码示例。如果您正苦于以下问题:PHP UUID::TryParse方法的具体用法?PHP UUID::TryParse怎么用?PHP UUID::TryParse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UUID
的用法示例。
在下文中一共展示了UUID::TryParse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Execute
public function Execute($db, $params)
{
if (isset($params["SceneID"]) && UUID::TryParse($params["SceneID"], $this->SceneID)) {
$sql = "DELETE FROM Scenes WHERE ID='" . $this->SceneID . "'";
} else {
if (isset($params["Name"])) {
$sql = "DELETE FROM Scenes WHERE Name='" . $params["Name"] . "'";
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
}
$sth = $db->prepare($sql);
if ($sth->execute()) {
header("Content-Type: application/json", true);
echo '{ "Success": true }';
exit;
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例2: Execute
public function Execute($db, $params)
{
if (isset($params["Identifier"], $params["Credential"], $params["Type"], $params["UserID"]) && UUID::TryParse($params["UserID"], $this->UserID)) {
if (isset($params["Enabled"]) && $params["Enabled"] == False) {
$parameters = array(':Identifier' => $params["Identifier"], ':Credential' => $params["Credential"], ':Type' => $params["Type"], ':UserID' => $this->UserID);
$sql = "INSERT INTO Identities (Identifier, Credential, Type, UserID, Enabled)\n VALUES (:Identifier, :Credential, :Type, :UserID, False)\n ON DUPLICATE KEY UPDATE Credential=VALUES(Credential), Type=VALUES(Type), UserID=VALUES(UserID), Enabled=VALUES(Enabled)";
} else {
$parameters = array(':Identifier' => $params["Identifier"], ':Credential' => $params["Credential"], ':Type' => $params["Type"], ':UserID' => $this->UserID);
$sql = "INSERT INTO Identities (Identifier, Credential, Type, UserID)\n VALUES (:Identifier, :Credential, :Type, :UserID)\n ON DUPLICATE KEY UPDATE Credential=VALUES(Credential), Type=VALUES(Type), UserID=VALUES(UserID), Enabled=1";
}
$sth = $db->prepare($sql);
if ($sth->execute($parameters)) {
header("Content-Type: application/json", true);
echo '{ "Success": true }';
exit;
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
}
示例3: Execute
public function Execute($db, $params)
{
// TODO: Sanity check the expiration date
// TODO: Also run a regex on Resource to make sure it's a valid (relative or absolute) URL
if (!isset($params["OwnerID"], $params["Resource"], $params["Expiration"]) || !UUID::TryParse($params["OwnerID"], $this->OwnerID)) {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
if (!isset($params["CapabilityID"]) || !UUID::TryParse($params["CapabilityID"], $this->CapabilityID)) {
$this->CapabilityID = UUID::Random();
}
$resource = $params["Resource"];
$expiration = $params["Expiration"];
$sql = "INSERT INTO Capabilities (ID, OwnerID, Resource, ExpirationDate) VALUES (:ID, :OwnerID, :Resource, :ExpirationDate)\n ON DUPLICATE KEY UPDATE OwnerID=VALUES(OwnerID), Resource=VALUES(Resource), ExpirationDate=VALUES(ExpirationDate)";
$sth = $db->prepare($sql);
if ($sth->execute(array(':ID' => $this->CapabilityID, ':OwnerID' => $this->OwnerID, ':Resource' => $resource, ':ExpirationDate' => $expiration))) {
header("Content-Type: application/json", true);
echo sprintf('{"Success": true, "CapabilityID": "%s"}', $this->CapabilityID);
exit;
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例4: Execute
public function Execute($db, $params)
{
$sql = "SELECT Identifier, Type, Credential, UserID, Enabled FROM Identities WHERE";
$id = null;
if (isset($params["UserID"]) && UUID::TryParse($params["UserID"], $id)) {
$sql .= " UserID=:ID";
} else {
if (isset($params["Identifier"])) {
$id = $params["Identifier"];
$sql .= " Identifier=:ID";
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
}
$sth = $db->prepare($sql);
if ($sth->execute(array(':ID' => $id))) {
$found = array();
while ($obj = $sth->fetchObject()) {
$found[] = sprintf('{"Identifier":"%s","Credential":"%s","Type":"%s","UserID":"%s","Enabled":%s}', $obj->Identifier, $obj->Credential, $obj->Type, $obj->UserID, $obj->Enabled ? 'true' : 'false');
}
header("Content-Type: application/json", true);
echo '{"Success":true,"Identities":[' . implode(',', $found) . ']}';
exit;
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例5: Execute
public function Execute($db, $params)
{
if (!isset($params["OwnerID"], $params["Resource"], $params["Expiration"]) || !UUID::TryParse($params["OwnerID"], $this->OwnerID)) {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
if (!isset($params["CapabilityID"]) || !UUID::TryParse($params["CapabilityID"], $this->CapabilityID)) {
$this->CapabilityID = UUID::Random();
}
$resource = $params["Resource"];
$expiration = intval($params["Expiration"]);
// Sanity check the expiration date
if ($expiration <= time()) {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid expiration date ' . $expiration . '" }';
exit;
}
log_message('debug', "Creating capability " . $this->CapabilityID . " owned by " . $this->OwnerID . " mapping to {$resource} until {$expiration}");
$sql = "INSERT INTO Capabilities (ID, OwnerID, Resource, ExpirationDate) VALUES (:ID, :OwnerID, :Resource, FROM_UNIXTIME(:ExpirationDate))\n ON DUPLICATE KEY UPDATE ID=VALUES(ID), Resource=VALUES(Resource), ExpirationDate=VALUES(ExpirationDate)";
$sth = $db->prepare($sql);
if ($sth->execute(array(':ID' => $this->CapabilityID, ':OwnerID' => $this->OwnerID, ':Resource' => $resource, ':ExpirationDate' => $expiration))) {
header("Content-Type: application/json", true);
echo sprintf('{"Success": true, "CapabilityID": "%s"}', $this->CapabilityID);
exit;
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例6: Execute
public function Execute($db, $params)
{
if (isset($params["SceneID"], $params["Enabled"]) && UUID::TryParse($params["SceneID"], $this->SceneID)) {
$sql = "UPDATE Scenes SET Enabled=:Enabled WHERE ID='" . $this->SceneID . "'";
} else {
if (isset($params["Name"], $params["Enabled"])) {
$sql = "UPDATE Scenes SET Enabled=:Enabled WHERE Name='" . $params["Name"] . "'";
} else {
log_message('error', sprintf("AddScene: Unable to parse passed parameters or parameter missing: '%s'", print_r($params, true)));
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
}
$sth = $db->prepare($sql);
if ($sth->execute(array(':Enabled' => $params["Enabled"]))) {
if ($sth->rowCount() > 0) {
header("Content-Type: application/json", true);
echo '{ "Success": true }';
exit;
} else {
log_message('error', "Failed updating the database");
header("Content-Type: application/json", true);
echo '{ "Message": "Database update failed" }';
exit;
}
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例7: Execute
public function Execute($db, $params)
{
$sql = "DELETE FROM Sessions";
if (isset($params['SessionID']) && UUID::TryParse($params['SessionID'], $this->ID)) {
$sql .= " WHERE SessionID=:ID";
} else {
if (isset($params['UserID']) && UUID::TryParse($params['UserID'], $this->ID)) {
$sql .= " WHERE UserID=:ID";
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
}
$sth = $db->prepare($sql);
if ($sth->execute(array(':ID' => $this->ID))) {
header("Content-Type: application/json", true);
echo '{ "Success": true }';
exit;
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例8: Execute
public function Execute($db, $params)
{
$this->inventory = new ALT($db);
$folderid = '';
if (!isset($params["FolderID"]) || !UUID::TryParse($params["FolderID"], $folderid)) {
$folderid = UUID::Random();
}
$this->Folder = new InventoryFolder($folderid);
if (!isset($params, $params["Name"], $params["ParentID"], $params["OwnerID"]) || !UUID::TryParse($params["ParentID"], $this->Folder->ParentID) || !UUID::TryParse($params["OwnerID"], $this->Folder->OwnerID)) {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
$this->Folder->Name = trim($params["Name"]);
$this->Folder->ContentType = isset($params["ContentType"]) && trim($params["ContentType"]) != '' ? trim($params["ContentType"]) : 'application/octet-stream';
$this->Folder->ExtraData = isset($params["ExtraData"]) ? trim($params["ExtraData"]) : '';
try {
$result = $this->inventory->InsertNode($this->Folder);
if ($result != FALSE) {
header("Content-Type: application/json", true);
echo sprintf('{ "Success": true, "FolderID": "%s" }', $result);
exit;
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Folder creation failed" }';
exit;
}
} catch (Exception $ex) {
log_message('error', sprintf("Error occurred during query: %s", $ex));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例9: Execute
public function Execute($db, $params)
{
$asset = null;
$assetID = null;
if (isset($params["ID"]) && UUID::TryParse($params["ID"], $assetID)) {
log_message('debug', "xGetAsset asset: {$assetID}");
$assets = new SQLAssets($db);
$asset = $assets->GetAsset($assetID);
}
$response = array();
if (!empty($asset)) {
$response['Success'] = TRUE;
$response['SHA256'] = $asset->SHA256;
$response['Last-Modified'] = gmdate(DATE_RFC850, $asset->CreationDate);
$response['CreatorID'] = $asset->CreatorID;
$response['ContentType'] = $asset->ContentType;
$response['ContentLength'] = $asset->ContentLength;
$response['EncodedData'] = base64_encode($asset->Data);
$response['Temporary'] = $asset->Temporary;
} else {
log_message('info', "Asset {$assetID} not found");
$response['Success'] = FALSE;
$response['Message'] = "Asset {$assetID} not found";
}
header("Content-Type: application/json", true);
echo json_encode($response);
exit;
}
示例10: Execute
public function Execute($db, $params)
{
if (!isset($params["CapabilityID"]) || !UUID::TryParse($params["CapabilityID"], $this->CapabilityID)) {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
$sql = "SELECT OwnerID,Resource,UNIX_TIMESTAMP(ExpirationDate) AS ExpirationDate FROM Capabilities WHERE ID=:ID AND UNIX_TIMESTAMP(ExpirationDate) > UNIX_TIMESTAMP() LIMIT 1";
$sth = $db->prepare($sql);
if ($sth->execute(array(':ID' => $this->CapabilityID))) {
if ($sth->rowCount() > 0) {
$obj = $sth->fetchObject();
header("Content-Type: application/json", true);
echo sprintf('{"Success": true, "CapabilityID": "%s", "OwnerID": "%s", "Resource": "%s", "Expiration": %u}', $this->CapabilityID, $obj->OwnerID, $obj->Resource, $obj->ExpirationDate);
exit;
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Capability not found" }';
exit;
}
}
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
示例11: Execute
public function Execute($db, $params)
{
if (!isset($params["OwnerID"]) || !UUID::TryParse($params["OwnerID"], $this->OwnerID)) {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
$sql = "SELECT ID,Resource,UNIX_TIMESTAMP(ExpirationDate) AS ExpirationDate FROM Capabilities WHERE OwnerID=:OwnerID AND UNIX_TIMESTAMP(ExpirationDate) > UNIX_TIMESTAMP()";
$sth = $db->prepare($sql);
if ($sth->execute(array(':OwnerID' => $this->OwnerID))) {
$caplist = array();
while ($obj = $sth->fetchObject()) {
$cap = sprintf('{"CapabilityID":"%s","Resource":"%s","Expiration":"%s"}', $obj->ID, $obj->Resource, $obj->ExpirationDate);
$caplist[] = $cap;
}
header("Content-Type: application/json", true);
echo '{ "Success":true,"Capabilities":[' . implode(',', $caplist) . ']}';
exit;
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例12: Execute
public function Execute($db, $params)
{
if (isset($params["UserID"], $params["Name"], $params["Email"]) && UUID::TryParse($params["UserID"], $this->UserID)) {
// Distinguish between a user insert, and a user update
$sql = "SELECT ID FROM Users WHERE ID=:ID";
$sth = $db->prepare($sql);
$sth->execute(array('ID' => $this->UserID));
if ($sth->rowCount() == 0) {
// New User Insertion
$sql = "INSERT INTO Users (ID, Name, Email, AccessLevel) VALUES (:ID, :Name, :Email, :AccessLevel)";
} else {
// UUID exists, update existing record
$sql = "UPDATE Users SET Name=:Name, Email=:Email, AccessLevel=:AccessLevel WHERE ID=:ID";
}
$sth->closeCursor();
// Set the AccessLevel for this user
if (isset($params["AccessLevel"]) && is_numeric($params["AccessLevel"])) {
$accessLevel = (int) $params["AccessLevel"];
if ($accessLevel > 255) {
$accessLevel = 255;
} else {
if ($accessLevel < 0) {
$accessLevel = 0;
}
}
} else {
$accessLevel = 0;
}
$sth = $db->prepare($sql);
if ($sth->execute(array('ID' => $this->UserID, 'Name' => $params["Name"], 'Email' => $params["Email"], 'AccessLevel' => $accessLevel))) {
if ($sth->rowCount() > 0) {
header("Content-Type: application/json", true);
echo '{ "Success": true }';
exit;
} else {
log_message('error', "Failed updating the database");
header("Content-Type: application/json", true);
echo '{ "Message": "Database update failed" }';
exit;
}
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
} else {
log_message('error', sprintf("Missing or invalid parameters: %s", print_r($params, true)));
header("Content-Type: application/json", true);
echo '{ "Message": "Missing or invalid parameters" }';
exit;
}
}
示例13: Execute
public function Execute($db, $params)
{
if (isset($params["UserID"]) && UUID::TryParse($params["UserID"], $this->UserID)) {
unset($params["RequestMethod"]);
unset($params["UserID"]);
if (count($params) > 0) {
$sql = "REPLACE INTO UserData (ID, `Key`, `Value`) VALUES";
$values = array(":ID" => $this->UserID);
$i = 0;
foreach ($params as $key => $value) {
if ($key === "UserID" || $key === "Name" || $key === "Email") {
header("Content-Type: application/json", true);
echo '{ "Message": "Field name is reserved" }';
exit;
}
if ($i > 0) {
$sql .= ',';
}
$sql .= '(:ID, :Key' . $i . ', :Value' . $i . ')';
$values[':Key' . $i] = preg_replace('/[^a-zA-Z0-9\\s]/', '', $key);
$values[':Value' . $i] = escape_json($value);
++$i;
}
$sth = $db->prepare($sql);
if ($sth->execute($values)) {
if ($sth->rowCount() > 0) {
header("Content-Type: application/json", true);
echo '{ "Success": true }';
exit;
} else {
log_message('error', "Failed updating the database");
header("Content-Type: application/json", true);
echo '{ "Message": "Database update failed" }';
exit;
}
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "No fields specified" }';
exit;
}
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Missing or invalid UserID" }';
exit;
}
}
示例14: Execute
public function Execute($db, $params)
{
$sql = "SELECT * FROM Sessions WHERE";
if (isset($params["UserID"]) && UUID::TryParse($params["UserID"], $this->ID)) {
$sql .= " UserID=:ID";
} else {
if (isset($params["SessionID"]) && UUID::TryParse($params["SessionID"], $this->ID)) {
$sql .= " SessionID=:ID";
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
}
$sth = $db->prepare($sql);
if ($sth->execute(array(':ID' => $this->ID))) {
if ($sth->rowCount() > 0) {
$obj = $sth->fetchObject();
$session = new Session();
$session->UserID = $obj->UserID;
$session->SessionID = $obj->SessionID;
$session->SecureSessionID = $obj->SecureSessionID;
$session->SceneID = $obj->SceneID;
$session->ScenePosition = Vector3::Parse($obj->ScenePosition);
$session->SceneLookAt = Vector3::Parse($obj->SceneLookAt);
$session->LastUpdate = $obj->LastUpdate;
$session->ExtraData = $obj->ExtraData;
if (empty($session->ExtraData)) {
$session->ExtraData = "{}";
}
$output = sprintf('{ "Success": true, "UserID": "%s", "SessionID": "%s", "SecureSessionID": "%s", "SceneID": "%s", "ScenePosition": %s, "SceneLookAt": %s, "ExtraData": %s }', $session->UserID, $session->SessionID, $session->SecureSessionID, $session->SceneID, $session->ScenePosition->toOSD(), $session->SceneLookAt->toOSD(), $session->ExtraData);
header("Content-Type: application/json", true);
echo $output;
exit;
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Session not found" }';
exit;
}
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
}
示例15: Execute
public function Execute($db, $params)
{
if (isset($params["SessionID"]) && UUID::TryParse($params["SessionID"], $this->SessionID)) {
$sql = "UPDATE Sessions SET";
$dbValues = array('SessionID' => $this->SessionID);
$addComma = FALSE;
handle_uuid_parameter("SecureSessionID", $params, $sql, $dbValues, $addComma);
handle_uuid_parameter("SceneID", $params, $sql, $dbValues, $addComma);
handle_vector_parameter("ScenePosition", $params, $sql, $dbValues, $addComma);
handle_vector_parameter("SceneLookAt", $params, $sql, $dbValues, $addComma);
handle_json_parameter("ExtraData", $params, $sql, $dbValues, $addComma);
$sql .= " WHERE SessionID=:SessionID";
$sth = $db->prepare($sql);
if ($sth->execute($dbValues)) {
// TODO: We don't currently check if a row was actually updated since rowCount() will be zero
// if there was no change (false negative).
header("Content-Type: application/json", true);
echo '{ "Success": true }';
exit;
//if ($sth->rowCount() > 0)
//{
// header("Content-Type: application/json", true);
// echo '{ "Success": true }';
// exit();
//}
//else
//{
// // FIXME: rowCount() will be 0 if no changes were made. No
// // change should still be reported as a success
// header("Content-Type: application/json", true);
// echo '{ "Message": "Session does not exist" }';
// exit();
//}
} else {
log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
log_message('debug', sprintf("Query: %s", $sql));
header("Content-Type: application/json", true);
echo '{ "Message": "Database query error" }';
exit;
}
} else {
header("Content-Type: application/json", true);
echo '{ "Message": "Invalid parameters" }';
exit;
}
}