Drahak\Restful\Application\UI\ResourcePresenter::startup PHP Method

startup() protected method

Presenter startup
protected startup ( )
    protected function startup()
    {
        parent::startup();
        $this->autoCanonicalize = FALSE;
        try {
            // Create resource object
            $this->resource = $this->resourceFactory->create();
            // calls $this->validate<Action>()
            $validationProcessed = $this->tryCall($this->formatValidateMethod($this->action), $this->params);
            // Check if input is validate
            if (!$this->getInput()->isValid() && $validationProcessed === TRUE) {
                $errors = $this->getInput()->validate();
                throw BadRequestException::unprocessableEntity($errors, 'Validation Failed: ' . $errors[0]->message);
            }
        } catch (BadRequestException $e) {
            if ($e->getCode() === 422) {
                $this->sendErrorResource($e);
                return;
            }
            throw $e;
        } catch (InvalidStateException $e) {
            $this->sendErrorResource($e);
        }
    }

Usage Example

Example #1
0
 public function startup()
 {
     try {
         $id = $this->getParameter('id');
         if ($id !== NULL && ($id = $this->isValidId($id)) === FALSE) {
             throw BadRequestException::methodNotSupported('Url must follow convention /presenter/id/relation/relationId.' . ' Valid ID is only positive, non zero integer.');
         }
         $action = $this->getAction();
         if ($action === 'create' && $id) {
             $this->changeAction('update');
         }
         parent::startup();
         if (strpos($action, 'read') === FALSE) {
             $this->inputData = $this->inputData ?: $this->getInputData();
         }
         if (($relation = $this->getParameter('relation')) !== NULL) {
             $this->table = $this->db->table($relation)->where($this->getTableName(), $id);
             $this->deepListing = $this->queryFilter = NULL;
         } else {
             $this->table = $this->db->table($this->getTableName());
         }
     } catch (BadRequestException $ex) {
         $this->sendErrorResource($ex);
     }
 }
All Usage Examples Of Drahak\Restful\Application\UI\ResourcePresenter::startup