Drest\Service::getDefaultAction PHP Method

getDefaultAction() protected method

Gets an instance of the "default" action based of request information
protected getDefaultAction ( ) : Drest\Service\Action\AbstractAction
return Drest\Service\Action\AbstractAction $action
    protected function getDefaultAction()
    {
        $httpMethod = $this->dm->calledWithANamedRoute() ? array_slice($this->matched_route->getVerbs(), 0, 1)[0] : $this->getRequest()->getHttpMethod();
        $className = '\\Drest\\Service\\Action\\' . ucfirst(strtolower($httpMethod));
        switch ($httpMethod) {
            case Request::METHOD_GET:
            case Request::METHOD_DELETE:
                $className .= $this->matched_route->isCollection() ? 'Collection' : 'Element';
                break;
            default:
                $className .= 'Element';
                break;
        }
        if (!class_exists($className)) {
            throw DrestException::unknownActionClass($className);
        }
        /** @var AbstractAction $object */
        $object = new $className();
        $object->setService($this);
        return $object;
    }