kernel/private/classes/ezautoloadgenerator.php
File containing the eZAutoloadGenerator class.
- Copyright
- Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
- License
- eZ Business Use License Agreement Version 2.0
- Package
- kernel
- Version
- 4.6.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
= 8
Bitmask for searching in a single extension only.
This mode is mutually exclusive from the other modes.

MODE_KERNEL_OVERRIDE
= 16
Bitmask for searching for kernel overrides.
This mode is mutually excluse from the other modes.

OUTPUT_PROGRESS_PHASE1
= 1
Represents the first phase of autoload generation, where the code searches for PHP source files.

OUTPUT_PROGRESS_PHASE2
= 2
Represents the second phase of autoload generation, where the code tokenizes the found PHP files to look for classes and interfaces.
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
)
:
void
Constructs class to generate autoload arrays.
Name | Type | Description |
---|---|---|
$options |


buildAutoloadArrays(
)
:
void
Searches 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
)
:
array
Builds a filelist of all PHP files in $path.
Name | Type | Description |
---|---|---|
$path | string | |
$extraFilter | array |
Type | Description |
---|---|
array |


buildPHPUnitConfigurationFile(
)
:
\DOMDocument;
Create phpunit configuration file adding whitelist from kernel autoload file
It writes file phpunit.xml in ./tests directory
Type | Description |
---|---|
\DOMDocument; |


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


checkMode(
)
:
int
Checks 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
)
:
boolean
Determines 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
)
:
boolean
Internal 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
)
:
string
Build string version of the autoload array with correct indenting.
Name | Type | Description |
---|---|---|
$sortedArray | array | |
$length | int |
Type | Description |
---|---|
string |


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


emit(
string $message, string $messageType
)
:
void
Will 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(
)
:
array
Returns an array indexed by location for classes and their filenames.
Type | Description |
---|---|
array |


findRecursive(
string $sourceDir, array $includeFilters
=
array(), array $excludeFilters
=
array(), \eZAutoloadGenerator $gen
)
:
array
Uses 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
)
:
void
Callback used ezcBaseFile
Name | Type | Description |
---|---|---|
$context | ||
$sourceDir | string | |
$fileName | string | |
$fileInfo | string |


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


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


handleDefaultExcludeFile(
)
:
array
Adds exclude directories specified in the default excludes files, to the exclude array.
If the default exclude file '.autoloadignore' does not exist, the function will just return the user specified exclude directories. This function relies on the options object being available in the instance.
Type | Description |
---|---|
array | The exclude directories |


incrementProgressStat(
int $phase, array $stat
)
:
void
Increment 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
)
:
void
Pushes $message to the messages stack.
The $message will also tried to be emitted.
Name | Type | Description |
---|---|---|
$message | string |


logIssue(
$class, $checkMode, $file, $inProgressAutoloadArray, $generatingMode
)
:
void
Helper 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
)
:
void
Pushes $message to the warning stack.
The warning $message will also tried to be emitted.
Name | Type | Description |
---|---|---|
$message | string |


nameTable(
string $lookup
)
:
string
Table 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
)
:
mixed
Prints 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(
)
:
int
Generates 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
)
:
void
Convenience 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
)
:
void
Sets callback for outputting messages.
Name | Type | Description |
---|---|---|
$callback | callback |


setOutputObject(
object $outputObject
)
:
void
Sets 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
)
:
void
Updates internal statistics data for $phase, with new array $data.
Name | Type | Description |
---|---|---|
$phase | int | |
$data | array |


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


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


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


updateProgressOutput(
int $phase
)
:
void
Calls 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 |


walkRecursive(
mixed $sourceDir, array $includeFilters
=
array(), array $excludeFilters
=
array(), mixed $callback, mixed $callbackContext
)
:
array
Walks files and directories recursively on a file system. This methods is the same as ezcBaseFile::walkRecursive() except that it applies $excludeFilters directories where the original only applies $excludeFilters on files. As soon as https://issues.apache.org/jira/browse/ZETACOMP-85 is implemented, this method could be removed.
Name | Type | Description |
---|---|---|
$sourceDir | mixed | |
$includeFilters | array | |
$excludeFilters | array | |
$callback | mixed | |
$callbackContext | mixed |
Type | Description |
---|---|
array |
Exception | Description |
---|---|
\ezcBaseFileNotFoundException | if the $sourceDir directory is not a directory or does not exist. |
\ezcBaseFilePermissionException | if the $sourceDir directory could not be opened for reading. |