本文整理汇总了PHP中yii\web\Request::getMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getMethod方法的具体用法?PHP Request::getMethod怎么用?PHP Request::getMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\Request
的用法示例。
在下文中一共展示了Request::getMethod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseRequest
/**
* @param \yii\web\UrlManager $manager
* @param \yii\web\Request $request
* @return array|bool
*/
public function parseRequest($manager, $request)
{
if ($this->mode === self::CREATION_ONLY) {
return false;
}
if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
return false;
}
$pathInfo = $request->getPathInfo();
if ($this->host !== null) {
$pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
}
$params = $request->getQueryParams();
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
$treeNode = null;
$originalDir = $pathInfo;
if ($suffix) {
$originalDir = substr($pathInfo, 0, strlen($pathInfo) - strlen($suffix));
}
$dependency = new TagDependency(['tags' => [(new Tree())->getTableCacheTag()]]);
if (!$pathInfo) {
$treeNode = Tree::getDb()->cache(function ($db) {
return Tree::find()->where(["site_code" => \Yii::$app->cms->site->code, "level" => 0])->one();
}, null, $dependency);
} else {
$treeNode = Tree::find()->where(["dir" => $originalDir, "site_code" => \Yii::$app->cms->site->code])->one();
}
if ($treeNode) {
\Yii::$app->cms->setCurrentTree($treeNode);
$params['id'] = $treeNode->id;
return ['cms/tree/view', $params];
} else {
return false;
}
}
示例2: getMethod
public function getMethod()
{
$method = @$_SERVER['REQUEST_METHOD'] ?: '?';
if (strtoupper($method) === 'POST') {
$type = $this->headers->get('Content-Type', '');
if (stripos($type, 'application/json') !== false || stripos($type, 'application/x-msgpack') !== false) {
$params = $this->getBodyParams();
if (@isset($params[$this->methodParam])) {
return strtoupper($params[$this->methodParam]);
}
}
}
return parent::getMethod();
}
示例3: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param UrlManager $manager the URL manager
* @param Request $request the request component
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
*/
public function parseRequest($manager, $request)
{
if ($this->mode === self::CREATION_ONLY) {
return false;
}
if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
return false;
}
$pathInfo = $request->getPathInfo();
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($suffix);
if (substr_compare($pathInfo, $suffix, -$n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
return false;
}
} else {
return false;
}
}
if ($this->host !== null) {
$pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
}
if (!preg_match($this->pattern, $pathInfo, $matches)) {
return false;
}
foreach ($this->defaults as $name => $value) {
if (!isset($matches[$name]) || $matches[$name] === '') {
$matches[$name] = $value;
}
}
$params = $this->defaults;
$tr = [];
foreach ($matches as $name => $value) {
if (isset($this->_routeParams[$name])) {
$tr[$this->_routeParams[$name]] = $value;
unset($params[$name]);
} elseif (isset($this->_paramRules[$name])) {
$params[$name] = $value;
}
}
if ($this->_routeRule !== null) {
$route = strtr($this->route, $tr);
} else {
$route = $this->route;
}
Yii::trace("Request parsed with URL rule: {$this->name}", __METHOD__);
return [$route, $params];
}
示例4: parseRequest
/**
* @param \yii\web\UrlManager $manager
* @param \yii\web\Request $request
* @return array|bool
*/
public function parseRequest($manager, $request)
{
if ($this->mode === self::CREATION_ONLY) {
return false;
}
if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
return false;
}
$pathInfo = $request->getPathInfo();
if ($this->host !== null) {
$pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
}
$params = $request->getQueryParams();
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
$treeNode = null;
if (!$pathInfo) {
return false;
}
if (!preg_match('/\\/(?<id>\\d+)\\-(?<code>\\S+)$/i', "/" . $pathInfo, $matches)) {
return false;
}
return ['cms/content-element/view', ['id' => $matches['id'], 'code' => $matches['code']]];
}
示例5: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param UrlManager $manager the URL manager
* @param \yii\web\Request $request the request component
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
*/
public function parseRequest($manager, $request)
{
if ($this->mode === self::CREATION_ONLY) {
return false;
}
if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
return false;
}
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
$pathInfo = $request->getPathInfo();
$normalized = false;
if ($this->hasNormalizer($manager)) {
$pathInfo = $this->getNormalizer($manager)->normalizePathInfo($pathInfo, $suffix, $normalized);
}
$pathInfoParams = [];
if ($this->paramsAfter !== null && strpos($pathInfo, '/') !== false) {
$segments = explode('/', trim($pathInfo, '/'));
if (count($segments) > $this->paramsAfter) {
$pathInfo = implode('/', array_slice($segments, 0, $this->paramsAfter));
$pathInfoParams = $manager->createPrettyUrl(array_slice($segments, $this->paramsAfter));
}
}
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($suffix);
if (substr_compare($pathInfo, $suffix, -$n, $n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
return false;
}
} else {
return false;
}
}
if ($this->host !== null) {
$pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
}
if (!preg_match($this->pattern, $pathInfo, $matches)) {
return false;
}
$matches = $this->substitutePlaceholderNames($matches);
foreach ($this->defaults as $name => $value) {
if (!isset($matches[$name]) || $matches[$name] === '') {
$matches[$name] = $value;
}
}
$params = ArrayHelper::merge($this->defaults, $pathInfoParams);
$tr = [];
foreach ($matches as $name => $value) {
if (isset($this->_routeParams[$name])) {
$tr[$this->_routeParams[$name]] = $value;
unset($params[$name]);
} elseif (isset($this->_paramRules[$name])) {
$params[$name] = $value;
}
}
if ($this->_routeRule !== null) {
$route = strtr($this->route, $tr);
} else {
$route = $this->route;
}
Yii::trace("Request parsed with URL rule: {$this->name}", __METHOD__);
if ($normalized) {
// pathInfo was changed by normalizer - we need also normalize route
return $this->getNormalizer($manager)->normalizeRoute([$route, $params]);
} else {
return [$route, $params];
}
}
示例6: allows
/**
* Checks whether the Web user is allowed to perform the specified action.
* @param Action $action the action to be performed
* @param User $user the user object
* @param Request $request
* @return boolean|null true if the user is allowed, false if the user is denied, null if the rule does not apply to the user
*/
public function allows($action, $user, $request)
{
if ($this->matchAction($action) && $this->matchRole($user) && $this->matchIP($request->getUserIP()) && $this->matchVerb($request->getMethod()) && $this->matchController($action->controller) && $this->matchCustom($action)) {
return $this->allow ? true : false;
} else {
return null;
}
}