Elgg  Version 1.9
autoloader.php
Go to the documentation of this file.
1 <?php
14 function _elgg_services() {
15  static $provider;
16  if (null === $provider) {
17  $provider = _elgg_create_service_provider();
18  }
19  return $provider;
20 }
21 
33  // manually load classes needed for autoloading
34  $dir = dirname(dirname(__FILE__)) . '/classes';
35  foreach (array('Elgg_ClassMap', 'Elgg_ClassLoader', 'Elgg_AutoloadManager') as $class) {
36  if (!class_exists($class)) {
37  $file = "{$dir}/" . strtr($class, '_\\', '//') . ".php";
38  include $file;
39  if (!class_exists($class, false)) {
40  throw new RuntimeException("Could not load {$class} in {$file}.");
41  }
42  }
43  }
44 
46  // until the cache can be loaded, just setup PSR-0 autoloading
47  // out of the classes directory. No need to build a full map.
48  $loader->addFallback($dir);
49  $loader->register();
50  $manager = new Elgg_AutoloadManager($loader);
51 
52  return new Elgg_Di_ServiceProvider($manager);
53 }
54 
63  $manager = _elgg_services()->autoloadManager;
64  $manager->setStorage(elgg_get_system_cache());
65  if (! $manager->loadCache()) {
66  $manager->addClasses(dirname(dirname(__FILE__)) . '/classes');
67  }
68 }
69 
76  _elgg_services()->autoloadManager->saveCache();
77 }
78 
85  _elgg_services()->autoloadManager->deleteCache();
86 }
87 
94  return _elgg_services()->autoloadManager->getLoader();
95 }
96 
109 function elgg_register_classes($dir) {
110  _elgg_services()->autoloadManager->addClasses($dir);
111 }
112 
122 function elgg_register_class($class, $location) {
123  _elgg_services()->autoloadManager->setClassPath($class, $location);
124  return true;
125 }
126 
127 // set up autoloading and DIC
129 
130 _elgg_services()->events->registerHandler('shutdown', 'system', '_elgg_save_autoload_cache', 1000);
131 _elgg_services()->events->registerHandler('upgrade', 'all', '_elgg_delete_autoload_cache');
_elgg_load_autoload_cache()
Load cached data into the autoload system.
Definition: autoloader.php:62
elgg_get_class_loader()
Get Elgg&#39;s class loader.
Definition: autoloader.php:93
elgg_register_class($class, $location)
Register a classname to a file.
Definition: autoloader.php:122
_elgg_create_service_provider()
Sets up autoloading and creates the service provider (DIC)
Definition: autoloader.php:32
elgg_get_system_cache()
Returns an ElggCache object suitable for caching system information.
Definition: cache.php:20
if(isset($vars['id'])) $class
Definition: ajax_loader.php:19
_elgg_save_autoload_cache()
Save the autoload system cache.
Definition: autoloader.php:75
_elgg_services()
Definition: autoloader.php:14
_elgg_delete_autoload_cache()
Delete the autoload system cache.
Definition: autoloader.php:84
elgg_register_classes($dir)
Register a directory tree for autoloading classes/interfaces/traits.
Definition: autoloader.php:109
$loader
Definition: ajax_loader.php:32