本文整理汇总了PHP中getType函数的典型用法代码示例。如果您正苦于以下问题:PHP getType函数的具体用法?PHP getType怎么用?PHP getType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
protected function update($data = array(), $params = array(), $otherTables = false)
{
$tables = "";
if (!empty($otherTables)) {
foreach ($otherTables as $table) {
$tables .= "," . $table . " ";
}
}
$values = '';
foreach ($data as $field => $value) {
if (getType($value) == 'integer') {
$values .= $field . "=" . addslashes($value) . ",";
} else {
$values .= $field . "='" . addslashes($value) . "',";
}
}
$condition = !empty($params['condition']) ? $params['condition'] : '1=1';
$sql = "UPDATE " . $this->table . $tables . " SET " . substr($values, 0, -1) . " WHERE " . $condition;
//echo "<meta charset='UTF-8'>UPDATE ".$this->table.$tables." SET ".substr($values,0,-1)." WHERE ".$condition.'<br>'.'<br>';
try {
$request = self::$connexion->prepare($sql);
$request->execute();
} catch (Exception $error) {
die('FAILED UPDATE : ' . $error->getMessage());
}
}
示例2: saveFile
public function saveFile($url, $file, $name)
{
$file_type = getType($file);
if ($file_type != '') {
copy($file['tmp_name'], $url . $name . '.' . $file_type);
}
}
示例3: CreateResponse
/**
* CreateResponse - Response handler to handle API Requests
*
* @param int $apiStatusCode The HTTP Status Code
*
* @return ApiResponse
*/
public static function CreateResponse($apiStatusCode, $requestResult = [])
{
if (getType($requestResult) == "array") {
$requestResult = json_encode($requestResult);
}
$request_result = json_decode($requestResult, true);
$request_result["records"] = array_key_exists("data", $request_result) ? count($request_result["data"]) : count($request_result);
$statusType = ApiResponse::$statusMessages[$apiStatusCode]["status_type"];
$successStatus = $statusType == "success" ? true : false;
$statusCode = ApiResponse::$statusMessages[$apiStatusCode]["status_code"];
$response = ["code" => $statusCode, "message" => Response::$statusTexts[$statusCode], "description" => ApiResponse::$statusCodeMessages[$statusCode], "reason" => ApiResponse::$statusMessages[$apiStatusCode]["status_text"], "apistatuscode" => $apiStatusCode];
$return = ["success" => $successStatus];
if ($statusType == "success") {
$return["response"] = $response;
} elseif ($statusType == "error") {
$return["error"] = $response;
}
if (!empty($requestResult)) {
$return["result"] = json_decode($requestResult, true);
$return["date"] = date("Y-m-d");
$return["time"] = date("H:i:s");
}
// Return Result
return $return;
}
示例4: convert
/**
* Map a PHP data type to ours
* @param mixed $value Any type of data
* @throws Exception
*/
public static function convert($type)
{
switch (getType($type)) {
case 'NULL':
return Type::NULL;
break;
case 'boolean':
return Type::BOOLEAN;
break;
case 'integer':
return Type::INTEGER;
break;
case 'double':
return Type::FLOAT;
break;
case 'string':
return Type::STRING;
break;
case 'array':
return Type::COLLECTION;
break;
case 'object':
return Type::OBJECT;
break;
case 'resource':
return Type::RESOURCE;
break;
case 'unknown type':
return Type::UNKNOWN;
break;
}
}
示例5: HTMLTemplate
function HTMLTemplate($name, $replace, $with)
{
$loc = $this->templateKey[$name];
$webRoot = getWebRoot();
if (getType($replace) == getType($with) && getType($replace) == "array" && count($replace) > 0) {
if (count($replace) == count($with)) {
array_unshift($replace, "{webRoot}");
array_unshift($with, $webRoot);
} else {
echo "error: Replace and With arrays are of different lengths.";
}
} else {
$replace = array('{webRoot}');
$with = array($webRoot);
}
if (isset($loc)) {
$html = file_get_contents($loc);
if ($html) {
if ($replace && $with) {
$htmlWithVars = str_replace($replace, $with, $html);
} else {
$htmlWithVars = $html;
}
echo $htmlWithVars;
}
} else {
// echo header("Location:error.php?num=2");
echo "error: Missing HTML template of {$name}";
}
}
示例6: setConfigParameter
/**
* Sets the name of the config-entry.
* @param string $strConfig the name of the config-entry.
* @return Dkplus_Controller_Plugin_Database
* @throws Zend_Controller_Exception on wrong parameter.
*/
public function setConfigParameter($strConfig)
{
if (!is_string($strConfig)) {
throw new Zend_Controller_Exception('$strConfig is an ' . getType($strConfig) . ', must be an string');
}
$this->_configName = $strConfig;
}
示例7: validate
/**
* 入力チェック処理
* @param array $data 入力データ
* @param array &$valid_data 入力チェック後の返却データ
* @param array $white_list 入力のチェック許可リスト
*/
public function validate($data, &$valid_data, $white_list = array())
{
$errors = array();
$valid_data = array();
$isWhiteList = !!count($white_list);
foreach ($this->validates as $key => $valid) {
// カラムのホワイトリストチェック
if ($isWhiteList && !in_array($key, $white_list)) {
continue;
}
foreach ($valid as $mKey => $options) {
$method = is_array($options) && isset($options['rule']) ? $options['rule'] : $mKey;
if (!isset($data[$key])) {
$data[$key] = null;
}
$error = Validate::$method($data[$key], $options, $key, $data, $this);
if ($error === false) {
break;
}
if (getType($error) === 'string') {
$errors[$key] = $error;
break;
}
}
if (isset($data[$key])) {
$valid_data[$key] = $data[$key];
}
}
return $errors;
}
示例8: serializeArrayToXml
protected function serializeArrayToXml(array $array, DOMElement $element)
{
foreach ($array as $name => $value) {
$property = $element->appendChild($element->ownerDocument->createElement('property'));
$property->setAttribute('key-type', is_string($name) ? 'string' : 'integer');
$property->setAttribute('key-name', $name);
switch ($type = gettype($value)) {
case 'double':
$type = 'float';
case 'integer':
// $type has already been set
$property->appendChild($element->ownerDocument->createTextNode((string) $value));
break;
case 'boolean':
// $type has already been set
$property->appendChild($element->ownerDocument->createTextNode($value ? '1' : '0'));
break;
case 'string':
$property->appendChild($element->ownerDocument->createCDATASection($value));
break;
case 'array':
// $type has been set
// recursively serialize the array
$this->serializeArrayToXml($value, $property);
break;
default:
//@todo
throw new Exception('Can not serialize type ' . getType($value) . ' in configuration setting ' . $name);
}
$property->setAttribute('value-type', $type);
}
}
示例9: __construct
/**
* Just set member variables and check the values are correct
*
* @param int $code The response code
* @param array of string $message The response message
* @return void
*/
public function __construct($code, array $message)
{
if (!is_numeric($code)) {
throw new InvalidArgumentException('SMTP response code must be a ' . 'number, but (' . getType($code) . ')' . $code . ' given.');
}
$this->code = $code;
$this->message = $message;
}
示例10: typeName
public static function typeName($arg)
{
$t = getType($arg);
if ($t == "object") {
return get_class($arg);
}
return $t;
}
示例11: __construct
/**
* Schedule generator constructor. Creates schedule sequence for selected objects
*
* @param array|Traversable $objects
*/
public function __construct($objects = [])
{
if (!is_array($objects) && !$objects instanceof \Traversable) {
throw new \InvalidArgumentException(sprintf("Expects an array or Traversable object, '%s' has given", getType($object)));
}
foreach ($objects as $object) {
$this->add($object);
}
}
示例12: toObject
public static function toObject($arr)
{/*{{{*/
if(gettype($arr) != 'array') return $arr;
foreach ($arr as $k=>$v)
{
if(gettype($v) == 'array' || getType($v) == 'object')
$arr[$k] = (object) self::toObject($v);
}
return (object) $arr;
}/*}}}*/
示例13: getBrokenThemeSettings
function getBrokenThemeSettings($id)
{
$themeSettings = WikiFactory::getVarByName('wgOasisThemeSettings', $id);
if (!is_object($themeSettings) || empty($themeSettings->cv_value)) {
return null;
}
$themeSettingsArray = unserialize($themeSettings->cv_value);
$backgroundImage = $themeSettingsArray['background-image'];
return getType($backgroundImage) !== 'string' || $backgroundImage === 'false' ? $themeSettingsArray : null;
}
示例14: debug
protected function debug($arrayToDebug = array(), $array_name = false)
{
$title = !empty($array_name) ? $array_name : "";
if (getType($arrayToDebug) == "array") {
ksort($arrayToDebug);
}
echo "<meta charset='UTF-8'>\n <h1 style='margin-bottom:-35px!important;position:relative;z-index:9999!important;'>" . $title . "</h1>\n <pre style='margin:50px!important;background-color:#AEAEAE!important;border:solid 2px red!important;z-index:9999!important;position:relative;'>";
print_r($arrayToDebug);
echo "</pre><br>";
}
示例15: extract
/**
* @param array|ModelInterface $dataOrModel
* @param HydratorInterface $hydrator
* @return array
*/
public function extract($dataOrModel, HydratorInterface $hydrator = null)
{
if (is_array($dataOrModel)) {
return $dataOrModel;
}
if (!$dataOrModel instanceof ModelInterface) {
throw new \InvalidArgumentException('Model object needs to implement ModelInterface got: ' . getType($dataOrModel));
}
$hydrator = $hydrator ?: $this->getHydrator();
return $hydrator->extract($dataOrModel);
}