本文整理匯總了PHP中CommonUtil::is_datetime方法的典型用法代碼示例。如果您正苦於以下問題:PHP CommonUtil::is_datetime方法的具體用法?PHP CommonUtil::is_datetime怎麽用?PHP CommonUtil::is_datetime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CommonUtil
的用法示例。
在下文中一共展示了CommonUtil::is_datetime方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getMessages
/**
* Gets Message based upon some filters
* @param mixed $start The date to start querying from.
* @param mixed $end The last possible time in the query.
* @param integer $index The number of results to skip from the result set. The default is 0.
* @param integer $limit The maximum number of results to return. This has a hard limit of 1000 messages.
* @param boolean $pending A true or false value used to indicate if only scheduled messages should be returned in the result set. By default only sent message are returned
* @param string $direction Used to filter the result by the direction of the message. Possible values are "in" (to return only inbound messages) and "out" (to return only outbound messages).
* @return ApiList|HttpResponse|null
* @throws ErrorException
*/
public function getMessages($start = null, $end = null, $index = null, $limit = null, $pending = null, $direction = null)
{
$resource = "/messages/";
if (!is_null($start)) {
if (!is_int($start) || !is_string($start)) {
throw new ErrorException("Parameter 'start' must be an integer Unix timestamp or a string time in this format (YYYY-MM-DD HH:MM:SS)");
}
if (is_string($start)) {
if (!CommonUtil::is_datetime($time)) {
throw new ErrorException("Parameter 'start' must be a string time in this format (YYYY-MM-DD HH:MM:SS)");
}
}
if (is_int($start) && $start < 0) {
throw new ErrorException("Parameter 'start' must be a positive integer");
}
}
if (!is_null($end)) {
if (!is_int($end) || !is_string($end)) {
throw new ErrorException("Parameter 'end' must be an integer Unix timestamp or a string time in this format (YYYY-MM-DD HH:MM:SS)");
}
if (is_string($end)) {
if (!CommonUtil::is_datetime($time)) {
throw new ErrorException("Parameter 'end' must be a string time in this format (YYYY-MM-DD HH:MM:SS)");
}
}
if (is_int($end) && $end < 0) {
throw new ErrorException("Parameter 'end' must be a positive integer");
}
}
if (!is_null($index) && !is_int($index)) {
throw new ErrorException("Parameter 'index' must be an integer");
}
if (!is_null($limit) && !is_int($limit)) {
throw new ErrorException("Parameter 'limit' must be an integer");
}
if (!is_null($pending) && (!CommonUtil::is_boolean($pending) || !is_bool($pending))) {
throw new ErrorException("Parameter 'pending' must be a boolean (1, 0, true, false)");
}
if (!is_null($direction)) {
if (!is_string($direction)) {
throw new ErrorException("Parameter 'direction' must be string");
} elseif ($direction !== MessageDirection::IN || $direction !== MessageDirection::OUT) {
throw new ErrorException("Parameter 'direction' must be string. Possible values are in or out");
}
}
try {
$params = array();
if (!is_null($start)) {
$params["start"] = is_string($start) ? $start : gmdate('Y-m-d H:i:s', $start);
}
if (!is_null($end)) {
$params["end"] = is_string($end) ? $end : gmdate('Y-m-d H:i:s', $end);
}
if (!is_null($index)) {
$params["index"] = $index > 0 ? $index : 0;
}
if (!is_null($limit)) {
$params["limit"] = $limit > 0 && $limit <= 1000 ? $limit : 1000;
}
if (!is_null($pending)) {
if ($pending === "true" || $pending || $pending === "1") {
$params["pending"] = "true";
}
if ($pending === "false" || $pending === false || $pending === "0") {
$params["pending"] = "false";
}
}
if (!is_null($direction)) {
$params["direction"] = $direction;
}
$response = $this->httpClient->get($resource, $params);
if ($response instanceof HttpResponse) {
if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
$json = JsonHelper::getJson($response->getBody());
if (isset($json)) {
return new ApiList($json);
}
} else {
return $response;
}
}
} catch (Exception $ex) {
echo $ex->getTraceAsString();
}
return null;
}