Read folder and retrun filelist

@param \Jodit\Config $source

@return object
@throws \Exception
332971
public function read(Config $source) {
		$path = $source->getPath();

		$sourceData = (object)[
			'baseurl' => $source->baseurl,
			'path' =>  str_replace(realpath($source->getRoot()) . Consts::DS, '', $path),
			'files' => [],
		];

		try {
			$this->accessControl->checkPermission($this->getUserRole(), $this->action, $path);
		} catch (\Exception $e) {
			return $sourceData;
		}


		$dir = opendir($path);

		$config = $this->config;

		while ($file = readdir($dir)) {
			if ($file != '.' && $file != '..' && is_file($path . $file)) {
				$file = new File($path . $file);

				if ($file->isGoodFile($source)) {
					$item = [
						'file' => $file->getPathByRoot($source),
					];

					if ($config->createThumb || !$file->isImage()) {
						$item['thumb'] = Image::getThumb($file, $source)->getPathByRoot($source);
					}

					$item['changed'] = date($config->datetimeFormat, $file->getTime());
					$item['size'] = Helper::humanFileSize($file->getSize());
					$item['isImage'] = $file->isImage();

					$sourceData->files[] = $item;
				}
			}
		}

		return $sourceData;
	}
1071033
protected function readConfiguration($actualDir)
    {
        $finder = new Finder();
        $finder->files()->in($actualDir)->name('*.yml');

        if (iterator_count($finder) < 1) {
            throw new \Exception('The configuration (.yml) file is missing.');
        }

        $files = iterator_to_array($finder);
        $file = current($files);

        $config = Yaml::parse($file->getContents());

        return $config;
    }
1044999
public function readSource($source)
    {
        $document = new \DOMDocument();
        $errorToExceptionContext = new ErrorToExceptionContext(E_WARNING, function () use ($source, $document) {
            $document->loadXML($source);
        });
        $errorToExceptionContext->invoke();

        return $this->readDocument($document);
    }
851260
private function getFileContents($source)
    {
        $this->assertSourceExists($source);
        $this->assertSourceIsNotFolder($source);
        $content = file_get_contents($source, true);

        $this->assertContentIsProperLoaded($source, $content);
        $this->assertContentIsNotEmpty($source, $content);

        return $content;
    }
610247
public function loadResource($source = null)
    {

        $routes     = array();
        $source     = $this->resolveResorceSource($source);
        $extension  = Path::getExtension($source);

        if (file_exists($source)) {
            $content = File::load($source);
            if ($extension == 'yml') {
                $array  = Yaml::parse($content);
            } elseif ($extension == 'json') {
                $array  = json_decode($content, true);
            } else {
                throw new \Exception("Unsupported routing file type. Routes can only be loaded from yml or json files");
            }

            if (is_array($array)) {

                if (isset($array['imports'])) {
                    foreach ($array['imports'] as $import) {
                        if (isset($import['resource'])) {
                            $extraSource = $this->resolveResorceSource($import['resource']);
                            foreach ($this->loadResource($import['resource']) as $name => $route) {
                                $routes[$name] = $route;
                            }
                        }
                    }
                }

                if (isset($array['routes'])) {
                    foreach ($array['routes'] as $name => $route) {
                        $routes[$name] = $route;
                    }
                }
            }
        }

        $this->resource = $routes;

        return $routes;
    }
13542
public function getContent($refresh = false)
    {
        if ($this->content === null || $refresh) {
            try{
                switch ($this->sourceType) {
                    case self::SOURCE_FILE:
                        //check file
                        if(!file_exists($this->source)){
                            throw new Exception("File {$this->source} not found.");
                        }
                        if(!is_readable($this->source)){
                            throw new Exception("Unable to read file {$this->source}.");
                        }
                        if(!preg_match("/\.{$this->fileExtension}$/", basename($this->source))){
                            throw new Exception("Wrong file extension in ".basename($this->source).", {$this->fileExtension} extension is expected");
                        }
                        if(!tao_helpers_File::securityCheck($this->source)){
                            throw new Exception("{$this->source} seems to contain some security issues");
                        }
                        $this->content = file_get_contents($this->source);
                        break;
                    case self::SOURCE_URL:
                        //only same domain
                        if(!preg_match("/^".preg_quote(BASE_URL, '/')."/", $this->source)){
                            throw new Exception("The given uri must be in the domain {$_SERVER['HTTP_HOST']}");
                        }
                        $this->content = tao_helpers_Request::load($this->source, true);
                        break;
                    case self::SOURCE_STRING:
                        $this->content = $this->source;
                        break;
                    case self::SOURCE_FLYFILE:
                        if (! $this->source->exists()) {
                            throw new Exception('Source file does not exists ("' . $this->source->getBasename() . '").');
                        }
                        if (! $this->content = $this->source->read()) {
                            throw new Exception('Unable to read file ("' . $this->source->getBasename() . '").');
                        }
                        break;
                }
            } catch(Exception $e) {
                $this->addError($e);
            }
        }
        
        return $this->content;
    }
1082990
public static function load($source) {

		if(false === is_string($source) && false === $source instanceof Viewmodel) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or instance of sFire\MVC\Viewmodel, "%s" given', __METHOD__, gettype($source)), E_USER_ERROR);
		}

		$file = $source;

		if($source instanceof Viewmodel) {

			$path 			= Path :: get('modules') . Router :: getRoute() -> getModule() . DIRECTORY_SEPARATOR;
			$views 			= $path . Application :: get(['directory', 'view']);
			$translations 	= $path . Application :: get(['directory', 'translation']);
			$extension 		= Application :: get(['extensions', 'view']);
			$file  			= preg_replace('#^'. preg_quote($views) .'#', '', $source -> getFile());
			$file  			= preg_replace('#'. preg_quote($extension) .'$#', '', $file);
		}

		$module 	= Router :: getRoute() -> getModule();
		$extension 	= Application :: get(['extensions', 'translation']);
		$file 		= str_replace('.', DIRECTORY_SEPARATOR, $file);
		$file 		= Path :: get('modules') . $module . DIRECTORY_SEPARATOR . Application :: get(['directory', 'translation']) . $file . $extension;
		$file 		= new File($file);
		$identifier = md5($file -> entity() -> getBasepath());
		$cache 		= new File(Path :: get('cache-translation') . $identifier);

		if(false === $file -> exists() && false === $source instanceof Viewmodel) {
			return trigger_error(sprintf('Translation file "%s" used in %s() does not exists', $file -> entity() -> getBasepath(), __METHOD__), E_USER_ERROR);
		}

		static :: cache($cache, $file);

		return $identifier;
	}
250531
private function readConfigFile()
    {
        // Check config.json exists
        $this->info("Reading config");

        // look for config in main directory
        if(file_exists($this->tmpDirectory.'/config.json')) {
            $this->configContent = json_decode(File::get($this->tmpDirectory.'/config.json'));
            return $this;
        }

        // look for config in the first directory
        // useful in case the plugin is downloaded via http
        $directories = File::directories($this->tmpDirectory);
        if(isset($directories[0])) {
            $pluginPathSource = $directories[0];
            if (file_exists($pluginPathSource . '/config.json')) {
                $this->configContent = json_decode(File::get($pluginPathSource.'/config.json'));
                return $this;
            }
        }

        // no config.json found
        $this->cleanTmp();
        throw new \Exception('config.json file not found');
    }
1220837
public function getPaths($source)
    {
        $source = $this->cleanSource($source);
        list(, $paths) = $this->parse($source);

        return $paths;
    }
205392
private function downloadFile($source)
    {
        $tmpFile = tempnam(sys_get_temp_dir(), 'maxmind_geoip2_');
        if (strpos($source, 'tar.gz') !== false) {
            @rename($tmpFile, $tmpFile.'.tar.gz');
            $tmpFile .= '.tar.gz';
        }

        if (!@copy($source, $tmpFile)) {
            return false;
        }

        return $tmpFile;
    }
443396
public function readDirectory($directory, $showDetail = false)
    {
        $this->ftp->chdir($this->getDefaultPath());
        if ($showDetail) {
            $list = $this->ftp->rawlist($directory);
            foreach ($list as &$file) {
                $file = new FileInfo($file);
            }

            return $list;
        } else {
            return $this->ftp->nlist($directory);
        }
    }
207352
public function getContent(Smarty_Template_Source $source)
    {
        if ($source->exists) {
            return file_get_contents($source->filepath);
        }
        throw new SmartyException('Unable to read ' . ($source->isConfig ? 'config' : 'template') .
                                  " {$source->type} '{$source->name}'");
    }
1087674
public function read($source) {
		$source = $this->escapePath($source);
		// since returned stream is closed by the caller we need to create a new instance
		// since we can't re-use the same file descriptor over multiple calls
		$connection = $this->getConnection();

		$connection->write('get ' . $source . ' ' . $this->system->getFD(5));
		$connection->write('exit');
		$fh = $connection->getFileOutputStream();
		stream_context_set_option($fh, 'file', 'connection', $connection);
		return $fh;
	}
1162040
public function get_file_reference($source) {
        global $USER;
        list($type, $fileid, $filename) = $this->split_part($source);
        $reference = new stdClass();
        $reference->fileid = $fileid;
        $reference->filename = $filename;
        $reference->userid = $USER->id;
        $reference->downloadurl = '';
        if (optional_param('usefilereference', false, PARAM_BOOL)) {
            try {
                $shareinfo = $this->boxnetclient->share_file($reference->fileid);
            } catch (moodle_exception $e) {
                throw new repository_exception('cannotcreatereference', 'repository_boxnet');
            }
            $reference->downloadurl = $shareinfo->download_url;
        }
        return serialize($reference);
    }
64878
public function load($source)
    {
        if ($source instanceof File) {
            $resource = $source->readStream();
        } else {
            if (!is_file($source)) {
                throw new InvalidArgumentException("Expected CSV file '" . $source . "' could not be open.");
            }
            if (!is_readable($source)) {
                throw new InvalidArgumentException("CSV file '" . $source . "' is not readable.");
            }
            $resource = fopen($source, 'r');
        }

        // More readable variables
        $enclosure = preg_quote($this->options['field_encloser'], '/');
        $delimiter = $this->options['field_delimiter'];
        $multiValueSeparator = $this->options['multi_values_delimiter'];

        $adle = ini_get('auto_detect_line_endings');
        ini_set('auto_detect_line_endings', true);

        if ($this->options['first_row_column_names']) {
            $fields = fgetcsv($resource, 0, $delimiter, $enclosure);
            $this->setColumnMapping($fields);
        }

        $data = array();
        while (($rowFields = fgetcsv($resource, 0, $delimiter, $enclosure)) !== false) {
            $lineData = [];
            foreach ($rowFields as $fieldData) {
                // If there is nothing in the cell, replace by null for abstraction consistency.
                if ($fieldData == '') {
                    $fieldData = null;
                } elseif (!empty($multiValueSeparator) && mb_strpos($fieldData, $multiValueSeparator) !== false) {
                    // try to split by multi_value_delimiter
                    $multiField = [];
                    foreach (explode($multiValueSeparator, $fieldData) as $item) {
                        if (!empty($item)) {
                            $multiField[] = $item;
                        }
                    }
                    $fieldData = $multiField;
                }
                $lineData[] = $fieldData;
            }
            $data[] = $lineData;

            // Update the column count.
            $currentRowColumnCount = count($rowFields);
            if ($this->getColumnCount() < $currentRowColumnCount) {
                $this->setColumnCount($currentRowColumnCount);
            }

        }
        ini_set('auto_detect_line_endings', $adle);
        fclose($resource);
        $this->setData($data);
    }
175395
public static function fromFile(string $filename = ''): self
    {
        if (!\file_exists($filename)) {
            throw new \Exception($filename.' does not exist');
        }
        $contents = \file_get_contents($filename);
        if (!\is_string($contents)) {
            throw new \Exception('Could not read file contents');
        }
        return self::fromData($contents);
    }
585092
public function addDirectory($source) {
        $source = str_replace('\\', '/', realpath($source));

        if (is_dir($source) === true) {
            $files = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

            foreach ($files as $file) {
                $file = str_replace('\\', '/', $file);

                // Ignore "." and ".." folders
                if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
                    continue;

                if (!is_link($file)) {
                    $file = realpath($file);
                }

                if (!is_link($file) && is_dir($file)) {
                    $this->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                } else if (is_link($file)) {
                    // @fixme This actually does not work. It will create a file in the zip, but it
                    // won't be a link pointing somewhere.
                    // I have not found a way to add a working symlink to a zip archive.
                    $this->addFile($file, str_replace($source . '/', '', $file));
                } else if (is_file($file)) {
                    $this->addFromString(str_replace($source . '/', '', $file),
                        file_get_contents($file));
                }
            }
        } else if (is_file($source) === true) {
            $this->addFromString(basename($source), file_get_contents($source));
        }
    }