/** * @param string $var_name * @param array $args * @throws Exception */ function __construct($var_name, $args = array()) { /** * If a string, could be 'foo' or 'var=foo' maybe */ if (is_string($args)) { /** * If just 'foo' set $var = 'foo' */ if (true === strpos($args, '=')) { $args = array('var' => $args); } else { /** * If 'var=foo' turn into array( 'var'=>'foo' ) */ parse_str($args, $args); } } if (!is_object($args) && !is_array($args)) { throw new Exception('Must pass a string, array or object for $args when creating a new ' . __CLASS__ . '.'); } $this->name = $var_name; /** * Copy properties in from $args, if they exist. */ foreach ($args as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } /* * Convert strings to arrays. */ if (is_string($this->options)) { $this->options = RESTian::parse_string($this->options); } if (is_string($this->not_vars)) { $this->not_vars = RESTian::parse_string($this->not_vars); } if (is_string($this->transforms)) { $this->transforms = RESTian::parse_transforms($this->transforms); } }
/** * @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; } }
/** * @param string $var_set_name * @param array $vars */ function register_var_set($var_set_name, $vars = array()) { $this->_var_sets[$var_set_name] = RESTian::parse_string($vars); }