Documentation

ExampleFinder
in package

Class used to find an example file's location based on a given ExampleDescriptor.

Table of Contents

$exampleDirectories  : array<string|int, string>
$sourceDirectory  : string
find()  : string
Attempts to find the example contents for the given descriptor.
getExampleDirectories()  : array<string|int, string>
Returns a series of directories that may contain examples.
getSourceDirectory()  : string
Returns the project's root directory where an 'examples' folder can be expected.
setExampleDirectories()  : void
Registers a series of directories that may contain examples.
setSourceDirectory()  : void
Registers the project's root directory where an 'examples' folder can be expected.
constructExamplePath()  : string
Returns a path to the example file in the given directory.
getExampleFileContents()  : array<string|int, string>
Attempts to find the requested example file and returns its contents or null if no file was found.
getExamplePathFromExampleDirectory()  : string
Get example filepath based on the example directory inside your project.
getExamplePathFromSource()  : string
Get example filepath based on sourcecode.

Properties

$exampleDirectories

private array<string|int, string> $exampleDirectories = []

Methods

find()

Attempts to find the example contents for the given descriptor.

public find(Example $example) : string
Parameters
$example : Example
Return values
string

getExampleDirectories()

Returns a series of directories that may contain examples.

public getExampleDirectories() : array<string|int, string>
Return values
array<string|int, string>

getSourceDirectory()

Returns the project's root directory where an 'examples' folder can be expected.

public getSourceDirectory() : string
Return values
string

setExampleDirectories()

Registers a series of directories that may contain examples.

public setExampleDirectories(array<string|int, string> $directories) : void
Parameters
$directories : array<string|int, string>
Return values
void

setSourceDirectory()

Registers the project's root directory where an 'examples' folder can be expected.

public setSourceDirectory([string $directory = '' ]) : void
Parameters
$directory : string = ''
Return values
void

constructExamplePath()

Returns a path to the example file in the given directory.

private constructExamplePath(string $directory, string $file) : string

.

Parameters
$directory : string
$file : string
Return values
string

getExampleFileContents()

Attempts to find the requested example file and returns its contents or null if no file was found.

private getExampleFileContents(string $filename) : array<string|int, string>

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
Parameters
$filename : string
Return values
array<string|int, string>

all lines of the example file

getExamplePathFromExampleDirectory()

Get example filepath based on the example directory inside your project.

private getExamplePathFromExampleDirectory(string $file) : string
Parameters
$file : string
Return values
string

getExamplePathFromSource()

Get example filepath based on sourcecode.

private getExamplePathFromSource(string $file) : string
Parameters
$file : string
Return values
string

Search results