public static function POST($params, $method, $headers) { $validationModel = new \Phramework\Validate\ObjectValidator(['title' => new \Phramework\Validate\StringValidator(3, 32), 'content' => new \Phramework\Validate\StringValidator(3, 1024), 'category' => (new \Phramework\Validate\EnumValidator(['blog', 'release', 'test']))->setDefault('blog')], ['title', 'content']); $data = $validationModel->parse($params); //Do something with parsed data //$data->title //$data-content //$data->category //Return 202 Accepted HTTP status code, since we din't store the data \Phramework\Models\Response::accepted(); /* //Uncomment to view the data object when debugging self::view([ 'data' => $data ]); */ }
public static function POST($params) { //Define model $model = ['title' => ['type' => Validate::TYPE_TEXT, 'max' => 12, 'min' => 3, Validate::REQUIRED], 'content' => ['type' => Validate::TYPE_TEXT, 'max' => 4096, 'min' => 12, Validate::REQUIRED]]; //Require and Validate model Validate::model($params, $model); //Declare them as variables $title = $params['title']; $content = $params['content']; $post = ['title' => $title, 'content' => $content, 'timestamp' => time()]; $post = \Phramework\Models\Filter::castEntry($post, ['timestamp' => Validate::TYPE_UNIX_TIMESTAMP]); //Store ($title, $content) somehow and get the id $id = rand(0, 100); $post['id'] = $id; \Phramework\Models\Response::created('http://localhost/post/' . $id . '/'); //Sample output Phramework::view(['post' => $post], 'post', 'Blog post'); }
public static function PUT($params, $method, $headers, $id) { \Phramework\Models\Response::noContent(); }