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