コード例 #1
0
 /**
  * sets a specific parameter
  *
  * @param $key
  * @param $val
  *
  * @return mixed
  */
 public function set(string $key, $val)
 {
     // set the variable
     if (empty($key)) {
         return $this;
     }
     $node = $this->mainNode->getLastByKey($key);
     if (!$node || !$node->getParent()) {
         $newNode = new Node($this->mainNode, $key, $val);
         $this->mainNode->addChild($newNode);
     } else {
         $newNode = new Node($node->getParent(), $key, $val);
         $node->getParent()->addChild($newNode);
     }
     $this->lastNewNode = $newNode;
     return $this;
 }
コード例 #2
0
 /**
  * @test
  */
 public function testGraphCollectionGetSpecificUnambigousChildNode()
 {
     $node1 = new Node(null, '*', null);
     $node2 = new Node(null, '.', null);
     $node1->addChild($node2);
     $collection = new Collection($node1->children->idList, $node1->children->keyList);
     $collection->addNode($node1);
     $retNode = $collection->getLastByKey('.');
     self::assertEquals($node2, $retNode);
 }
コード例 #3
0
ファイル: Ini.php プロジェクト: chilimatic/config-component
 /**
  * @param null $param
  *
  * @throws ExceptionConfig
  * @throws \Exception
  *
  * @return void
  */
 public function load($param = null)
 {
     try {
         if (empty($param[self::FILE_INDEX])) {
             throw new ExceptionConfig(_('No config file was given, please make sure one is provided in the param array'), 0, 1, __METHOD__, __LINE__);
         }
         if (is_dir($param[self::FILE_INDEX])) {
             $path = $param[self::FILE_INDEX];
             $this->configFileSet = array_map(function ($fileName) use($path) {
                 return $path . DIRECTORY_SEPARATOR . $fileName;
             }, array_filter(scandir($param[self::FILE_INDEX]), function ($file) {
                 if (strpos($file, '.ini') !== false) {
                     return true;
                 }
                 return false;
             }));
         } else {
             $this->configFileSet[] = $param[self::FILE_INDEX];
         }
         if (isset($param[self::PROCESS_SECTION_INDEX])) {
             $this->processSections = (bool) $param[self::PROCESS_SECTION_INDEX];
         }
         if (isset($param[self::SCANNER_MODE_INDEX])) {
             $this->scannerMode = (int) $param[self::SCANNER_MODE_INDEX];
         }
         $data = [];
         if ($this->configFileSet) {
             foreach ($this->configFileSet as $fileName) {
                 $data = array_merge_recursive(parse_ini_file($fileName, $this->processSections, $this->scannerMode));
             }
         }
         $this->mainNode = new Node(null, IConfig::MAIN_NODE_KEY, 'main node');
         foreach ($data as $key => $group) {
             if (!is_array($group)) {
                 $newNode = new Node($this->mainNode, $key, $group);
                 $this->mainNode->addChild($newNode);
                 continue;
             }
             $newNode = new Node($this->mainNode, $key, $key);
             foreach ($group as $name => $value) {
                 $childNode = new Node($newNode, $name, $value);
                 $newNode->addChild($childNode);
             }
             $this->mainNode->addChild($newNode);
         }
     } catch (ExceptionConfig $e) {
         throw $e;
     }
 }