24
24
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
25
25
*/
26
26
27
+ use PrestaShop \Autoload \LegacyClassLoader ;
28
+
29
+ @trigger_error ('Using PrestaShopAutoload is deprecated, use Prestashop\Autoload\PrestaShopAutoload instead ' , E_USER_DEPRECATED );
30
+
27
31
/**
28
32
* Class PrestaShopAutoload.
29
33
*
@@ -48,6 +52,11 @@ class PrestaShopAutoload
48
52
49
53
public $ _include_override_path = true ;
50
54
55
+ /**
56
+ * @var LegacyClassLoader
57
+ */
58
+ protected $ classLoader ;
59
+
51
60
protected static $ class_aliases = [
52
61
'Collection ' => 'PrestaShopCollection ' ,
53
62
'Autoload ' => 'PrestaShopAutoload ' ,
@@ -58,7 +67,8 @@ class PrestaShopAutoload
58
67
protected function __construct ()
59
68
{
60
69
$ this ->root_dir = _PS_CORE_DIR_ . '/ ' ;
61
- $ file = static ::getCacheFileIndex ();
70
+ $ this ->classLoader = new LegacyClassLoader (_PS_ROOT_DIR_ , _PS_CACHE_DIR_ );
71
+ $ file = $ this ->classLoader ->getClassIndexFilepath ();
62
72
$ stubFile = static ::getStubFileIndex ();
63
73
if (@filemtime ($ file ) && is_readable ($ file ) && @filemtime ($ stubFile ) && is_readable ($ stubFile )) {
64
74
$ this ->index = include $ file ;
@@ -154,7 +164,9 @@ public function load($className)
154
164
require_once $ this ->root_dir . $ this ->index [$ className ]['path ' ];
155
165
}
156
166
if (strpos ($ className , 'PrestaShop\PrestaShop\Adapter\Entity ' ) !== false ) {
157
- require_once static ::getNamespacedStubFileIndex ();
167
+ $ legacyClass = substr ($ className , 37 );
168
+ $ this ->load ($ legacyClass );
169
+ class_alias ($ legacyClass , '\\' . $ className );
158
170
}
159
171
}
160
172
@@ -172,70 +184,7 @@ public function generateIndex()
172
184
}
173
185
}
174
186
175
- $ coreClasses = $ this ->getClassesFromDir ('classes/ ' );
176
-
177
- $ classes = array_merge (
178
- $ coreClasses ,
179
- $ this ->getClassesFromDir ('controllers/ ' )
180
- );
181
-
182
- $ contentNamespacedStub = '<?php ' . "\n" . 'namespace PrestaShop \\PrestaShop \\Adapter \\Entity; ' . "\n\n" ;
183
-
184
- foreach ($ coreClasses as $ coreClassName => $ coreClass ) {
185
- if (substr ($ coreClassName , -4 ) == 'Core ' ) {
186
- $ coreClassName = substr ($ coreClassName , 0 , -4 );
187
- if ($ coreClass ['type ' ] != 'interface ' ) {
188
- $ contentNamespacedStub .= $ coreClass ['type ' ] . ' ' . $ coreClassName . ' extends \\' . $ coreClassName . ' {}; ' . "\n" ;
189
- }
190
- }
191
- }
192
-
193
- if ($ this ->_include_override_path ) {
194
- $ coreOverrideClasses = $ this ->getClassesFromDir ('override/classes/ ' );
195
- $ coreClassesWOOverrides = array_diff_key ($ coreClasses , $ coreOverrideClasses );
196
-
197
- $ classes = array_merge (
198
- $ classes ,
199
- $ coreOverrideClasses ,
200
- $ this ->getClassesFromDir ('override/controllers/ ' )
201
- );
202
- } else {
203
- $ coreClassesWOOverrides = $ coreClasses ;
204
- }
205
-
206
- $ contentStub = '<?php ' . "\n\n" ;
207
-
208
- foreach ($ coreClassesWOOverrides as $ coreClassName => $ coreClass ) {
209
- if (substr ($ coreClassName , -4 ) == 'Core ' ) {
210
- $ coreClassNameNoCore = substr ($ coreClassName , 0 , -4 );
211
- if ($ coreClass ['type ' ] != 'interface ' ) {
212
- $ contentStub .= $ coreClass ['type ' ] . ' ' . $ coreClassNameNoCore . ' extends ' . $ coreClassName . ' {}; ' . "\n" ;
213
- }
214
- }
215
- }
216
-
217
- ksort ($ classes );
218
- $ content = '<?php return ' . var_export ($ classes , true ) . '; ?> ' ;
219
-
220
- // Write classes index on disc to cache it
221
- $ filename = static ::getCacheFileIndex ();
222
- @mkdir (_PS_CACHE_DIR_ , 0777 , true );
223
-
224
- if (!$ this ->dumpFile ($ filename , $ content )) {
225
- Tools::error_log ('Cannot write temporary file ' . $ filename );
226
- }
227
-
228
- $ stubFilename = static ::getStubFileIndex ();
229
- if (!$ this ->dumpFile ($ stubFilename , $ contentStub )) {
230
- Tools::error_log ('Cannot write temporary file ' . $ stubFilename );
231
- }
232
-
233
- $ namespacedStubFilename = static ::getNamespacedStubFileIndex ();
234
- if (!$ this ->dumpFile ($ namespacedStubFilename , $ contentNamespacedStub )) {
235
- Tools::error_log ('Cannot write temporary file ' . $ namespacedStubFilename );
236
- }
237
-
238
- $ this ->index = $ classes ;
187
+ $ this ->index = $ this ->classLoader ->buildClassIndex ($ this ->_include_override_path );
239
188
}
240
189
241
190
/**
@@ -330,5 +279,3 @@ public function getClassPath($classname)
330
279
return (isset ($ this ->index [$ classname ]['path ' ])) ? $ this ->index [$ classname ]['path ' ] : null ;
331
280
}
332
281
}
333
-
334
- spl_autoload_register ([PrestaShopAutoload::getInstance (), 'load ' ]);
0 commit comments