Example #1
0
 function read_block()
 {
     $block = fgets($this->stream);
     if ($json = JsonDataParser::decode($block)) {
         return $json;
     }
     if (strlen($block)) {
         $this->stderr->write("Unable to read block from input");
         die;
     }
 }
Example #2
0
 function read_block()
 {
     $block = '';
     while (!feof($this->stream) && ($c = fgetc($this->stream)) != "") {
         $block .= $c;
     }
     if ($json = JsonDataParser::decode($block)) {
         return $json;
     }
     if (strlen($block)) {
         $this->stderr->write("Unable to read block from input");
         die;
     }
 }
Example #3
0
 /**
  * getConfiguration
  *
  * Loads configuration information from database into hashtable format.
  * Also, the defaults from ::getConfigurationOptions() are integrated
  * into the database-backed options, so that if options have not yet
  * been set or a new option has been added and not saved for this field,
  * the default value will be reflected in the returned configuration.
  */
 function getConfiguration()
 {
     if (!$this->_config) {
         $this->_config = $this->get('configuration');
         if (is_string($this->_config)) {
             $this->_config = JsonDataParser::parse($this->_config);
         } elseif (!$this->_config) {
             $this->_config = array();
         }
         foreach ($this->getConfigurationOptions() as $name => $field) {
             if (!isset($this->_config[$name])) {
                 $this->_config[$name] = $field->get('default');
             }
         }
     }
     return $this->_config;
 }
 function getConfiguration()
 {
     if (!$this->_config) {
         $this->_config = $this->get('properties');
         if (is_string($this->_config)) {
             $this->_config = JsonDataParser::parse($this->_config);
         } elseif (!$this->_config) {
             $this->_config = array();
         }
     }
     return $this->_config;
 }
Example #5
0
 private function getProperties()
 {
     if (!isset($this->_properties)) {
         $this->_properties = $this->get('properties');
         if (is_string($this->_properties)) {
             $this->_properties = JsonDataParser::parse($this->_properties);
         } elseif (!$this->_properties) {
             $this->_properties = array();
         }
     }
     return $this->_properties;
 }
 function to_php($value, $id = false)
 {
     if (is_string($value)) {
         $value = JsonDataParser::parse($value) ?: $value;
     }
     if (!is_array($value)) {
         $values = array();
         $choices = $this->getChoices();
         foreach (explode(',', $value) as $V) {
             if (isset($choices[$V])) {
                 $values[$V] = $choices[$V];
             }
         }
         if ($id && isset($choices[$id])) {
             $values[$id] = $choices[$id];
         }
         if ($values) {
             return $values;
         }
         // else return $value unchanged
     }
     // Don't set the ID here as multiselect prevents using exactly one
     // ID value. Instead, stick with the JSON value only.
     return $value;
 }
Example #7
0
 function parse($stream)
 {
     return $this->fixup(parent::parse($stream));
 }
Example #8
0
 function to_php($value)
 {
     return JsonDataParser::decode($value);
 }
 function to_php($value, $id = false)
 {
     if (is_string($value)) {
         $value = JsonDataParser::parse($value) ?: $value;
     }
     if (!is_array($value)) {
         $config = $this->getConfiguration();
         if (!$config['multiselect']) {
             // CDATA may be built with comma-list
             list($value, ) = explode(',', $value, 2);
         }
         $choices = $this->getChoices();
         if (isset($choices[$value])) {
             $value = array($value => $choices[$value]);
         } elseif ($id && isset($choices[$id])) {
             $value = array($id => $choices[$id]);
         }
     }
     // Don't set the ID here as multiselect prevents using exactly one
     // ID value. Instead, stick with the JSON value only.
     return $value;
 }