获得请求方法

@return string
@throws \InvalidArgumentException
@throws \One\Protocol\Exceptions\InvalidMethodException
5390
public function getMethod(): string
    {
        if ($this->method === null) {
            $this->method = $this->originalMethod;
            $customMethod = $this->getHeaderLine('X-Http-Method-Override');

            if ($customMethod) {
                $this->method = $this->filterMethod($customMethod);
            } elseif ($this->originalMethod === 'POST') {
                if (($overrideMethod = $this->filterMethod($this->getParsedBodyParam('_METHOD'))) !== null) {
                    $this->method = $overrideMethod;
                }
            }
        }

        return $this->method;
    }
471902
public function callAction()
    {
        $request    = $this->getRequest();
        $response   = $this->getResponse();
        $formatName = $this->params()
                           ->fromRoute( 'format', 'json' );

        try
        {
            try
            {
                $format = $this->getServiceLocator()
                               ->get( 'Grid\\Core\\Model\\Rpc\\' .
                                      ucfirst( $formatName ) );
            }
            catch ( ServiceNotFoundException $ex )
            {
                throw new DomainException(
                    'The rpc-format (' . $formatName . ') not understood', 0, $ex
                );
            }

            if ( ! $format || ! $format instanceof RpcAbstract )
            {
                throw new DomainException(
                    'The rpc-format (' . $formatName . ') not understood'
                );
            }
        }
        catch ( DomainException $ex )
        {
            $this->logException( $ex, Logger::WARN );
            $response->setStatusCode( 500 );

            if ( ini_get('display_errors') )
            {
                if ( $response instanceof HttpResponse )
                {
                    $response->getHeaders()
                             ->addHeaderLine(
                                    'Content-Type',
                                    'text/plain; charset=utf-8'
                                );
                }

                $response->setContent( (string) $ex );
            }

            return $response;
        }

        $error = $format->parse( $request, $response );

        if ( $error )
        {
            try
            {
                throw new RpcException\BadMethodCallException(
                    'Parse error',
                    $format->errorCodes[ $error ]
                );
            }
            catch ( RpcException\BadMethodCallException $ex )
            {
                $this->logException( $ex, Logger::WARN );
            }

            return $format->error(
                $error,
                $format->errorCodes[ $error ],
                $error
            );
        }

        @ list( $serviceName,
                $method ) = explode( '::', $format->getMethod(), 2 );

        if ( empty( $method ) )
        {
            $method = '__invoke';
        }

        try
        {
            $service = $this->getServiceLocator()
                            ->get( $serviceName );
        }
        catch ( ServiceNotFoundException $ex )
        {
            $this->logException( $ex, Logger::WARN );

            return $format->error(
                RpcAbstract::METHOD_NOT_FOUND . ': ' . $format->getMethod(),
                $format->errorCodes[RpcAbstract::METHOD_NOT_FOUND],
                array(
                    'service'   => $serviceName,
                    'exception' => self::rawException( $ex ),
                )
            );
        }

        if ( empty( $service ) || ! $service instanceof CallableInterface )
        {
            $this->logException( $ex, Logger::WARN );

            return $format->error(
                RpcAbstract::METHOD_NOT_FOUND . ': ' . $format->getMethod(),
                $format->errorCodes[RpcAbstract::METHOD_NOT_FOUND],
                array(
                    'service'   => $serviceName,
                )
            );
        }
        else
        {
            try
            {
                ErrorHandler::start( E_ALL );
                $result = $service->call( $method, $format->getParams() );
                ErrorHandler::stop( true );
                return $format->response( $result );
            }
            catch ( RpcException\BadMethodCallException $ex )
            {
                ErrorHandler::stop( false );
                $this->logException( $ex, Logger::WARN );

                return $format->error(
                    RpcAbstract::METHOD_NOT_FOUND . ': ' . $format->getMethod(),
                    $format->errorCodes[RpcAbstract::METHOD_NOT_FOUND],
                    array(
                        'service'   => $serviceName,
                        'method'    => $method,
                        'exception' => self::rawException( $ex ),
                    )
                );
            }
            catch ( RpcException\InvalidArgumentException $ex )
            {
                ErrorHandler::stop( false );
                $this->logException( $ex, Logger::WARN );

                return $format->error(
                    $ex->getMessage(),
                    $format->errorCodes[RpcAbstract::INVALID_PARAMS],
                    self::rawException( $ex )
                );
            }
            catch ( Exception $ex )
            {
                ErrorHandler::stop( false );
                $this->logException( $ex );

                return $format->error(
                    RpcAbstract::INTERNAL . ': #' .
                        $ex->getCode() . ' - ' . $ex->getMessage(),
                    $format->errorCodes[RpcAbstract::INTERNAL],
                    self::rawException( $ex )
                );
            }
        }
    }
1069554
public function getMethod()
    {
        // method in request.
        if ($method = $this->get('_method')) {
            return strtoupper($method);
        }

        $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
        return strtoupper($method);
    }
770365
public function getMethod()
    {
        if (isset($this->swooleRequest->post[$this->methodParam])) {
            return strtoupper($this->swooleRequest->post[$this->methodParam]);
        }

        if (isset($this->swooleRequest->server['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
            return strtoupper($this->swooleRequest->server['HTTP_X_HTTP_METHOD_OVERRIDE']);
        }

        if (isset($this->swooleRequest->server['REQUEST_METHOD'])) {
            return strtoupper($this->swooleRequest->server['REQUEST_METHOD']);
        }

        return 'GET';
    }
443972
public function method()
    {
        $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null;

        if ($method !== 'POST') {
            return $method;
        }

        if (array_key_exists('HTTP_X_HTTP_METHOD', $_SERVER)) {
            if (in_array($_SERVER['HTTP_X_HTTP_METHOD'], ['PUT', 'DELETE'])) {
                $method = $_SERVER['HTTP_X_HTTP_METHOD'];
            }
        }

        return $method;
    }
569900
public function method()
    {
        // Return the emulated method from GET
        $emulated = filter_input(INPUT_GET, '_method', FILTER_SANITIZE_STRING);

        // Return the emulated method from POST
        if (!$emulated) {
            $emulated = filter_input(INPUT_POST, '_method', FILTER_SANITIZE_STRING);
        }

        // Set the emulated method
        if ($this->app->config('request.emulate') && $emulated) {
            return $emulated;
        }

        // Or the real method
        return $_SERVER['REQUEST_METHOD'];
    }
19715
public function getMethod()
    {
        if ($this->method === null) {
            if (is_null($this->method_override)) {
                $this->method = $this->server->get('request-method');
            } else {
                $this->method = $this->method_override;
            }
            $this->method = strtoupper($this->method);
        }
        return $this->method;
    }
778996
private function _set_method()
    {
        switch (strtoupper($this->method)) {
        case 'HEAD':
            //CURLOPT_NOBODY TRUE 时将不输出 BODY 部分。同时 Mehtod 变成了 HEAD。修改为 FALSE 时不会变成 GET。
            if (!isset($this->config['CURLOPT_NOBODY'])) {
                $this->config['CURLOPT_NOBODY'] = true;
            }
            break;

        case 'GET':

            if (!empty($this->config['parameters'])) {

                $url = (stripos($this->config['CURLOPT_URL'], '?') !== false) ? '&' : '?';

                if (is_array($this->config['parameters'])) {  //参数是数组
                    $url .= http_build_query($this->_parameters, '', '&');
                } else { //参数是字符串
                    $url .= $this->config['parameters'];
                }

                $this->config['CURLOPT_URL'] = $url;
                unset($url);
            }

            $this->config['CURLOPT_HTTPGET'] = true;  //TRUE 时会设置 HTTP 的 method 为 GET

            break;

        case 'POST':

            if (!empty($this->parameters) && is_array($this->parameters)) { //参数是数组
                $data = http_build_query($this->parameters); //为了更好的兼容性
            } else {  //参数是字符串
                $data = $this->parameters;
            }

            $this->config['CURLOPT_POSTFIELDS'] = $data;  //post请求的数据
            $this->config['CURLOPT_POST'] = true;   //TRUE 时会发送 POST 请求，类型为：application/x-www-form-urlencoded，是 HTML 表单提交时最常见的一种。

            unset($data);

            break;

        default:
            throw new CurlException('该请求方式不支持！');
        }
    }
1128557
public function getMethod()
    {
        if (null !== $this->method) {
            return $this->method;
        }

        $method = isset($this->server['REQUEST_METHOD']) ? strtoupper($this->server['REQUEST_METHOD']) : 'GET';
        if ('POST' !== $method) {
            return $this->method = $method;
        }

        $override = $this->getHeader('x-http-method-override') ?: $this->post('_method');
        if ($override) {
            if (is_array($override)) {
                $override = array_shift($override);
            }

            $method = $override;
        }

        return $this->method = strtoupper($method);
    }
557829
public function getMethod()
    {
        if (null !== $this->method) {
            return $this->method;
        }

        // If the form was created from a button rather than the form node, check for HTML5 method override
        if ($this->button !== $this->node && $this->button->getAttribute('formmethod')) {
            return strtoupper($this->button->getAttribute('formmethod'));
        }

        return $this->node->getAttribute('method') ? strtoupper($this->node->getAttribute('method')) : 'GET';
    }
407757
private function init()
    {
        $this->refClass = new \ReflectionClass($this->object);
        $className = $this->refClass->getParentClass()->getName();
        // 每个类只需处理一次
        if(!isset(static::$aspects[$className]))
        {
            static::$aspects[$className] = new \SplPriorityQueue;
            $aspects = AnnotationManager::getAnnotationPoints(Aspect::class);
            foreach($aspects as $item)
            {
                // 判断是否属于当前类方法的切面
                $pointCutsSet = AnnotationManager::getMethodsAnnotations($item['class'], PointCut::class);
                foreach($pointCutsSet as $methodName => $pointCuts)
                {
                    foreach($pointCuts as $pointCut)
                    {
                        switch($pointCut->type)
                        {
                            case PointCutType::METHOD:
                                foreach($pointCut->allow as $allowItem)
                                {
                                    if(Imi::checkClassRule($allowItem, $className))
                                    {
                                        static::$aspects[$className]->insert([
                                            'class'     =>  $item['class'],
                                            'method'    =>  $methodName,
                                            'pointCut'  =>  $pointCut,
                                        ], $item['annotation']->priority);
                                        break;
                                    }
                                }
                                break;
                            case PointCutType::ANNOTATION:
                                foreach($this->refClass->getMethods() as $method)
                                {
                                    $methodAnnotations = AnnotationManager::getMethodAnnotations($className, $method->getName());
                                    foreach($pointCut->allow as $allowItem)
                                    {
                                        foreach($methodAnnotations as $annotation)
                                        {
                                            if($annotation instanceof $allowItem)
                                            {
                                                static::$aspects[$className]->insert([
                                                    'class'     =>  $item['class'],
                                                    'method'    =>  $methodName,
                                                    'pointCut'  =>  $pointCut,
                                                ], $item['annotation']->priority);
                                                break 3;
                                            }
                                        }
                                    }
                                }
                                break;
                        }
                    }
                }
                // 判断是否属于当前类的切面
                $pointCuts = AnnotationManager::getMethodsAnnotations($item['class'], PointCut::class);
                foreach($pointCuts as $methodName => $pointCuts)
                {
                    foreach($pointCuts as $pointCut)
                    {
                        switch($pointCut->type)
                        {
                            case PointCutType::CONSTRUCT:
                                // 构造方法
                                foreach($pointCut->allow as $allowItem)
                                {
                                    if(Imi::checkRuleMatch($allowItem, $className))
                                    {
                                        static::$aspects[$className]->insert([
                                            'class'     =>  $item['class'],
                                            'method'    =>  $methodName,
                                            'pointCut'  =>  $pointCut,
                                        ], $item['annotation']->priority);
                                        break;
                                    }
                                }
                                break;
                            case PointCutType::ANNOTATION_CONSTRUCT:
                                // 注解构造方法
                                $classAnnotations = AnnotationManager::getClassAnnotations($className);
                                foreach($pointCut->allow as $allowItem)
                                {
                                    foreach($classAnnotations as $annotation)
                                    {
                                        if($annotation instanceof $allowItem)
                                        {
                                            static::$aspects[$className]->insert([
                                                'class'     =>  $item['class'],
                                                'method'    =>  $methodName,
                                                'pointCut'  =>  $pointCut,
                                            ], $item['annotation']->priority);
                                            break 2;
                                        }
                                    }
                                }
                                break;
                        }
                    }
                }
            }
        }
    }
1344399
public function cache()
    {
        $paramCount = func_num_args();

        if (1 === $paramCount) {
            return $this["cache"]->get(func_get_arg(0));
        }

        if (2 === $paramCount) {
            return $this["cache"]->set(func_get_arg(0), func_get_arg(1));
        }

        if (3 === $paramCount) {
            return $this["cache"]->set(func_get_arg(0), func_get_arg(1), func_get_arg(2));
        }

        throw new InvalidArgumentException("App::cache() method expects 1 or 2(3) parameters. {$paramCount} given.");
    }
402595
protected function getRequestMethod()
    {
        if (isset($this->server['REQUEST_METHOD'])) {
            // check for X-HTTP-Method-Override
            if (isset($this->server['HTTP_X_HTTP_METHOD_OVERRIDE']) && in_array($this->server['HTTP_X_HTTP_METHOD_OVERRIDE'], ['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH'])) {
                return $this->server['HTTP_X_HTTP_METHOD_OVERRIDE'];
            } else {
                return $this->server['REQUEST_METHOD'];
            }
        } else {
            return 'GET';
        }
    }
558835
public function getMethod()
    {
        if (!isset($this->method)) {
            $this->method = $this->determineMethod();
        }
        
        return $this->method;
    }
398728
public function getShebang()
    {
        if (isset($this->raw->shebang)) {
            if (('' === $this->raw->shebang) || (false === $this->raw->shebang)) {
                return '';
            }

            $shebang = trim($this->raw->shebang);

            if ('#!' !== substr($shebang, 0, 2)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'The shebang line must start with "#!": %s',
                        $shebang
                    )
                );
            }

            return $shebang;
        }

        return null;
    }
664510
private function getHttpMethod(): string
    {
        if (!empty($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
            $method = mb_strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
        } else {
            $method = mb_strtoupper($_SERVER['REQUEST_METHOD']);
        }

        switch ($method) {
            case 'GET':
                return static::HTTP_METHOD_GET;
            case 'HEAD':
                return static::HTTP_METHOD_HEAD;
            case 'POST':
                return static::HTTP_METHOD_POST;
            case 'OPTIONS':
                return static::HTTP_METHOD_OPTIONS;
            case 'CONNECT':
                return static::HTTP_METHOD_CONNECT;
            case 'TRACE':
                return static::HTTP_METHOD_TRACE;
            case 'PUT':
                return static::HTTP_METHOD_PUT;
            case 'DELETE':
                return static::HTTP_METHOD_DELETE;
            default:
                return static::HTTP_METHOD_UNKNOWN;
        }
    }
128280
public function callMe()
    {
        $output = $this->dispatchStartEvent();

        $this->parameters[static::CURRENT_PREFIX] = 'get';
        $output .= $this->goThroughMethodList($this->parameters[static::PARAM_NORMAL_GETTER]);

        $this->parameters[static::CURRENT_PREFIX] = 'is';
        $output .= $this->goThroughMethodList($this->parameters[static::PARAM_IS_GETTER]);

        $this->parameters[static::CURRENT_PREFIX] = 'has';
        return $output . $this->goThroughMethodList($this->parameters[static::PARAM_HAS_GETTER]);
    }