| 1 | <?php |
| 2 | /** |
| 3 | * Autoloader definition for eZ Publish |
| 4 | * |
| 5 | * @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved. |
| 6 | * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 |
| 7 | * @version 2011.7 |
| 8 | * @package kernel |
| 9 | */ |
| 10 | |
| 11 | // config.php can set the components path like: |
| 12 | // ini_set( 'include_path', ini_get( 'include_path' ). ':../ezcomponents/trunk' ); |
| 13 | // It is also possible to push a custom autoload method to the autoload |
| 14 | // function stack. Remember to check for class prefixes in such a method, if it |
| 15 | // will not serve classes from eZ Publish and eZ Components |
| 16 | |
| 17 | if ( file_exists( 'config.php' ) ) |
| 18 | { |
| 19 | require 'config.php'; |
| 20 | } |
| 21 | |
| 22 | $useBundledComponents = defined( 'EZP_USE_BUNDLED_COMPONENTS' ) ? EZP_USE_BUNDLED_COMPONENTS === true : file_exists( 'lib/ezc' ); |
| 23 | if ( $useBundledComponents ) |
| 24 | { |
| 25 | set_include_path( '.' . PATH_SEPARATOR . './lib/ezc' . PATH_SEPARATOR . get_include_path() ); |
| 26 | require 'Base/src/base.php'; |
| 27 | $baseEnabled = true; |
| 28 | } |
| 29 | else if ( defined( 'EZC_BASE_PATH' ) ) |
| 30 | { |
| 31 | require EZC_BASE_PATH; |
| 32 | $baseEnabled = true; |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | $baseEnabled = @include 'ezc/Base/base.php'; |
| 37 | if ( !$baseEnabled ) |
| 38 | { |
| 39 | $baseEnabled = @include 'Base/src/base.php'; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | define( 'EZCBASE_ENABLED', $baseEnabled ); |
| 44 | |
| 45 | /** |
| 46 | * Provides the native autoload functionality for eZ Publish |
| 47 | * |
| 48 | * @package kernel |
| 49 | */ |
| 50 | class ezpAutoloader |
| 51 | { |
| 52 | protected static $ezpClasses = null; |
| 53 | |
| 54 | public static function autoload( $className ) |
| 55 | { |
| 56 | if ( self::$ezpClasses === null ) |
| 57 | { |
| 58 | $ezpKernelClasses = require 'autoload/ezp_kernel.php'; |
| 59 | $ezpExtensionClasses = false; |
| 60 | $ezpTestClasses = false; |
| 61 | |
| 62 | if ( file_exists( 'var/autoload/ezp_extension.php' ) ) |
| 63 | { |
| 64 | $ezpExtensionClasses = require 'var/autoload/ezp_extension.php'; |
| 65 | } |
| 66 | |
| 67 | if ( file_exists( 'var/autoload/ezp_tests.php' ) ) |
| 68 | { |
| 69 | $ezpTestClasses = require 'var/autoload/ezp_tests.php'; |
| 70 | } |
| 71 | |
| 72 | if ( $ezpExtensionClasses and $ezpTestClasses ) |
| 73 | { |
| 74 | self::$ezpClasses = array_merge( $ezpKernelClasses, $ezpExtensionClasses, $ezpTestClasses ); |
| 75 | } |
| 76 | else if ( $ezpExtensionClasses ) |
| 77 | { |
| 78 | self::$ezpClasses = array_merge( $ezpKernelClasses, $ezpExtensionClasses ); |
| 79 | } |
| 80 | else if ( $ezpTestClasses ) |
| 81 | { |
| 82 | self::$ezpClasses = array_merge( $ezpKernelClasses, $ezpTestClasses ); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | self::$ezpClasses = $ezpKernelClasses; |
| 87 | } |
| 88 | |
| 89 | if ( defined( 'EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE' ) and EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE ) |
| 90 | { |
| 91 | // won't work, as eZDebug isn't initialized yet at that time |
| 92 | // eZDebug::writeError( "Kernel override is enabled, but var/autoload/ezp_override.php has not been generated\nUse bin/php/ezpgenerateautoloads.php -o", 'autoload.php' ); |
| 93 | if ( $ezpKernelOverrideClasses = include 'var/autoload/ezp_override.php' ) |
| 94 | { |
| 95 | self::$ezpClasses = array_merge( self::$ezpClasses, $ezpKernelOverrideClasses ); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if ( isset( self::$ezpClasses[$className] ) ) |
| 101 | { |
| 102 | require( self::$ezpClasses[$className] ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Resets the local, in-memory autoload cache. |
| 108 | * |
| 109 | * If the autoload arrays are extended during a requests lifetime, this |
| 110 | * method must be called, to make them available. |
| 111 | * |
| 112 | * @return void |
| 113 | */ |
| 114 | public static function reset() |
| 115 | { |
| 116 | self::$ezpClasses = null; |
| 117 | } |
| 118 | |
| 119 | public static function updateExtensionAutoloadArray() |
| 120 | { |
| 121 | $autoloadGenerator = new eZAutoloadGenerator(); |
| 122 | try |
| 123 | { |
| 124 | $autoloadGenerator->buildAutoloadArrays(); |
| 125 | |
| 126 | self::reset(); |
| 127 | } |
| 128 | catch ( Exception $e ) |
| 129 | { |
| 130 | echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine(); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | spl_autoload_register( array( 'ezpAutoloader', 'autoload' ) ); |
| 136 | |
| 137 | if ( EZCBASE_ENABLED ) |
| 138 | { |
| 139 | spl_autoload_register( array( 'ezcBase', 'autoload' ) ); |
| 140 | } |
| 141 | |
| 142 | ?> |
| 143 | |