function __construct($settings_name, $args = array()) { $this->modifier_name = $settings_name; if (!is_object($args) && !is_array($args)) { throw new Exception('Must pass a string, array or object for $args when creating a new ' . __CLASS__ . '.'); } $args = RESTian::expand_shortnames($args, array('method' => 'http_method', 'type' => 'content_type')); if (isset($args['content_type'])) { $args['content_type'] = RESTian::expand_content_type($args['content_type']); } /** * Copy properties in from $args, if they exist. */ foreach ($args as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } }
/** * @return bool|string */ function get_body() { $body = false; if (preg_match('#^(POST|PUT)$#i', $this->http_method)) { if ($this->body) { $body = $this->body; } else { if ($settings = $this->service->get_request_settings()) { if (RESTian::expand_content_type('form') == $settings->content_type) { $body = http_build_query($this->vars); } else { if (count($this->vars) && RESTian::expand_content_type('json') == $settings->content_type) { $body = json_encode((object) $this->vars); } } } else { if (count($this->vars)) { $body = http_build_query($this->vars); $this->vars = null; } } } } return $body; }
/** * @param string $service_name * @param RESTian_Client $client * @param array $args * @throws Exception */ function __construct($service_name, $client, $args = array()) { $this->service_name = strtolower($service_name); $this->client = $client; /** * Set any defaults not set */ foreach ($this->client->get_service_defaults() as $name => $value) { if (!isset($args[$name])) { $args[$name] = $value; } } /** * Allow shorthand of 'auth' for 'needs_authentication' */ $args = RESTian::expand_shortnames($args, array('auth' => 'needs_authentication', 'settings' => 'settings_name')); /** * Copy properties in from $args, if they exist. */ foreach ($args as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } /* * Transform from shortcut names like json and xml to valid mime type names application/json and application/xml. * @see: http://www.iana.org/assignments/media-types/index.html */ $this->content_type = RESTian::expand_content_type($this->content_type); /* * Convert strings to arrays. */ if (is_string($this->requires)) { $this->requires = RESTian::parse_string($this->requires); } /* * TODO: Note=> 'not_vars' is not yet tested. */ if (is_string($this->not_vars)) { $this->not_vars = RESTian::parse_string($this->not_vars); } if (is_string($this->vars)) { $this->vars = RESTian::parse_string($this->vars); } if (isset($args['var_set'])) { $var_set_vars = $client->get_var_set($args['var_set']); $this->vars = $this->vars ? array_merge($var_set_vars, $this->vars) : $var_set_vars; } }