title = $title; $this->body = $body; $this->image = $image; $this->fields = array(); } public function title($value) { $this->title = $value; } public function body($value) { $this->body = $value; } public function image($value) { $this->image = $value; } public function getFields() { return $this->fields; } public function buildFields() { try { $this->check_parameter(); } catch (Exception $e) { echo $e; } $keys = array( 'title', 'body', 'image' ); foreach ($keys as $key) { if (isset($this->$key)) { $this->fields[$key] = $this->$key; } } } private function check_parameter() { if (empty($this->title)) { throw new Exception("title should be set"); } if (empty($this->body)) { throw new Exception("body should be set"); } } }