function ExampleFinder::getExampleFileContents
Attempts to find the requested example file and returns its contents or null if no file was found.
This method will try several methods in search of the given example file, the first one it encounters is returned:
1. Iterates through all examples folders for the given filename 2. Checks the source folder for the given filename 3. Checks the 'examples' folder in the current working directory for examples 4. Checks the path relative to the current working directory for the given filename
Return value
string[] all lines of the example file
1 call to ExampleFinder::getExampleFileContents()
- ExampleFinder::find in vendor/
phpdocumentor/ reflection-docblock/ src/ DocBlock/ ExampleFinder.php - Attempts to find the example contents for the given descriptor.
File
-
vendor/
phpdocumentor/ reflection-docblock/ src/ DocBlock/ ExampleFinder.php, line 103
Class
- ExampleFinder
- Class used to find an example file's location based on a given ExampleDescriptor.
Namespace
phpDocumentor\Reflection\DocBlockCode
private function getExampleFileContents(string $filename) : ?array {
$normalizedPath = null;
foreach ($this->exampleDirectories as $directory) {
$exampleFileFromConfig = $this->constructExamplePath($directory, $filename);
if (is_readable($exampleFileFromConfig)) {
$normalizedPath = $exampleFileFromConfig;
break;
}
}
if ($normalizedPath === null) {
if (is_readable($this->getExamplePathFromSource($filename))) {
$normalizedPath = $this->getExamplePathFromSource($filename);
}
elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) {
$normalizedPath = $this->getExamplePathFromExampleDirectory($filename);
}
elseif (is_readable($filename)) {
$normalizedPath = $filename;
}
}
$lines = $normalizedPath !== null && is_readable($normalizedPath) ? file($normalizedPath) : false;
return $lines !== false ? $lines : null;
}