Gather related (present) files.

Matches: foo(_local)?\.*(.dist)?

i.e., if we're editing config.yml, we also want to check for
config.yml.dist and config_local.yml

@param FileInterface $file

@return FileInterface[]
507105
private function getRelatedFiles(FileInterface $file)
    {
        // Match foo(_local).*(.dist)
        $base = $file->getFilename();
        $ext = Path::getExtension($base);
        $base = Path::getFilenameWithoutExtension($base);
        $base = Str::replaceLast($base, '_local', '');

        $dir = $file->getParent();
        $related = [];
        foreach ([".$ext", "_local.$ext"] as $tail) {
            $f = $dir->getFile($base . $tail);
            if ($f->getFilename() !== $file->getFilename() && $f->exists()) {
                $related[] = $f;
            }
        }

        return $related;
    }
873456
protected function _loadConfig($file) {
        $suffix = pathinfo($file, PATHINFO_EXTENSION);
        $suffix = ($suffix === 'dist') ?
                    pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION) : $suffix;
        if ($suffix == 'ini') {
            $config = Garp_Config_Ini::getCached($file, $this->getEnvironment())->toArray();
        } else {
            $config = parent::_loadConfig($file);
        }
        return $config;
    }
717833
protected function _handleFiles(EntityInterface $entity) {
		$files = $this->getConfig('file');
		if (is_string($files)) {
			$files = [$files => $this->getConfig('defaults')];
		}

		$results = [];
		foreach ($files as $key => $file) {
			if (is_string($key)) {
				$field = $key;
				$options = $this->getConfig('defaults');
				$options += $file;
			}
			if (is_string($file)) {
				$field = $file;
				$options = $this->getConfig('defaults');
			}
			$results[$field] = $this->saveFile($entity->{$field}, $options);
		}

		return $results;
	}
24897
public function readInteractions($file)
    {
        return array_map(
            function (array $interaction) {
                return new Interaction(
                    $this->messageHandler->convertFromRequest(
                        new SimplifiedRequest(
                            $interaction['request']['method'],
                            $interaction['request']['path'],
                            $this->mapHeaders($interaction['request']['headers']),
                            $interaction['request']['content']
                        )
                    ),
                    $this->messageHandler->convertFromResponse(
                        new SimplifiedResponse(
                            $interaction['request']['path'],
                            $interaction['response']['code'],
                            $this->mapHeaders($interaction['response']['headers']),
                            $interaction['response']['content']
                        )
                    )
                );
            },
            $this->decoder->decode(file_get_contents($file))
        );
    }
44835
public function loadFile($file)
    {
        if (is_array($file)) {
            return collect($file)->mapWithKeys(function ($subFile, $key) {
                return [$key => $this->loadFile($subFile)];
            })->toArray();
        }

        return $this->parser->parseFile($file);
    }
269406
public function getCompression(LocalFileNodeInterface $file)
    {
        $cmd = "file --brief --uncompress --mime {$file->getPath()}";

        $process = $this->getProcess($cmd);
        $process->mustRun();

        $result = $process->getOutput();
        if (preg_match('/compressed-encoding=application\/(?:x-)?(.+?);/i', $result, $matches)) {
            if ($this->factory->isCompression($matches[1])) {
                $this->log(LogLevel::DEBUG, "Found the compression for '{file}' as '{compression}'", [
                    'file'        => $file,
                    'compression' => $matches[1],
                ]);
                return $matches[1];
            }
            return CompressionFactory::TYPE_UNKNOWN;
        }
        return CompressionFactory::TYPE_NONE;
    }
1153114
public function load( $file )
    {
        $retVal = array( );

        try
        {
            $retVal = SymFonyYaml::parse( $file );
        }
        catch ( \Exception $e )
        {
            throw new YamlException( $e->getmessage( ), $e->getCode( ), $e );
        }

        return $this->filter( self::ON_YAML_LOAD_FILTER, $retVal, $file );
    }
1209394
public function read($file)
    {
        $file = '/settings/' . $file;

        /**
         * @todo validate that $file is a string
         */

        $result = [];

        if ($this->source_filesystem->has($file . '.yml')) {

            $result = $this->yaml->parse($this->source_filesystem->read($file . '.yml'));
        }

        return $result;
    }
250152
public function load($file, $type = null)
    {
        $path = $this->locator->locate($file);

        if (!stream_is_local($path)) {
            throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
        }

        if (!file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
        }

        if (null === $this->yamlParser) {
            $this->yamlParser = new YamlParser();
        }

        try {
            $parsedConfig = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
        } catch (ParseException $e) {
            throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
        }

        $collection = new RouteCollection();
        $collection->addResource(new FileResource($path));

        // empty file
        if (null === $parsedConfig) {
            return $collection;
        }

        // not an array
        if (!\is_array($parsedConfig)) {
            throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
        }

        foreach ($parsedConfig as $name => $config) {
            $this->validate($config, $name, $path);

            if (isset($config['resource'])) {
                $this->parseImport($collection, $config, $path, $file);
            } else {
                $this->parseRoute($collection, $name, $config, $path);
            }
        }

        return $collection;
    }
1344147
private static function loadDefinitionsFromFile(string $file): array
    {
        if (!\is_file($file) || !\is_readable($file)) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException(\sprintf('"%s" must be a readable file', $file));
            // @codeCoverageIgnoreEnd
        }

        $definitions = require $file;

        if (!\is_array($definitions)) {
            throw new \RuntimeException(
                \sprintf('Definitions file should return an array. "%s" returned', \gettype($definitions))
            );
        }

        return $definitions;
    }
1240991
public function loadFile($file)
    {
        if ($this->enableSpyc()) {
            if (! file_exists($file)) return [];

            // parse environment
            $content = file_get_contents($file);
            $content = $this->parseEnvironmentVariables($content);

            return $this->loadBySpyc($content);
        } else {
            throw new NotFoundException('Not found YAML parser.');
        }
    }
1371449
public function upload($file) {

        if (is_array($file['name'])) {
            $files = $this->reArrayFiles($file);

            $results = [];

            foreach ($files as $singleFile) {
                $result = $this->uploadSingle($singleFile);

                $results[] = $result;
            }

            return $results;

        } else {

            return Array($this->uploadSingle($file));

        }
    }
742353
private function getImage(FileInterface $file) {
    // Make sure we deal with a file.
    $image_factory = \Drupal::service('image.factory');

    return $image_factory->get($file->getFileUri());
  }
612788
public function analyze_file(string $file): array
  {
    $res = [];
    $ext = bbn\str::file_ext($file);
    if ( \in_array($ext, self::$extensions, true) && is_file($file) ){
      switch ( $ext ){
        case 'html':
          $res = $this->analyze_php($file);
          break;
        case 'php':
          $res = $this->analyze_php($file);
          break;
        case 'js':
          $res = $this->analyze_js($file);
          break;
        /*case 'json':
          $res = $this->analyze_json($file);
          break;*/
      }
    }
    return $res;
  }
740233
protected function getJsonConfig($file)
    {
        // check if file exists
        $configFile = $this->path . DIRECTORY_SEPARATOR . $file;
        if (!file_exists($this->path . DIRECTORY_SEPARATOR . $file)) {
            trigger_error("Couldn't load Autobahn config from `{$configFile}`: File not found.", E_USER_NOTICE);
            return [];
        }

        // read config
        $config = json_decode(file_get_contents($configFile), true);

        // invalid json
        if (is_null($config)) {
            trigger_error("'Couldn't load Autobahn config from `{$configFile}`: Invalid JSON (" . json_last_error_msg() . ").",
                E_USER_WARNING);
        }

        return $config;
    }
1121825
protected function parseImports(RepositoryInterface $repository, string $file) : RepositoryInterface
    {
        if (!isset($repository[self::IMPORT_KEY])) {
            return $repository;
        }

        if (!is_array($repository[self::IMPORT_KEY])) {
            $keyName = self::IMPORT_KEY;
            $message = "The \"{$keyName}\" key should contain an array in {$file}. Check your YAML syntax.";
            throw new \InvalidArgumentException($message);
        }

        foreach ($repository[self::IMPORT_KEY] as $import) {
            if (!is_array($import)) {
                $import = ['resource' => $import];
            }
            
            $ignoreErrors = isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false;

            $importedResource = $this->import($import['resource'], null, $ignoreErrors, $file);

            if ($importedResource) {
                $repository = $repository->union($importedResource);
            }
        }

        $repository->del(self::IMPORT_KEY);

        return $repository;
    }
1144098
public static function readConfigFile($file = self::DEFAULT_CONFIG_FILE)
    {
        if (!is_string($file)) {
            throw new InvalidArgumentException('The config file path must be a string, type passed "'.gettype($file).'".');
        }

        $baseDir = realpath(dirname($file));
        $searchDirs = array(
            $baseDir.'/',
            $baseDir.'/../',
            $baseDir.'/../../',
            $baseDir.'/config/',
            $baseDir.'/../config/',
            $baseDir.'/../../config/'
        );

        $filename = basename($file);

        $configFile = null;
        foreach ($searchDirs as $dir) {
            if (realpath($dir.$filename) and is_readable($dir.$filename)) {
                $configFile = realpath($dir.$filename);
                break;
            }
        }

        if (is_null($configFile) and $file !== self::DEFAULT_CONFIG_FILE) {
            throw new InvalidArgumentException('The config file "'.$file.'" cannot be found or read.');
        }

        if (!$configFile) {
            return static::$config;
        }

        // Try to parse the contents
        try {
            $yaml = Yaml\Yaml::parse(file_get_contents($configFile));
        } catch (Yaml\Exception\ParseException $e) {
            throw new Exception('Unable to parse the config file: '.$e->getMessage());
        }

        return static::$config = $yaml;
    }