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; }
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); }
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)); }
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)); }