Esempio n. 1
0
 public function forField($field)
 {
     if (method_exists($this->model, $field)) {
         throw new Exception('The field name: ' . $field . ' cannot be used as it is reserved');
     }
     $this->field = $field;
     $this->config = $this->model->getBlueprintFields()->get($this->field);
     if (is_a($this->model, 'Page')) {
         $source = $this->model->content()->get($this->field);
         $decode = true;
     } else {
         if (is_a($this->model, 'File')) {
             $source = $this->model->meta()->get($this->field);
             $decode = true;
         } else {
             if (is_a($this->model, 'User')) {
                 $source = $this->model->{$this->field}();
                 $decode = false;
             } else {
                 throw new Exception('Invalid model for structure field: ' . $this->field);
             }
         }
     }
     $this->source = $decode ? (array) yaml::decode($source) : (array) $source;
     $this->store = new Store($this, $this->source);
     return $this;
 }
Esempio n. 2
0
 public function value()
 {
     if (is_string($this->value)) {
         $this->value = yaml::decode($this->value);
     }
     return $this->value;
 }
Esempio n. 3
0
 public function forField($field)
 {
     if (method_exists($this->model, $field)) {
         throw new Exception('The field name: ' . $field . ' cannot be used as it is reserved');
     }
     $this->field = $field;
     $this->config = $this->model->getBlueprintFields()->get($this->field);
     $this->source = (array) yaml::decode($this->model->{$this->field}());
     $this->store = new Store($this, $this->source());
     return $this;
 }
Esempio n. 4
0
 public function getEmailParams()
 {
     //if we have a correct email template
     if ($this->emailTemplate) {
         //store template content in a string
         $emailWithPlaceholders = $this->emailTemplate->read();
         //replace placeholders in $emailWithPlaceholders with data
         $emailWithData = str::template($emailWithPlaceholders, $this->emailData);
         //return array
         return yaml::decode($emailWithData);
     }
     //return emmpty array in case of error while getting email template
     return '';
 }
Esempio n. 5
0
    // loop through all fields and add them to the content
    foreach ($fields as $field) {
        $pos = strpos($field, ':');
        $key = str_replace(array('-', ' '), '_', strtolower(trim(substr($field, 0, $pos))));
        // Don't add fields with empty keys
        if (empty($key)) {
            continue;
        }
        $data[$key] = trim(substr($field, $pos + 1));
    }
    return $data;
});
/**
 * PHP serializer adapter
 */
data::$adapters['php'] = array('extension' => array('php'), 'encode' => function ($array) {
    return '<?php ' . PHP_EOL . PHP_EOL . 'return ' . var_export($array, true) . PHP_EOL . PHP_EOL . '?>';
}, 'decode' => function ($string) {
    throw new Error('Decoding PHP strings is not supported');
}, 'read' => function ($file) {
    $array = (require $file);
    return $array;
});
/**
 * YAML adapter
 */
data::$adapters['yaml'] = array('extension' => array('yaml', 'yml'), 'encode' => function ($data) {
    return yaml::encode($data);
}, 'decode' => function ($string) {
    return yaml::decode($string);
});
Esempio n. 6
0
/**
 * Parses yaml structured text
 *
 * @param string $text
 * @return string parsed text
 */
function yaml($string)
{
    return yaml::decode($string);
}
Esempio n. 7
0
 /**
  * Return the current value
  *
  * @since 1.0.0
  *
  * @return array
  */
 public function items()
 {
     $ret = array();
     if (is_string($this->value)) {
         $this->value = yaml::decode($this->value);
         if (isset($this->value[0])) {
             foreach ($this->value[0] as $key => $value) {
                 $ret[$key] = $value;
             }
         }
     }
     return $ret;
 }
Esempio n. 8
0
 public function value()
 {
     $value = parent::value();
     return yaml::decode($value);
 }