ruleset = new Ruleset(strict: true); $this->ruleset->POST([ (new Rules(PermalinksTable::ID->value)) ->required() ->type(Type::STRING) ->min(1) ->max(parent::SIZE_VARCHAR), (new Rules(PermalinksTable::REF_WORK_ID->value)) ->required() ->type(Type::STRING) ->min(1) ->max(parent::SIZE_VARCHAR), (new Rules(PermalinksTable::DATE_CREATED->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::SIZE_UINT8) ->default(time()) ]); $this->ruleset->validate_or_exit(); parent::__construct(); } private static function get_entity(): Response { return (new Call(Endpoints::WORK->value))->params([ WorkTable::ID->value => $_POST[TagsTable::REF_WORK_ID->value] ])->get(); } public function main(): Response { // Bail out if work entity could not be fetched $entity = self::get_entity(); if (!$entity->ok) { return $entity; } return $this->db->for(PermalinksTable::NAME)->insert($_POST) === true ? new Response($_POST[PermalinksTable::ID->value], 201) : new Response("Failed to add permalink to work entity", 500); } }