kernel/private/classes/ezautoloadgenerator.php

Show: inherited
Table of Contents

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

Package: kernel

Utility class for generating autoload arrays for eZ Publish.

The class can handle classes from the kernel and extensions.

Constants

Constant  MODE_NONE = 0

Bitmask for searching in no files.

Constant  MODE_KERNEL = 1

Bitmask for searhing in kernel files

Constant  MODE_EXTENSION = 2

Bitmask for search in extension files

Constant  MODE_TESTS = 4

Bitmask for searching in test files

Constant  MODE_SINGLE_EXTENSION = 8

Bitmask for searching in a single extension only.

This mode is mutually exclusive from the other modes.

Constant  MODE_KERNEL_OVERRIDE = 16

Bitmask for searching for kernel overrides.

This mode is mutually excluse from the other modes.

Constant  OUTPUT_PROGRESS_PHASE1 = 1

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

Constant  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.

Constant  DEFAULT_EXCLUDE_FILE = '.autoloadignore'

The name of the file which contains default exclude directories for the autoload generator.

Properties

Propertyprotectedarray  $autoloadArrays= ''

Contains newly generated autoload data.

Used for sharing data between the printAutloadArrays() and writeAutoloadFiles() methods.

Details
Type
array
Propertyprotectedarray  $existingAutoloadArrays= ''

Contains the contents of already created autoload files.

If the files are not existing, the corresponding arrays will be empty.

Details
Type
array
Propertyprotectedint  $mask= ''

The bitmask containing all the operation modes.

Details
Type
int
Propertyprotectedarray  $messages= ''

Contains all the logged messages.

Details
Type
array
Propertyprotectedarray  $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.

Default valuearray( 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
Propertyprotected\ezpAutoloadGeneratorOptions  $options= ''

eZAutoloadGenerator options

Propertyprotectedobject  $output= ''

Object handling output of information for a given context.

Details
Type
object
Propertyprotectedcallback  $outputCallback= ''

The callback to be used in when logging messages.

Details
Type
callback
Propertyprotectedarray  $warnings= ''

Contains all the logged warning messages.

Details
Type
array

Methods

methodpublic__construct(  $options = null ) : void

Constructs class to generate autoload arrays.

Parameters
Name Type Description
$options
methodpublicbuildAutoloadArrays( ) : void

Searches specified directories for classes, and build autoload arrays.

Throws
Exception Description
\Exception if desired output directory is not a directory, or if the autoload arrays are not writeable by the script.
methodprotectedbuildFileList( string $path, array $extraFilter = null ) : array

Builds a filelist of all PHP files in $path.

Parameters
Name Type Description
$path string
$extraFilter array
Returns
Type Description
array
methodpublicbuildPHPUnitConfigurationFile( ) : \DOMDocument;

Create phpunit configuration file adding whitelist from kernel autoload file

It writes file phpunit.xml in ./tests directory

Returns
Type Description
\DOMDocument;
methodprotectedcheckMaxClassLength( array $depData ) : mixed

Calculates the length of the longest class name present in $depdata

Parameters
Name Type Description
$depData array
Returns
Type Description
mixed
methodprotectedcheckMode( ) : int

Checks which runmode the script should operate in: kernel-mode, extension-mode or both.

Returns
Type Description
int
methodprotectedclassCanBeAdded( string $class, string $file, int $mode, array $inProgressAutoloadArray ) : boolean

Determines if a class can be added to the autoload array.

  1. When regenerating array for MODE, do not check for existance of class duplicates in the existing array for the same mode.

  2. 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.

  3. If kernel array is not present, issue warning that class name collisions cannot be checked until kernel array is generated.

  4. Class collisions with kernel classes is only allowed for MODE_KERNEL_OVERRIDE

Parameters
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.

Returns
Type Description
boolean
methodprotectedclassExistsInArray( string $class, int $checkMode, string $file, array $inProgressAutoloadArray = null, int $generatingMode = null ) : boolean

Internal method used to check if an class exist autoload arrays.

Parameters
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.

Returns
Type Description
boolean
methodprotecteddumpArray( array $sortedArray, int $length ) : string

Build string version of the autoload array with correct indenting.

Parameters
Name Type Description
$sortedArray array
$length int
Returns
Type Description
string
methodprotecteddumpArrayEnd( ) : void

Prints generated code for end of the autoload files

methodprotecteddumpArrayStart( string $part ) : string

Prints generated code used for the autoload files

Parameters
Name Type Description
$part string
Returns
Type Description
string
methodprotectedemit( 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

Parameters
Name Type Description
$message string
$messageType string
methodprotectedfetchFiles( ) : array

Returns an array indexed by location for classes and their filenames.

Returns
Type Description
array
methodpublicfindRecursive( string $sourceDir, array $includeFilters = array(), array $excludeFilters = array(), \eZAutoloadGenerator $gen ) : array
static

Uses the walker in ezcBaseFile to find files.

This also uses the callback to get progress information about the file search.

Parameters
Name Type Description
$sourceDir string
$includeFilters array
$excludeFilters array
$gen \eZAutoloadGenerator
Returns
Type Description
array
methodpublicfindRecursiveCallback(  $context, string $sourceDir, string $fileName, string $fileInfo ) : void
static

Callback used ezcBaseFile

Parameters
Name Type Description
$context
$sourceDir string
$fileName string
$fileInfo string
methodprotectedgetClassFileList(  $fileList,  $mode ) : array

Extracts class information from PHP sourcecode.

Parameters
Name Type Description
$fileList
$mode
Returns
Type Description
array (className=>filename)
methodpublicgetMessages( ) : array

Get the array of logged messaages

Returns
Type Description
array
methodprotectedgetStatArray( int $phase ) : void

Fetches statistics array for $phase form the output object.

Parameters
Name Type Description
$phase int
methodpublicgetWarnings( ) : array

Get the array of logged warnings

Returns
Type Description
array
methodprotectedhandleDefaultExcludeFile( ) : 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.

Returns
Type Description
array The exclude directories
methodprotectedincrementProgressStat( 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.

Parameters
Name Type Description
$phase int
$stat array
methodprotectedlog( string $message ) : void

Pushes $message to the messages stack.

The $message will also tried to be emitted.

Parameters
Name Type Description
$message string
methodprotectedlogIssue(  $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().

Parameters
Name Type Description
$class
$checkMode
$file
$inProgressAutoloadArray
$generatingMode
methodprotectedlogWarning( string $message ) : void

Pushes $message to the warning stack.

The warning $message will also tried to be emitted.

Parameters
Name Type Description
$message string
methodprotectednameTable( string $lookup ) : string

Table to look up file names to use for different run modes.

Parameters
Name Type Description
$lookup string

Mode to look up, can be extension, or kernel.

Returns
Type Description
string
methodpublicprintAutoloadArray( 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.

Parameters
Name Type Description
$printForMode string

Run mode specified by the MODE_* constants.

Returns
Type Description
mixed
methodprotectedrunMode( ) : int

Generates the active bitmask for this instance of the autoload generation script depending on the parameters it sets the corresponding flags.

Returns
Type Description
int
methodpublicsetMode( 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 );
Parameters
Name Type Description
$modeValue int
methodpublicsetOptions(  $options ) : void

Parameters
Name Type Description
$options
methodpublicsetOutputCallback( callback $callback ) : void

Sets callback for outputting messages.

Parameters
Name Type Description
$callback callback
methodpublicsetOutputObject( object $outputObject ) : void

Sets the object to handle out from the autoload generation.

Currently this is only handled for the CLI.

Parameters
Name Type Description
$outputObject object
Details
See
\ezpAutoloadCliOutput  
methodprotectedsetStatArray( int $phase, array $data ) : void

Updates internal statistics data for $phase, with new array $data.

Parameters
Name Type Description
$phase int
$data array
methodprotectedstartProgressOutput( int $phase ) : void

Initializes progress output for $phase

Parameters
Name Type Description
$phase int
methodprotectedstopProgressOutput( int $phase ) : void

Stops progress output for $phase

Parameters
Name Type Description
$phase int
methodprotectedtargetTable( int $lookup ) : string

Provides a look-up for which base directory to use depending on mode.

Parameters
Name Type Description
$lookup int
Returns
Type Description
string
methodprotectedupdateProgressOutput( 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.

Parameters
Name Type Description
$phase int
methodprotectedwalkRecursive( mixed $sourceDir, array $includeFilters = array(), array $excludeFilters = array(), mixed $callback, mixed $callbackContext ) : array
static

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.

Parameters
Name Type Description
$sourceDir mixed
$includeFilters array
$excludeFilters array
$callback mixed
$callbackContext mixed
Returns
Type Description
array
Throws
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.
methodprotectedwriteAutoloadFiles( ) : void

Writes the autoload data in $data for the mode/location $location to actual files.

This method also make sure that the target directory exists, and directs the different autoload arrays to different destinations, depending on the operation mode.

Documentation was generated by DocBlox 0.18.1.