Elgg  Version 1.10
ServiceProvider.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Di;
3 
58 
64  public function __construct(\Elgg\AutoloadManager $autoload_manager) {
65  $this->setValue('autoloadManager', $autoload_manager);
66 
67  $this->setClassName('access', '\Elgg\Access');
68 
69  $this->setFactory('accessCache', function(ServiceProvider $c) {
70  return new \ElggStaticVariableCache('access');
71  });
72 
73  $this->setFactory('accessCollections', function(ServiceProvider $c) {
74  return new \Elgg\Database\AccessCollections($c->config->get('site_guid'));
75  });
76 
77  $this->setClassName('actions', '\Elgg\ActionsService');
78 
79  $this->setClassName('adminNotices', '\Elgg\Database\AdminNotices');
80 
81  $this->setFactory('amdConfig', function(ServiceProvider $c) {
82  $obj = new \Elgg\Amd\Config();
83  $obj->setBaseUrl($c->simpleCache->getRoot() . "js/");
84  return $obj;
85  });
86 
87  $this->setClassName('annotations', '\Elgg\Database\Annotations');
88 
89  $this->setClassName('autoP', '\ElggAutoP');
90 
91  $this->setClassName('config', '\Elgg\Config');
92 
93  $this->setClassName('configTable', '\Elgg\Database\ConfigTable');
94 
95  $this->setClassName('context', '\Elgg\Context');
96 
97  $this->setClassName('crypto', '\ElggCrypto');
98 
99  $this->setFactory('datalist', function(ServiceProvider $c) {
100  // TODO(ewinslow): Add back memcached support
101  $db = $c->db;
102  $dbprefix = $db->getTablePrefix();
103  $pool = new \Elgg\Cache\MemoryPool();
104  return new \Elgg\Database\Datalist($pool, $db, $c->logger, "{$dbprefix}datalists");
105  });
106 
107  $this->setFactory('db', function(ServiceProvider $c) {
108  global $CONFIG;
109  $db_config = new \Elgg\Database\Config($CONFIG);
110  return new \Elgg\Database($db_config, $c->logger);
111  });
112 
113  $this->setClassName('entityTable', '\Elgg\Database\EntityTable');
114 
115  $this->setFactory('events', function(ServiceProvider $c) {
116  return $this->resolveLoggerDependencies('events');
117  });
118 
119  $this->setFactory('externalFiles', function(ServiceProvider $c) {
120  global $CONFIG;
121  return new \Elgg\Assets\ExternalFiles($CONFIG);
122  });
123 
124  $this->setFactory('hooks', function(ServiceProvider $c) {
125  return $this->resolveLoggerDependencies('hooks');
126  });
127 
128  $this->setClassName('input', 'Elgg\Http\Input');
129 
130  $this->setFactory('logger', function(ServiceProvider $c) {
131  return $this->resolveLoggerDependencies('logger');
132  });
133 
134  $this->setClassName('metadataCache', '\ElggVolatileMetadataCache');
135 
136  $this->setFactory('metadataTable', function(ServiceProvider $c) {
137  // TODO(ewinslow): Use Elgg\Cache\Pool instead of MetadataCache
138  return new \Elgg\Database\MetadataTable(
139  $c->metadataCache, $c->db, $c->entityTable, $c->events, $c->metastringsTable, $c->session);
140  });
141 
142  $this->setFactory('metastringsTable', function(ServiceProvider $c) {
143  // TODO(ewinslow): Use memcache-based Pool if available...
144  $pool = new \Elgg\Cache\MemoryPool();
145  return new \Elgg\Database\MetastringsTable($pool, $c->db);
146  });
147 
148  $this->setFactory('notifications', function(ServiceProvider $c) {
149  // @todo move queue in service provider
151  $queue = new \Elgg\Queue\DatabaseQueue($queue_name, $c->db);
152  $sub = new \Elgg\Notifications\SubscriptionsService($c->db);
153  return new \Elgg\Notifications\NotificationsService($sub, $queue, $c->hooks, $c->access);
154  });
155 
156  $this->setFactory('ownerPreloader', function(ServiceProvider $c) {
157  return new \Elgg\EntityPreloader(array('owner_guid'));
158  });
159 
160  $this->setFactory('persistentLogin', function(ServiceProvider $c) {
161  $global_cookies_config = _elgg_services()->config->get('cookies');
162  $cookie_config = $global_cookies_config['remember_me'];
163  $cookie_name = $cookie_config['name'];
164  $cookie_token = $c->request->cookies->get($cookie_name, '');
165  return new \Elgg\PersistentLoginService(
166  $c->db, $c->session, $c->crypto, $cookie_config, $cookie_token);
167  });
168 
169  $this->setFactory('passwords', function (ServiceProvider $c) {
170  if (!function_exists('password_hash')) {
171  $root = $c->config->getRootPath();
172  require "{$root}vendor/ircmaxell/password-compat/lib/password.php";
173  }
174  return new \Elgg\PasswordService();
175  });
176 
177  $this->setClassName('plugins', '\Elgg\Database\Plugins');
178 
179  $this->setFactory('queryCounter', function(ServiceProvider $c) {
180  return new \Elgg\Database\QueryCounter($c->db);
181  }, false);
182 
183  $this->setClassName('relationshipsTable', '\Elgg\Database\RelationshipsTable');
184 
185  $this->setFactory('request', '\Elgg\Http\Request::createFromGlobals');
186 
187  $this->setFactory('router', function(ServiceProvider $c) {
188  // TODO(evan): Init routes from plugins or cache
189  return new \Elgg\Router($c->hooks);
190  });
191 
192  $this->setFactory('session', function(ServiceProvider $c) {
193  // account for difference of session_get_cookie_params() and ini key names
194  $params = $c->config->get('cookies')['session'];
195  foreach ($params as $key => $value) {
196  if (in_array($key, array('path', 'domain', 'secure', 'httponly'))) {
197  $params["cookie_$key"] = $value;
198  unset($params[$key]);
199  }
200  }
201 
202  $handler = new \Elgg\Http\DatabaseSessionHandler($c->db);
203  $storage = new \Elgg\Http\NativeSessionStorage($params, $handler);
204  return new \ElggSession($storage);
205  });
206 
207  $this->setClassName('simpleCache', '\Elgg\Cache\SimpleCache');
208 
209  $this->setClassName('siteSecret', '\Elgg\Database\SiteSecret');
210 
211  $this->setClassName('stickyForms', 'Elgg\Forms\StickyForms');
212 
213  $this->setClassName('subtypeTable', '\Elgg\Database\SubtypeTable');
214 
215  $this->setClassName('systemCache', '\Elgg\Cache\SystemCache');
216 
217  $this->setClassName('translator', '\Elgg\I18n\Translator');
218 
219  $this->setClassName('usersTable', '\Elgg\Database\UsersTable');
220 
221  $this->setFactory('views', function(ServiceProvider $c) {
222  return new \Elgg\ViewsService($c->hooks, $c->logger);
223  });
224 
225  $this->setClassName('widgets', '\Elgg\WidgetsService');
226 
227  }
228 
236  protected function resolveLoggerDependencies($service_needed) {
237  $svcs['hooks'] = new \Elgg\PluginHooksService();
238  $svcs['logger'] = new \Elgg\Logger($svcs['hooks']);
239  $svcs['hooks']->setLogger($svcs['logger']);
240  $svcs['events'] = new \Elgg\EventsService();
241  $svcs['events']->setLogger($svcs['logger']);
242 
243  foreach ($svcs as $key => $service) {
244  $this->setValue($key, $service);
245  }
246  return $svcs[$service_needed];
247  }
248 }
$dbprefix
Definition: index.php:13
$value
Definition: longtext.php:29
if(!$autoload_available) _elgg_services()
Definition: autoloader.php:20
__construct(\Elgg\AutoloadManager $autoload_manager)
Constructor.
resolveLoggerDependencies($service_needed)
Returns the first requested service of the logger, events, and hooks.
$params
Definition: login.php:72
Save menu items.
$key
Definition: summary.php:34
global $CONFIG
setClassName($name, $class_name, $shared=true)
Set a factory based on instantiating a class with no arguments.
setValue($name, $value)
Set a value to be returned without modification.
Definition: DiContainer.php:99
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
elgg global
Pointer to the global context.
Definition: elgglib.js:12
setFactory($name, $callable, $shared=true)
Set a factory to generate a value when the container is read.
$handler
Definition: add.php:10