Пример #1
0
 /**
  * Method that retrieves list field options.
  *
  * @param  string $listName list name
  * @param  string $prefix   nested option prefix
  * @return array
  */
 private function __getListFieldOptions($listName, $prefix = null)
 {
     $result = [];
     $listData = [];
     try {
         $pathFinder = new ListPathFinder();
         $path = $pathFinder->find(null, $listName);
         $parser = new ListParser();
         $listData = $parser->parseFromPath($path);
     } catch (\Exception $e) {
         /* Do nothing.
          *
          * ListPathFinder and ListParser check for the
          * file to exist and to be readable and so on,
          * but here we do load lists recursively (for
          * sub-lists, etc), which might result in files
          * not always being there.
          *
          * In this particular case, it's not the end of the
          * world.
          */
     }
     if (!empty($listData)) {
         $result = $this->__prepareListOptions($listData, $listName, $prefix);
     }
     return $result;
 }
 public function testParseFromPath()
 {
     $file = dirname(dirname(dirname(__DIR__))) . DS . 'data' . DS . 'CsvMigrations' . DS . 'lists' . DS . 'genders.csv';
     $parser = new ListParser();
     $result = $parser->parseFromPath($file);
     $this->assertTrue(is_array($result), "Parser returned a non-array");
     $this->assertFalse(empty($result), "Parser returned empty result");
 }
 /**
  * Check if the given list is valid
  *
  * Lists with no items are assumed to be
  * invalid.
  *
  * @param string $list List name to check
  * @return bool True if valid, false is otherwise
  */
 protected function _isValidList($list)
 {
     $result = false;
     $listItems = [];
     try {
         $pathFinder = new ListPathFinder();
         $path = $pathFinder->find(null, $list);
         $parser = new ListParser();
         $listItems = $parser->parseFromPath($path);
     } catch (\Exception $e) {
         // We don't care about the specifics of the failure
     }
     if ($listItems) {
         $result = true;
     }
     return $result;
 }