Ejemplo n.º 1
0
 /**
  * @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);
     }
 }