Elgg  Version 1.9
ServiceProvider.php
Go to the documentation of this file.
1 <?php
2 
33 
39  public function __construct(Elgg_AutoloadManager $autoload_manager) {
40  $this->setValue('autoloadManager', $autoload_manager);
41 
42  $this->setClassName('actions', 'Elgg_ActionsService');
43  $this->setFactory('amdConfig', array($this, 'getAmdConfig'));
44  $this->setClassName('autoP', 'ElggAutoP');
45  $this->setClassName('crypto', 'ElggCrypto');
46  $this->setFactory('db', array($this, 'getDatabase'));
47  $this->setFactory('events', array($this, 'getEvents'));
48  $this->setFactory('hooks', array($this, 'getHooks'));
49  $this->setFactory('logger', array($this, 'getLogger'));
50  $this->setClassName('metadataCache', 'ElggVolatileMetadataCache');
51  $this->setFactory('persistentLogin', array($this, 'getPersistentLogin'));
52  $this->setFactory('queryCounter', array($this, 'getQueryCounter'), false);
53  $this->setFactory('request', array($this, 'getRequest'));
54  $this->setFactory('router', array($this, 'getRouter'));
55  $this->setFactory('session', array($this, 'getSession'));
56  $this->setFactory('views', array($this, 'getViews'));
57  $this->setClassName('widgets', 'Elgg_WidgetsService');
58  $this->setFactory('notifications', array($this, 'getNotifications'));
59  }
60 
67  protected function getDatabase(Elgg_Di_ServiceProvider $c) {
69  return new Elgg_Database(new Elgg_Database_Config($CONFIG), $c->logger);
70  }
71 
78  protected function getEvents(Elgg_Di_ServiceProvider $c) {
79  return $this->resolveLoggerDependencies('events');
80  }
81 
88  protected function getLogger(Elgg_Di_ServiceProvider $c) {
89  return $this->resolveLoggerDependencies('logger');
90  }
91 
98  protected function getHooks(Elgg_Di_ServiceProvider $c) {
99  return $this->resolveLoggerDependencies('hooks');
100  }
101 
109  protected function resolveLoggerDependencies($service_needed) {
110  $svcs['hooks'] = new Elgg_PluginHooksService();
111  $svcs['logger'] = new Elgg_Logger($svcs['hooks']);
112  $svcs['hooks']->setLogger($svcs['logger']);
113  $svcs['events'] = new Elgg_EventsService();
114  $svcs['events']->setLogger($svcs['logger']);
115 
116  foreach ($svcs as $key => $service) {
117  $this->setValue($key, $service);
118  }
119  return $svcs[$service_needed];
120  }
121 
128  protected function getViews(Elgg_Di_ServiceProvider $c) {
129  return new Elgg_ViewsService($c->hooks, $c->logger);
130  }
131 
139  $obj = new Elgg_Amd_Config();
140  $obj->setBaseUrl(_elgg_get_simplecache_root() . "js/");
141  return $obj;
142  }
143 
150  protected function getSession(Elgg_Di_ServiceProvider $c) {
151  global $CONFIG;
152 
153  // account for difference of session_get_cookie_params() and ini key names
154  $params = $CONFIG->cookies['session'];
155  foreach ($params as $key => $value) {
156  if (in_array($key, array('path', 'domain', 'secure', 'httponly'))) {
157  $params["cookie_$key"] = $value;
158  unset($params[$key]);
159  }
160  }
161 
164  $session = new ElggSession($storage);
165 
166  return $session;
167  }
168 
175  protected function getRequest(Elgg_Di_ServiceProvider $c) {
177  }
178 
185  protected function getRouter(Elgg_Di_ServiceProvider $c) {
186  // TODO(evan): Init routes from plugins or cache
187  return new Elgg_Router($c->hooks);
188  }
189 
197  // @todo move queue in service provider
199  $sub = new Elgg_Notifications_SubscriptionsService($c->db);
201  return new Elgg_Notifications_NotificationsService($sub, $queue, $c->hooks, $access);
202  }
203 
211  $cookies_config = elgg_get_config('cookies');
212  $remember_me_cookies_config = $cookies_config['remember_me'];
213  $cookie_name = $remember_me_cookies_config['name'];
214  $cookie_token = $c->request->cookies->get($cookie_name, '');
215  return new Elgg_PersistentLoginService($c->db, $c->session, $c->crypto, $remember_me_cookies_config, $cookie_token);
216  }
217 
225  return new Elgg_Database_QueryCounter($c->db);
226  }
227 }
getRequest(Elgg_Di_ServiceProvider $c)
Request factory.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
setFactory($name, $callable, $shared=true)
Set a factory to generate a value when the container is read.
getQueryCounter(Elgg_Di_ServiceProvider $c)
Query counter factory.
resolveLoggerDependencies($service_needed)
Returns the first requested service of the logger, events, and hooks.
setClassName($name, $class_name, $shared=true)
Set a factory based on instantiating a class with no arguments.
getLogger(Elgg_Di_ServiceProvider $c)
Logger factory.
$session
Definition: login.php:9
$value
Definition: longtext.php:29
getAmdConfig(Elgg_Di_ServiceProvider $c)
AMD Config factory.
getRouter(Elgg_Di_ServiceProvider $c)
Router factory.
$params
Definition: login.php:72
getDatabase(Elgg_Di_ServiceProvider $c)
Database factory.
getSession(Elgg_Di_ServiceProvider $c)
Session factory.
$key
Definition: summary.php:34
global $CONFIG
setValue($name, $value)
Set a value to be returned without modification.
Definition: DiContainer.php:99
elgg global
Pointer to the global context.
Definition: elgglib.js:12
_elgg_get_simplecache_root()
Get the base url for simple cache requests.
Definition: cache.php:172
static createFromGlobals()
Creates a request from PHP&#39;s globals.
Definition: Request.php:131
getNotifications(Elgg_Di_ServiceProvider $c)
Notification service factory.
elgg_get_access_object()
Returns the Elgg_Access object.
Definition: access.php:1002
__construct(Elgg_AutoloadManager $autoload_manager)
Constructor.
$handler
Definition: add.php:10
getEvents(Elgg_Di_ServiceProvider $c)
Events service factory.
getHooks(Elgg_Di_ServiceProvider $c)
Plugin hooks service factory.
getPersistentLogin(Elgg_Di_ServiceProvider $c)
Persistent login service factory.
$access
Definition: save.php:15
getViews(Elgg_Di_ServiceProvider $c)
Views service factory.