Esempio n. 1
0
 /**
  * Parcour le tableau pour récupérer les données
  *
  * @param Conf|null $conf Configuration dans laquelle mettre les données
  * @param array     $data Données à ajouter dans la configuration
  *
  * @return Conf
  */
 protected function arrayConvert($conf, $data)
 {
     if ($conf === null) {
         $conf = new Conf();
     }
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $conf->set($this->arrayConvert(null, $value), $key);
             continue;
         }
         $conf->set($value, $key);
     }
     return $conf;
 }
Esempio n. 2
0
 /**
  * Parcours $conTwo pour alimenter $conf
  *
  * @param Conf $conf    Configuration alimentée
  * @param Conf $confTwo Configuration parcourue
  *
  * @return void
  */
 protected static function each(Conf $conf, Conf $confTwo)
 {
     foreach ($confTwo->each() as $key => $data) {
         if ($conf->has($key) === false) {
             $conf->set($data, $key);
             continue;
         }
         if (gettype($conf->get($key)) !== 'object') {
             $conf->set($data, $key);
             continue;
         }
         if (is_a($conf->get($key), Conf::class) === true) {
             if (is_a($data, Conf::class) === true) {
                 self::each($conf->get($key), $data);
                 continue;
             }
             continue;
         }
         $conf->set($data, $key);
     }
 }
Esempio n. 3
0
 /**
  * Remplace les noms des variables par leurs valeurs
  *
  * @param Conf $conf Configuration dans laquelle parser les variables
  *
  * @return void
  */
 private static function parseVar(Conf $conf)
 {
     foreach ($conf as $key => $value) {
         if (is_object($value)) {
             self::parseVar($value);
             continue;
         }
         if (strpos($value, self::START_VAR) === false || strpos($value, self::END_VAR) === false) {
             continue;
         }
         $pattern = '/(?<=' . preg_quote(self::START_VAR) . ')' . '(?<selector>[a-zA-Z0-9' . self::DELIMITER . ']+)' . '(?=' . preg_quote(self::END_VAR) . ')/';
         preg_match_all($pattern, $value, $matchs);
         foreach ($matchs['selector'] as $selector) {
             $varSelector = explode(self::DELIMITER, $selector);
             $target = self::START_VAR . $selector . self::END_VAR;
             $varValue = $conf->get(...$varSelector);
             if ($varValue === null) {
                 $varValue = self::$globalConf->get(...$varSelector);
             }
             $value = str_replace($target, $varValue, $value);
             $conf->set($value, $key);
         }
     }
 }
Esempio n. 4
0
 /**
  * Build / complete the configuration of a column
  *
  * @param type $name   The name of the column
  * @param Conf $column The column configuration
  *
  * @return void
  */
 protected function buildColumnConf($name, Conf $column)
 {
     $column->name = $name;
     foreach (self::$fields as $fieldName => $defaults) {
         if ($column->has($fieldName)) {
             continue;
         }
         foreach ($defaults['fields'] as $field) {
             if ($column->has($field)) {
                 $column->set($column->get($field), $fieldName);
                 break;
             }
         }
         if ($column->has($fieldName)) {
             continue;
         }
         $column->set($defaults['default'], $fieldName);
     }
 }
Esempio n. 5
0
 /**
  * Contrôle construct
  *
  * @return void
  */
 public function testParseVar()
 {
     $this->if($conf = new Conf())->and($conf->set('varName1', 'section1', 'name1'))->and($conf->set('{%name1}', 'section1', 'name2'))->and($conf->set('toto', 'stringSection'))->and($conf->set('{%section1:name2} et {%stringSection}', 'toto', 'foo', 'bar'))->if(call_user_func(['\\Solire\\Conf\\Process\\ParseVar', 'run'], $conf))->string($conf->get('section1', 'name2'))->isEqualTo('varName1')->string($conf->toto->foo->bar)->isEqualTo('varName1 et toto');
 }
Esempio n. 6
0
File: Conf.php Progetto: solire/conf
 /**
  * Contrôle parcour d'éléments
  *
  * @return void
  */
 public function testEach()
 {
     $this->if($conf = new TestClass())->and($conf->set(1, 'section1', 'name1'))->and($conf->set(2, 'section1', 'name2'))->and($conf->set('toto', 'stringSection'))->array($conf->each())->isEqualTo(['section1' => $conf->get('section1'), 'stringSection' => 'toto'])->array($conf->each('section1'))->isEqualTo(['name1' => 1, 'name2' => 2])->array($conf->each('nonPresent'))->isEqualTo([]);
 }
Esempio n. 7
0
 /**
  * Contrôle construct
  *
  * @return void
  */
 public function testParseVar()
 {
     $this->if($conf = new Conf())->and($conf->set('varName1', 'section1', 'name1'))->and($conf->set('varConf', 'sectionConf', 'name'))->and($conf->set('toto', 'stringSection'))->and($conf->set('toto', 'stringSectionSec'))->and($conf->set(new \stdClass(), 'object'))->if($confTwo = new Conf())->and($confTwo->set('varName1TWO', 'section1', 'name1'))->and($confTwo->set('varTestTWO', 'sectionTest', 'name1'))->and($confTwo->set('totoTWO', 'stringSection'))->and($confTwo->set('messageTWO', 'newSection'))->and($confTwo->set('osefVar', 'sectionConf'))->and($confTwo->set('replaceObject', 'object'))->if(call_user_func(['\\Solire\\Conf\\Process\\Merge', 'run'], $conf, $confTwo))->string($conf->get('section1', 'name1'))->isEqualTo('varName1TWO')->string($conf->get('stringSection'))->isEqualTo('totoTWO')->string($conf->get('stringSectionSec'))->isEqualTo('toto')->string($conf->get('sectionTest', 'name1'))->isEqualTo('varTestTWO')->string($conf->get('object'))->isEqualTo('replaceObject')->object($conf->get('sectionConf'))->isInstanceOf('\\Solire\\Conf\\Conf');
 }