Author: Kevin Hutchinson (kevin@guanoo.com)
Inheritance: extends YAWF
示例#1
0
文件: YAMLTest.php 项目: gekt/www
 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));
 }
 public function control_panel__add_routes()
 {
     $app = \Slim\Slim::getInstance();
     $app->get('/globes', function () use($app) {
         authenticateForRole('admin');
         doStatamicVersionCheck($app);
         Statamic_View::set_templates(array('globes-overview'), __DIR__ . '/templates');
         $data = $this->tasks->getThemeSettings();
         $app->render(null, array('route' => 'globes', 'app' => $app) + $data);
     })->name('globes');
     // Update global vars
     $app->post('/globes/update', function () use($app) {
         authenticateForRole('admin');
         doStatamicVersionCheck($app);
         $data = $this->tasks->getThemeSettings();
         $vars = Request::fetch('pageglobals');
         foreach ($vars as $name => $var) {
             foreach ($data['globals'] as $key => $item) {
                 if ($item['name'] === $name) {
                     $data['globals'][$key]['value'] = $var;
                 }
             }
         }
         File::put($this->tasks->getThemeSettingsPath(), YAML::dump($data, 1));
         $app->flash('success', Localization::fetch('update_success'));
         $app->redirect($app->urlFor('globes'));
     });
 }
示例#3
0
文件: localization.php 项目: nob/joi
 /**
  * Fetch an L10n content string
  *
  * @param $key      string  YAML key of the desired text string
  * @param $language string  Optionally override the desired language
  * @return mixed
  */
 public static function fetch($key, $language = null, $lower = false)
 {
     $app = \Slim\Slim::getInstance();
     $language = $language ? $language : Config::getCurrentLanguage();
     $value = $key;
     /*
     |--------------------------------------------------------------------------
     | Check for new language
     |--------------------------------------------------------------------------
     |
     | English is loaded by default. If requesting a language not already
     | cached, go grab it.
     |
     */
     if (!isset($app->config['_translations'][$language])) {
         $app->config['_translations'][$language] = YAML::parse(Config::getTranslation($language));
     }
     /*
     |--------------------------------------------------------------------------
     | Resolve translation
     |--------------------------------------------------------------------------
     |
     | If the set language is found and the key exists, return it. Falls back to
     | English, and then falls back to the slug-style key itself.
     |
     */
     if (array_get($app->config['_translations'][$language]['translations'], $value, false)) {
         $value = array_get($app->config['_translations'][$language]['translations'], $value);
     } else {
         $value = array_get($app->config['_translations']['en']['translations'], $value, $value);
     }
     return $lower ? strtolower($value) : $value;
 }
示例#4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $method = $input->getOption('method');
     switch ($method) {
         case 'drush':
             $alias = $input->getOption('alias');
             if (empty($alias)) {
                 throw new RuntimeException("You must supply a valid Drush alias using the --alias argument.");
             }
             if ($alias[0] != '@') {
                 throw new RuntimeException("Invalid alias \"{$alas}\".");
             }
             $config = array('fetch-method' => $method, 'fetch-alias' => $alias);
             break;
         case 'dump-n-config':
             $config = array('fetch-method' => $method, 'fetch-dumpfile' => $input->getOption('dumpfile'), 'fetch-staging' => $input->getOption('staging'));
             break;
         default:
             throw new RuntimeException("Unknown fetching method \"{$method}\".");
     }
     $fileName = 'tests/proctor/drupal.yml';
     $dirName = dirname($fileName);
     if (!file_exists($dirName) && !mkdir($dirName, 0777, true)) {
         throw new RuntimeException("Could not create {$dirName}", 1);
     }
     $config = YAML::dump($config);
     if (file_put_contents($fileName, $config) === false) {
         throw new RuntimeException("Could not write {$fileName}", 1);
     }
     $output->writeln("<info>Wrote " . $fileName . "</info>");
 }
 /**
  * Singleton pattern.
  *
  * @throws Exceptions\DatacashRequestException
  */
 protected function __construct()
 {
     // Get the default configurations.
     $env_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/environment.yaml"));
     $datacash_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/datacash.yaml"));
     $datacash_config = $datacash_config[$env_config['environment']]['parameters'];
     // Set the configurations for the request.
     if (!empty($datacash_config['server_url'])) {
         $this->hostName = $datacash_config['server_url'];
     } else {
         throw new DatacashRequestException("Not set or invalid hostname.");
     }
     if (!empty($datacash_config['timeout'])) {
         $this->timeout = $datacash_config['timeout'];
     }
     if (!empty($datacash_config['datacash_network_ssl_path'])) {
         $this->sslCertPath = $datacash_config['datacash_network_ssl_path'];
         // Do not set cert SSL verifiation if we don't have a certificate.
         if (!empty($datacash_config['datacash_network_ssl_verify'])) {
             $this->sslVerify = $datacash_config['datacash_network_ssl_verify'];
         }
     } else {
         $this->sslVerify = FALSE;
     }
     // Use proxy only if proxy url is available.
     if (!empty($datacash_config['proxy_url'])) {
         $this->proxyUrl = $datacash_config['proxy_url'];
     }
 }
 public function go()
 {
     //$feed = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/_add-ons/wordpress/wp_posts.xml');
     //$items = simplexml_load_string($feed);
     $posts_object = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . '/_add-ons/wordpress/roobottom_old_posts.xml');
     $posts = object_to_array($posts_object);
     $yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/01-blog/';
     foreach ($posts['table'] as $post) {
         if ($post['column'][8] == "publish") {
             $slug = Slug::make($post['column'][5]);
             $slug = preg_replace('/[^a-z\\d]+/i', '-', $slug);
             if (substr($slug, -1) == '-') {
                 $slug = substr($slug, 0, -1);
             }
             $date = date('Y-m-d-Hi', strtotime($post['column'][3]));
             $file = $date . "-" . $slug . ".md";
             if (!File::exists($yaml_path . $file)) {
                 $yaml = [];
                 $yaml['title'] = $post['column'][5];
                 $content = $post['column'][4];
                 $markdown = new HTML_To_Markdown($content, array('header_style' => 'atx'));
                 File::put($yaml_path . $file, YAML::dump($yaml) . '---' . "\n" . $markdown);
             }
             echo $slug . "-" . $date;
             echo "<br/><hr/><br/>";
         }
     }
     return "ok";
 }
示例#7
0
 public function decode($data)
 {
     $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $data, 3);
     $yaml = parent::decode($parts[1]);
     $yaml[$this->contentFieldName] = $parts[2];
     return $yaml;
 }
 /**
  * Get datacash redirect URL for payment page.
  *
  * @return string
  */
 public function getRedirectUrl()
 {
     // Get the default configurations.
     $env_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/environment.yaml"));
     $datacash_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/datacash.yaml"));
     $datacash_config = $datacash_config[$env_config['environment']]['parameters'];
     return $datacash_config['redirect_url'] . $this->HpsTxn->session_id->getValue();
 }
 /**
  * Sets the current environment to the given $environment
  *
  * @param string  $environment  Environment to set
  * @param array  $config  Config to set to
  * @return void
  */
 public static function set($environment, &$config)
 {
     $config['environment'] = $environment;
     $config['is_' . $environment] = true;
     $environment_config = YAML::parse("_config/environments/{$environment}.yaml");
     if (is_array($environment_config)) {
         $config = array_merge($config, $environment_config);
     }
 }
示例#10
0
文件: environment.php 项目: nob/joi
 /**
  * Sets the current environment to the given $environment
  *
  * @param string  $environment  Environment to set
  * @return void
  */
 public static function set($environment)
 {
     $app = \Slim\Slim::getInstance();
     $app->config['environment'] = $environment;
     $app->config['is_' . $environment] = TRUE;
     $environment_config = YAML::parse("_config/environments/{$environment}.yaml");
     if (is_array($environment_config)) {
         $app->config = array_merge($app->config, $environment_config);
     }
 }
示例#11
0
 public static function fetch_fieldset($fieldset)
 {
     $defaults = array('fields' => array());
     if (File::exists("_config/fieldsets/{$fieldset}.yaml")) {
         $meta_raw = file_get_contents("_config/fieldsets/{$fieldset}.yaml");
         $meta = array_merge($defaults, YAML::Parse($meta_raw));
         return $meta;
     }
     return $defaults;
 }
示例#12
0
 public static function fetch($form_name)
 {
     $filename = dirname(__DIR__) . '/forms/' . $form_name . '.yaml';
     if (file_exists($filename)) {
         return YAML::parse(file_get_contents($filename));
     } else {
         $error = 'missing form: ' . $filename;
         throw new Exception($error);
     }
 }
示例#13
0
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);
}
 /**
  * Parse YAML data into an array
  * @param  {String}       the text to be parsed
  *
  * @return {Array}        the parsed content
  */
 public static function convertYAML($text)
 {
     try {
         $yaml = YAML::parse($text);
     } catch (ParseException $e) {
         printf("unable to parse documentation: %s..\n", $e->getMessage());
     }
     // single line of text won't throw a YAML error. returns as string
     if (gettype($yaml) == "string") {
         $yaml = array();
     }
     return $yaml;
 }
示例#15
0
文件: Theme.php 项目: eadz/chyrp
 /**
  * Function: __construct
  * Loads the Twig parser into <Theme>, and sets up the theme l10n domain.
  */
 private function __construct()
 {
     $config = Config::current();
     # Load the theme translator
     if (file_exists(THEME_DIR . "/locale/" . $config->locale . ".mo")) {
         load_translator("theme", THEME_DIR . "/locale/" . $config->locale . ".mo");
     }
     # Load the theme's info into the Theme class.
     foreach (YAML::load(THEME_DIR . "/info.yaml") as $key => $val) {
         $this->{$key} = $val;
     }
     $this->url = THEME_URL;
 }
示例#16
0
 public static function load($config_dir)
 {
     $config_file = $config_dir . '/elib.yml';
     if (!file_exists($config_file)) {
         die('Config error: ' . $config_file . ' does not exist');
     }
     $config = YAML::load($config_file);
     foreach ($config as $index => $item) {
         if (!is_array($item)) {
             $index = 'ELIB_' . $index;
             define(strtoupper($index), $item);
         }
     }
 }
示例#17
0
 /**
  * Returns a given user's profile
  * 
  * @param string  $username  Username's profile to return
  * @return array
  */
 public static function getUserProfile($username)
 {
     if (!UserAuth::isUser($username)) {
         return null;
     }
     $content = substr(File::get(Config::getConfigPath() . "/users/" . $username . ".yaml"), 3);
     $divide = strpos($content, "\n---");
     $front_matter = trim(substr($content, 0, $divide));
     $content_raw = trim(substr($content, $divide + 4));
     $profile = YAML::parse($front_matter);
     $profile['biography_raw'] = $content_raw;
     $profile['biography'] = Content::transform($content_raw);
     $profile['username'] = $username;
     return $profile;
 }
 public function testYAMLSerializer()
 {
     $yaml_output = $this->debtAmortizatorFactory->getSerializedResult(new YAMLSerializer());
     $yamlObject = YAML::parse($yaml_output);
     // WE WILL TEST EACH AND EVERY PROPERTY OF THIS OBJECT
     // Debt principal
     $this->assertEquals("40000", $yamlObject["debtPrincipal"]);
     // Debt number of compounding periods
     $this->assertEquals("6", $yamlObject["debtNoOfCompoundingPeriods"]);
     // Debt length period
     $this->assertEquals("1", $yamlObject["debtPeriodLength"]["years"]);
     $this->assertEquals("12", $yamlObject["debtPeriodLength"]["months"]);
     $this->assertEquals("360", $yamlObject["debtPeriodLength"]["days"]);
     // Debt interest
     $this->assertEquals("0.12", $yamlObject["debtInterest"]);
     // Debt discount factor
     $this->assertEquals("0.89", $this->round2DP($yamlObject["debtDiscountFactor"]));
     // Debt duration
     $this->assertEquals("6", $yamlObject["debtDuration"]["years"]);
     $this->assertEquals("72", $yamlObject["debtDuration"]["months"]);
     $this->assertEquals("2160", $yamlObject["debtDuration"]["days"]);
     // Debt amount of single repayment
     $INDIVIDUAL_REPAYMENT = "9729.03";
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtSingleRepayment"]));
     // Debt repayments (principal part, interest part, total = principal part + interest part)
     $this->assertEquals("4929.03", $this->round2DP($yamlObject["debtRepayments"]["1"]["principalAmount"]));
     $this->assertEquals("4800.00", $this->round2DP($yamlObject["debtRepayments"]["1"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["1"]["totalAmount"]));
     $this->assertEquals("5520.51", $this->round2DP($yamlObject["debtRepayments"]["2"]["principalAmount"]));
     $this->assertEquals("4208.52", $this->round2DP($yamlObject["debtRepayments"]["2"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["2"]["totalAmount"]));
     $this->assertEquals("6182.97", $this->round2DP($yamlObject["debtRepayments"]["3"]["principalAmount"]));
     $this->assertEquals("3546.06", $this->round2DP($yamlObject["debtRepayments"]["3"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["3"]["totalAmount"]));
     $this->assertEquals("6924.93", $this->round2DP($yamlObject["debtRepayments"]["4"]["principalAmount"]));
     $this->assertEquals("2804.10", $this->round2DP($yamlObject["debtRepayments"]["4"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["4"]["totalAmount"]));
     $this->assertEquals("7755.92", $this->round2DP($yamlObject["debtRepayments"]["5"]["principalAmount"]));
     $this->assertEquals("1973.11", $this->round2DP($yamlObject["debtRepayments"]["5"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["5"]["totalAmount"]));
     $this->assertEquals("8686.63", $this->round2DP($yamlObject["debtRepayments"]["6"]["principalAmount"]));
     $this->assertEquals("1042.4", $this->round2DP($yamlObject["debtRepayments"]["6"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["6"]["totalAmount"]));
 }
示例#19
0
 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));
     }
 }
示例#20
0
文件: Config.php 项目: hutchike/YAWF
 /**
  * Load a config file, and optionally force a file reload
  *
  * @param String $config_file the name of the config to load (excl ".yaml")
  * @param Boolean $reload whether to reload a file that's already loaded
  * @return Array the config data as an assoc array
  */
 public static function load($config_file = 'app', $reload = FALSE)
 {
     // Return a matching loaded config (unless reloading)
     if ($reload) {
         self::$configs[$config_file] = NULL;
     }
     if ($config = array_key(self::$configs, $config_file)) {
         return $config;
     }
     // Load a config file by looking in "app" and "yawf"
     $file = '/configs/' . $config_file . '.yaml';
     if (file_exists(Symbol::APP . $file)) {
         self::$configs[$config_file] = YAML::parse_file(Symbol::APP . $file);
     } elseif (file_exists(Symbol::YAWF . $file)) {
         self::$configs[$config_file] = YAML::parse_file(Symbol::YAWF . $file);
     } else {
         throw new Exception("Config file \"{$config_file}.yaml\" not found");
     }
     // Return the loaded config file as a PHP data array
     return self::$configs[$config_file];
 }
 public function run($depth, $ext, $path, $pathName, $name)
 {
     // load default vars
     $patternTypeDash = PatternData::getPatternTypeDash();
     // should this pattern get rendered?
     $hidden = $name[0] == "_";
     // set-up the names, $name == foo.json
     $pattern = str_replace("." . $ext, "", $name);
     // foo
     $patternDash = $this->getPatternName($pattern, false);
     // foo
     $patternPartial = $patternTypeDash . "-" . $patternDash;
     // atoms-foo
     if (!$hidden) {
         $patternStoreData = array("category" => "pattern");
         $file = file_get_contents(Config::getOption("patternSourceDir") . "/" . $pathName);
         if ($ext == "json") {
             $data = json_decode($file, true);
             if ($jsonErrorMessage = JSON::hasError()) {
                 JSON::lastErrorMsg($name, $jsonErrorMessage, $data);
             }
         } else {
             try {
                 $data = YAML::parse($file);
             } catch (ParseException $e) {
                 printf("unable to parse " . $pathNameClean . ": %s..\n", $e->getMessage());
             }
             // single line of text won't throw a YAML error. returns as string
             if (gettype($data) == "string") {
                 $data = array();
             }
         }
         $patternStoreData["data"] = $data;
         // create a key for the data store
         $patternStoreKey = $patternPartial;
         // if the pattern data store already exists make sure it is merged and overwrites this data
         $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData;
         PatternData::setOption($patternStoreKey, $patternStoreData);
     }
 }
示例#22
0
 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);
     }
 }
示例#23
0
 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));
         }
     }
 }
示例#24
0
 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));
     }
 }
示例#25
0
function fix_quotes()
{
    $sql = SQL::current();
    if (!($tags = $sql->select("post_attributes", array("post_id", "value"), array("name" => "tags")))) {
        return;
    }
    foreach ($tags->fetchAll() as $attr) {
        $sql->replace("post_attributes", array("post_id" => $attr["post_id"], "name" => "tags", "value" => YAML::dump(YAML::load($attr["value"]))));
    }
}
示例#26
0
 /**
  * Builds a file with YAML front-matter
  *
  * @param array  $data  Front-matter data
  * @param string  $content  Content
  * @return string
  */
 public static function buildContent(array $data, $content)
 {
     Debug::increment('content', 'files_built');
     $file_content = "---\n";
     $file_content .= preg_replace('/\\A^---\\s/ism', "", YAML::dump($data));
     $file_content .= "---\n";
     $file_content .= $content;
     return $file_content;
 }
示例#27
0
文件: hc_old.php 项目: niieani/napkin
            toFile($config, $filename);
            break;
        case 'generateAll':
            //  $result = process_dir($args[1],TRUE);
            $yamls = getAllYaml($args[1]);
            // Output each opened file and then close
            /*  foreach ($result as $file) {
                if (is_resource($file['handle'])) {
                    echo "\n\nFILE (" . $file['dirpath'].'/'.$file['filename'] . "):\n\n" . fread($file['handle'], filesize($file['dirpath'].'/'.$file['filename']));
                    fclose($file['handle']);
                }
              }*/
            //var_dump($yamls);
            foreach ($yamls as $yaml) {
                echo "\nGenerating from {$yaml}:\n";
                $config = YAML::load($yaml);
                foreach ($config['nginx.sites'] as $siteName => $siteData) {
                    echo "site {$siteName} domain is: " . $siteData['domain'] . "\n";
                }
            }
    }
}
function toFile($array, $file = "tmp.yml")
{
    $dumper = new Dumper();
    $yaml = $dumper->dump($array, 3);
    file_put_contents(__DIR__ . '/' . $file, $yaml);
}
function getAllYaml($path = '.')
{
    $Directory = new RecursiveDirectoryIterator($path);
 public function getThemeSettings()
 {
     $path = $this->getThemeSettingsPath();
     $yaml = YAML::parseFile($path);
     return $yaml;
 }
示例#29
0
文件: parse.php 项目: nob/joi
 /**
  * Parse a block of YAML into PHP
  *
  * @param string  $yaml  YAML-formatted string to parse
  * @return array
  */
 public static function yaml($yaml)
 {
     return YAML::parse($yaml);
 }
示例#30
0
文件: Admin.php 项目: eadz/chyrp
 /**
  * Function: subnav_context
  * Generates the context variables for the subnav.
  */
 public function subnav_context($action)
 {
     $trigger = Trigger::current();
     $visitor = Visitor::current();
     $this->context["subnav"] = array();
     $subnav =& $this->context["subnav"];
     $subnav["write"] = array();
     $pages = array("manage" => array());
     foreach (Config::current()->enabled_feathers as $index => $feather) {
         $info = YAML::load(FEATHERS_DIR . "/" . $feather . "/info.yaml");
         $subnav["write"]["write_post&feather=" . $feather] = array("title" => __($info["name"], $feather), "show" => $visitor->group->can("add_draft", "add_post"), "attributes" => ' id="list_feathers[' . $feather . ']"', "selected" => isset($_GET['feather']) and $_GET['feather'] == $feather or !isset($_GET['feather']) and $action == "write_post" and !$index);
     }
     # Write navs
     $subnav["write"]["write_page"] = array("title" => __("Page"), "show" => $visitor->group->can("add_page"));
     $trigger->filter($subnav["write"], array("admin_write_nav", "write_nav"));
     $pages["write"] = array_merge(array("write_post"), array_keys($subnav["write"]));
     # Manage navs
     $subnav["manage"] = array("manage_posts" => array("title" => __("Posts"), "show" => Post::any_editable() or Post::any_deletable(), "selected" => array("edit_post", "delete_post")), "manage_pages" => array("title" => __("Pages"), "show" => $visitor->group->can("edit_page", "delete_page"), "selected" => array("edit_page", "delete_page")), "manage_users" => array("title" => __("Users"), "show" => $visitor->group->can("add_user", "edit_user", "delete_user"), "selected" => array("edit_user", "delete_user", "new_user")), "manage_groups" => array("title" => __("Groups"), "show" => $visitor->group->can("add_group", "edit_group", "delete_group"), "selected" => array("edit_group", "delete_group", "new_group")));
     $trigger->filter($subnav["manage"], "manage_nav");
     $subnav["manage"]["import"] = array("title" => __("Import"), "show" => $visitor->group->can("add_post"));
     $subnav["manage"]["export"] = array("title" => __("Export"), "show" => $visitor->group->can("add_post"));
     $pages["manage"][] = "new_user";
     $pages["manage"][] = "new_group";
     foreach (array_keys($subnav["manage"]) as $manage) {
         $pages["manage"] = array_merge($pages["manage"], array($manage, preg_replace("/manage_(.+)/e", "'edit_'.depluralize('\\1')", $manage), preg_replace("/manage_(.+)/e", "'delete_'.depluralize('\\1')", $manage)));
     }
     # Settings navs
     $subnav["settings"] = array("general_settings" => array("title" => __("General"), "show" => $visitor->group->can("change_settings")), "content_settings" => array("title" => __("Content"), "show" => $visitor->group->can("change_settings")), "user_settings" => array("title" => __("Users"), "show" => $visitor->group->can("change_settings")), "route_settings" => array("title" => __("Routes"), "show" => $visitor->group->can("change_settings")));
     $trigger->filter($subnav["settings"], "settings_nav");
     $pages["settings"] = array_keys($subnav["settings"]);
     # Extend navs
     $subnav["extend"] = array("modules" => array("title" => __("Modules"), "show" => $visitor->group->can("toggle_extensions")), "feathers" => array("title" => __("Feathers"), "show" => $visitor->group->can("toggle_extensions")), "themes" => array("title" => __("Themes"), "show" => $visitor->group->can("toggle_extensions")));
     $trigger->filter($subnav["extend"], "extend_nav");
     $pages["extend"] = array_keys($subnav["extend"]);
     foreach (array_keys($subnav) as $main_nav) {
         foreach ($trigger->filter($pages[$main_nav], $main_nav . "_nav_pages") as $extend) {
             $subnav[$extend] =& $subnav[$main_nav];
         }
     }
     foreach ($subnav as $main_nav => &$sub_nav) {
         foreach ($sub_nav as &$nav) {
             $nav["show"] = (!isset($nav["show"]) or $nav["show"]);
         }
     }
     $trigger->filter($subnav, "admin_subnav");
 }