Read synonyms from file.

@param string $filepath

@return Synonym[]

@throws SynonymsException
497207
public function readSynonymsFromFile(string $filepath): array
    {
        if (
            !is_file($filepath) ||
            !is_readable($filepath)
        ) {
            throw SynonymsException::synonymsFileNotFound($filepath);
        }

        $data = file_get_contents($filepath);

        if (!is_string($data)) {
            throw SynonymsException::synonymsMalformedData($filepath);
        }

        return array_filter(array_map(function ($line) {
            if (!is_string($line)) {
                return false;
            }

            $words = str_getcsv($line, ',');

            if (count($words) <= 1) {
                return false;
            }

            return Synonym::createByWords($words);
        }, str_getcsv($data, "\n")));
    }
475143
public static byte[] readFileToBytes( String filePath ) throws IOException {
        Path path = Paths.get(filePath);
        byte[] bytes = Files.readAllBytes(path);
        return bytes;
    }
1075121
public function findMatchingFiles(string $path): array
    {
        $path = $this->validatePath($path);

        if (is_dir($path)) {
            $pathCollection = $this->findMatchingFilesInDirectory($path);
        } elseif (is_file($path)) {
            $pathCollection = [$path];
        } else {
            throw new FileException(sprintf('Could not get file(s) for path %s', $path));
        }

        $fileIncludingTests = [];
        foreach ($pathCollection as $path) {
            $file = new File($path);
            if ($this->getFileIncludesTest($file)) {
                $fileIncludingTests[] = $file;
            }
        }

        return $fileIncludingTests;
    }
40217
public function getData(string $filePath): array
    {
        if (!is_readable($filePath) || is_dir($filePath)) {
            throw new \InvalidArgumentException('File ' . $filePath . ' is not a readable or not even a file');
        }
        $this->filePath = $filePath;
        $normalizedMetaData = $this->getNormalizedMetaDataFileContent();
        $normalizedMetaData = $this->addPathToData($normalizedMetaData);
        $normalizedMetaData = $this->addFilePathToData($normalizedMetaData);
        $normalizedMetaData = $this->addCheckSumToData($normalizedMetaData);

        return $normalizedMetaData;
    }
1332275
public function readFile($filePath)
    {
        if (false === $fileContent = @file_get_contents($filePath)) {
            throw new RuntimeException(
                sprintf('unable to read file "%s"', $filePath)
            );
        }

        return $fileContent;
    }
1043111
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $pharArchive = new PharData($filePath, null, null, Phar::GZ);
        $pharArchive->extractTo($directory);

        return $this->createFinderFromDirectory($directory);
    }
1182988
public function fileGetContents($filePath)
    {
        if ($this->fileExists($filePath) == false) {
            throw new FileSystemException('File '.$filePath.' was not found');
        }
        return file_get_contents($filePath);
    }
81000
private static function findDeclarations($filePath) {

		// Defaults
		$gathered = array();
		$gatheringNamespace = false;
		$namespace = null;

		// Get PHP tokens from the specified file.
		$tokens = token_get_all(file_get_contents($filePath));

		foreach ($tokens as $index => $token) {

			// Namespace detection.
			if ($gatheringNamespace) {
				if (isset($token[1])) $namespace .= $token[1];
				if ($token == ";") {
					$namespace = trim($namespace, " ;\\");
					$namespace = $namespace . '\\';
					$gatheringNamespace = false;
				}
			}

			if ($namespace === null && $token[0] === T_NAMESPACE) {
				$gatheringNamespace = true;
			}

			if (isset($tokens[$index - 2]) && in_array($tokens[$index - 2][0], self::$autoloadableTokens, true)) {
				if ($tokens[$index - 1][0] === T_WHITESPACE &&
					$token[0] === T_STRING) {
					$gathered[] = $namespace . $token[1];
				}
			}

		}

		return $gathered;

	}
1073766
public static function parseFile($filepath)
    {
        if (!is_file($filepath)) {
            throw new \RuntimeException('File not found: ' . $filepath);
        }

        if (!$filedata = static::readFiledata($filepath)) {
            throw new \RuntimeException('Error reading file: ' . $filepath);
        }

        if (!$json = self::decode($filedata)) {
            throw new \RuntimeException('Error parsing json: ' . $filepath);
        }

        return $json;
    }
1366623
protected function findCheckCriteria($filepath, $criteria)
	{
		$match = true;
		$filename = basename($filepath);
		if ($match && isset($criteria['regexs'])) {
			if (!is_array($criteria['regexs'])) {
				$criteria['regexs'] = array($criteria['regexs']);
			}
			$match = false;
			foreach ($criteria['regexs'] as $regex) {
				if (preg_match($regex, $filename)) {
					$match = true;
					break;
				}
			}
		}
		if ($match && isset($criteria['mod_since'])) {
			$match = $criteria['mod_since'] < @filemtime($filepath);
		}
		if ($match && isset($criteria['mod_before'])) {
			$match = $criteria['mod_before'] > @filemtime($filepath);
		}
		if ($match && isset($criteria['contains'])) {
			$match = false;
			if (preg_match('/\.(.*?)$/', $filename, $matches)) {
				$extension = strtolower($matches[1]);
				if (in_array($extension, $criteria['search_extensions'])) {
					if ($contents = file_get_contents($filepath)) {
						$match = preg_match($criteria['contains'], $contents);
						unset($contents);
					}
				}
			}
		}
		return $match;
	}
1347264
protected function getReflection($filepath)
    {
        // Regexp instead of tokenizer because of the bad perf @link > https://gist.github.com/1886076
        if (!preg_match('#^namespace\s+(.+?);.*class\s+(\w+).+;$#sm', file_get_contents($filepath), $captured)) {
            throw new \RuntimeException('Unable to find namespace or class declaration');
        }

        $fqcn = $captured[1].'\\'.$captured[2];

        try {
            $reflectedClass = new \ReflectionClass($fqcn);
        } catch (\ReflectionException $exception) {
            $this->registerAutoload($fqcn, $filepath);
            $reflectedClass = new \ReflectionClass($fqcn);
        }

        return $reflectedClass;
    }
883759
protected function readJson($filePath)
    {

        if (!file_exists($filePath) || is_dir($filePath)) {
            $filePath = realpath($this->rootPath . '/' . $filePath);
        }
        if (!file_exists($filePath) || is_dir($filePath)) {
            $filePath = $this->rootPath . '/' . $filePath;
        }

        $json = json_decode(file_get_contents($filePath), true);

        return $json;
    }
241549
protected static function convertSynonymFileLineForImport($line, $synonymList) : array
    {
        $lineParts = GeneralUtility::trimExplode('=>', $line, true);

        if (isset($lineParts[1])) {
            $baseWord = mb_strtolower($lineParts[0]);
            $synonyms = GeneralUtility::trimExplode(',', mb_strtolower($lineParts[1]), true);
        } else {
            $synonyms = GeneralUtility::trimExplode(',', mb_strtolower($lineParts[0]), true);
            $baseWord = mb_strtolower(reset($synonyms));
        }
        $synonymList[$baseWord] = $synonyms;

        return $synonymList;
    }
697582
protected function getFileFunctions($filePath)
    {
        $source = file_get_contents($filePath);
        $tokens = token_get_all($source);

        $functions = [];
        $nextStringIsFunc = false;
        foreach($tokens as $token) {
            switch($token[0]) {
                case T_FUNCTION:
                    $nextStringIsFunc = true;
                    break;

                case T_STRING:
                    if ($nextStringIsFunc) {
                        $nextStringIsFunc = false;
                        $functions[] = $token[1];
                    }
                    break;
            }
        }

        return $functions;
    }
116118
private function getClassNameFromFile($filepath)
    {
        $contents = file_get_contents($filepath);
        $namespace = $class = '';
        $getting_namespace = $getting_class = false;
        foreach (token_get_all($contents) as $token) {
            if (is_array($token) && $token[0] == T_NAMESPACE) {
                $getting_namespace = true;
            }

            if (is_array($token) && in_array($token[0], [T_CLASS, T_TRAIT, T_INTERFACE])) {
                $getting_class = true;
            }

            if ($getting_namespace === true) {
                if (is_array($token) && in_array($token[0], [T_STRING, T_NS_SEPARATOR])) {
                    $namespace .= $token[1];
                } elseif ($token === ';') {
                    $getting_namespace = false;
                }
            }

            if ($getting_class === true) {
                if (is_array($token) && $token[0] == T_STRING) {
                    $class = $token[1];
                    break;
                }
            }
        }

        return $namespace ? $namespace.'\\'.$class : $class;
    }
1355794
public function parse($filepath)
    {
        $metadata = array();

        $reflectedClass = $this->getReflection($filepath);
        $metadata['class'] = $reflectedClass->getName();

        $propertiesMetadata = $this->processPropertiesParsing($reflectedClass);
        $metadata = array_merge($metadata, $propertiesMetadata);

        return $metadata;
    }
942074
public static function getImageDimensions(string $filePath): ?\stdClass {
        list($width, $height, $type) = getimagesize($filePath);

        if ($type === null) {
            return null;
        }

        return (object)[
            'width' => (int)$width,
            'height' => (int)$height,
            'mime' => image_type_to_mime_type($type),
        ];
    }