当前位置: 首页>>代码示例>>PHP>>正文


PHP YAML::decode方法代码示例

本文整理汇总了PHP中YAML::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP YAML::decode方法的具体用法?PHP YAML::decode怎么用?PHP YAML::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YAML的用法示例。


在下文中一共展示了YAML::decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDecoding

 public function testDecoding()
 {
     $formatter = new YAML();
     $data = array('name' => 'Joe', 'age' => 21, 'employed' => true);
     $raw = file_get_contents(__DIR__ . '/fixtures/joe.yaml');
     $this->assertEquals($data, $formatter->decode($raw));
 }
开发者ID:gekt,项目名称:www,代码行数:7,代码来源:YAMLTest.php

示例2: decode

 public function decode($data)
 {
     $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $data, 3);
     $yaml = parent::decode($parts[1]);
     $yaml[$this->contentFieldName] = $parts[2];
     return $yaml;
 }
开发者ID:jamesmoss,项目名称:flywheel,代码行数:7,代码来源:Markdown.php

示例3: parse_manifest

 private function parse_manifest($package_path)
 {
     $package_path = preg_replace('/\\/$/', '', $package_path) . '/';
     $manifest = YAML::decode_file($package_path . 'package.yml');
     if (empty($manifest)) {
         throw new Exception("package.yml not found in {$package_path}, or unable to parse manifest.");
     }
     $package_name = $manifest['name'];
     if ($this->root == null) {
         $this->root = $package_name;
     }
     if (array_has($this->manifests, $package_name)) {
         return;
     }
     $manifest['path'] = $package_path;
     $this->manifests[$package_name] = $manifest;
     foreach ($manifest['sources'] as $i => $path) {
         $path = $package_path . $path;
         // this is where we "hook" for possible other replacers.
         $source = $this->replace_build($package_path, file_get_contents($path));
         $descriptor = array();
         // get contents of first comment
         preg_match('/^\\s*\\/\\*\\s*(.*?)\\s*\\*\\//s', $source, $matches);
         if (!empty($matches)) {
             // get contents of YAML front matter
             preg_match('/^-{3}\\s*$(.*?)^(?:-{3}|\\.{3})\\s*$/ms', $matches[1], $matches);
             if (!empty($matches)) {
                 $descriptor = YAML::decode($matches[1]);
             }
         }
         // populate / convert to array requires and provides
         $requires = (array) (!empty($descriptor['requires']) ? $descriptor['requires'] : array());
         $provides = (array) (!empty($descriptor['provides']) ? $descriptor['provides'] : array());
         $file_name = !empty($descriptor['name']) ? $descriptor['name'] : basename($path, '.js');
         // "normalization" for requires. Fills up the default package name from requires, if not present.
         foreach ($requires as $i => $require) {
             $requires[$i] = implode('/', $this->parse_name($package_name, $require));
         }
         $license = array_get($descriptor, 'license');
         $this->packages[$package_name][$file_name] = array_merge($descriptor, array('package' => $package_name, 'requires' => $requires, 'provides' => $provides, 'source' => $source, 'path' => $path, 'package/name' => $package_name . '/' . $file_name, 'license' => empty($license) ? array_get($manifest, 'license') : $license));
     }
 }
开发者ID:pizarrodiego,项目名称:packager,代码行数:42,代码来源:packager.php

示例4: __construct

 public function __construct($manifest_path)
 {
     $this->package_path = dirname($manifest_path) . '/';
     $this->manifest = YAML::decode_file($manifest_path);
     $this->files = array();
     foreach ($this->manifest['sources'] as $i => $path) {
         $path = $this->package_path . $path;
         $file = file_get_contents($path);
         // yaml header
         preg_match("/\\/\\*\\s*[-]{3}(.*)[.]{3}\\s*\\*\\//s", $file, $matches);
         // this is a crappy regexp :)
         // hack to support unindented lists. hell might break loose. -- Taken from http://github.com/Guille/PluginsKit by Guillermo Rauch
         $rawYAML = preg_replace('/$([\\s]+)-/m', '$1 -', trim($matches[1]));
         $descriptor = YAML::decode($rawYAML);
         // populate / convert to array requires and provides
         if (!empty($descriptor['requires'])) {
             if (!is_array($descriptor['requires'])) {
                 $descriptor['requires'] = array($descriptor['requires']);
             }
         } else {
             $descriptor['requires'] = array();
         }
         if (!empty($descriptor['provides'])) {
             if (!is_array($descriptor['provides'])) {
                 $descriptor['provides'] = array($descriptor['provides']);
             }
         } else {
             $descriptor['provides'] = array();
         }
         if (!array_key_exists('name', $descriptor)) {
             $descriptor['name'] = basename($path, '.js');
         }
         // Strip out beginning "/" to support `requires: [/Foo, /Bar]`
         foreach ($descriptor['requires'] as $key => $require) {
             $descriptor['requires'][$key] = preg_replace('/^\\//', '', $require);
         }
         $this->files[$descriptor['name']] = array('description' => $descriptor['description'], 'requires' => $descriptor['requires'], 'provides' => $descriptor['provides'], 'source' => $file, 'path' => $path);
     }
 }
开发者ID:subtleGradient,项目名称:packager,代码行数:39,代码来源:packager.php

示例5: load_repo

 private function load_repo($name, $config)
 {
     $path = $this->find_path($config['paths']['js']);
     //grab a recursiveDirectoryIterator and process each file it finds
     $it = new RecursiveDirectoryIterator($path);
     foreach (new RecursiveIteratorIterator($it) as $filename => $file) {
         if ($file->isFile()) {
             $p = $file->getRealPath();
             $source = file_get_contents($p);
             $descriptor = array();
             // get contents of first comment
             preg_match('/\\s*\\/\\*\\s*(.*?)\\s*\\*\\//s', $source, $matches);
             if (!empty($matches)) {
                 //echo "<br>Got contents of first comment.";
                 // get contents of YAML front matter
                 preg_match('/^-{3}\\s*$(.*?)^(?:-{3}|\\.{3})\\s*$/ms', $matches[1], $matches);
                 if (!empty($matches)) {
                     $descriptor = YAML::decode($matches[1]);
                 }
             }
             // populate / convert to array requires and provides
             $requires = (array) (!empty($descriptor['requires']) ? $descriptor['requires'] : array());
             $provides = (array) (!empty($descriptor['provides']) ? $descriptor['provides'] : array());
             $optional = (array) (!empty($descriptor['optional']) ? $descriptor['optional'] : array());
             $file_name = $file->getFilename();
             // "normalization" for requires. Fills up the default package name from requires, if not present.
             // and removes any version information
             foreach ($requires as $i => $require) {
                 $requires[$i] = implode('/', $this->parse_name($name, $require));
             }
             //do same for any optional ones...
             foreach ($optional as $i => $require) {
                 $optional[$i] = implode('/', $this->parse_name($name, $require));
             }
             $this->repos[$name][$file_name] = array_merge($descriptor, array('repo' => $name, 'requires' => $requires, 'provides' => $provides, 'optional' => $optional, 'path' => $p));
         }
     }
 }
开发者ID:jonlb,项目名称:jxLoader,代码行数:38,代码来源:loader.class.php

示例6: parse_manifest

 private function parse_manifest($path)
 {
     $pathinfo = pathinfo($path);
     if (is_dir($path)) {
         $package_path = $pathinfo['dirname'] . '/' . $pathinfo['basename'] . '/';
         if (file_exists($package_path . 'package.yml')) {
             $manifest_path = $package_path . 'package.yml';
             $manifest_format = 'yaml';
         } else {
             if (file_exists($package_path . 'package.yaml')) {
                 $manifest_path = $package_path . 'package.yaml';
                 $manifest_format = 'yaml';
             } else {
                 if (file_exists($package_path . 'package.json')) {
                     $manifest_path = $package_path . 'package.json';
                     $manifest_format = 'json';
                 }
             }
         }
     } else {
         if (file_exists($path)) {
             $package_path = $pathinfo['dirname'] . '/';
             $manifest_path = $package_path . $pathinfo['basename'];
             $manifest_format = $pathinfo['extension'];
         }
     }
     if ($manifest_format == 'json') {
         $manifest = json_decode(file_get_contents($manifest_path), true);
     } else {
         if ($manifest_format == 'yaml' || $manifest_format == 'yml') {
             $manifest = YAML::decode_file($manifest_path);
         }
     }
     if (empty($manifest)) {
         throw new Exception("manifest not found in {$package_path}, or unable to parse manifest.");
     }
     $package_name = $manifest['name'];
     if ($this->root == null) {
         $this->root = $package_name;
     }
     if (array_has($this->manifests, $package_name)) {
         return;
     }
     $manifest['path'] = $package_path;
     $manifest['manifest'] = $manifest_path;
     $this->manifests[$package_name] = $manifest;
     foreach ($manifest['sources'] as $i => $path) {
         $path = $package_path . $path;
         // this is where we "hook" for possible other replacers.
         $source = file_get_contents($path);
         $descriptor = array();
         // get contents of first comment
         preg_match('/\\/\\*\\s*^---(.*?)^\\.\\.\\.\\s*\\*\\//ms', $source, $matches);
         if (!empty($matches)) {
             $descriptor = YAML::decode($matches[0]);
         }
         // populate / convert to array requires and provides
         $requires = (array) (!empty($descriptor['requires']) ? $descriptor['requires'] : array());
         $provides = (array) (!empty($descriptor['provides']) ? $descriptor['provides'] : array());
         $file_name = !empty($descriptor['name']) ? $descriptor['name'] : basename($path, '.js');
         // "normalization" for requires. Fills up the default package name from requires, if not present.
         foreach ($requires as $i => $require) {
             $requires[$i] = implode('/', $this->parse_name($package_name, $require));
         }
         $license = array_get($descriptor, 'license');
         $this->packages[$package_name][$file_name] = array_merge($descriptor, array('package' => $package_name, 'requires' => $requires, 'provides' => $provides, 'source' => $source, 'path' => $path, 'package/name' => $package_name . '/' . $file_name, 'license' => empty($license) ? array_get($manifest, 'license') : $license));
     }
 }
开发者ID:joeke,项目名称:modx-minify,代码行数:68,代码来源:packager.php

示例7: dirname

<?php

$demo = false;
if (isset($_GET['demo'])) {
    $demo = $_GET['demo'];
    // check if the demo is valid
    if (strpos($demo, '/') !== false || !is_dir(dirname(__FILE__) . '/demos/' . $demo)) {
        $demo = false;
    } else {
        include dirname(__FILE__) . '/libs/yaml.php';
        $path = dirname(__FILE__) . '/demos/' . $_GET['demo'] . '/';
        $details = file_get_contents($path . 'demo.details');
        preg_match('/\\/\\*\\s*^---(.*?)^\\.\\.\\.\\s*\\*\\/(.*)/ms', $details, $matches);
        $descriptor = array();
        if (!empty($matches)) {
            $descriptor = YAML::decode($matches[1]);
            $description = $matches[2];
        }
        $html = file_get_contents($path . 'demo.html');
        $css = file_get_contents($path . 'demo.css');
        $js = file_get_contents($path . 'demo.js');
        // Fix links for Request, so they both work here and on jsfiddle
        $html_demo = preg_replace('/\\/echo\\/(html|json)\\//', 'Request.php', $html);
        $js_demo = preg_replace('/\\/echo\\/(html|json)\\//', 'Request.php', $js);
    }
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
开发者ID:GerHobbelt,项目名称:mootools-demos,代码行数:31,代码来源:index.php


注:本文中的YAML::decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。