Exemple #1
0
 public static function write($file, $data, $type = null)
 {
     // type autodetection
     if (is_null($type)) {
         $type = f::extension($file);
     }
     return f::write($file, data::encode($data, $type));
 }
 public function _default($default)
 {
     if ($default === true) {
         return 'true';
     } else {
         if ($default === false) {
             return 'false';
         } else {
             if (empty($default)) {
                 return '';
             } else {
                 if (is_string($default)) {
                     return $default;
                 } else {
                     $type = a::get($default, 'type');
                     switch ($type) {
                         case 'date':
                             $format = a::get($default, 'format', 'Y-m-d');
                             return date($format);
                             break;
                         case 'datetime':
                             $format = a::get($default, 'format', 'Y-m-d H:i:s');
                             return date($format);
                             break;
                         case 'user':
                             $user = isset($default['user']) ? site()->users()->find($default['user']) : site()->user();
                             if (!$user) {
                                 return '';
                             }
                             return (isset($default['field']) and $default['field'] != 'password') ? $user->{$default['field']}() : $user->username();
                             break;
                         case 'structure':
                             return "\n" . \data::encode(array($default), 'yaml') . "\n";
                             break;
                         default:
                             return $default;
                             break;
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
 protected static function save($file, $data)
 {
     $yaml = '<?php if(!defined(\'KIRBY\')) exit ?>' . PHP_EOL . PHP_EOL;
     $yaml .= data::encode($data, 'yaml');
     if (!f::write($file, $yaml)) {
         throw new Exception('The user account could not be saved');
     } else {
         return true;
     }
 }