Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ***********************************************************************
Inheritance: extends Lib
コード例 #1
0
ファイル: YamlTest.php プロジェクト: raphhh/balloon
 public function testWrite()
 {
     $data = [['key1' => 'value1'], ['key2' => 'value2']];
     $fileReader = new DummyFileReader();
     $yaml = new Yaml($fileReader, new Parser(), new Dumper(), 2);
     $yaml->write($data);
     $this->assertSame("-\n    key1: value1\n-\n    key2: value2\n", $fileReader->read());
 }
コード例 #2
0
 public function testMergeImports()
 {
     $app = new \Slim\Slim();
     $data = array('item-a' => 'Item A', 'item-1' => 'Item 1', 'item-2' => 'Item 2', 'item-3' => 'Item 3');
     Yaml::_()->addFile(dirname(__FILE__) . '/fixtures/merge1.yml');
     $this->assertEquals($data, $app->config('items'));
 }
コード例 #3
0
ファイル: Port.php プロジェクト: rgigger/zinc
 public static function import($datafile)
 {
     db('import')->echoOn();
     db('import')->beginTransaction();
     $data = Yaml::read($datafile);
     $schema = $data['schema'];
     $tables = $data['data'];
     $automap = array();
     foreach ($tables as $tableName => $rows) {
         foreach ($rows as $row) {
             $values = array();
             foreach ($row as $fieldName => $fieldValue) {
                 if (!isset($schema[$tableName]['auto']) || !in_array($fieldName, $schema[$tableName]['auto'])) {
                     $values[$fieldName] = $fieldValue;
                 }
             }
             if (isset($schema[$tableName]['refs'])) {
                 foreach ($schema[$tableName]['refs'] as $fieldName => $referee) {
                     $values[$fieldName] = $automap[$referee[0]][$referee[1]][$row[$fieldName]];
                 }
             }
             $id = db('import')->insertArray($tableName, $values);
             if (isset($row['id'])) {
                 $automap[$tableName]['id'][$row['id']] = $id;
             }
         }
     }
     db('import')->rollbackTransaction();
 }
コード例 #4
0
 public function testEscapedParameters()
 {
     $app = new \Slim\Slim();
     $data = array('%Item 1%', 'Item 2', 'Item 3');
     Yaml::_()->addParameters(array('item2' => 'Item 2'))->addFile(dirname(__FILE__) . '/fixtures/escape.yml');
     $this->assertEquals($data, $app->config('items'));
 }
コード例 #5
0
ファイル: Yaml.php プロジェクト: nagyist/NursingRecord
 /**
  * Sets the YAML specification version to use.
  *
  * @param string $version The YAML specification version
  */
 function setSpecVersion($version)
 {
     if (!in_array($version, array('1.1', '1.2'))) {
         throw new InvalidArgumentException(sprintf('Version %s of the YAML specifications is not supported', $version));
     }
     self::$spec = $version;
 }
コード例 #6
0
ファイル: Post.php プロジェクト: zrosiak/fields
 public function afterFetch()
 {
     // dodawanie pól json
     if (empty($this->template_id) === false) {
         $jsonable = Cache::get("template{$this->template_id}_jsonable", function () {
             $jsonable = [];
             foreach ($this->template->field->toArray() as $key => $value) {
                 $code = \Yaml::parse($value['code']);
                 if (isset($code['jsonable']) && $code['jsonable'] == true) {
                     $jsonable[] = $value['name'];
                 }
             }
             Cache::put("template{$this->template_id}_jsonable", $jsonable, 3);
             return $jsonable;
         });
         foreach ($jsonable as $value) {
             $this->jsonable[] = $value;
         }
     }
     if (empty($this->additional) === false) {
         // wstrzykiwanie wartości pól do modelu
         foreach ($this->additional as $key => $value) {
             $this->{$key} = in_array($key, $this->jsonable) ? json_decode($value) : $value;
         }
     }
 }
コード例 #7
0
ファイル: Cache.php プロジェクト: stopsopa/utils
 public static function getConfig($key = null)
 {
     if (!static::$config) {
         $file = static::getConfigJson();
         if (!file_exists($file)) {
             file_put_contents($file, json_encode(Yaml::parse(static::getConfigYml())));
         }
         static::$config = json_decode(file_get_contents($file), true);
         static::_bindConfig(self::$config);
         static::_bindConfig(self::$config);
     }
     if (!$key) {
         return static::$config;
     }
     if (array_key_exists($key, static::$config)) {
         return static::$config[$key];
     }
     if (strpos($key, '.') !== false) {
         $parts = explode('.', $key, 2);
         $data = static::getConfig($parts[0]);
         $data = UtilArray::cascadeGet($data, $parts[1]);
         if ($data) {
             return $data;
         }
     }
     throw new Exception("Config '{$key}' not found");
 }
コード例 #8
0
ファイル: Config.php プロジェクト: laiello/zoop
 public static function insist($file, $prefix = NULL)
 {
     if ($prefix) {
         $root =& self::getReference($prefix);
     } else {
         $root =& self::$info;
     }
     $root = self::mergeArray($root, Yaml::read($file), false);
 }
コード例 #9
0
ファイル: Config.php プロジェクト: rgigger/zinc
 public static function insist($file, $prefix = NULL)
 {
     // echo "inisting: $file<br>";
     if ($prefix) {
         $root =& self::getReference($prefix);
     } else {
         $root =& self::$info;
     }
     $root = self::mergeArray($root, Yaml::read($file));
 }
コード例 #10
0
 /**
  * Load and return the feed_language dropdown options
  *
  * @return array
  */
 public function getFeedLanguageOptions()
 {
     $pluginPath = PluginManager::instance()->getPluginPath(Plugin::KODERHUT_RSSFEEDSTER_NS);
     $path = $pluginPath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'language_codes.yaml';
     if (!File::exists($path)) {
         return [];
     }
     $languages = YamlParser::parseFile($path);
     $languages = is_array($languages) ? array_flip($languages) : [];
     return $languages;
 }
コード例 #11
0
 /**
  * Loads the routes of a bundle.
  *
  * @param string $name Bundle name
  *
  * @return bool
  */
 public function loadBundleRoutes($name)
 {
     $routes_path = BUNDLE . $name . '/routing.yml';
     if (file_exists($routes_path)) {
         $content = file_get_contents($routes_path);
         $this->bundle_routes = Yaml::parse($content);
         return true;
     } else {
         return false;
     }
 }
コード例 #12
0
ファイル: Json.php プロジェクト: tany/php-note
 public static function bsonSerialize(&$item, $key)
 {
     if (!is_string($item)) {
         return;
     }
     if (!preg_match('/^\\!<([^>]+?)> (.+)$/', $item, $m)) {
         return;
     }
     if ($serialized = Yaml::bsonSerialize($m[2], $m[1], 1)) {
         $item = $serialized;
     }
 }
コード例 #13
0
ファイル: YamlTest.php プロジェクト: RanLee/XoopsCore
 /**
  * @covers Xoops\Core\Yaml::saveWrapped
  * @covers Xoops\Core\Yaml::readWrapped
  */
 public function testSaveAndReadWrapped()
 {
     $tmpfname = tempnam(sys_get_temp_dir(), 'TEST');
     $inputArray = array('one' => 1, 'two' => array(1, 2), 'three' => '');
     $byteCount = Yaml::saveWrapped($inputArray, $tmpfname);
     $this->assertFalse($byteCount === false);
     $this->assertGreaterThan(0, $byteCount);
     $outputArray = Yaml::readWrapped($tmpfname);
     $this->assertTrue(is_array($outputArray));
     $this->assertSame($inputArray, $outputArray);
     unlink($tmpfname);
 }
コード例 #14
0
 /**
  * Parses a YAML file or string
  * @param string $input The YAML file path or YAML string
  * @param bool $isString Switch to true for string input instead of file
  * @return array
  * @throws \InvalidArgumentException when config cannot be parsed
  */
 public static function fromYaml($input, $isString = false)
 {
     $contents = $isString ? $input : file_get_contents($input);
     $yaml = Yaml::parse(trim($contents));
     if (null === $yaml) {
         // empty file
         $yaml = [];
     }
     if (!is_array($yaml)) {
         // not an array
         throw new \InvalidArgumentException(sprintf('The input "%s" must ' . 'contain or be a valid YAML structure.', $input));
     }
     return $yaml;
 }
コード例 #15
0
ファイル: Plugins.php プロジェクト: cv0/fansoro
 /**
  * Constructor.
  *
  * @access  protected
  */
 protected function __construct()
 {
     $plugins_cache_id = '';
     $plugin_manifest = [];
     $plugin_settings = [];
     // Get Plugins List
     $plugins_list = Config::get('system.plugins');
     // If Plugins List isnt empty then create plugin cache ID
     if (is_array($plugins_list) && count($plugins_list) > 0) {
         // Go through...
         foreach ($plugins_list as $plugin) {
             if (File::exists($_plugin = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
                 $plugins_cache_id .= filemtime($_plugin);
             }
         }
         // Create Unique Cache ID for Plugins
         $plugins_cache_id = md5('plugins' . ROOT_DIR . PLUGINS_PATH . $plugins_cache_id);
     }
     // Get plugins list from cache or scan plugins folder and create new plugins cache item
     if (Cache::driver()->contains($plugins_cache_id)) {
         Config::set('plugins', Cache::driver()->fetch($plugins_cache_id));
     } else {
         // If Plugins List isnt empty
         if (is_array($plugins_list) && count($plugins_list) > 0) {
             // Go through...
             foreach ($plugins_list as $plugin) {
                 if (File::exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
                     $plugin_manifest = Yaml::parseFile($_plugin_manifest);
                 }
                 if (File::exists($_plugin_settings = PLUGINS_PATH . '/' . $plugin . '/settings.yml')) {
                     $plugin_settings = Yaml::parseFile($_plugin_settings);
                 }
                 $_plugins_config[File::name($_plugin_manifest)] = array_merge($plugin_manifest, $plugin_settings);
             }
             Config::set('plugins', $_plugins_config);
             Cache::driver()->save($plugins_cache_id, $_plugins_config);
         }
     }
     // Include enabled plugins
     if (is_array(Config::get('plugins')) && count(Config::get('plugins')) > 0) {
         foreach (Config::get('plugins') as $plugin_name => $plugin) {
             if (Config::get('plugins.' . $plugin_name . '.enabled')) {
                 include_once PLUGINS_PATH . '/' . $plugin_name . '/' . $plugin_name . '.php';
             }
         }
     }
     // Run Actions on plugins_loaded
     Action::run('plugins_loaded');
 }
コード例 #16
0
ファイル: YamlLoader.php プロジェクト: innmind/rest-server
 /**
  * {@inheritdoc}
  */
 public function load(SetInterface $files) : MapInterface
 {
     if ((string) $files->type() !== 'string') {
         throw new InvalidArgumentException();
     }
     $config = (new Processor())->processConfiguration(new Configuration(), $files->reduce([], function (array $carry, string $file) {
         $carry[] = Yaml::parse(file_get_contents($file));
         return $carry;
     }));
     $directories = new Map('string', Directory::class);
     foreach ($config as $key => $value) {
         $directories = $directories->put($key, $this->loadDirectory($key, $value));
     }
     return $directories;
 }
コード例 #17
0
ファイル: spark_spec.php プロジェクト: souparno/getsparks.org
 /**
  * Load a spark spec file and tries to validate it
  * @param string $filepath
  * @throws SpecValidationException
  * @return Spark_spec
  */
 public static function loadFromDirectory($filepath)
 {
     $spec = array();
     $filepath = rtrim($filepath, '/') . '/';
     $filename = 'spark.info';
     $specfile = $filepath . $filename;
     /* Check that the spark file exists */
     if (!file_exists($specfile)) {
         throw new SpecValidationException("The '{$filename}' does not exist in the spark's root: See http://getsparks.org/spec-format");
     }
     /* Load it, it should have a $spec setup inside it */
     $spec = Yaml::parse_file($specfile);
     if (!is_array($spec)) {
         throw new SpecValidationException("The '{$filename}' does not contain valid spec information: See http://getsparks.org/spec-format");
     }
     /* Create a spec instance */
     $spark = new self();
     $spark->_specFile = $specfile;
     $spark->_sparkPath = $filepath;
     /* Check for each individual component and load it */
     if (!array_key_exists('name', $spec)) {
         throw new SpecValidationException("The spec does not contain a spec name: {$filename}");
     }
     $spark->name = $spec['name'];
     if (!array_key_exists('version', $spec)) {
         throw new SpecValidationException("The spec does not contain a spec version: {$filename}");
     }
     $spark->version = $spec['version'];
     if (!array_key_exists('compatibility', $spec)) {
         throw new SpecValidationException("The spec does not contain a compatibility (tested up until): {$filename}");
     }
     $spark->compatibility = $spec['compatibility'];
     if (!array_key_exists('dependencies', $spec)) {
         $spark->dependencies = array();
     } else {
         $spark->dependencies = $spec['dependencies'];
     }
     if (!array_key_exists('tags', $spec)) {
         $spark->tags = array();
     } else {
         $spark->tags = $spec['tags'];
     }
     $spark->validate();
     return $spark;
 }
コード例 #18
0
ファイル: Loader.php プロジェクト: mheydt/scalr
 /**
  * Re-reads config and refreshes cache.
  *
  * @return  Yaml
  * @throws  Exception\LoaderException
  */
 protected function refreshCache()
 {
     $ext = new Extension();
     $ext->load();
     try {
         $yaml = Yaml::load(self::YAML_FILE);
     } catch (\Exception $e) {
         throw new Exception\LoaderException(sprintf('Could not load config. %s', $e->getMessage()));
     }
     $refSet = new \ReflectionMethod($yaml, 'set');
     $refSet->setAccessible(true);
     $before = clone $yaml;
     foreach ($ext as $key => $obj) {
         if (property_exists($obj, 'default') && (!$yaml->defined($key) || $yaml($key) === null)) {
             //Set defaults only in the case it is provided in the Extension.
             //Set defaults only if they are not overriden in config and not null.
             $refSet->invoke($yaml, $key, $obj->default);
         }
         //Checks if at least one from all parents is not required.
         $token = $key;
         while (strpos($token, '.')) {
             $token = preg_replace('/\\.[^\\.]+$/', '', $token);
             //Parent bag is not required
             if (!$ext->defined($token)) {
                 //And it is not defined in config
                 if (!$before->defined($token)) {
                     continue 2;
                 } else {
                     //check presence of nodes if it is defined in config
                     break;
                 }
             }
         }
         if (!$yaml->defined($key)) {
             //If, after all, value has not been defined in the Extension, it is considered as user error.
             throw new Exception\LoaderException(sprintf('Parameter "%s" must be defined in the config', $key));
         }
     }
     unset($before);
     //serialize yaml
     file_put_contents(self::YAML_CACHE_FILE, serialize($yaml));
     @chmod(self::YAML_CACHE_FILE, 0666);
     return $yaml;
 }
コード例 #19
0
ファイル: Template.php プロジェクト: xamedow/bqs-site
 /**
  * Template factory
  *
  *  <code>
  *      $template = Template::factory('templates_path');
  *  </code>
  *
  * @param string|Fenom\ProviderInterface $source path to templates or custom provider
  * @param string $compile_dir path to compiled files
  * @param int|array $options
  * @throws InvalidArgumentException
  * @return Fenom
  */
 public static function factory($source, $compile_dir = '/tmp', $options = 0)
 {
     // Create fenom cache directory if its not exists
     !Dir::exists(CACHE_PATH . '/fenom/') and Dir::create(CACHE_PATH . '/fenom/');
     // Create Unique Cache ID for Theme
     $theme_config_file = THEMES_PATH . '/' . Config::get('system.theme') . '/' . Config::get('system.theme') . '.yml';
     $theme_cache_id = md5('theme' . ROOT_DIR . $theme_config_file . filemtime($theme_config_file));
     // Set current them options
     if (Cache::driver()->contains($theme_cache_id)) {
         Config::set('theme', Cache::driver()->fetch($theme_cache_id));
     } else {
         $theme_config = Yaml::parseFile($theme_config_file);
         Config::set('theme', $theme_config);
         Cache::driver()->save($theme_cache_id, $theme_config);
     }
     $compile_dir = CACHE_PATH . '/fenom/';
     $options = Config::get('system.fenom');
     $fenom = parent::factory($source, $compile_dir, $options);
     $fenom->assign('config', Config::getConfig());
     return $fenom;
 }
コード例 #20
0
 /**
  * Opens a translation file, and stores its content.
  *
  * @param string $file_path The path of the file to open
  */
 private function openFile($file_path, $stop = false)
 {
     if (file_exists($file_path)) {
         $this->file_content = Yaml::parse(file_get_contents($file_path));
         if (!empty($this->file_content)) {
             $this->file_path = $file_path;
         }
         return true;
     } else {
         if (ENVIRONMENT == 'production') {
             $this->file_content = '';
             return true;
         } else {
             if ($stop == false) {
                 $this->setVar('file_path', $file_path);
                 App::translate("translation_file_missing", $this, ['bundle' => false, 'theme' => 'sybil', 'domain' => 'debug'], true);
                 die;
             } else {
                 App::debug('[TRANSLATION_ERROR: File "' . $file_path . '" is missing.]');
                 die;
             }
         }
     }
 }
コード例 #21
0
ファイル: Config.php プロジェクト: xamedow/bqs-site
 /**
  * Constructor.
  *
  * @access  protected
  */
 protected function __construct()
 {
     static::$config['site'] = Yaml::parseFile(CONFIG_PATH . '/' . 'site.yml');
     static::$config['system'] = Yaml::parseFile(CONFIG_PATH . '/' . 'system.yml');
 }
コード例 #22
0
ファイル: Config.php プロジェクト: rgigger/zoopframework
 public static function insist($file, $prefix = NULL)
 {
     $root = $prefix ? self::getReference($prefix) : self::$info;
     self::$info = self::mergeArray($root, Yaml::read($file));
 }
コード例 #23
0
 function _startMigration($id, $direction)
 {
     $migration = $this->migrations[$id];
     if ($migration['format'] == 'yml') {
         $yml = $this->_parsePhp(MIGRATIONS_PATH . DS . $migration['filename']);
         $array = Yaml::Load($yml);
         if (!is_array($array)) {
             return "Unable to parse YAML Migration file";
         }
         $direction = strtoupper($direction);
     } else {
         include MIGRATIONS_PATH . DS . $migration['filename'];
         $array = $migration;
         unset($migration);
     }
     if (!$array[$direction]) {
         return "Direction does not exist!";
     }
     return $this->_array2Sql($array[$direction]);
 }
コード例 #24
0
ファイル: PageFields.php プロジェクト: bauwils/jacobhair
 /**
  * [getFields description]
  *
  * @param  [string] $filename The template name
  *
  * @return [type]           [description]
  */
 private function getFields($filename)
 {
     $fields = [];
     $fullPath = $this->getDir() . 'forms/' . $filename . '.yaml';
     if (file_exists($fullPath)) {
         $fields = \Yaml::parseFile($fullPath);
     }
     $defaultFieldsPath = $this->getDir() . 'forms/_default.yaml';
     if (file_exists($defaultFieldsPath)) {
         $defaultFields = \Yaml::parseFile();
         foreach ($defaultFields['fields'] as $name => $field) {
             $fields['fields'][$name] = $field;
         }
     }
     return $fields;
 }
コード例 #25
0
ファイル: Pages.php プロジェクト: cv0/fansoro
 /**
  * Get page
  *
  *  <code>
  *      $page = Pages::getPage('downloads');
  *  </code>
  *
  * @access  public
  * @param  string $url Url
  * @return array
  */
 public static function getPage($url)
 {
     // If url is empty that its a homepage
     if ($url) {
         $file = STORAGE_PATH . '/pages/' . $url;
     } else {
         $file = STORAGE_PATH . '/pages/' . 'index';
     }
     // Select the file
     if (is_dir($file)) {
         $file = STORAGE_PATH . '/pages/' . $url . '/index.md';
     } else {
         $file .= '.md';
     }
     // Get 404 page if file not exists
     if (!file_exists($file)) {
         $file = STORAGE_PATH . '/pages/' . '404.md';
         Response::status(404);
     }
     // Create Unique Cache ID for requested page
     $page_cache_id = md5('page' . ROOT_DIR . $file . filemtime($file));
     if (Cache::driver()->contains($page_cache_id) && Config::get('system.pages.flush_cache') == false) {
         return Cache::driver()->fetch($page_cache_id);
     } else {
         $content = file_get_contents($file);
         $_page = explode('---', $content, 3);
         $page = Yaml::parse($_page[1]);
         $url = str_replace(STORAGE_PATH . '/pages', Url::getBase(), $file);
         $url = str_replace('index.md', '', $url);
         $url = str_replace('.md', '', $url);
         $url = str_replace('\\', '/', $url);
         $url = rtrim($url, '/');
         $page['url'] = $url;
         $_content = $_page[2];
         // Parse page for summary <!--more-->
         if (($pos = strpos($_content, "<!--more-->")) === false) {
             $_content = Filter::apply('content', $_content);
         } else {
             $_content = explode("<!--more-->", $_content);
             $_content['summary'] = Filter::apply('content', $_content[0]);
             $_content['content'] = Filter::apply('content', $_content[0] . $_content[1]);
         }
         if (is_array($_content)) {
             $page['summary'] = $_content['summary'];
             $page['content'] = $_content['content'];
         } else {
             $page['content'] = $_content;
         }
         $page['slug'] = basename($file, '.md');
         // Overload page title, keywords and description if needed
         empty($page['title']) and $page['title'] = Config::get('site.title');
         empty($page['keywords']) and $page['keywords'] = Config::get('site.keywords');
         empty($page['description']) and $page['description'] = Config::get('site.description');
         Cache::driver()->save($page_cache_id, $page);
         return $page;
     }
 }
コード例 #26
0
ファイル: Inline.php プロジェクト: bill97420/symfony
 /**
  * Evaluates scalars and replaces magic values.
  *
  * @param string $scalar
  *
  * @return string A YAML string
  */
 protected static function evaluateScalar($scalar)
 {
     $scalar = trim($scalar);
     $trueValues = '1.1' == Yaml::getSpecVersion() ? array('true', 'on', '+', 'yes', 'y') : array('true');
     $falseValues = '1.1' == Yaml::getSpecVersion() ? array('false', 'off', '-', 'no', 'n') : array('false');
     switch (true) {
         case 'null' == strtolower($scalar):
         case '' == $scalar:
         case '~' == $scalar:
             return null;
         case 0 === strpos($scalar, '!str'):
             return (string) substr($scalar, 5);
         case 0 === strpos($scalar, '! '):
             return intval(self::parseScalar(substr($scalar, 2)));
         case 0 === strpos($scalar, '!!php/object:'):
             return unserialize(substr($scalar, 13));
         case ctype_digit($scalar):
             $raw = $scalar;
             $cast = intval($scalar);
             return '0' == $scalar[0] ? octdec($scalar) : ((string) $raw == (string) $cast ? $cast : $raw);
         case in_array(strtolower($scalar), $trueValues):
             return true;
         case in_array(strtolower($scalar), $falseValues):
             return false;
         case is_numeric($scalar):
             return '0x' == $scalar[0] . $scalar[1] ? hexdec($scalar) : floatval($scalar);
         case 0 == strcasecmp($scalar, '.inf'):
         case 0 == strcasecmp($scalar, '.NaN'):
             return -log(0);
         case 0 == strcasecmp($scalar, '-.inf'):
             return log(0);
         case preg_match('/^(-|\\+)?[0-9,]+(\\.[0-9]+)?$/', $scalar):
             return floatval(str_replace(',', '', $scalar));
         case preg_match(self::getTimestampRegex(), $scalar):
             return strtotime($scalar);
         default:
             return (string) $scalar;
     }
 }
コード例 #27
0
ファイル: yaml.php プロジェクト: scalia/Vevui
 public function __construct($installation_data)
 {
     parent::__construct($installation_data);
     require SYS_PATH . '/libraries/spyc/spyc.php';
     self::$_parser = new Spyc();
 }
コード例 #28
0
ファイル: Config.php プロジェクト: getherbie/herbie
 /**
  */
 private function loadPluginFiles()
 {
     $dir = $this->sitePath . '/config/plugins';
     if (is_readable($dir)) {
         $files = scandir($dir);
         foreach ($files as $file) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             $basename = pathinfo($file, PATHINFO_FILENAME);
             $content = $this->loadFile($dir . '/' . $file);
             $this->set('plugins.config.' . $basename, Yaml::parse($content));
         }
     }
 }
コード例 #29
0
ファイル: hooks.raven.php プロジェクト: jeffreyDcreative/gkp
 /**
  * Save submission to file
  *
  * @param array  $data  Array of values to store
  * @param array  $config  Array of configuration values
  * @param string  $location  Path to folder where submissions should be saved
  * @param string  $prefix  Filename prefix to use for submission file
  * @param string  $suffix  Filename suffix to use for submission file
  * @return void
  */
 private function save($data, $config, $location, $is_spam = false)
 {
     if (array_get($this->config, 'master_killswitch')) {
         return;
     }
     $EXT = array_get($config, 'submission_save_extension', 'yaml');
     // Clean up whitespace
     array_walk_recursive($data, function (&$value, $key) {
         $value = trim($value);
     });
     if (!File::exists($location)) {
         Folder::make($location);
     }
     if ($format = array_get($config, 'filename_format')) {
         $now = time();
         $time_variables = array('year' => date('Y', $now), 'month' => date('m', $now), 'day' => date('d', $now), 'hour' => date('G', $now), 'minute' => date('i', $now), 'minutes' => date('i', $now), 'second' => date('s', $now), 'seconds' => date('s', $now));
         $available_variables = $time_variables + $data;
         $filename = Parse::template($format, $available_variables);
     } else {
         $filename = date('Y-m-d-Gi-s', time());
     }
     if ($is_spam) {
         $location = $location . 'spam/';
         Folder::make($location);
     }
     // Put it in the right folder
     $filename = $location . $filename;
     // Ensure a unique filename in the event two forms are submitted in the same second
     if (File::exists($filename . '.' . $EXT)) {
         for ($i = 1; $i < 60; $i++) {
             if (!file_exists($filename . '-' . $i . '.' . $EXT)) {
                 $filename = $filename . '-' . $i;
                 break;
             }
         }
     }
     $filename .= '.' . $EXT;
     if ($EXT === 'json') {
         File::put($filename, json_encode($data));
     } else {
         File::put($filename, Yaml::dump($data) . '---');
     }
 }
コード例 #30
-1
 public function testAddFile()
 {
     $app = new \Slim\Slim();
     $data = array('item1', 'item2');
     Yaml::_()->addFile(dirname(__FILE__) . '/fixtures/index.yml');
     $this->assertEquals($data, $app->config('items'));
 }