load() public method

public load ( $filePath )
Ejemplo n.º 1
0
 /**
  * @covers Xoops\Core\Yaml::dump
  * @covers Xoops\Core\Yaml::load
  */
 public function testDumpAndLoad()
 {
     $inputArray = array('one' => 1, 'two' => array(1, 2), 'three' => '');
     $string = Yaml::dump($inputArray);
     $this->assertTrue(!empty($string));
     $this->assertTrue(is_string($string));
     $outputArray = Yaml::load((string) $string);
     $this->assertTrue(is_array($outputArray));
     $this->assertSame($inputArray, $outputArray);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * Loads configuration from given directory
  *
  * @param $dir
  * @return Config
  */
 static function load($dir)
 {
     $config = Yaml::load($dir . "/" . self::MAIN_YAML_FILE);
     $config['base_directory'] = $dir;
     return new Config($config);
 }
Ejemplo n.º 4
0
<?php

#
#    S P Y C
#      a simple php yaml class
#
# license: [MIT License, http://www.opensource.org/licenses/mit-license.php]
#
include '../../Yaml.php';
$yaml = new Yaml();
$array = $yaml->load('../Fixtures/sample.yaml');
echo '<pre><a href="../Fixtures/sample.yaml">sample.yaml</a> loaded into PHP:<br/>';
print_r($array);
echo '</pre>';
echo '<pre>YAML Data dumped back:<br/>';
echo $yaml->dump($array);
echo '</pre>';