YAMLDump() публичный статический Метод

The dump method, when supplied with an array, will do its best to convert the array into friendly YAML. Pretty simple. Feel free to save the returned string as nothing.yaml and pass it around. Oh, and you can decide how big the indent is and what the wordwrap for folding is. Pretty cool -- just pass in 'false' for either if you want to use the default. Indent's default is 2 spaces, wordwrap's default is 40 characters. And you can turn off wordwrap by passing in 0.
public static YAMLDump ( array $array, integer $indent = false, integer $wordwrap = false, integer $no_opening_dashes = false ) : string
$array array PHP array
$indent integer Pass in false to use the default, which is 2
$wordwrap integer Pass in 0 for no wordwrap, false for default (40)
$no_opening_dashes integer Do not start YAML file with "---\n"
Результат string
Пример #1
0
function output()
{
    global $config, $pages, $ums, $blog, $user, $coms, $editor;
    //First Requirements (Components)
    $error = "";
    foreach ($pages['pacedit']['reqs'] as $req) {
        if (!in_array($req, $config['coms'])) {
            $error .= "Component: " . $req . " is missing<br>";
        }
    }
    if ($error != "") {
        $out = $error;
    } else {
        if (!in_array($user['id'], $coms['pacman']['admins'])) {
            $out = "You are not a package manager";
        } else {
            $out = "<h1>Package Manager - Edit</h1>";
            if (!$_GET['pac']) {
                $out .= 'Please Go back and try again';
            } else {
                $com = $_GET['pac'];
                $content = Spyc::YAMLDump($coms[$com]);
                $out .= '<form action="?var=pacsub" method="POST">
					<input type="hidden" value="' . $com . '" name="com" />
					<textarea name="yaml" id="yaml" cols="70" rows="15">' . str_replace("- --\n", '', $content) . '</textarea><input type="submit" value="Save" /></form>';
            }
        }
    }
    return $out;
}
 /**
  * edit
  *
  * @return void
  */
 public function edit()
 {
     //リクエストセット
     if ($this->request->is('post')) {
         //登録処理
         if (!$this->request->data['SiteSetting']['only_session']) {
             unset($this->request->data['SiteSetting']['only_session']);
             $this->Session->write('debug', null);
             //application.ymlに書き込み
             $conf = Spyc::YAMLLoad(APP . 'Config' . DS . 'application.yml');
             $conf['debug'] = (int) $this->request->data['SiteSetting']['debug']['0']['value'];
             $file = new File(APP . 'Config' . DS . $this->appYmlPrefix . 'application.yml', true);
             $file->write(Spyc::YAMLDump($conf));
             $this->SiteManager->saveData();
         } else {
             $this->SiteSetting->validateDeveloper($this->request->data);
             if (!$this->SiteSetting->validationErrors) {
                 $this->Session->write('debug', (int) $this->request->data['SiteSetting']['debug']['0']['value']);
                 $this->NetCommons->setFlashNotification(__d('net_commons', 'Successfully saved.'), array('class' => 'success'));
                 $this->redirect($this->referer());
             } else {
                 $this->NetCommons->handleValidationError($this->SiteSetting->validationErrors);
             }
         }
     } else {
         $this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit(array('SiteSetting.key' => array('debug')));
         $onlySession = $this->Session->read('debug');
         $this->request->data['SiteSetting']['only_session'] = isset($onlySession);
         if ($this->request->data['SiteSetting']['only_session']) {
             $this->request->data['SiteSetting']['debug']['0']['value'] = $onlySession;
         }
     }
 }
function save_data($obj)
{
    global $wpdb;
    require_once "../../../../../wp-load.php";
    require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/class/Spyc.php';
    require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/defines-const.php';
    if (!current_user_can('manage_options')) {
        echo 'ADMIN BABY !!!';
        die;
    }
    /*	echo '<h2>Save</h2>';
    	echo '<pre>';
    	var_dump($obj['data']);
    	echo '</pre>';*/
    $prop_path = GLOBALDATA_PATH . 'template-hierarchy';
    $posttypes_array = Spyc::YAMLLoad($prop_path . '/arguments/' . $obj['ui_page_name'] . '-slots-properties.yaml');
    //var_dump($posttypes_array[$_POST['slotname']]);
    //echo '<br>---<br>';
    //var_dump($_POST['data']);
    $execute_array = array_merge($posttypes_array[$obj['slotname']], $obj['data']);
    //echo '<br>---<br>';
    //var_dump($execute_array);
    $posttypes_array[$obj['slotname']] = $execute_array;
    //var_dump($posttypes_array);
    file_put_contents($prop_path . '/arguments/' . $obj['ui_page_name'] . '-slots-properties.yaml', Spyc::YAMLDump($posttypes_array));
}
Пример #4
0
 function beforeSave($options = array())
 {
     if ($this->data[$this->name]['type'] == 'IssueCustomField' && !empty($this->data['CustomField']['id'])) {
         $assoc_trackers = Set::extract('{n}.CustomFieldsTracker.tracker_id', $this->CustomFieldsTracker->find('all', array('conditions' => array('custom_field_id' => $this->data['CustomField']['id']))));
         $tracker_ids = empty($this->data[$this->name]['tracker_id']) ? array() : $this->data[$this->name]['tracker_id'];
         $this->__add_trackers = array_diff($tracker_ids, $assoc_trackers);
         $this->__del_trackers = array_diff($assoc_trackers, $tracker_ids);
     }
     unset($this->data[$this->name]['tracker_id']);
     App::Import('vendor', 'spyc');
     if (!empty($this->data[$this->name]['possible_values']) && $this->data[$this->name]['field_format'] == 'list') {
         if (empty($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1])) {
             unset($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1]);
         }
         $this->data[$this->name]['possible_values'] = Spyc::YAMLDump($this->data[$this->name]['possible_values'], true);
     } else {
         $this->data[$this->name]['possible_values'] = '--- []';
     }
     if (empty($this->data[$this->name]['min_length'])) {
         $this->data[$this->name]['min_length'] = 0;
     }
     if (empty($this->data[$this->name]['max_length'])) {
         $this->data[$this->name]['max_length'] = 0;
     }
     return true;
 }
Пример #5
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->name]['type']) && $this->data[$this->name]['type'] == 'IssueCustomField' && !empty($this->data['CustomField']['id'])) {
         $this->bindModel(array('hasMany' => array('CustomFieldsTracker')), false);
         $assoc_trackers = Set::extract('{n}.CustomFieldsTracker.tracker_id', $this->CustomFieldsTracker->find('all', array('conditions' => array('custom_field_id' => $this->data['CustomField']['id']))));
         $tracker_ids = empty($this->data[$this->name]['tracker_id']) ? array() : $this->data[$this->name]['tracker_id'];
         $this->__add_trackers = array_diff($tracker_ids, $assoc_trackers ? $assoc_trackers : array());
         $this->__del_trackers = array_diff($assoc_trackers ? $assoc_trackers : array(), $tracker_ids);
     }
     unset($this->data[$this->name]['tracker_id']);
     App::Import('vendor', 'georgious-cakephp-yaml-migrations-and-fixtures/spyc/spyc');
     if (!empty($this->data[$this->name]['possible_values']) && $this->data[$this->name]['field_format'] == 'list') {
         if (empty($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1])) {
             unset($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1]);
         }
         $this->data[$this->name]['possible_values'] = Spyc::YAMLDump($this->data[$this->name]['possible_values'], true);
     } else {
         $this->data[$this->name]['possible_values'] = '--- []';
     }
     if (empty($this->data[$this->name]['min_length'])) {
         $this->data[$this->name]['min_length'] = 0;
     }
     if (empty($this->data[$this->name]['max_length'])) {
         $this->data[$this->name]['max_length'] = 0;
     }
     return true;
 }
Пример #6
0
 function preset($lang)
 {
     session_start();
     $language = $this->general_model->get_language_by_code($lang);
     if ($language != 0) {
         $_SESSION["language"] = $language;
         $this->data["lang"] = $lang;
     } else {
         $language = $this->general_model->get_language_default();
         if ($language != 0) {
             redirect(base_url() . $language["code"]);
         } else {
             die("System error 1");
         }
     }
     $this->lang->load($lang, $language["language_name"]);
     $_SERVER['DOCUMENT_ROOT'] = dirname(dirname(dirname(__FILE__)));
     //        die($_SERVER["REQUEST_URI"]);
     $this->data['lang_url'] = $_SERVER["REQUEST_URI"];
     $this->data['action'] = $_SERVER["REQUEST_URI"];
     $this->data['redirect'] = $_SERVER["REQUEST_URI"];
     $this->data['settings'] = $this->general_model->get_website_info();
     $this->data['settings']["options"] = $this->general_model->get_website_info_options($language["language_id"]);
     $visitor = $this->general_model->get_duplicate_visitor(session_id(), $_SERVER["REQUEST_URI"]);
     if (count($visitor) == 0) {
         // Get IP address
         if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) {
             $ip = $_SERVER['HTTP_CLIENT_IP'];
         } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
             $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
         } else {
             $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
         }
         $ip = filter_var($ip, FILTER_VALIDATE_IP);
         $ip = $ip === false ? '0.0.0.0' : $ip;
         $this->load->library('spyc');
         $visitor_data = array("session_id" => session_id(), "user_id" => isset($_SESSION["user"]["user_id"]) ? $_SESSION["user"]["user_id"] : 0, "created_date" => time(), "updated_date" => time(), "user_agent" => Spyc::YAMLDump($_SERVER["HTTP_USER_AGENT"]), "user_ip" => $ip, "language_id" => $language["language_id"], "language_code" => $language["code"], "referrer" => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "", "request_url" => $_SERVER['REQUEST_URI'], "count_view" => 1);
         $this->general_model->insert_visitors($visitor_data);
     } else {
         $visitor = @reset($visitor);
         $visitor_data = array("user_id" => isset($_SESSION["user"]["user_id"]) ? $_SESSION["user"]["user_id"] : 0, "updated_date" => time(), "count_view" => $visitor["count_view"] + 1);
         $this->general_model->update_duplicate_visitor(session_id(), $_SERVER["REQUEST_URI"], $visitor_data);
     }
     $data_menu = array();
     $menu = $this->general_model->get_menu();
     $i = 0;
     foreach ($menu as $menu) {
         $data_menu[$i] = array('id' => $menu['page_id'], 'name' => $menu['title_caption'], 'url' => $menu['page_id'] != 0 ? base_url() . $lang . "/page/" . $menu['page_id'] : $menu['menu_url']);
         $i++;
     }
     $this->data['languages'] = $this->general_model->get_languages();
     foreach ($this->data['languages'] as &$value) {
         $url_array = explode("/", $this->data["lang_url"]);
         $url_array[array_search($lang, $url_array)] = $value["code"];
         $value["lang_url"] = implode("/", $url_array);
     }
     $this->data['data_menu'] = $data_menu;
     $this->data['link_contact'] = base_url() . "contact";
 }
 /**
  * Pretty-print YAML
  *
  * @return bool|null|string
  */
 public function beautifyYAML()
 {
     $decoded = $this->getYamlData();
     if (!is_array($decoded)) {
         return null;
     }
     return Spyc::YAMLDump($decoded, 4, 0);
 }
Пример #8
0
 /**
  * Returns the formatted config file contents.
  *
  * @param   array   $content  config array
  * @return  string  formatted config file contents
  */
 protected function export_format($contents)
 {
     if (!function_exists('spyc_load')) {
         import('spyc/spyc', 'vendor');
     }
     $this->prep_vars($contents);
     return \Spyc::YAMLDump($contents);
 }
Пример #9
0
 public function save()
 {
     self::purge($this);
     if (file_put_contents($this->path, Spyc::YAMLDump($this))) {
         cache::getInstance()->config = $this;
     }
     return $this;
 }
Пример #10
0
 /**
  * beforeSave
  *
  */
 function beforeSave()
 {
     //pr($this->data);
     if (isset($this->data['UserPreference']['pref'])) {
         $this->data['UserPreference']['others'] = Spyc::YAMLDump($this->data['UserPreference']['pref']);
     }
     #    self.others ||= {}
     return true;
 }
Пример #11
0
 public function writeLog($data)
 {
     if (sizeof($data) > 0) {
         $yaml = \Spyc::YAMLDump($data, 4, 60);
         $fh = fopen(DOC_ROOT . '/logs/paypal', "a");
         fwrite($fh, $yaml);
         fclose($fh);
     }
 }
Пример #12
0
 public function save()
 {
     $fp = fopen($this->fileName, 'w+');
     fputs($fp, Spyc::YAMLDump($this->toArray(), true, 0));
     fclose($fp);
     if ($this->useCache == true) {
         $this->writeCache();
     }
 }
Пример #13
0
 public function save()
 {
     // If settings is null
     //  -> means the file was never loaded because no setting was changed
     //  -> means no need to save
     if ($this->settings === null) {
         return;
     }
     $yaml = Spyc::YAMLDump($this->settings);
 }
Пример #14
0
function prepare_job($workdir, $info)
{
    $BASE = $info['BASE'];
    mkdir($workdir);
    $fp = fopen("{$workdir}/info.yaml", 'w');
    fwrite($fp, Spyc::YAMLDump($info));
    fclose($fp);
    system("chmod 777 -R {$workdir}");
    return $workdir;
}
Пример #15
0
function ui_save_data_grid($obj)
{
    if (current_user_can('manage_options')) {
        //var_dump($obj['yaml']);
        require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/defines-const.php';
        file_put_contents(GLOBALDATA_PATH . 'uigen-data-grids/' . $obj['filename'], Spyc::YAMLDump($obj['yaml']));
    } else {
        echo '<span>Error:ui_save_data_grid is admin method. Login as admin</span>';
    }
}
Пример #16
0
 function afterFind()
 {
     parent::afterFind();
     $this->_widget = unserialize($this->widget);
     $this->_rules = unserialize($this->rules);
     $this->_automodel = unserialize($this->automodel);
     $this->widget = Spyc::YAMLDump($this->_widget);
     $this->rules = Spyc::YAMLDump($this->_rules);
     $this->automodel = Spyc::YAMLDump($this->_automodel);
 }
Пример #17
0
 public function testQuotes()
 {
     $test_values = array("adjacent '''' \"\"\"\" quotes.", "adjacent '''' quotes.", "adjacent \"\"\"\" quotes.");
     foreach ($test_values as $value) {
         $yaml = array($value);
         $dump = Spyc::YAMLDump($yaml);
         $yaml_loaded = Spyc::YAMLLoad($dump);
         $this->assertEquals($yaml, $yaml_loaded);
     }
 }
Пример #18
0
function convertArray2Formatted($type = '', $data = '')
{
    $resultString = '';
    if ($type == 'json') {
        $resultString = json_encode($data);
    }
    if ($type == 'yaml') {
        $resultString = Spyc::YAMLDump($data);
    }
    return $resultString;
}
Пример #19
0
function yaml_dump($array, $indent = null, $wrap = null, $streamed = false)
{
    if ($indent === null) {
        $indent = false;
    }
    if ($wrap === null) {
        $wrap = 78;
    }
    $val = Spyc::YAMLDump($array, $indent, $wrap);
    return $streamed ? $val : str_replace("---\n", '', $val);
}
Пример #20
0
 public function serializeFields()
 {
     if (!isset($this->serialize) || !is_array($this->serialize)) {
         return;
     }
     foreach ($this->serialize as $field) {
         if (empty($this->data[$this->alias][$field])) {
             continue;
         }
         $this->set($field, Spyc::YAMLDump($this->data[$this->alias][$field]));
     }
 }
Пример #21
0
 public function testABCD2()
 {
     $a = array('a', 'b', 'c', 'd');
     // Create a simple list
     $b = Spyc::YAMLDump($a);
     // Dump the list as YAML
     $c = Spyc::YAMLLoad($b);
     // Load the dumped YAML
     $d = Spyc::YAMLDump($c);
     // Re-dump the data
     $this->assertSame($b, $d);
 }
Пример #22
0
 /**
  * Generates an YAML file from the current DB schema
  */
 function generate()
 {
     $aResult = array();
     $aResult['UP'] = $aResult['DOWN'] = array();
     $aResult['UP']['create_table'] = $aResult['DOWN']['drop_table'] = array();
     $aTables = $this->oDb->listSources();
     foreach ($aTables as $sTable) {
         $sTableName = str_replace($this->getPrefix(), '', $sTable);
         $aTableSchema = $this->_buildSchema($sTableName);
         $aResult['UP']['create_table'][$sTableName] = $aTableSchema;
         $aResult['DOWN']['drop_table'][] = $sTableName;
     }
     return Spyc::YAMLDump($aResult);
 }
Пример #23
0
 /**
  * instead of self.[] method of ruby version
  *
  * @param string $name
  * @param mixed $value
  */
 public function store($name, $value)
 {
     if (is_array($value)) {
         $value = Spyc::YAMLDump($value);
     }
     $setting = $this->findByName($name);
     $this->create(false);
     if (!empty($setting)) {
         $id = $this->id = $setting['Setting']['id'];
         $data = compact('id', 'value');
     } else {
         $data = compact('name', 'value');
     }
     return $this->save($data);
 }
Пример #24
0
 public function convert()
 {
     $attributes = array();
     if ($this->source instanceof ArrayAccess) {
         foreach ($this->source as $Model) {
             if ($Model instanceof AkBaseModel) {
                 $attributes[$Model->getId()] = $Model->getAttributes();
             }
         }
     } elseif ($this->source instanceof AkBaseModel) {
         $attributes[$this->source->getId()] = $this->source->getAttributes();
     }
     require_once AK_CONTRIB_DIR . DS . 'TextParsers' . DS . 'spyc.php';
     return Spyc::YAMLDump($attributes);
 }
Пример #25
0
 public function convert()
 {
     $attributes = array();
     if (is_array($this->source)) {
         foreach (array_keys($this->source) as $k) {
             if ($this->_isActiveRecord($this->source[$k])) {
                 $attributes[$this->source[$k]->getId()] = $this->source[$k]->getAttributes();
             }
         }
     } elseif ($this->_isActiveRecord($this->source)) {
         $attributes[$this->source->getId()] = $this->source->getAttributes();
     }
     require_once AK_VENDOR_DIR . DS . 'TextParsers' . DS . 'spyc.php';
     return Spyc::YAMLDump($attributes);
 }
Пример #26
0
function yaml_encode($struct, $opt = array())
{
    // Si PHP4
    if (_LIB_YAML == 'spyc-php4') {
        require_once _DIR_PLUGIN_YAML . 'spyc/spyc-php4.php';
        return Spyc::YAMLDump($struct);
    }
    // test temporaire
    if (_LIB_YAML == 'spyc') {
        require_once _DIR_PLUGIN_YAML . 'spyc/spyc.php';
        return Spyc::YAMLDump($struct);
    }
    require_once _DIR_PLUGIN_YAML . 'inc/yaml_sfyaml.php';
    return yaml_sfyaml_encode($struct, $opt);
}
Пример #27
0
 public function __construct()
 {
     $base = Site::model('Environment')->database_atheist_tables_base;
     $page = Site::model('Environment')->database_atheist_tables_page;
     $page['fields'] = array_merge($base['fields'], $page['fields']);
     $dbPage = 'page';
     $dbPage = $this->describe('profiles_fields');
     echo '<pre>';
     print_r($dbPage);
     echo $this->create_table($dbPage);
     echo '=====';
     $spyc = new Spyc();
     echo $spyc->YAMLDump($dbPage, true);
     die;
 }
Пример #28
0
function write_to_hostgroup_yml()
{
    global $server_cfg, $game, $current_yaml_file;
    //	Creating a copy of current yaml file
    $hostgroupConfigObj = new HostgroupConfig($server_cfg, $game);
    $current_yaml_file = $hostgroupConfigObj->load_hostgroup_config();
    $final_array = json_decode($_POST["json_final"], true);
    foreach ($final_array as $regex => $config) {
        if (!isset($config["class"])) {
            $final_array[$regex] = "";
        }
    }
    $file_path = sprintf($server_cfg["hostgroups_config"], $game);
    $yaml_str = Spyc::YAMLDump($final_array);
    file_put_contents($file_path, $yaml_str) or die("Unable to modify hostgroup.yml file. Exiting....");
}
Пример #29
0
function create_album($id, $sizes)
{
    global $params;
    $album_path = album_dir($id);
    if (is_dir(album_dir($id))) {
        //--Create configuration file
        if (!file_exists(album_dir($id) . "info.yml")) {
            // There could be more parameters if necessary
            $info_yaml = Spyc::YAMLDump(array('album_title' => $params['album'], 'album_description' => ''));
            if (!($fp = fopen(album_dir($id) . 'info.yml', 'a'))) {
                $params['flash'] = 'Album info file could not be created in <code>' . album_dir($id) . 'info.yml</code>.';
                render('error');
            }
            if (!fwrite($fp, $info_yaml)) {
                $params['flash'] = 'Could not write to file <code>' . album_dir($id) . 'info.yml</code>.';
                render('error');
            }
            fclose($fp);
        }
        $originals = get_images(album_dir($id));
        //--Create ZIP-Archive to download
        //$zip = new PclZip('archive.zip');
        foreach ($originals as $image) {
            $images[] = album_dir($id) . $image;
        }
        $zip = new PclZip(album_dir($id) . 'archive.zip');
        $test = $zip->create($images, PCLZIP_OPT_REMOVE_ALL_PATH);
        if ($test == 0) {
            die("Error: " . $zip->errorInfo(true));
        }
        //--Resize images
        foreach ($sizes as $size_name => $size_pixels) {
            $resized_album_path = album_dir($id, $size_name);
            if (!is_dir($resized_album_path)) {
                mkdir($resized_album_path, 0755);
            }
            foreach ($originals as $photo) {
                scale(album_dir($id) . $photo, "{$resized_album_path}/{$photo}", $size_pixels);
            }
        }
    } else {
        $params['flash'] = "Resizing the images in <code>{$album_path}</code> failed. Could there be a permission problem?";
        render('error');
        exit;
    }
}
Пример #30
0
 public static function schema_to_yaml($table)
 {
     // Run SQL
     $sqlite = new sqlite();
     $result = $sqlite->query("PRAGMA table_info({$table})");
     $array = array();
     foreach ($result as $k => $v) {
         $array[] = array('name' => $v->name, 'type' => $v->type, 'notnul' => $v->notnull, 'default' => $v->dflt_value, 'isprimarykey' => $v->pk);
     }
     // Write to file
     $fp = fopen('db/' . $table . '.yaml', 'w+');
     fwrite($fp, Spyc::YAMLDump($array));
     fclose($fp);
     // Return json
     // return array('yaml' => Spyc::YAMLDump($array));
     return Spyc::YAMLDump($array);
 }