本文整理汇总了PHP中Thin\Inflector::length方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::length方法的具体用法?PHP Inflector::length怎么用?PHP Inflector::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thin\Inflector
的用法示例。
在下文中一共展示了Inflector::length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
private function insert(array $data)
{
$id = $data['id'];
foreach ($data as $k => $v) {
if ($k == 'id') {
continue;
}
$motor = 'string';
if (fnmatch('*_id', $k)) {
$motor = 'int';
$v = (int) $v;
} elseif (is_numeric($v)) {
if (fnmatch('*.*', $v) || fnmatch('*.*', $v)) {
$motor = 'float';
$v = (double) $v;
} else {
$motor = 'int';
$v = (int) $v;
}
} else {
if (!is_string($v)) {
throw new Exception("An error occured to save this model. Please check the values.");
}
$length = Inflector::length($v);
$motor = 255 < $length ? 'text' : 'string';
}
$fieldRow = $motor . '_value';
$row = lib('mysql', 'kvdatas')->where('object_database', '=', $this->db)->where('object_table', '=', $this->table)->where('object_field', '=', $k)->where('object_id', '=', $id)->first();
if ($row) {
$row->{$fieldRow} = $v;
$row->save();
} else {
lib('mysql', 'kvdatas')->create(['object_database' => $this->db, 'object_table' => $this->table, 'object_field' => $k, 'object_id' => $id, $fieldRow => $v]);
}
}
}
示例2: getToken
public static function getToken($clientId, $clientSecret, $environment = 'development')
{
$url = 'development' == $environment ? 'https://api.sandbox.paypal.com/v1/oauth2/token' : 'https://api.paypal.com/v1/oauth2/token';
$auth = $clientId . ':' . $clientSecret;
$ch = curl_init();
$postData = "grant_type=client_credentials";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Accept-Language: en_US", "Content-length: " . Inflector::length($postData)));
curl_setopt($ch, CURLOPT_USERPWD, $auth);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
return $data['access_token'];
}