eZPublishCommunityProject(LegacyStack)  2013.9
eZAutoloadGenerator Class Reference

Public Member Functions

 __construct (ezpAutoloadGeneratorOptions $options=null)
 Constructs class to generate autoload arrays. More...
 
 buildAutoloadArrays ()
 Searches specified directories for classes, and build autoload arrays. More...
 
 getMessages ()
 Get the array of logged messaages. More...
 
 getWarnings ()
 Get the array of logged warnings. More...
 
 printAutoloadArray ($printForMode=null)
 Prints out the generated autoload arrays. More...
 
 setMode ($modeValue)
 Convenience method to set the mode directly. More...
 
 setOptions ($options)
 
 setOutputCallback ($callback)
 Sets callback for outputting messages. More...
 
 setOutputObject ($outputObject)
 Sets the object to handle out from the autoload generation. More...
 

Static Public Member Functions

static findRecursive ($sourceDir, array $includeFilters=array(), array $excludeFilters=array(), eZAutoloadGenerator $gen)
 Uses the walker in ezcBaseFile to find files. More...
 
static findRecursiveCallback (ezpAutoloadFileFindContext $context, $sourceDir, $fileName, $fileInfo)
 Callback used ezcBaseFile. More...
 

Public Attributes

const DEFAULT_EXCLUDE_FILE = '.autoloadignore'
 The name of the file which contains default exclude directories for the autoload generator. More...
 
const MODE_EXTENSION = 2
 Bitmask for search in extension files. More...
 
const MODE_KERNEL = 1
 Bitmask for searhing in kernel files. More...
 
const MODE_KERNEL_OVERRIDE = 16
 Bitmask for searching for kernel overrides. More...
 
const MODE_NONE = 0
 Bitmask for searching in no files. More...
 
const MODE_SINGLE_EXTENSION = 8
 Bitmask for searching in a single extension only. More...
 
const MODE_TESTS = 4
 Bitmask for searching in test files. More...
 
const OUTPUT_PROGRESS_PHASE1 = 1
 Represents the first phase of autoload generation, where the code searches for PHP source files. More...
 
const 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. More...
 
const UNDEFINED_TOKEN = -1
 Undefined token value. More...
 

Protected Member Functions

 buildFileList ($path, $extraFilter=null)
 Builds a filelist of all PHP files in $path. More...
 
 checkMaxClassLength ($depData)
 Calculates the length of the longest class name present in $depdata. More...
 
 checkMode ()
 Checks which runmode the script should operate in: kernel-mode, extension-mode or both. More...
 
 classCanBeAdded ($class, $file, $mode, $inProgressAutoloadArray)
 Determines if a class can be added to the autoload array. More...
 
 classExistsInArray ($class, $checkMode, $file, $inProgressAutoloadArray=null, $generatingMode=null)
 Internal method used to check if an class exist autoload arrays. More...
 
 dumpArray ($sortedArray, $length)
 Build string version of the autoload array with correct indenting. More...
 
 dumpArrayEnd ()
 Prints generated code for end of the autoload files. More...
 
 dumpArrayStart ($part)
 Prints generated code used for the autoload files. More...
 
 emit ($message, $messageType)
 Will call output callback if defined. More...
 
 fetchFiles ()
 Returns an array indexed by location for classes and their filenames. More...
 
 getClassFileList ($fileList, $mode)
 Extracts class information from PHP sourcecode. More...
 
 getStatArray ($phase)
 Fetches statistics array for $phase form the output object. More...
 
 handleDefaultExcludeFile ()
 Adds exclude directories specified in the default excludes files, to the exclude array. More...
 
 incrementProgressStat ($phase, $stat)
 Increment counters used for statistics in the progress output. More...
 
 log ($message)
 Pushes $message to the messages stack. More...
 
 logIssue ($class, $checkMode, $file, $inProgressAutoloadArray, $generatingMode)
 Helper method for giving user feedback when check for class collisions. More...
 
 logWarning ($message)
 Pushes $message to the warning stack. More...
 
 nameTable ($lookup)
 Table to look up file names to use for different run modes. More...
 
 runMode ()
 Generates the active bitmask for this instance of the autoload generation script depending on the parameters it sets the corresponding flags. More...
 
 setStatArray ($phase, $data)
 Updates internal statistics data for $phase, with new array $data. More...
 
 startProgressOutput ($phase)
 Initializes progress output for $phase More...
 
 stopProgressOutput ($phase)
 Stops progress output for $phase More...
 
 targetTable ($lookup)
 Provides a look-up for which base directory to use depending on mode. More...
 
 updateProgressOutput ($phase)
 Calls updateProgress on the output object. More...
 
 writeAutoloadFiles ()
 Writes the autoload data in $data for the mode/location $location to actual files. More...
 

Static Protected Member Functions

static walkRecursive ($sourceDir, array $includeFilters=array(), array $excludeFilters=array(), $callback, &$callbackContext)
 Walks files and directories recursively on a file system. More...
 

Protected Attributes

 $autoloadArrays
 
 $existingAutoloadArrays
 
 $mask
 
 $messages
 
 $modeName
 
 $options
 
 $output
 
 $outputCallback
 
 $warnings
 

Constructor & Destructor Documentation

eZAutoloadGenerator::__construct ( ezpAutoloadGeneratorOptions  $options = null)

Constructs class to generate autoload arrays.

Member Function Documentation

eZAutoloadGenerator::buildAutoloadArrays ( )

Searches specified directories for classes, and build autoload arrays.

Exceptions
Exceptionif desired output directory is not a directory, or if the autoload arrays are not writeable by the script.
Returns
void
eZAutoloadGenerator::buildFileList (   $path,
  $extraFilter = null 
)
protected

Builds a filelist of all PHP files in $path.

Parameters
string$path
array$extraFilter
Returns
array

Referenced by fetchFiles().

eZAutoloadGenerator::checkMaxClassLength (   $depData)
protected

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

Parameters
array$depData
Returns
mixed

Referenced by buildAutoloadArrays().

eZAutoloadGenerator::checkMode ( )
protected

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

Parameters
int$maskBitmask to check for run mode.
Returns
int

Referenced by fetchFiles().

eZAutoloadGenerator::classCanBeAdded (   $class,
  $file,
  $mode,
  $inProgressAutoloadArray 
)
protected

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
string$classThe name of the class being checked.
string$fileThe filename where the class is found.
int$modeThe mode representing the current run mode.
array$inProgressAutoloadArrayArray of the already detected classes for the current mode.
Returns
boolean

Referenced by getClassFileList().

eZAutoloadGenerator::classExistsInArray (   $class,
  $checkMode,
  $file,
  $inProgressAutoloadArray = null,
  $generatingMode = null 
)
protected

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

Parameters
string$classThe name of the class being checked.
int$checkModeThe mode whose autoload arrays will be checked.
string$fileFilename containing the class.
array$inProgressAutoloadArrayThe autoload array generated so far.
int$generatingModeThe mode we are generating for autoloads for.
Returns
boolean

Referenced by classCanBeAdded().

eZAutoloadGenerator::dumpArray (   $sortedArray,
  $length 
)
protected

Build string version of the autoload array with correct indenting.

Parameters
array$sortedArray
int$length
Returns
string

Referenced by buildAutoloadArrays().

eZAutoloadGenerator::dumpArrayEnd ( )
protected

Prints generated code for end of the autoload files.

Returns
void

Referenced by printAutoloadArray(), and writeAutoloadFiles().

eZAutoloadGenerator::dumpArrayStart (   $part)
protected

Prints generated code used for the autoload files.

Parameters
string$part
Returns
string

Referenced by printAutoloadArray(), and writeAutoloadFiles().

eZAutoloadGenerator::emit (   $message,
  $messageType 
)
protected

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 Also
setOutputCallback(), that method will be called with $message and $messageType
Parameters
string$message
string$messageType
Returns
void

Referenced by log(), and logWarning().

eZAutoloadGenerator::fetchFiles ( )
protected

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

Parameters
string$pathThe base path to start the search from.
string$maskA binary mask which instructs the function whether to fetch kernel-related or extension-related files.
Returns
array

Referenced by buildAutoloadArrays().

static eZAutoloadGenerator::findRecursive (   $sourceDir,
array  $includeFilters = array(),
array  $excludeFilters = array(),
eZAutoloadGenerator  $gen 
)
static

Uses the walker in ezcBaseFile to find files.

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

Parameters
string$sourceDir
array$includeFilters
array$excludeFilters
eZAutoloadGenerator$gen
Returns
array
static eZAutoloadGenerator::findRecursiveCallback ( ezpAutoloadFileFindContext  $context,
  $sourceDir,
  $fileName,
  $fileInfo 
)
static

Callback used ezcBaseFile.

Parameters
string$ezpAutoloadFileFindContext
string$sourceDir
string$fileName
string$fileInfo
Returns
void
eZAutoloadGenerator::getClassFileList (   $fileList,
  $mode 
)
protected

Extracts class information from PHP sourcecode.

Returns
array (className=>filename)

Referenced by buildAutoloadArrays().

eZAutoloadGenerator::getMessages ( )

Get the array of logged messaages.

Returns
array
eZAutoloadGenerator::getStatArray (   $phase)
protected

Fetches statistics array for $phase form the output object.

Parameters
int$phase
Returns
void

Referenced by getClassFileList().

eZAutoloadGenerator::getWarnings ( )

Get the array of logged warnings.

Returns
array
eZAutoloadGenerator::handleDefaultExcludeFile ( )
protected

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
array The exclude directories

Referenced by fetchFiles().

eZAutoloadGenerator::incrementProgressStat (   $phase,
  $stat 
)
protected

Increment counters used for statistics in the progress output.

If the output object is not set, the method will not do anything.

Parameters
int$phase
array$stat
Returns
void

Referenced by getClassFileList().

eZAutoloadGenerator::log (   $message)
protected

Pushes $message to the messages stack.

The $message will also tried to be emitted.

Parameters
string$message
Returns
void

Referenced by findRecursive(), getClassFileList(), logIssue(), and printAutoloadArray().

eZAutoloadGenerator::logIssue (   $class,
  $checkMode,
  $file,
  $inProgressAutoloadArray,
  $generatingMode 
)
protected

Helper method for giving user feedback when check for class collisions.

The params are the same as for classExistsInArray().

Returns
void

Referenced by classExistsInArray().

eZAutoloadGenerator::logWarning (   $message)
protected

Pushes $message to the warning stack.

The warning $message will also tried to be emitted.

Parameters
string$message
Returns
void

Referenced by classCanBeAdded(), and logIssue().

eZAutoloadGenerator::nameTable (   $lookup)
protected

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

Parameters
string$lookupMode to look up, can be extension, or kernel.
Returns
string

Referenced by writeAutoloadFiles().

eZAutoloadGenerator::printAutoloadArray (   $printForMode = null)

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
string$printForModeRun mode specified by the MODE_* constants.
Returns
mixed
eZAutoloadGenerator::runMode ( )
protected

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

Returns
int

Referenced by __construct().

eZAutoloadGenerator::setMode (   $modeValue)

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
int$modeValue
Returns
void
eZAutoloadGenerator::setOptions (   $options)
eZAutoloadGenerator::setOutputCallback (   $callback)

Sets callback for outputting messages.

Parameters
callback$callback
Returns
void
eZAutoloadGenerator::setOutputObject (   $outputObject)

Sets the object to handle out from the autoload generation.

Currently this is only handled for the CLI.

See Also
ezpAutoloadCliOutput
Parameters
object$outputObject
Returns
void
eZAutoloadGenerator::setStatArray (   $phase,
  $data 
)
protected

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

Parameters
int$phase
array$data
Returns
void

Referenced by getClassFileList().

eZAutoloadGenerator::startProgressOutput (   $phase)
protected

Initializes progress output for $phase

Parameters
int$phase
Returns
void

Referenced by findRecursive(), and getClassFileList().

eZAutoloadGenerator::stopProgressOutput (   $phase)
protected

Stops progress output for $phase

Parameters
int$phase
Returns
void

Referenced by findRecursive(), and getClassFileList().

eZAutoloadGenerator::targetTable (   $lookup)
protected

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

Parameters
int$lookup
Returns
string

Referenced by writeAutoloadFiles().

eZAutoloadGenerator::updateProgressOutput (   $phase)
protected

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
int$phase
string$array
Returns
void

Referenced by getClassFileList().

static eZAutoloadGenerator::walkRecursive (   $sourceDir,
array  $includeFilters = array(),
array  $excludeFilters = array(),
  $callback,
$callbackContext 
)
staticprotected

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
mixed$sourceDir
array$includeFilters
array$excludeFilters
mixed$callback
mixed$callbackContext
Exceptions
ezcBaseFileNotFoundExceptionif the $sourceDir directory is not a directory or does not exist.
ezcBaseFilePermissionExceptionif the $sourceDir directory could not be opened for reading.
Returns
array
eZAutoloadGenerator::writeAutoloadFiles ( )
protected

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.

Parameters
int$location
string$data
Returns
void

Referenced by buildAutoloadArrays().

Member Data Documentation

eZAutoloadGenerator::$autoloadArrays
protected
eZAutoloadGenerator::$existingAutoloadArrays
protected
eZAutoloadGenerator::$mask
protected
eZAutoloadGenerator::$messages
protected
eZAutoloadGenerator::$modeName
protected
Initial value:
= 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",
)
eZAutoloadGenerator::$options
protected

Referenced by __construct().

eZAutoloadGenerator::$output
protected
eZAutoloadGenerator::$outputCallback
protected
eZAutoloadGenerator::$warnings
protected
const eZAutoloadGenerator::DEFAULT_EXCLUDE_FILE = '.autoloadignore'

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

const eZAutoloadGenerator::MODE_EXTENSION = 2

Bitmask for search in extension files.

const eZAutoloadGenerator::MODE_KERNEL = 1

Bitmask for searhing in kernel files.

const eZAutoloadGenerator::MODE_KERNEL_OVERRIDE = 16

Bitmask for searching for kernel overrides.

This mode is mutually excluse from the other modes.

const eZAutoloadGenerator::MODE_NONE = 0

Bitmask for searching in no files.

const eZAutoloadGenerator::MODE_SINGLE_EXTENSION = 8

Bitmask for searching in a single extension only.

This mode is mutually exclusive from the other modes.

const eZAutoloadGenerator::MODE_TESTS = 4

Bitmask for searching in test files.

const eZAutoloadGenerator::OUTPUT_PROGRESS_PHASE1 = 1

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

Referenced by findRecursiveCallback(), ezpAutoloadCliOutput\getData(), and ezpAutoloadCliOutput\updateProgress().

const eZAutoloadGenerator::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.

Referenced by ezpAutoloadCliOutput\getData(), and ezpAutoloadCliOutput\updateProgress().

const eZAutoloadGenerator::UNDEFINED_TOKEN = -1

Undefined token value.


The documentation for this class was generated from the following file: