wrong_method

Easily handle a response for when the wrong HTTP method is used to call on a route endpoint

@param mixed $possible_methods	The string or array containing the possible allowable methods for that route/endpoint
@access public
@return void
181055
public function wrong_method( $possible_methods = array() ) {
		// Any defined possible methods?
		if ( is_array($possible_methods) && count($possible_methods) > 0 ) {
			// Uppercase whatever was passed, for good measure
			$possible_methods = array_map( 'strtoupper', $possible_methods );

			// Add them to our response
			$this->response->possible_methods = $possible_methods;
		}
		elseif ( is_string($possible_methods) && !empty($possible_methods) ) {
			// Uppercase whatever was passed, for good measure
			$possible_methods = strtoupper($possible_methods);

			// Add it to our response as an array so that it stays consistent
			$this->response->possible_methods = array( $possible_methods );
		}

		// Also add the possible methods to our "more_info" for readability
		$more_info = array(
			'possible_methods' => $this->response->possible_methods
		);

		// We didn't match their request, create and throw an exception
		$wrong_method_exception = new WrongMethod();
		$wrong_method_exception->set_more_info( $more_info );
		throw $wrong_method_exception;
	}
748072
def method_missing(method_name, *args, &block)
      if controller.respond_to? method_name
        controller.send method_name, *args, &block
      else
        super
      end
    end
276005
public function options()
    {
        if (!($this->response instanceof ResponseInterface)) {
            throw new MethodNotAllowed();
        }

        // Get all implemented methods for this resources
        $methods = get_class_methods(get_class($this));

        // Get supported verbs
        $validMethods = $this->container['validHttpVerbs'];

        // Loop though class functions/methods
        foreach ($methods as $key => &$method) {
            $method = strtoupper($method);
            // If class function/method isn't a verb, then unset it
            if (!in_array($method, $validMethods)) {
                unset($methods[$key]);
            }
        }

        // Set accept header
        $this->response = $this->response->withAddedHeader('Allow', implode(', ', $methods));

        // Prepare output
        $output = [];
        $output['Content-Type'] = $this->container['contentTypes'];
        $output['Accept'] = $this->container['acceptTypes'];

        foreach ($methods as $verb) {
            $doc = $this->parseMethodDoc($verb);

            // Check if there is any output to show
            if (!empty($doc)) {
                $output['methods'][$verb] = $doc;
            }
        }

        // return output
        return $output;
    }
230323
public final function isAllowedRequestMethod(string $method): bool
    {
        return $this->allowedRequestMethods == null || in_array($method, (array) $this->allowedRequestMethods);
    }
1035307
protected function _validateMethod($method) {
        if (in_array(strtoupper($method), $this->_validMethods)) {
            return true;
        }
        $exception = new Garp_Content_Api_Rest_Exception('Method not allowed');
        $exception->setHttpStatusCode(405);
        throw $exception;
    }
1212755
private function methods($methods): void
    {
        if (is_callable($methods)) {
            if ($methods instanceof Closure) {
                $this->options["methods"] = $methods->bindTo($this);
            } else {
                $this->options["methods"] = $methods;
            }
        } else {
            $this->options["methods"] = (array) $methods;
        }
    }
1066195
public static function methodNotAllowed(string $method, string $uri, string $protocol = Protocol::HTTP): self
    {
        return new static(sprintf('`%s` not allowed `%s` method', $uri, $method), $protocol, 405);
    }
871518
private static function hookError(App $cdl, Slim $app, string $method, array $options){
        $routing = $app->{$method}($options['url'], System::jsonResponse(function (){
            return Route::noRoute();
        }));
        self::applyMiddleware($cdl, $options, $routing);
    }
259881
private function matchRequestMethod(
        string $method = null,
        array $supported = null
    ) {
        if ($supported && !in_array($method, $supported)) {
            return false;
        }

        return true;
    }
753979
public static function methodNotAllowed(string $requestMethod, array $allowedMethods): self
    {
        return new self(
                'The given request method '
                . strtoupper($requestMethod)
                . ' is not valid. Please use one of '
                . join(', ', $allowedMethods) . '.',
                'Method Not Allowed'
        );
    }
1032957
def method_missing(method, *args, &block)
      if method.to_s.end_with?('_path', '_url')
        if main_app.respond_to?(method)
          main_app.send(method, *args)
        else
          super
        end
      else
        super
      end
    end
609470
public function handleNotAllowed(ServerRequestInterface $request, ResponseInterface $response, array $methods)
    {
        if ($level = $this->shouldLog('not-allowed')) {
            $message = sprintf('%s on %s', $request->getMethod(), $request->getRequestTarget());
            $this->logEvent('not-allowed', $message, $level);
        }

        return $this->handler->handleNotAllowed($request, $response, $methods);
    }
64920
private function checkMethod() {
        if (strpos(self::$currentRoute['method'], '|') !== false) {
            if (!in_array($_SERVER['REQUEST_METHOD'], explode('|', self::$currentRoute['method']))) {
                throw new RouteException(_message(ExceptionMessages::INCORRECT_METHOD, $_SERVER['REQUEST_METHOD']));
            }
        } else if ($_SERVER['REQUEST_METHOD'] != self::$currentRoute['method']) {
            throw new RouteException(_message(ExceptionMessages::INCORRECT_METHOD, $_SERVER['REQUEST_METHOD']));
        }
    }
695393
private function setMethod($Resource, $method) {
        switch ($method) {
            case Request::METHOD_GET:
                curl_setopt($Resource, CURLOPT_HTTPGET, true);
                break;
            case Request::METHOD_POST:
                curl_setopt($Resource, CURLOPT_POST, true);
                break;
        }
    }
112065
protected function setMethods($methods): void
    {
        if (\is_string($methods)) {
            $methods = [$methods];
        } elseif (!\is_array($methods)) {
            throw new RouterException('Method invalid');
        }

        foreach ($methods as $method) {
            if (!\in_array($method, Request::$methods, true)) {
                throw new RouterException('Method invalid: ' . $method);
            }
        }

        $this->methods = $methods;
    }
277058
function checkMethod(expected, actual){
    if(!expected || !actual){
        return;
    }
    if(actual.toLowerCase() !== expected.toLowerCase()){
        return {
            error: "HTTP Methods are not equal",
            actual: actual,
            expected: expected,
            showDiff: true
        };
    }
}
555118
public function handleOptionsRequest()
    {
        // Generate the "Allow" header
        $allow = '';
        foreach ($this->router->getMethodsByRoute($this->uri) as $method) {
            $allow .= strtoupper($method) . ',';
        }
        $allow = substr($allow, 0, strlen($allow) - 1);
        header('Allow: ' . $allow);
        $this->setResponse('');
    }