Commit 07745dea781f2b7932a7253fd8fc6d54067884a1

Authored by Benjamin Renard
1 parent 5210c93f

Do not use global in autoload

Showing 1 changed file with 86 additions and 54 deletions   Show diff stats
src/amdaintegration_autoload.php
1 <?php 1 <?php
2 //autoload configuration 2 //autoload configuration
3 3
4 -$autoload_cache = array(); 4 +class AutoloadData {
  5 + private static $integration_dirs = NULL;
5 6
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 -); 7 + private static $ihm_dirs = NULL;
43 8
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 -); 9 + private static $cache = NULL;
  10 +
  11 + public static function integration_dirs() {
  12 + if (self::$integration_dirs == NULL) {
  13 + self::$integration_dirs = array(
  14 + 'InputOutput',
  15 + 'InputOutput/IHMImpl',
  16 + 'InputOutput/IHMImpl/Config',
  17 + 'InputOutput/IHMImpl/Params',
  18 + 'InputOutput/IHMImpl/Params/DataMiningImpl',
  19 + 'InputOutput/IHMImpl/Params/StatisticsImpl',
  20 + 'InputOutput/IHMImpl/Params/DownloadImpl',
  21 + 'InputOutput/IHMImpl/Params/PlotImpl',
  22 + 'InputOutput/IHMImpl/Params/GeneratorImpl',
  23 + 'InputOutput/IHMImpl/Params/GenInfoParamImpl',
  24 + 'InputOutput/IHMImpl/Process',
  25 + 'InputOutput/IHMImpl/ParamInfo',
  26 + 'InputOutput/IHMImpl/Tools',
  27 + 'InputOutput/IHMImpl/TimeTables',
  28 + 'InputOutput/TestImpl',
  29 + 'InputOutput/WSImpl',
  30 + 'InputOutput/WSImpl/Config',
  31 + 'InputOutput/WSImpl/Process',
  32 + 'InputOutput/WSImpl/Params/DownloadImpl',
  33 + 'InputOutput/WSImpl/Params/PlotImpl',
  34 + 'InputOutput/WSImpl/Tools',
  35 + 'InputOutput/WSImpl/TimeTables',
  36 + 'InputOutput/SharedObjectsUpdater',
  37 + 'InputOutput/SharedObjectsUpdater/TimeTables',
  38 + 'Request',
  39 + 'Request/Config',
  40 + 'Request/ParamsRequestImpl',
  41 + 'Request/ParamsRequestImpl/Nodes',
  42 + 'Request/ParamsRequestImpl/Nodes/Infos',
  43 + 'Request/ParamsRequestImpl/Nodes/Params',
  44 + 'Request/ParamsRequestImpl/Nodes/Requests',
  45 + 'Request/ProcessRequestImpl',
  46 + 'Request/ProcessRequestImpl/Process',
  47 + 'Request/TTRequestImpl',
  48 + 'Request/ParserRequestImpl',
  49 + );
  50 + }
  51 + return self::$integration_dirs;
  52 + }
  53 +
  54 + public static function ihm_dirs() {
  55 + if (self::$ihm_dirs == NULL) {
  56 + self::$ihm_dirs = array(
  57 + IHM_SRC_DIR.'/php/classes',
  58 + IHM_SRC_DIR.'/php/RemoteDataCenter',
  59 + IHM_SRC_DIR.'/php/WebServices',
  60 + IHM_SRC_DIR.'/php/WebServices/Client'
  61 + );
  62 + }
  63 + return self::$ihm_dirs;
  64 + }
  65 +
  66 + public static function get_cache($class_name) {
  67 + if (self::$cache == NULL) {
  68 + self::$cache = array();
  69 + }
  70 + if (isset(self::$cache[$class_name])) {
  71 + return self::$cache[$class_name];
  72 + }
  73 + return NULL;
  74 + }
  75 +
  76 + public static function set_cache($class_name, $file) {
  77 + if (self::$cache == NULL) {
  78 + self::$cache = array();
  79 + }
  80 + self::$cache[$class_name] = $file;
  81 + }
  82 +}
50 83
51 function amdaintegration_autoload($class_name) 84 function amdaintegration_autoload($class_name)
52 { 85 {
53 - global $autoload_cache, $autoload_dirs, $autoload_ihm_dirs;  
54 -  
55 - if (isset($autoload_cache[$class_name])) {  
56 - require $autoload_cache[$class_name]; 86 + $file = AutoloadData::get_cache($class_name);
  87 + if (isset($file)) {
  88 + require $file;
57 return; 89 return;
58 } 90 }
59 91
@@ -62,28 +94,28 @@ function amdaintegration_autoload($class_name) @@ -62,28 +94,28 @@ function amdaintegration_autoload($class_name)
62 if (file_exists($file)) 94 if (file_exists($file))
63 { 95 {
64 require $file; 96 require $file;
65 - $autoload_cache[$class_name] = $file; 97 + AutoloadData::set_cache($class_name, $file);
66 return; 98 return;
67 } 99 }
68 -  
69 - foreach($autoload_dirs as $dir) 100 +
  101 + foreach(AutoloadData::integration_dirs() as $dir)
70 { 102 {
71 $file = __DIR__.'/'.$dir.'/'.$class_name.'.php'; 103 $file = __DIR__.'/'.$dir.'/'.$class_name.'.php';
72 if (file_exists($file)) 104 if (file_exists($file))
73 { 105 {
74 require $file; 106 require $file;
75 - $autoload_cache[$class_name] = $file; 107 + AutoloadData::set_cache($class_name, $file);
76 return; 108 return;
77 } 109 }
78 } 110 }
79 111
80 - foreach($autoload_ihm_dirs as $dir) 112 + foreach(AutoloadData::ihm_dirs() as $dir)
81 { 113 {
82 $file = $dir.'/'.$class_name.'.php'; 114 $file = $dir.'/'.$class_name.'.php';
83 if (file_exists($file)) 115 if (file_exists($file))
84 { 116 {
85 require $file; 117 require $file;
86 - $autoload_cache[$class_name] = $file; 118 + AutoloadData::set_cache($class_name, $file);
87 break; 119 break;
88 } 120 }
89 } 121 }