container.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <?php namespace Laravel;
  2. return array(
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Laravel Components
  6. |--------------------------------------------------------------------------
  7. */
  8. 'laravel.asset' => array('singleton' => true, 'resolver' => function($container)
  9. {
  10. return new Asset($container->resolve('laravel.html'));
  11. }),
  12. 'laravel.auth' => array('singleton' => true, 'resolver' => function($container)
  13. {
  14. return new Security\Auth($container->resolve('laravel.config'), $container->resolve('laravel.session'));
  15. }),
  16. 'laravel.config' => array('singleton' => true, 'resolver' => function($container)
  17. {
  18. $paths = array(SYS_CONFIG_PATH, CONFIG_PATH);
  19. if (isset($_SERVER['LARAVEL_ENV']))
  20. {
  21. $paths[] = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/';
  22. }
  23. return new Config($paths);
  24. }),
  25. 'laravel.crypter' => array('resolver' => function($container)
  26. {
  27. $key = $container->resolve('laravel.config')->get('application.key');
  28. return new Security\Crypter(MCRYPT_RIJNDAEL_256, 'cbc', $key);
  29. }),
  30. 'laravel.cookie' => array('singleton' => true, 'resolver' => function()
  31. {
  32. return new Cookie($_COOKIE);
  33. }),
  34. 'laravel.database' => array('singleton' => true, 'resolver' => function($container)
  35. {
  36. return new Database\Manager($container->resolve('laravel.config')->get('database'));
  37. }),
  38. 'laravel.download' => array('singleton' => true, 'resolver' => function($container)
  39. {
  40. return new Download($container->resolve('laravel.file'));
  41. }),
  42. 'laravel.file' => array('singleton' => true, 'resolver' => function($container)
  43. {
  44. return new File($container->resolve('laravel.config')->get('mimes'));
  45. }),
  46. 'laravel.form' => array('singleton' => true, 'resolver' => function($container)
  47. {
  48. list($request, $html, $url) = array(
  49. $container->resolve('laravel.request'),
  50. $container->resolve('laravel.html'),
  51. $container->resolve('laravel.url'),
  52. );
  53. return new Form($request, $html, $url);
  54. }),
  55. 'laravel.hasher' => array('singleton' => true, 'resolver' => function($container)
  56. {
  57. return new Security\Hashing\Bcrypt(8);
  58. }),
  59. 'laravel.html' => array('singleton' => true, 'resolver' => function($container)
  60. {
  61. return new HTML($container->resolve('laravel.url'), $container->resolve('laravel.config')->get('application.encoding'));
  62. }),
  63. 'laravel.input' => array('singleton' => true, 'resolver' => function($container)
  64. {
  65. $request = $container->resolve('laravel.request');
  66. $input = array();
  67. if ($request->method() == 'GET')
  68. {
  69. $input = $_GET;
  70. }
  71. elseif ($request->method() == 'POST')
  72. {
  73. $input = $_POST;
  74. }
  75. elseif ($request->method() == 'PUT' or $request->method == 'DELETE')
  76. {
  77. ($request->spoofed()) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input);
  78. }
  79. return new Input($container->resolve('laravel.file'), $container->resolve('laravel.cookie'), $input, $_FILES);
  80. }),
  81. 'laravel.lang' => array('singleton' => true, 'resolver' => function($container)
  82. {
  83. require_once SYS_PATH.'lang'.EXT;
  84. return new Lang_Factory($container->resolve('laravel.config'), array(SYS_LANG_PATH, LANG_PATH));
  85. }),
  86. 'laravel.loader' => array('singleton' => true, 'resolver' => function($container)
  87. {
  88. require_once SYS_PATH.'loader'.EXT;
  89. $aliases = $container->resolve('laravel.config')->get('aliases');
  90. return new Loader(array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/'), $aliases);
  91. }),
  92. 'laravel.package' => array('singleton' => true, 'resolver' => function()
  93. {
  94. return new Package(PACKAGE_PATH);
  95. }),
  96. 'laravel.redirect' => array('singleton' => true, 'resolver' => function($container)
  97. {
  98. return new Redirect($container->resolve('laravel.url'));
  99. }),
  100. 'laravel.request' => array('singleton' => true, 'resolver' => function($container)
  101. {
  102. return new Request($_SERVER, $_POST, $container->resolve('laravel.config')->get('application.url'));
  103. }),
  104. 'laravel.response' => array('singleton' => true, 'resolver' => function($container)
  105. {
  106. require_once SYS_PATH.'response'.EXT;
  107. return new Response_Factory($container->resolve('laravel.view'), $container->resolve('laravel.file'));
  108. }),
  109. 'laravel.routing.router' => array('singleton' => true, 'resolver' => function($container)
  110. {
  111. return new Routing\Router(require APP_PATH.'routes'.EXT, CONTROLLER_PATH);
  112. }),
  113. 'laravel.routing.caller' => array('resolver' => function($container)
  114. {
  115. return new Routing\Caller($container, require APP_PATH.'filters'.EXT, CONTROLLER_PATH);
  116. }),
  117. 'laravel.session' => array('singleton' => true, 'resolver' => function($container)
  118. {
  119. return $container->resolve('laravel.session.manager')->driver($container->resolve('laravel.config')->get('session.driver'));
  120. }),
  121. 'laravel.session.manager' => array('singleton' => true, 'resolver' => function($container)
  122. {
  123. return new Session\Manager($container);
  124. }),
  125. 'laravel.url' => array('singleton' => true, 'resolver' => function($container)
  126. {
  127. list($request, $base, $index) = array(
  128. $container->resolve('laravel.request'),
  129. $container->resolve('laravel.config')->get('application.url'),
  130. $container->resolve('laravel.config')->get('application.index'),
  131. );
  132. return new URL($container->resolve('laravel.routing.router'), $base, $index, $request->secure());
  133. }),
  134. 'laravel.validator' => array('singleton' => true, 'resolver' => function($container)
  135. {
  136. require_once SYS_PATH.'validation/validator'.EXT;
  137. return new Validation\Validator_Factory($container->resolve('laravel.lang'));
  138. }),
  139. 'laravel.view' => array('singleton' => true, 'resolver' => function($container)
  140. {
  141. require_once SYS_PATH.'view'.EXT;
  142. return new View_Factory($container->resolve('laravel.view.composer'), VIEW_PATH);
  143. }),
  144. 'laravel.view.composer' => array('resolver' => function($container)
  145. {
  146. return new View_Composer(require APP_PATH.'composers'.EXT);
  147. }),
  148. /*
  149. |--------------------------------------------------------------------------
  150. | Laravel Cookie Session Components
  151. |--------------------------------------------------------------------------
  152. */
  153. 'laravel.session.cookie' => array('resolver' => function($container)
  154. {
  155. $cookies = $container->resolve('laravel.request')->input->cookies;
  156. $config = $container->resolve('laravel.config')->get('session');
  157. return new Session\Drivers\Cookie(Security\Crypter::make(), $cookies);
  158. }),
  159. /*
  160. |--------------------------------------------------------------------------
  161. | Laravel Database Session Components
  162. |--------------------------------------------------------------------------
  163. */
  164. 'laravel.session.database' => array('resolver' => function($container)
  165. {
  166. $table = $container->resolve('laravel.config')->get('session.table');
  167. return new Session\Drivers\Database($container->resolve('laravel.database.manager')->connection());
  168. }),
  169. /*
  170. |--------------------------------------------------------------------------
  171. | Laravel Cache Manager
  172. |--------------------------------------------------------------------------
  173. */
  174. 'laravel.cache' => array('singleton' => true, 'resolver' => function($container)
  175. {
  176. return new Cache\Manager($container, $container->resolve('laravel.config')->get('cache.driver'));
  177. }),
  178. /*
  179. |--------------------------------------------------------------------------
  180. | Laravel File Cache & Session Components
  181. |--------------------------------------------------------------------------
  182. */
  183. 'laravel.cache.file' => array('resolver' => function($container)
  184. {
  185. return new Cache\Drivers\File($container->resolve('laravel.file'), CACHE_PATH);
  186. }),
  187. 'laravel.session.file' => array('resolver' => function($container)
  188. {
  189. return new Session\Drivers\File($container->resolve('laravel.file'), SESSION_PATH);
  190. }),
  191. /*
  192. |--------------------------------------------------------------------------
  193. | Laravel APC Cache & Session Components
  194. |--------------------------------------------------------------------------
  195. */
  196. 'laravel.cache.apc' => array('resolver' => function($container)
  197. {
  198. return new Cache\Drivers\APC(new Proxy, $container->resolve('laravel.config')->get('cache.key'));
  199. }),
  200. 'laravel.session.id' => array('singleton' => true, 'resolver' => function($container)
  201. {
  202. return $container->resolve('laravel.cookie')->get('laravel_session');
  203. }),
  204. 'laravel.session.apc' => array('resolver' => function($container)
  205. {
  206. $lifetime = $container->resolve('laravel.config')->get('session.lifetime');
  207. return new Session\Drivers\APC($container->resolve('laravel.cache.apc'));
  208. }),
  209. /*
  210. |--------------------------------------------------------------------------
  211. | Laravel Memcached Cache & Session Components
  212. |--------------------------------------------------------------------------
  213. */
  214. 'laravel.cache.memcached' => array('resolver' => function($container)
  215. {
  216. $connection = $container->resolve('laravel.cache.memcache.connection');
  217. $key = $container->resolve('laravel.config')->get('cache.key');
  218. return new Cache\Drivers\Memcached($connection, $key);
  219. }),
  220. 'laravel.session.memcached' => array('resolver' => function($container)
  221. {
  222. $lifetime = $container->resolve('laravel.config')->get('session.lifetime');
  223. return new Session\Drivers\Memcached($container->resolve('laravel.cache.memcached'));
  224. }),
  225. 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($container)
  226. {
  227. if ( ! class_exists('Memcache'))
  228. {
  229. throw new \Exception('Attempting to use Memcached, but the Memcache PHP extension is not installed on this server.');
  230. }
  231. $memcache = new \Memcache;
  232. foreach ($container->resolve('laravel.config')->get('cache.servers') as $server)
  233. {
  234. $memcache->addServer($server['host'], $server['port'], true, $server['weight']);
  235. }
  236. if ($memcache->getVersion() === false)
  237. {
  238. throw new \Exception('Memcached is configured. However, no connections could be made. Please verify your memcached configuration.');
  239. }
  240. return $memcache;
  241. }),
  242. );