Get the content in the given file path.

@param string $filePath
@param bool $createIfNotExists
@return array
@throws \Illuminate\Contracts\Filesystem\FileNotFoundException
164824
public function getFileContent($filePath, $createIfNotExists = false)
    {
        if ($createIfNotExists && ! $this->disk->exists($filePath)) {
            if (! $this->disk->exists($directory = dirname($filePath))) {
                mkdir($directory, 0777, true);
            }

            file_put_contents($filePath, "<?php\n\nreturn [];");

            return [];
        }

        try {
            return (array) include $filePath;
        } catch (\ErrorException $e) {
            throw new FileNotFoundException('File not found: '.$filePath);
        }
    }
208160
public static function getXmlContent($filePath)
    {
        $useErrors = libxml_use_internal_errors(true);
        $content = simplexml_load_file($filePath);
        if (false === $content) {
            $error = libxml_get_last_error();
            throw new \Exception(sprintf("%s in %s", $error->message, $error->file));
        }

        libxml_clear_errors();
        libxml_use_internal_errors($useErrors);

        return $content;
    }
1172903
public function openFileAsArray(string $filepath):array
    {
        if ($filepath == $this->filepath && $this->file != null) {
            return ($this->file);
        }

        if (!file_exists($filepath)) {
            Server::create($filepath, 'file');
        }

        if (!is_readable($filepath)) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Cannot open file $filepath : File not readable",
                "solution" => "Please set the readable permission")));
        }

        $this->perm = null;
        $this->filepath = $filepath;
        $this->file = file($filepath);

        if (!is_array($this->file)) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Invalid file array for $filepath",
                "solution" =>
                    "Use FileListener::open to open a file resource.")));
        }

        return ($this->file);
    }
712047
public function readFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;

        $result = new ArrayIterator();

        if (false !== ($xml = simplexml_load_file($filePath))) {
            $contents = json_decode(json_encode($xml), true); // force to array conversion

            if (count($contents) == 1) {
                $contents = reset($contents);
            }

            if (json_last_error() === JSON_ERROR_NONE) {
                foreach ($contents as $content) {
                    $result[] = new SplArrayObject($content);
                }
            }
        }

        return $result;
    }
381066
public function getSchemaFileContent($filePath)
    {
        if (!$this->fs->exists($filePath)) {
            throw new SchemaDefinitionException(sprintf('The schema file "%s" was not found', $filePath));
        }

        $content = file_get_contents($filePath);

        try {
            $schema = Yaml::parse($content);

            return $schema;
        } catch (ParseException $e) {
            throw new SchemaDefinitionException($e->getMessage());
        }
    }
879918
private function getFileNode($path, $create = false)
    {
        $fileName = PathHelper::getNodeName('/'.$path);
        $folderPath = PathHelper::getParentPath('/'.$path);
        $folder = $this->getFolderNode($folderPath, $create);

        if ($folder->hasNode($fileName) || !$create) {
            return $folder->getNode($fileName);
        }

        $file = $folder->addNode($fileName, 'nt:file');
        $file->addNode('jcr:content', 'nt:resource');

        return $file;
    }
1162567
public function createFolderIfNotExists($folderPath) {
        if (file_exists($folderPath) && is_dir($folderPath)) {
            return;
        }
        
        $arrFolder = explode(DIRECTORY_SEPARATOR, $folderPath);
        
        $fullPath = "";
        $first = true;
        foreach ($arrFolder as $folder) {
            if (!$folder) {
                continue; //Happens if the first char is a slash
            }
            if (!$first) {
                $fullPath .= DIRECTORY_SEPARATOR;
            } else {
                $first = false;
            }
            
            $fullPath .= $folder;
            
            try {
                $this->createSingleFolderIfNotExists($fullPath);
            } catch (Exception $e) {
                $msg = $e->getMessage();
                echo "Could not generate folder '".$fullPath."' <br />\n"
                        . $msg
                        . "<br />";
            }
        }        
    }
734592
public static function createEmptyByFilePath(string $filepath) : Repository
    {
        $filename = basename($filepath);
        list($domain, $language, $extension) = explode('.', $filename, 3);

        return new self(
            TranslationCollection::create([]),
            $filepath,
            $language,
            $domain
        );
    }
364058
public static function loadJsonFromFile($filePath)
    {
        if (!file_exists($filePath)) {
            throw new \RuntimeException("File '{$filePath}' doesn't exist");
        }

        $content = json_decode(file_get_contents($filePath));

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new JsonDecodeException(sprintf(
                'Cannot decode JSON from file "%s" (error: %s)',
                $filePath,
                static::lastJsonErrorMessage()
            ));
        }

        return $content;
    }
1053678
public static function loadContextFromFile(string $filePath): ContextInterface
    {
        if(!file_exists($filePath)){
            throw new Exception\FileNotFoundException('Context file not found: '.$filePath, 404, null, $filePath);
        }

        $contents = file_get_contents($filePath);
        $context_array = json_decode($contents, true);

        if($context_array === null){
            throw new Exception\MalformedJsonException('JSON sintax error.');
        }

        return new self($context_array);
    }
1002137
private function getTranslationsInFile($filePath)
    {
        
	 	// File extension ?
        $extOk = in_array(\Jig\Utils\FsUtils::getFileExtension($filePath), $this->getFileTypes());

        if ($extOk){
            foreach ($this->getBannedFileType() as $bannedExt){
                $extOk &= substr_compare($filePath, $bannedExt, strlen($filePath)-strlen($bannedExt), strlen($bannedExt)) !== 0;
            }
        }

        if ($extOk) {
            
		 	// We read the file.
		 	$lines = file($filePath);
		 	foreach ($lines as $line) {
                $strings = $this->getTranslationPhrases( $line );
                //preg_match_all("/__(\(| )+['\"](.*?)['\"](\))?/u", $line, $string);
                
                //lookup for __('to translate') or __ 'to translate'
            //    preg_match_all("/__(\(| )+(('(.*?)')|(\"(.*?)\"))(\))?/u", $line, $string);
            
                foreach($strings as $s) {
                    $tu = new tao_helpers_translation_TranslationUnit();
                    $tu->setSource(tao_helpers_translation_POUtils::sanitize($s));
                    $tus = $this->getTranslationUnits();
                    $found = false;
                    
                    // We must add the string as a new TranslationUnit only
                    // if a similiar source does not exist.
                    foreach ($tus as $t) {
                        if ($tu->getSource() == $t->getSource()) {
                            $found = true;
                            break;
                        }
                    }
                    
                    if (!$found) {
                        $tus[] = $tu;
                        $this->setTranslationUnits($tus);
                    }
                }
		 	}
		}
        
    }
996182
public static function readFile($filePath)
    {
        if (false === self::exists($filePath)) {
            throw new RuntimeException(sprintf('unable to find "%s"', $filePath));
        }
        if (false === $fileData = file_get_contents($filePath)) {
            throw new RuntimeException(sprintf('unable to read file "%s"', $filePath));
        }

        return $fileData;
    }
1276972
protected function getFileAsset($filePath)
    {
        $file = new \SplFileInfo($filePath);

        if (!$file->isReadable() || $file->isDir()) {
            return null;
        }

        $filePath = $file->getRealPath();

        return new FileAsset($filePath);
    }
170372
function fileFetchContents( $filePath )
    {
        $filePath = self::cleanPath( $filePath );
        eZDebugSetting::writeDebug( 'kernel-clustering', "dfs::fileFetchContents( '$filePath' )" );

        $contents = self::$dbbackend->_fetchContents( $filePath );
        return $contents;
    }
369869
public function parse($filePath)
    {
        if (!$this->isAvailable()) {
            throw new IllegalStateException("Zephir Parser extension couldn't be loaded.");
        }

        if (!is_file($filePath) || !is_readable($filePath)) {
            throw new InvalidArgumentException('Unable to locate source file to parse.');
        }

        $content = file_get_contents($filePath);

        if (false === $content) {
            throw new ParseException('Unable to read source file to parse.');
        }

        return zephir_parse_file($content, $filePath);
    }
389145
public function store_destfile_from_path($filepath) {
        if ($record = $this->get_file_record()) {
            $fs = get_file_storage();
            $existing = $fs->get_file(
                $record['contextid'],
                $record['component'],
                $record['filearea'],
                $record['itemid'],
                $record['filepath'],
                $record['filename']
            );
            if ($existing) {
                $existing->delete();
            }
            $file = $fs->create_file_from_pathname($record, $filepath);

            $this->raw_set('destfileid', $file->get_id());
        }

        return $this;
    }
1167498
protected function createFile($filePath, $contents)
    {
        $this->createDirectory(dirname($filePath));
        
        if (is_file($filePath)) {
            // if (!$this->opt('force')) {
            $this->output->setDecorated(true);
            $this->output->writeln(sprintf(
                "<comment>file exists  <cyan>%s</cyan></comment>",
                $this->prettyPath($filePath)
            ));
                // return;
            // } else {
                // $this->output->writeln(sprintf(
                    // "<comment>overwriten  <cyan>%s</cyan></comment>",
                    // $filePath
                // ));
            // }
        } else {
            $this->output->writeln(sprintf(
                "<info>create  <cyan>%s</cyan></info>",
                $this->prettyPath($filePath)
            ));
            file_put_contents($filePath, $contents);
        }
        
    }