container.php 9.6 KB

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