本文整理汇总了PHP中Version::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Version::get方法的具体用法?PHP Version::get怎么用?PHP Version::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Version
的用法示例。
在下文中一共展示了Version::get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doRequest
public function doRequest($context, $method, $host, $path, $params, $data, $connectTimeout, $readTimeout)
{
if (strpos($host, "http") === 0) {
$url = $host . $path;
} else {
$url = "https://" . $host . $path;
}
if ($params != null && count($params) > 0) {
$params2 = array();
foreach ($params as $key => $val) {
if (is_array($val)) {
$params2[$key] = json_encode($val);
} else {
$params2[$key] = $val;
}
}
$url .= "?" . http_build_query($params2);
}
// initialize curl library
$curlHandle = curl_init();
// set curl options
try {
foreach ($this->curlOptions as $curlOption => $optionValue) {
curl_setopt($curlHandle, constant($curlOption), $optionValue);
}
} catch (\Exception $e) {
$this->invalidOptions($this->curlOptions, $e->getMessage());
}
//curl_setopt($curlHandle, CURLOPT_VERBOSE, true);
if ($context->adminAPIKey == null) {
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array_merge(array('X-Algolia-Application-Id: ' . $context->applicationID, 'X-Algolia-API-Key: ' . $context->apiKey, 'Content-type: application/json'), $context->headers));
} else {
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array_merge(array('X-Algolia-Application-Id: ' . $context->applicationID, 'X-Algolia-API-Key: ' . $context->adminAPIKey, 'X-Forwarded-For: ' . $context->endUserIP, 'X-Forwarded-API-Key: ' . $context->rateLimitAPIKey, 'Content-type: application/json'), $context->headers));
}
curl_setopt($curlHandle, CURLOPT_USERAGENT, "Algolia for PHP " . Version::get());
//Return the output instead of printing it
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_FAILONERROR, true);
curl_setopt($curlHandle, CURLOPT_ENCODING, '');
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curlHandle, CURLOPT_CAINFO, $this->cainfoPath);
curl_setopt($curlHandle, CURLOPT_URL, $url);
$version = curl_version();
if (version_compare(phpversion(), '5.2.3', '>=') && version_compare($version['version'], '7.16.2', '>=') && $connectTimeout < 1) {
curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT_MS, $connectTimeout * 1000);
curl_setopt($curlHandle, CURLOPT_TIMEOUT_MS, $readTimeout * 1000);
} else {
curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, $connectTimeout);
curl_setopt($curlHandle, CURLOPT_TIMEOUT, $readTimeout);
}
curl_setopt($curlHandle, CURLOPT_NOSIGNAL, 1);
# The problem is that on (Li|U)nix, when libcurl uses the standard name resolver, a SIGALRM is raised during name resolution which libcurl thinks is the timeout alarm.
curl_setopt($curlHandle, CURLOPT_FAILONERROR, false);
if ($method === 'GET') {
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curlHandle, CURLOPT_HTTPGET, true);
curl_setopt($curlHandle, CURLOPT_POST, false);
} else {
if ($method === 'POST') {
$body = $data ? json_encode($data) : '';
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curlHandle, CURLOPT_POST, true);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $body);
} elseif ($method === 'DELETE') {
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($curlHandle, CURLOPT_POST, false);
} elseif ($method === 'PUT') {
$body = $data ? json_encode($data) : '';
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $body);
curl_setopt($curlHandle, CURLOPT_POST, true);
}
}
$mhandle = $context->getMHandle($curlHandle);
// Do all the processing.
$running = null;
do {
$mrc = curl_multi_exec($mhandle, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($running && $mrc == CURLM_OK) {
if (curl_multi_select($mhandle, 0.1) == -1) {
usleep(100);
}
do {
$mrc = curl_multi_exec($mhandle, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
$http_status = (int) curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
$response = curl_multi_getcontent($curlHandle);
$error = curl_error($curlHandle);
if (!empty($error)) {
throw new \Exception($error);
}
if ($http_status === 0 || $http_status === 503) {
// Could not reach host or service unavailable, try with another one if we have it
$context->releaseMHandle($curlHandle);
curl_close($curlHandle);
return null;
}
//.........这里部分代码省略.........
示例2: _doUrlRequest
public function _doUrlRequest($httpVerb, $url, $requestBody = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_TIMEOUT, $this->_config->timeout());
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
$headers = $this->_getHeaders($curl);
$headers[] = 'User-Agent: Braintree PHP Library ' . Version::get();
$headers[] = 'X-ApiVersion: ' . Configuration::API_VERSION;
$authorization = $this->_getAuthorization();
if (isset($authorization['user'])) {
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $authorization['user'] . ':' . $authorization['password']);
} else {
if (isset($authorization['token'])) {
$headers[] = 'Authorization: Bearer ' . $authorization['token'];
}
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($curl, CURLOPT_VERBOSE, true);
if ($this->_config->sslOn()) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAINFO, $this->getCaFile());
}
if (!empty($requestBody)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
}
if ($this->_config->isUsingProxy()) {
$proxyHost = $this->_config->getProxyHost();
$proxyPort = $this->_config->getProxyPort();
$proxyType = $this->_config->getProxyType();
curl_setopt($curl, CURLOPT_PROXY, $proxyHost . ':' . $proxyPort);
if (!empty($proxyType)) {
curl_setopt($curl, CURLOPT_PROXYTYPE, $proxyType);
}
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$error_code = curl_errno($curl);
if ($error_code == 28 && $httpStatus == 0) {
throw new Exception\Timeout();
}
curl_close($curl);
if ($this->_config->sslOn()) {
if ($httpStatus == 0) {
throw new Exception\SSLCertificate();
}
}
return ['status' => $httpStatus, 'body' => $response];
}
示例3: getMajorVersion
/**
* Returns the major framework's version
*
* @return string
*/
public function getMajorVersion()
{
$parts = explode(' ', Version::get());
return (string) $parts[0];
}
示例4: test2
public function test2()
{
$x = new Version('r123');
$this->assertEquals($x->get(), 'r123');
}
示例5: hasVersion
/**
* Returns whether resource has version
*
* @param mixed $version
* @return boolean
*/
public function hasVersion($version)
{
$version = Version::get($version);
return in_array($version->toString(), $this->getVersions());
}