rich_resource = null; $this->url = null; } public function type($value) { $this->type = $value; } public function intent($value) { $this->intent = $value; } public function url($value) { $this->url = $value; } public function rich_resource($value) { $this->rich_resource = $value; } // added public function action($value) { $this->action = $value; } public function getFields() { return $this->fields; } public function buildFields() { try { $this->check_parameter(); } catch (Exception $e) { echo $e; } $keys = array( 'type', 'intent', 'url', 'rich_resource', // add 'action' ); foreach ($keys as $key) { if (isset($this->$key)) { $this->fields[$key] = $this->$key; } } } private function check_parameter() { if (($this->type) && (gettype($this->type) != "integer")) { throw new Exception("type of type is wrong."); } if (!in_array($this->type, array(1, 2, 3, 4))) { throw new Exception("click type should be one of 1: customize action, 2: open url, 3: open app, 4: open rich media"); } $PATTERN = "/^https.*/"; switch ($this->type) { case 1: { if (is_null($this->intent) && is_null($this->action)) { throw new Exception("when type=1,intent/action at least one is valid"); } } break; case 2: { if (is_null($this->url)) { throw new Exception("url is required when click type=2"); } if (FALSE == ValidatorUtil::validatePattern($PATTERN, $this->url)) { throw new Exception("url must start with https"); } } break; case 4: { if (is_null($this->richResource)) { throw new Exception("richResource is required when click type=4"); } if (FALSE == ValidatorUtil::validatePattern($PATTERN, $this->richResource)) { throw new Exception("richResource must start with https"); } } break; } } }