From daaa00c2f38c382593a8f38958155fffca2832d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vieilledent?= Date: Wed, 22 Jun 2011 16:13:13 +0200 Subject: [PATCH] Autoload generator now compatible with namespaces --- .../private/classes/ezautoloadgenerator.php | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/kernel/private/classes/ezautoloadgenerator.php b/kernel/private/classes/ezautoloadgenerator.php index e77f0442bd7..5c36b82303e 100644 --- a/kernel/private/classes/ezautoloadgenerator.php +++ b/kernel/private/classes/ezautoloadgenerator.php @@ -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 ); @@ -468,12 +473,31 @@ 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. @@ -481,6 +505,10 @@ protected function getClassFileList( $fileList, $mode ) // CLASS_TOKEN - WHITESPACE_TOKEN - TEXT_TOKEN (containing class name) $className = $tokens[$key+2][1]; + if ( $namespace !== null ) + { + $className = $namespace . "\\" . $className; + } $filePath = $file; @@ -510,6 +538,7 @@ protected function getClassFileList( $fileList, $mode ) $retArray[$className] = $filePath; } + break; } } @@ -1163,7 +1192,7 @@ public function setOutputObject( $outputObject ) */ public function buildPHPUnitConfigurationFile() { - + if ( $this->mask == self::MODE_KERNEL ) { $this->log('Creating phpunit configuration file.'); @@ -1171,7 +1200,7 @@ public function buildPHPUnitConfigurationFile() $autoloadArray = @include 'autoload/ezp_kernel.php'; $baseDir = getcwd(); - + $dom = new DOMDocument( '1.0', 'utf-8' ); $dom->formatOutput = true; @@ -1199,6 +1228,6 @@ public function buildPHPUnitConfigurationFile() } } - + } ?>