/** * Makes the Controller instance executable, must be given the URI segments to continue * * @param array $args * * @throws Request\Exception\NotFound * * @return Response * * @since 2.0.0 */ public function __invoke(array $args) { // get the route that got us here $this->route = array_shift($args); // determine the method to call $action = $this->route->action ?: $this->defaultAction; if (!is_callable(array($this, $method = strtolower($this->route->method) . $action))) { if (!is_callable(array($this, $method = $this->actionPrefix . $action))) { throw new NotFound('FOU-026: No such action [' . $action . '] found in Controller: [\\' . get_class($this) . ']'); } } // only public methods can be called via a request $method = new \ReflectionMethod($this, $method); if (!$method->isPublic()) { throw new NotFound('FOU-027: Unavailable action [' . $method->name . '] in Controller: [\\' . get_class($this) . ']'); } // create a response object if (empty($this->responseFormat)) { // pick a default, JSON for ajax calls, HTML for non-ajax requests $this->responseFormat = $this->request->getInput()->isAjax() ? 'json' : 'html'; } // store the current response format, so we can detect runtime changes $this->initialResponseFormat = $this->responseFormat; // construct a new response object $this->response = $this->factory->createResponseInstance($this->responseFormat, array($this->request)); // execute the request return $this->execute($method, $args); }
<?php require_once 'libs/Request.php'; $request = new Request(); //Sample Usage //Get request Array $aData = $request->getArray(); //Get request Input name $aData = ['name' => $request->getInput('name'), 'address' => $request->getInput('address'), 'number' => $request->getInput('number')]; //Get request property name according to form data inputs $aData = ['name' => $request->name, 'address' => $request->address, 'number' => $request->number]; var_dump($aData); //sample database insertion //User::create($aData);