Commit 6111df45b34881007b4d56a168584f7e2608d501

Authored by Benjamin Renard
1 parent b9c60707

Optimize autoload (#7508)

Showing 1 changed file with 72 additions and 63 deletions   Show diff stats
src/amdaintegration_autoload.php
1 1 <?php
2 2 //autoload configuration
  3 +
  4 +$autoload_cache = array();
  5 +
  6 +$autoload_dirs = array(
  7 + 'InputOutput',
  8 + 'InputOutput/IHMImpl',
  9 + 'InputOutput/IHMImpl/Config',
  10 + 'InputOutput/IHMImpl/Params',
  11 + 'InputOutput/IHMImpl/Params/DataMiningImpl',
  12 + 'InputOutput/IHMImpl/Params/StatisticsImpl',
  13 + 'InputOutput/IHMImpl/Params/DownloadImpl',
  14 + 'InputOutput/IHMImpl/Params/PlotImpl',
  15 + 'InputOutput/IHMImpl/Params/GeneratorImpl',
  16 + 'InputOutput/IHMImpl/Params/GenInfoParamImpl',
  17 + 'InputOutput/IHMImpl/Process',
  18 + 'InputOutput/IHMImpl/ParamInfo',
  19 + 'InputOutput/IHMImpl/Tools',
  20 + 'InputOutput/IHMImpl/TimeTables',
  21 + 'InputOutput/TestImpl',
  22 + 'InputOutput/WSImpl',
  23 + 'InputOutput/WSImpl/Config',
  24 + 'InputOutput/WSImpl/Process',
  25 + 'InputOutput/WSImpl/Params/DownloadImpl',
  26 + 'InputOutput/WSImpl/Params/PlotImpl',
  27 + 'InputOutput/WSImpl/Tools',
  28 + 'InputOutput/WSImpl/TimeTables',
  29 + 'InputOutput/SharedObjectsUpdater',
  30 + 'InputOutput/SharedObjectsUpdater/TimeTables',
  31 + 'Request',
  32 + 'Request/Config',
  33 + 'Request/ParamsRequestImpl',
  34 + 'Request/ParamsRequestImpl/Nodes',
  35 + 'Request/ParamsRequestImpl/Nodes/Infos',
  36 + 'Request/ParamsRequestImpl/Nodes/Params',
  37 + 'Request/ParamsRequestImpl/Nodes/Requests',
  38 + 'Request/ProcessRequestImpl',
  39 + 'Request/ProcessRequestImpl/Process',
  40 + 'Request/TTRequestImpl',
  41 + 'Request/ParserRequestImpl',
  42 +);
  43 +
  44 +$autoload_ihm_dirs = array(
  45 + IHM_SRC_DIR.'/php/classes',
  46 + IHM_SRC_DIR.'/php/RemoteDataCenter',
  47 + IHM_SRC_DIR.'/php/WebServices',
  48 + IHM_SRC_DIR.'/php/WebServices/Client'
  49 +);
  50 +
3 51 function amdaintegration_autoload($class_name)
4 52 {
5   - $dirs = array(
6   - 'InputOutput',
7   - 'InputOutput/IHMImpl',
8   - 'InputOutput/IHMImpl/Config',
9   - 'InputOutput/IHMImpl/Params',
10   - 'InputOutput/IHMImpl/Params/DataMiningImpl',
11   - 'InputOutput/IHMImpl/Params/StatisticsImpl',
12   - 'InputOutput/IHMImpl/Params/DownloadImpl',
13   - 'InputOutput/IHMImpl/Params/PlotImpl',
14   - 'InputOutput/IHMImpl/Params/GeneratorImpl',
15   - 'InputOutput/IHMImpl/Params/GenInfoParamImpl',
16   - 'InputOutput/IHMImpl/Process',
17   - 'InputOutput/IHMImpl/ParamInfo',
18   - 'InputOutput/IHMImpl/Tools',
19   - 'InputOutput/IHMImpl/TimeTables',
20   - 'InputOutput/TestImpl',
21   - 'InputOutput/WSImpl',
22   - 'InputOutput/WSImpl/Config',
23   - 'InputOutput/WSImpl/Process',
24   - 'InputOutput/WSImpl/Params/DownloadImpl',
25   - 'InputOutput/WSImpl/Params/PlotImpl',
26   - 'InputOutput/WSImpl/Tools',
27   - 'InputOutput/WSImpl/TimeTables',
28   - 'InputOutput/SharedObjectsUpdater',
29   - 'InputOutput/SharedObjectsUpdater/TimeTables',
30   - 'Request',
31   - 'Request/Config',
32   - 'Request/ParamsRequestImpl',
33   - 'Request/ParamsRequestImpl/Nodes',
34   - 'Request/ParamsRequestImpl/Nodes/Infos',
35   - 'Request/ParamsRequestImpl/Nodes/Params',
36   - 'Request/ParamsRequestImpl/Nodes/Requests',
37   - 'Request/ProcessRequestImpl',
38   - 'Request/ProcessRequestImpl/Process',
39   - 'Request/TTRequestImpl',
40   - 'Request/ParserRequestImpl',
41   - );
42   -
43   - $ihm_dirs = array(
44   - IHM_SRC_DIR.'/php/classes',
45   - IHM_SRC_DIR.'/php/RemoteDataCenter',
46   - IHM_SRC_DIR.'/php/WebServices',
47   - IHM_SRC_DIR.'/php/WebServices/Client'
48   - );
49   -
50   - $find = false;
  53 + global $autoload_cache, $autoload_dirs, $autoload_ihm_dirs;
  54 +
  55 + if (isset($autoload_cache[$class_name])) {
  56 + require $autoload_cache[$class_name];
  57 + return;
  58 + }
  59 +
51 60 $file = __DIR__.'/'.$class_name.'.php';
52 61  
53 62 if (file_exists($file))
54 63 {
55 64 require $file;
  65 + $autoload_cache[$class_name] = $file;
56 66 return;
57 67 }
58 68  
59   - if (!$find)
60   - foreach($dirs as $dir)
  69 + foreach($autoload_dirs as $dir)
  70 + {
  71 + $file = __DIR__.'/'.$dir.'/'.$class_name.'.php';
  72 + if (file_exists($file))
61 73 {
62   - $file = __DIR__.'/'.$dir.'/'.$class_name.'.php';
63   - if (file_exists($file))
64   - {
65   - require $file;
66   - $find = true;
67   - break;
68   - }
  74 + require $file;
  75 + $autoload_cache[$class_name] = $file;
  76 + return;
69 77 }
  78 + }
70 79  
71   - if (!$find)
72   - foreach($ihm_dirs as $dir)
  80 + foreach($autoload_ihm_dirs as $dir)
  81 + {
  82 + $file = $dir.'/'.$class_name.'.php';
  83 + if (file_exists($file))
73 84 {
74   - $file = $dir.'/'.$class_name.'.php';
75   - if (file_exists($file))
76   - {
77   - require $file;
78   - break;
79   - }
  85 + require $file;
  86 + $autoload_cache[$class_name] = $file;
  87 + break;
80 88 }
  89 + }
81 90 }
82 91  
83 92 spl_autoload_register('amdaintegration_autoload');
... ...