本文整理汇总了PHP中YAML::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP YAML::encode方法的具体用法?PHP YAML::encode怎么用?PHP YAML::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YAML
的用法示例。
在下文中一共展示了YAML::encode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encode
public function encode(array $data)
{
$body = isset($data[$this->contentFieldName]) ? $data[$this->contentFieldName] : '';
unset($data[$this->contentFieldName]);
$str = "---\n";
$str .= parent::encode($data);
$str .= "---\n";
$str .= $body;
return $str;
}
示例2: generate_schema
function generate_schema($model)
{
global $mysql;
$cols = array();
$result = mysql_query("DESCRIBE `{$model}`") or die("Error in query: {$sql} \n" . mysql_error() . "\n");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$cols[$row['Field']] = $row;
}
$yaml = YAML::encode($cols);
$comments = "# This file is auto-generated by script/generate_schema \n# Do not edit or you'll ruin Christmas!!\n\n";
file_put_contents("db/schemas/{$model}.yml", $comments . $yaml);
}
示例3: __construct
public function __construct($config)
{
$this->config = $config;
$dir = dirname(__FILE__);
if (file_exists($dir . '/repos.yml')) {
$this->repos = YAML::decode_file($dir . '/repos.yml');
if ($this->verify_repos() && file_exists($dir . '/flat.yml')) {
$this->flat = YAML::decode_file($dir . '/flat.yml');
} else {
$this->flat = $this->flatten($this->repos);
}
} else {
$this->rebuild();
}
//write file back out
file_put_contents($dir . '/repos.yml', YAML::encode($this->repos));
file_put_contents($dir . '/flat.yml', YAML::encode($this->flat));
}
示例4: testEncoding
public function testEncoding()
{
$formatter = new YAML();
$data = array('name' => 'Joe', 'age' => 21, 'employed' => true);
$this->assertSame(file_get_contents(__DIR__ . '/fixtures/joe.yaml'), $formatter->encode($data));
}