本文整理汇总了PHP中AppHelper::isPhpDevServer方法的典型用法代码示例。如果您正苦于以下问题:PHP AppHelper::isPhpDevServer方法的具体用法?PHP AppHelper::isPhpDevServer怎么用?PHP AppHelper::isPhpDevServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppHelper
的用法示例。
在下文中一共展示了AppHelper::isPhpDevServer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: usePathInfo
/**
* Returns whether generated URLs should be formatted using PATH_INFO, taking the
* [usePathInfo](http://craftcms.com/docs/config-settings#usePathInfo) config setting value into account.
*
* This method will usually only be called in the event that {@link omitScriptNameInUrls()} returns `false`
* (so “index.php” _should_ be included), and it determines what follows “index.php” in the URL.
*
* If it returns `true`, a forward slash will be used, making “index.php” look like just another segment of the URL
* (e.g. http://example.com/index.php/some/path). Otherwise the Craft path will be included in the URL as a query
* string param named ‘p’ (e.g. http://example.com/index.php?p=some/path).
*
* If the usePathInfo config setting is set to `true` or `false`, then its value will be returned directly.
* Otherwise, `usePathInfo()` will try to determine whether the server is set up to support PATH_INFO.
* (See http://craftcms.com/help/enable-path-info for instructions.)
*
* It does that by creating a dummy request to the site URL with the URI “/index.php/testPathInfo”. If the server
* supports it, that request should be sent to Craft’s index.php file, which will detect that this is an
* PATH_INFO-testing request, and simply return “success”. If anything besides “success” is returned
* (i.e. an Apache-styled 404 error), then Craft assumes the server is not set up to support PATH_INFO.
*
* Results of the PATH_INFO test request will be cached for the amount of time specified by the
* [cacheDuration](http://craftcms.com/docs/config-settings#cacheDuration) config setting.
*
* @return bool Whether generaletd URLs should be formatted using PATH_INFO.
*/
public function usePathInfo()
{
if (!isset($this->_usePathInfo)) {
$this->_usePathInfo = 'n';
// Check if the config value has actually been set to true/false
$configVal = $this->get('usePathInfo');
if (is_bool($configVal)) {
$this->_usePathInfo = $configVal === true ? 'y' : 'n';
} else {
// Check if it's cached
$cachedVal = craft()->cache->get('usePathInfo');
if ($cachedVal !== false) {
$this->_usePathInfo = $cachedVal;
} else {
// If there is already a PATH_INFO var available, we know it supports it.
// Added the !empty() check for nginx.
if (!empty($_SERVER['PATH_INFO'])) {
$this->_usePathInfo = 'y';
} else {
if (AppHelper::isPhpDevServer()) {
$this->_usePathInfo = 'y';
} else {
// Cache it early so the testPathInfo request isn't checking for it too
craft()->cache->set('usePathInfo', 'n');
// Test the server for it
try {
$url = craft()->request->getHostInfo() . craft()->request->getScriptUrl() . '/testPathInfo';
$client = new \Guzzle\Http\Client();
$response = $client->get($url, array(), array('connect_timeout' => 2, 'timeout' => 4))->send();
if ($response->isSuccessful() && $response->getBody(true) === 'success') {
$this->_usePathInfo = 'y';
}
} catch (\Exception $e) {
Craft::log('Unable to determine if PATH_INFO is enabled on the server: ' . $e->getMessage(), LogLevel::Error);
}
}
}
// Cache it
craft()->cache->set('usePathInfo', $this->_usePathInfo);
}
}
}
return $this->_usePathInfo == 'y';
}
示例2: usePathInfo
/**
* Returns whether generated URLs should be formatted using PATH_INFO.
*
* @return bool
*/
public function usePathInfo()
{
if (!isset($this->_usePathInfo)) {
$this->_usePathInfo = 'no';
// Check if the config value has actually been set to true/false
$configVal = $this->get('usePathInfo');
if (is_bool($configVal)) {
$this->_usePathInfo = $configVal == true ? 'yes' : 'no';
} else {
// Check if it's cached
$cachedVal = craft()->fileCache->get('usePathInfo');
if ($cachedVal !== false) {
$this->_usePathInfo = $cachedVal;
} else {
// If there is already a PATH_INFO var available, we know it supports it.
// Added the !empty() check for nginx.
if (!empty($_SERVER['PATH_INFO'])) {
$this->_usePathInfo = true;
} else {
if (AppHelper::isPhpDevServer()) {
$this->_usePathInfo = true;
} else {
// Test the server for it
try {
$url = craft()->request->getHostInfo() . craft()->request->getScriptUrl() . '/testPathInfo';
$response = \Requests::get($url);
if ($response->success && $response->body === 'success') {
$this->_usePathInfo = 'yes';
}
} catch (\Exception $e) {
Craft::log('Unable to determine if PATH_INFO is enabled on the server: ' . $e->getMessage(), LogLevel::Error);
}
}
}
// Cache it
craft()->fileCache->set('usePathInfo', $this->_usePathInfo);
}
}
}
return $this->_usePathInfo == 'no' ? false : true;
}