{@inheritdoc}

@throws \BEAR\Resource\Exception\MethodException
432024
public function object(ResourceObject $ro) : RequestInterface
    {
        return new Request($this->invoker, $ro, $this->method);
    }
1003993
protected function getResourceMethodConfiguration(): array
    {
        return [
            ResourceMethodEnum::GET_ALL => RequestPathFormatEnum::INVITATIONS,
            ResourceMethodEnum::CREATE => RequestPathFormatEnum::INVITATIONS,
            ResourceMethodEnum::UPDATE => RequestPathFormatEnum::INVITATIONS_BY_ID,
            ResourceMethodEnum::DELETE => RequestPathFormatEnum::INVITATIONS_BY_ID,
        ];
    }
488225
public function request($method = null)
    {
        if (! $this->uri instanceof Zend_Uri_Http) {
            /**
 * @see Zend_Http_Client_Exception 
*/
            include_once 'Zend/Http/Client/Exception.php';
            throw new Zend_Http_Client_Exception('No valid URI has been passed to the client');
        }

        if ($method) { $this->setMethod($method);
        }
        $this->redirectCounter = 0;
        $response = null;

        // Make sure the adapter is loaded
        if ($this->adapter == null) { $this->setAdapter($this->config['adapter']);
        }

        // Send the first request. If redirected, continue.
        do {
            // Clone the URI and add the additional GET parameters to it
            $uri = clone $this->uri;
            if (! empty($this->paramsGet)) {
                $query = $uri->getQuery();
                if (! empty($query)) { $query .= '&';
                }
                $query .= http_build_query($this->paramsGet, null, '&');

                $uri->setQuery($query);
            }

            $body = $this->_prepareBody();
            $headers = $this->_prepareHeaders();

            // Open the connection, send the request and read the response
            $this->adapter->connect(
                $uri->getHost(), $uri->getPort(),
                ($uri->getScheme() == 'https' ? true : false)
            );

            $this->last_request = $this->adapter->write(
                $this->method,
                $uri, $this->config['httpversion'], $headers, $body
            );

            $response = $this->adapter->read();
            if (! $response) {
                /**
 * @see Zend_Http_Client_Exception 
*/
                include_once 'Zend/Http/Client/Exception.php';
                throw new Zend_Http_Client_Exception('Unable to read response, or response is empty');
            }

            $response = Zend_Http_Response::fromString($response);
            if ($this->config['storeresponse']) { $this->last_response = $response;
            }

            // Load cookies into cookie jar
            if (isset($this->cookiejar)) { $this->cookiejar->addCookiesFromResponse($response, $uri);
            }

            // If we got redirected, look for the Location header
            if ($response->isRedirect() && ($location = $response->getHeader('location'))) {

                // Check whether we send the exact same request again, or drop the parameters
                // and send a GET request
                if ($response->getStatus() == 303 
                    || ((! $this->config['strictredirects']) && ($response->getStatus() == 302 
                    || $response->getStatus() == 301))
                ) {

                    $this->resetParameters();
                    $this->setMethod(self::GET);
                }

                // If we got a well formed absolute URI
                if (Zend_Uri_Http::check($location)) {
                    $this->setHeaders('host', null);
                    $this->setUri($location);

                } else {

                    // Split into path and query and set the query
                    if (strpos($location, '?') !== false) {
                        list($location, $query) = explode('?', $location, 2);
                    } else {
                        $query = '';
                    }
                    $this->uri->setQuery($query);

                    // Else, if we got just an absolute path, set it
                    if(strpos($location, '/') === 0) {
                        $this->uri->setPath($location);

                        // Else, assume we have a relative path
                    } else {
                        // Get the current path directory, removing any trailing slashes
                        $path = $this->uri->getPath();
                        $path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
                        $this->uri->setPath($path . '/' . $location);
                    }
                }
                ++$this->redirectCounter;

            } else {
                // If we didn't get any location, stop redirecting
                break;
            }

        } while ($this->redirectCounter < $this->config['maxredirects']);

        return $response;
    }
66607
public function invoke($object, $value)
    {
        if (null !== $value) {
            $this->method->invoke($object, $value);
        }
    }
1126047
public function handleRequest(ServiceRequestInterface $request, $resource = null)
    {
        $this->setRequest($request);
        $this->setAction($request->getMethod());
        $this->setResourceMembers($resource);
        $this->response = null;

        $resources = $this->getResourceHandlers();
        if (!empty($resources) && !empty($this->resource)) {
            try {
                if (false === $this->response = $this->handleResource($resources)) {
                    $message = ucfirst($this->action) . " requests for resource '{$this->resourcePath}' are not currently supported by the '{$this->name}' service.";
                    throw new BadRequestException($message);
                }

                if (!($this->response instanceof ServiceResponseInterface ||
                    $this->response instanceof RedirectResponse ||
                    $this->response instanceof StreamedResponse
                )
                ) {
                    $this->response = ResponseFactory::create($this->response);
                }
            } catch (\Exception $e) {
                $this->response = static::exceptionToServiceResponse($e);
            }

            return $this->response;
        }

        try {
            //  Perform any pre-processing
            $this->preProcess();

            // pre-process can now create a response along with throw exceptions to circumvent the processRequest
            if (null === $this->response) {
                if (false === $this->response = $this->processRequest()) {
                    $message = ucfirst($this->action) . " requests without a resource are not currently supported by the '{$this->name}' service.";
                    throw new BadRequestException($message);
                }
            }

            if (!($this->response instanceof ServiceResponseInterface ||
                $this->response instanceof RedirectResponse ||
                $this->response instanceof StreamedResponse
            )
            ) {
                $this->response = ResponseFactory::create($this->response);
            }
        } catch (\Exception $e) {
            $this->response = static::exceptionToServiceResponse($e);
        }

        //  Perform any post-processing
        try {
            $this->postProcess();
        } catch (\Exception $e) {
            // override the actual response with the exception
            $this->response = static::exceptionToServiceResponse($e);
        }

        //  Perform any response processing
        return $this->respond();
    }
667282
public function run()
  {
    $moduleFile = $this->getModulePath();
    $moduleName = $this->getModuleClass();

    /* load required /app/mod_{$this->moduleName}.php file */
    if(!file_exists($moduleFile) || !is_readable($moduleFile))
    {
      throw new Exception("Module resource not found (" . $this->getModuleName() . ")", 404);
    }
    else
    {
      require_once($moduleFile);
    }

    /* check if required module class exists */
    if(!class_exists($moduleName) || !in_array("TS3WA_Module", class_parents($moduleName)))
    {
      throw new Exception("Module resource not found (" . $this->getModuleName() . ")", 404);
    }

    /* spawn new module */
    $this->module = new $moduleName($this);

    /* check if required action method exists */
    if(!method_exists($this->module, $this->getActionMethod()))
    {
      throw new Exception("Action resource not found (" . $this->getActionName() . ")", 404);
    }

    /* call required action method */
    call_user_func(array($this->module, $this->getActionMethod()));

    /* render template */
    if($this->module->isRender())
    {
      $this->module->dispatch();
    }
  }
627938
public function bootstrap(): void
    {
        foreach ($this->bootstrap as $mixed) {
            $component = null;
            if ($mixed instanceof \Closure) {
                $this->debug('Bootstrap with Closure', __METHOD__);
                if (empty($component = call_user_func($mixed, $this))) {
                    continue;
                }
            } elseif (is_string($mixed)) {
                if ($this->has($mixed)) {
                    $component = $this->get($mixed);
                } elseif ($this->hasModule($mixed)) {
                    $component = $this->getModule($mixed);
                } elseif (strpos($mixed, '\\') === false) {
                    throw new InvalidConfigException("Unknown bootstrapping component ID: $mixed");
                }
            }

            if (!isset($component)) {
                $component = $this->createObject($mixed);
            }

            if ($component instanceof BootstrapInterface) {
                $this->debug('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__);
                $component->bootstrap($this);
            } else {
                $this->debug('Bootstrap with ' . get_class($component), __METHOD__);
            }
        }
    }
747808
public function init(): void
    {
        parent::init();

        if ($this->default !== '' && $this->default !== null && !is_array($this->default)) {
            try {
                $default = Json::decode($this->default);

                if (is_array($default)) {
                    $this->default = $default;
                }
            } catch (InvalidArgumentException $exception) {}
        }
    }
328688
public function execute()
    {
        if (!$this->isEmpty()) {
            $this->table->update($this->context + $this->values, $this->where)->run();
        }

        parent::execute();
    }
222321
public function methodExists($method)
    {
        $key = 'method.'.$method;

        if (!self::_cache($this)->offsetExists($key)) {
            $result = false;

            if (method_exists($this, $method)) {
                $result = true;
            } elseif (self::_cache($this)->offsetExists('behavior.'.$method)) {
                $result = self::_cache($this)->offsetGet('behavior.'.$method);
            } else {
                $behaviors = $this->getRepository()->getBehaviors();

                foreach ($behaviors as $behavior) {
                    if (in_array($method, $behavior->getMixableMethods($this))) {
                        $result = true;
                        break;
                    }
                }
            }

            self::_cache($this)->offsetSet($key, $result);
        }

        return self::_cache($this)->offsetGet($key);
    }
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;
    }
81872
protected function handleGET()
    {
        if (!empty($this->resource)) {
            /** @type ServiceTypeInterface $type */
            if (null === $type = ServiceManager::getServiceType($this->resource)) {
                throw new NotFoundException("Service type '{$this->resource}' not found.");
            }

            return $type->toArray();
        }

        $resources = [];
        $group = $this->request->getParameter('group');
        $types = ServiceManager::getServiceTypes($group);
        /** @type ServiceTypeInterface $type */
        foreach ($types as $type) {
            $resources[] = $type->toArray();
        }

        $asList = $this->request->getParameterAsBool(ApiOptions::AS_LIST);
        $idField = $this->request->getParameter(ApiOptions::ID_FIELD, static::getResourceIdentifier());
        $fields = $this->request->getParameter(ApiOptions::FIELDS, ApiOptions::FIELDS_ALL);

        return ResourcesWrapper::cleanResources($resources, $asList, $idField, $fields);
    }
1076707
public function read(RestRouteCollection $collection, \ReflectionMethod $method, $resource)
    {
        // check that every route parent has non-empty singular name
        foreach ($this->parents as $parent) {
            if (empty($parent) || '/' === substr($parent, -1)) {
                throw new \InvalidArgumentException('Every parent controller must have `get{SINGULAR}Action(\$id)` method where {SINGULAR} is a singular form of associated object');
            }
        }

        // if method is not readable - skip
        if (!$this->isMethodReadable($method)) {
            return;
        }

        // if we can't get http-method and resources from method name - skip
        $httpMethodAndResources = $this->getHttpMethodAndResourcesFromMethod($method, $resource);
        if (!$httpMethodAndResources) {
            return;
        }

        list($httpMethod, $resources, $isCollection, $isInflectable) = $httpMethodAndResources;
        $arguments = $this->getMethodArguments($method);

        // if we have only 1 resource & 1 argument passed, then it's object call, so
        // we can set collection singular name
        if (1 === count($resources) && 1 === count($arguments) - count($this->parents)) {
            $collection->setSingularName($resources[0]);
        }

        // if we have parents passed - merge them with own resource names
        if (count($this->parents)) {
            $resources = array_merge($this->parents, $resources);
        }

        if (empty($resources)) {
            $resources[] = null;
        }

        $routeName = $httpMethod.$this->generateRouteName($resources);
        $urlParts = $this->generateUrlParts($resources, $arguments, $httpMethod);

        // if passed method is not valid HTTP method then it's either
        // a hypertext driver, a custom object (PUT) or collection (GET)
        // method
        if (!in_array($httpMethod, $this->availableHTTPMethods)) {
            $urlParts[] = $httpMethod;
            $httpMethod = $this->getCustomHttpMethod($httpMethod, $resources, $arguments);
        }

        // generated parameters
        $routeName = strtolower($routeName);
        $path = implode('/', $urlParts);
        $defaults = ['_controller' => $method->getName()];
        $requirements = [];
        $options = [];
        $host = '';
        $versionCondition = $this->getVersionCondition();
        $versionRequirement = $this->getVersionRequirement();

        $annotations = $this->readRouteAnnotation($method);
        if (!empty($annotations)) {
            foreach ($annotations as $annotation) {
                $path = implode('/', $urlParts);
                $defaults = ['_controller' => $method->getName()];
                $requirements = [];
                $options = [];
                $methods = explode('|', $httpMethod);

                $annoRequirements = $annotation->getRequirements();
                $annoMethods = $annotation->getMethods();

                if (!empty($annoMethods)) {
                    $methods = $annoMethods;
                }

                $path = null !== $annotation->getPath() ? $this->routePrefix.$annotation->getPath() : $path;
                $requirements = array_merge($requirements, $annoRequirements);
                $options = array_merge($options, $annotation->getOptions());
                $defaults = array_merge($defaults, $annotation->getDefaults());
                $host = $annotation->getHost();
                $schemes = $annotation->getSchemes();

                if ($this->hasVersionPlaceholder($path)) {
                    $combinedCondition = $annotation->getCondition();
                    $requirements = array_merge($versionRequirement, $requirements);
                } else {
                    $combinedCondition = $this->combineConditions($versionCondition, $annotation->getCondition());
                }

                $this->includeFormatIfNeeded($path, $requirements);

                // add route to collection
                $route = new Route(
                    $path, $defaults, $requirements, $options, $host, $schemes, $methods, $combinedCondition
                );
                $this->addRoute($collection, $routeName, $route, $isCollection, $isInflectable, $annotation);
            }
        } else {
            if ($this->hasVersionPlaceholder($path)) {
                $versionCondition = null;
                $requirements = $versionRequirement;
            }

            $this->includeFormatIfNeeded($path, $requirements);

            $methods = explode('|', strtoupper($httpMethod));

            // add route to collection
            $route = new Route(
                $path, $defaults, $requirements, $options, $host, [], $methods, $versionCondition
            );
            $this->addRoute($collection, $routeName, $route, $isCollection, $isInflectable);
        }
    }
503861
public function execute(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;
        try {
            $this->doExecute($input, $output);
        } catch (\Exception $e) {
            $this->writeException($e);
        }
    }
740754
public function callAction($method, $parameters)
    {
        $this->responseArray['type'] = Response::TYPE_CONTENT;
        $this->responseArray['method'] = Request::method();
        $this->responseArray['code'] = Response::NO_ERROR;

        if (isset($this->requiredFields[$method]) and is_array($this->requiredFields[$method])) {
            $this->validateParameters($this->requiredFields[$method]);
        }

        $response = parent::callAction($method, $parameters);

        if ($response instanceof RedirectResponse) {
            $this->responseArray['type'] = Response::TYPE_REDIRECT;
            $this->responseArray['targetUrl'] = $response->getTargetUrl();
            $this->responseArray['code'] = $response->getStatusCode();
        } else {
            if ($response instanceof View) {
                return new JsonResponse($response->render());
            } else {
                if ($response instanceof JsonResponse) {
                    return $response;
                }
            }
        }

        return (new Response(config('app.debug')))->createResponse($this->responseArray);
    }
50031
public function perform()
    {
        /** @var ServiceDeclaration $declaration */
        $declaration = $this->createDeclaration();

        foreach ($this->option('method') as $method) {
            $declaration->method($method)->setAccess(MethodDeclaration::ACCESS_PUBLIC);
        }

        $this->writeDeclaration($declaration);
    }
571926
public function fulfillRequest()
    {
        if (! $this->supportsMethod($this->request->method)) {
            throw new Exception(
                'Method not allowed',
                static::ERROR_SCOPE | static::ERROR_HTTP_METHOD_NOT_ALLOWED,
                BaseResponse::HTTP_METHOD_NOT_ALLOWED
            );
        }

        $methodName = static::methodHandlerName($this->request->method);
        $models = $this->{$methodName}($this->request);

        if (is_null($models)) {
            throw new Exception(
                'Unknown ID',
                static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
                BaseResponse::HTTP_NOT_FOUND
            );
        }

        if ($models instanceof Response) {
            $response = $models;
        } elseif ($models instanceof LengthAwarePaginator) {
            $items = new Collection($models->items());
            foreach ($items as $model) {
                $this->loadRelatedModels($model);
            }

            $response = new Response($items, static::successfulHttpStatusCode($this->request->method));

            $response->links = $this->getPaginationLinks($models);
            $response->included = $this->getIncludedModels($items);
            $response->errors = $this->getNonBreakingErrors();
        } else {
            if ($models instanceof Collection) {
                foreach ($models as $model) {
                    $this->loadRelatedModels($model);
                }
            } else {
                $this->loadRelatedModels($models);
            }

            $response = new Response($models, static::successfulHttpStatusCode($this->request->method, $models));

            $response->included = $this->getIncludedModels($models);
            $response->errors = $this->getNonBreakingErrors();
        }

        return $response;
    }