Skip to content

Commit

Permalink
Autoload generator now compatible with namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Vieilledent committed Jun 23, 2011
1 parent 745c07b commit daaa00c
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions kernel/private/classes/ezautoloadgenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ protected function getClassFileList( $fileList, $mode )
$this->setStatArray( self::OUTPUT_PROGRESS_PHASE2, $statArray );
$this->startProgressOutput( self::OUTPUT_PROGRESS_PHASE2 );

// Compatibility with PHP 5.2 where T_NAMESPACE constant is not available
// Assigning the constant value to $tNamespace
// 377 is the value for T_NAMESPACE in PHP 5.3.x
$tNamespace = defined( 'T_NAMESPACE' ) ? T_NAMESPACE : 377;

foreach( $fileList as $file )
{
$this->updateProgressOutput( self::OUTPUT_PROGRESS_PHASE2 );
Expand All @@ -468,19 +473,42 @@ protected function getClassFileList( $fileList, $mode )
}

$tokens = @token_get_all( file_get_contents( $file ) );
$namespace = null;
foreach( $tokens as $key => $token )
{
if ( is_array( $token ) )
{
switch( $token[0] )
{
// Store namespace name, if applicable, to concatenate with class name
case $tNamespace:
// NAMESPACE_TOKEN - WHITESPACE_TOKEN - TEXT_TOKENS (containing namespace name)
$offset = $key + 2;
$namespace = "";
while ( $tokens[$offset] !== ";" )
{
if ( is_array( $tokens[$offset] ) )
{
$namespace .= $tokens[$offset][1];
}

$offset++;
}

$namespace = trim( $namespace );
break;

case T_CLASS:
case T_INTERFACE:
// Increment stat for found class.
$this->incrementProgressStat( self::OUTPUT_PROGRESS_PHASE2, 'classCount' );

// CLASS_TOKEN - WHITESPACE_TOKEN - TEXT_TOKEN (containing class name)
$className = $tokens[$key+2][1];
if ( $namespace !== null )
{
$className = $namespace . "\\" . $className;
}

$filePath = $file;

Expand Down Expand Up @@ -510,6 +538,7 @@ protected function getClassFileList( $fileList, $mode )

$retArray[$className] = $filePath;
}

break;
}
}
Expand Down Expand Up @@ -1163,15 +1192,15 @@ public function setOutputObject( $outputObject )
*/
public function buildPHPUnitConfigurationFile()
{

if ( $this->mask == self::MODE_KERNEL )
{
$this->log('Creating phpunit configuration file.');

$autoloadArray = @include 'autoload/ezp_kernel.php';

$baseDir = getcwd();

$dom = new DOMDocument( '1.0', 'utf-8' );
$dom->formatOutput = true;

Expand Down Expand Up @@ -1199,6 +1228,6 @@ public function buildPHPUnitConfigurationFile()
}

}

}
?>

0 comments on commit daaa00c

Please sign in to comment.