kernel/private/classes/ezautoloadgenerator.php
File containing the eZAutoloadGenerator class.
- Copyright
- Copyright (C) 1999-2010 eZ Systems AS. All rights reserved.
- License
- GNU General Public License v2.0
- Package
- kernel
- Version
- 4.4.0
\eZAutoloadGenerator
Utility class for generating autoload arrays for eZ Publish.
The class can handle classes from the kernel and extensions.
Constants
MODE_SINGLE_EXTENSION
= 8Bitmask for searching in a single extension only.
This mode is mutually exclusive from the other modes.
MODE_KERNEL_OVERRIDE
= 16Bitmask for searching for kernel overrides.
This mode is mutually excluse from the other modes.
OUTPUT_PROGRESS_PHASE1
= 1Represents the first phase of autoload generation, where the code searches for PHP source files.
Properties

array
$autoloadArrays= ''
Contains newly generated autoload data.
Used for sharing data between the printAutloadArrays() and writeAutoloadFiles() methods.
- Type
- array

array
$existingAutoloadArrays= ''
Contains the contents of already created autoload files.
If the files are not existing, the corresponding arrays will be empty.
- Type
- array

array
$modeName= 'array(
self::MODE_KERNEL => "Kernel",
self::MODE_EXTENSION => "Extension",
self::MODE_TESTS => "Test",
self::MODE_SINGLE_EXTENSION =>"Single extension",
self::MODE_KERNEL_OVERRIDE => "Kernel overrides",
)'
Nametable for each of the MODE_* modes defined in the class.
array(
self::MODE_KERNEL => "Kernel",
self::MODE_EXTENSION => "Extension",
self::MODE_TESTS => "Test",
self::MODE_SINGLE_EXTENSION =>"Single extension",
self::MODE_KERNEL_OVERRIDE => "Kernel overrides",
)Details- Type
- array

callback
$outputCallback= ''
The callback to be used in when logging messages.
- Type
- callback
Methods

__construct(
$options
=
null
)
:
voidConstructs class to generate autoload arrays.
| Name | Type | Description |
|---|---|---|
| $options |

buildAutoloadArrays(
)
:
voidSearches specified directories for classes, and build autoload arrays.
| Exception | Description |
|---|---|
| \Exception | if desired output directory is not a directory, or if the autoload arrays are not writeable by the script. |

buildFileList(
string $path, array $extraFilter
=
null
)
:
arrayBuilds a filelist of all PHP files in $path.
| Name | Type | Description |
|---|---|---|
| $path | string | |
| $extraFilter | array |
| Type | Description |
|---|---|
| array |

checkMaxClassLength(
array $depData
)
:
mixedCalculates the length of the longest class name present in $depdata
| Name | Type | Description |
|---|---|---|
| $depData | array |
| Type | Description |
|---|---|
| mixed |

checkMode(
)
:
intChecks which runmode the script should operate in: kernel-mode, extension-mode or both.
| Type | Description |
|---|---|
| int |

classCanBeAdded(
string $class, string $file, int $mode, array $inProgressAutoloadArray
)
:
booleanDetermines if a class can be added to the autoload array.
When regenerating array for MODE, do not check for existance of class duplicates in the existing array for the same mode.
When adding a new class to the in-progress autoload array, check for matching keys, before adding. If match is found then add a warning message to the warnings stack, and mark the class not to be added.
If kernel array is not present, issue warning that class name collisions cannot be checked until kernel array is generated.
Class collisions with kernel classes is only allowed for MODE_KERNEL_OVERRIDE
| Name | Type | Description |
|---|---|---|
| $class | string | The name of the class being checked. |
| $file | string | The filename where the class is found. |
| $mode | int | The mode representing the current run mode. |
| $inProgressAutoloadArray | array | Array of the already detected classes for the current mode. |
| Type | Description |
|---|---|
| boolean |

classExistsInArray(
string $class, int $checkMode, string $file, array $inProgressAutoloadArray
=
null, int $generatingMode
=
null
)
:
booleanInternal method used to check if an class exist autoload arrays.
| Name | Type | Description |
|---|---|---|
| $class | string | The name of the class being checked. |
| $checkMode | int | The mode whose autoload arrays will be checked. |
| $file | string | Filename containing the class. |
| $inProgressAutoloadArray | array | The autoload array generated so far. |
| $generatingMode | int | The mode we are generating for autoloads for. |
| Type | Description |
|---|---|
| boolean |

dumpArray(
array $sortedArray, int $length
)
:
stringBuild string version of the autoload array with correct indenting.
| Name | Type | Description |
|---|---|---|
| $sortedArray | array | |
| $length | int |
| Type | Description |
|---|---|
| string |

dumpArrayStart(
string $part
)
:
stringPrints generated code used for the autoload files
| Name | Type | Description |
|---|---|---|
| $part | string |
| Type | Description |
|---|---|
| string |

emit(
string $message, string $messageType
)
:
voidWill call output callback if defined.
The purpose of this function is to directly emit messages, for instance when the class is being used from shell scripts. If a valid callback has been setup with @see setOutputCallback(), that method will be called with $message and $messageType
| Name | Type | Description |
|---|---|---|
| $message | string | |
| $messageType | string |

fetchFiles(
)
:
arrayReturns an array indexed by location for classes and their filenames.
| Type | Description |
|---|---|
| array |

findRecursive(
string $sourceDir, array $includeFilters
=
array(), array $excludeFilters
=
array(), \eZAutoloadGenerator $gen
)
:
arrayUses the walker in ezcBaseFile to find files.
This also uses the callback to get progress information about the file search.
| Name | Type | Description |
|---|---|---|
| $sourceDir | string | |
| $includeFilters | array | |
| $excludeFilters | array | |
| $gen | \eZAutoloadGenerator |
| Type | Description |
|---|---|
| array |

findRecursiveCallback(
$context, string $sourceDir, string $fileName, string $fileInfo
)
:
voidCallback used ezcBaseFile
| Name | Type | Description |
|---|---|---|
| $context | ||
| $sourceDir | string | |
| $fileName | string | |
| $fileInfo | string |

getClassFileList(
$fileList, $mode
)
:
arrayExtracts class information from PHP sourcecode.
| Name | Type | Description |
|---|---|---|
| $fileList | ||
| $mode |
| Type | Description |
|---|---|
| array | (className=>filename) |

getStatArray(
int $phase
)
:
voidFetches statistics array for $phase form the output object.
| Name | Type | Description |
|---|---|---|
| $phase | int |

incrementProgressStat(
int $phase, array $stat
)
:
voidIncrement counters used for statistics in the progress output.
If the output object is not set, the method will not do anything.
| Name | Type | Description |
|---|---|---|
| $phase | int | |
| $stat | array |

log(
string $message
)
:
voidPushes $message to the messages stack.
The $message will also tried to be emitted.
| Name | Type | Description |
|---|---|---|
| $message | string |

logIssue(
$class, $checkMode, $file, $inProgressAutoloadArray, $generatingMode
)
:
voidHelper method for giving user feedback when check for class collisions.
The params are the same as for classExistsInArray().
| Name | Type | Description |
|---|---|---|
| $class | ||
| $checkMode | ||
| $file | ||
| $inProgressAutoloadArray | ||
| $generatingMode |

logWarning(
string $message
)
:
voidPushes $message to the warning stack.
The warning $message will also tried to be emitted.
| Name | Type | Description |
|---|---|---|
| $message | string |

nameTable(
string $lookup
)
:
stringTable to look up file names to use for different run modes.
| Name | Type | Description |
|---|---|---|
| $lookup | string | Mode to look up, can be extension, or kernel. |
| Type | Description |
|---|---|
| string |

printAutoloadArray(
string $printForMode
=
null
)
:
mixedPrints out the generated autoload arrays.
Meant to provide a user-viewable output of the defined autoload arrays. If $printForMode is provided, only the array for that mode will be printed.
| Name | Type | Description |
|---|---|---|
| $printForMode | string | Run mode specified by the MODE_* constants. |
| Type | Description |
|---|---|
| mixed |

runMode(
)
:
intGenerates the active bitmask for this instance of the autoload generation script depending on the parameters it sets the corresponding flags.
| Type | Description |
|---|---|
| int |

setMode(
int $modeValue
)
:
voidConvenience method to set the mode directly.
This is a method which allow you to set the operation mode directly and bypass the options object. The bitmask $modeValue can be set using the MODE_* class constants.
$gen = new eZAutoloadGenerator();
$gen->setMode( eZAutoloadGenerator::MODE_EXTENSION | eZAutoloadGenerator::MODE_TESTS );
| Name | Type | Description |
|---|---|---|
| $modeValue | int |

setOutputCallback(
callback $callback
)
:
voidSets callback for outputting messages.
| Name | Type | Description |
|---|---|---|
| $callback | callback |

setOutputObject(
object $outputObject
)
:
voidSets the object to handle out from the autoload generation.
Currently this is only handled for the CLI.
| Name | Type | Description |
|---|---|---|
| $outputObject | object |

setStatArray(
int $phase, array $data
)
:
voidUpdates internal statistics data for $phase, with new array $data.
| Name | Type | Description |
|---|---|---|
| $phase | int | |
| $data | array |

startProgressOutput(
int $phase
)
:
voidInitializes progress output for $phase
| Name | Type | Description |
|---|---|---|
| $phase | int |

stopProgressOutput(
int $phase
)
:
voidStops progress output for $phase
| Name | Type | Description |
|---|---|---|
| $phase | int |

targetTable(
int $lookup
)
:
stringProvides a look-up for which base directory to use depending on mode.
| Name | Type | Description |
|---|---|---|
| $lookup | int |
| Type | Description |
|---|---|
| string |

updateProgressOutput(
int $phase
)
:
voidCalls updateProgress on the output object.
If progress output is not enabled or the output object is not set, this method will not do anything.
| Name | Type | Description |
|---|---|---|
| $phase | int |