container.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php namespace Laravel;
  2. return array(
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Laravel Routing Components
  6. |--------------------------------------------------------------------------
  7. |
  8. | The following components are used by the Laravel routing system.
  9. |
  10. | The router is used to map a given method and URI to a route intance.
  11. |
  12. | The route loader is responsible for loading the appropriates routes file
  13. | for a given request URI, as well as loading all routes when the framework
  14. | needs to find a named route wtihin the application.
  15. |
  16. | The route caller is responsible for receiving a route and taking the
  17. | appropriate action to execute that route. Some routes delegate execution
  18. | to a controller, so this class will also resolve controllers out of the
  19. | container and call the appropriate methods on those controllers.
  20. |
  21. */
  22. 'laravel.routing.router' => array('singleton' => true, 'resolver' => function($c)
  23. {
  24. return new Routing\Router($c->core('routing.loader'), CONTROLLER_PATH);
  25. }),
  26. 'laravel.routing.loader' => array('singleton' => true, 'resolver' => function($c)
  27. {
  28. return new Routing\Loader(APP_PATH, ROUTE_PATH);
  29. }),
  30. 'laravel.routing.caller' => array('resolver' => function($c)
  31. {
  32. return new Routing\Caller($c, require APP_PATH.'filters'.EXT, CONTROLLER_PATH);
  33. }),
  34. /*
  35. |--------------------------------------------------------------------------
  36. | Laravel Database Connectors
  37. |--------------------------------------------------------------------------
  38. |
  39. | The following components are used to establish PDO database connections
  40. | to the various database systems supported by Laravel. By resolving these
  41. | connectors out of the IoC container, new database systems may be added
  42. | by simply registering a connector in the container.
  43. |
  44. */
  45. 'laravel.database.connectors.sqlite' => array('resolver' => function($c)
  46. {
  47. return new Database\Connectors\SQLite(DATABASE_PATH);
  48. }),
  49. 'laravel.database.connectors.mysql' => array('resolver' => function($c)
  50. {
  51. return new Database\Connectors\MySQL;
  52. }),
  53. 'laravel.database.connectors.pgsql' => array('resolver' => function($c)
  54. {
  55. return new Database\Connectors\Postgres;
  56. }),
  57. /*
  58. |--------------------------------------------------------------------------
  59. | Laravel Caching Components
  60. |--------------------------------------------------------------------------
  61. |
  62. | The following components are used by the wonderfully simple Laravel cache
  63. | system. Each driver is resolved through the container, so new drivers may
  64. | be added by simply registering them in the container.
  65. |
  66. */
  67. 'laravel.cache.apc' => array('resolver' => function($c)
  68. {
  69. return new Cache\Drivers\APC(Config::get('cache.key'));
  70. }),
  71. 'laravel.cache.file' => array('resolver' => function($c)
  72. {
  73. return new Cache\Drivers\File(CACHE_PATH);
  74. }),
  75. 'laravel.cache.redis' => array('resolver' => function()
  76. {
  77. return new Cache\Drivers\Redis(Redis::db());
  78. }),
  79. 'laravel.cache.memcached' => array('resolver' => function($c)
  80. {
  81. return new Cache\Drivers\Memcached($c->core('cache.memcache.connection'), Config::get('cache.key'));
  82. }),
  83. 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($c)
  84. {
  85. $memcache = new \Memcache;
  86. foreach (Config::get('cache.memcached') as $server)
  87. {
  88. $memcache->addServer($server['host'], $server['port'], true, $server['weight']);
  89. }
  90. if ($memcache->getVersion() === false)
  91. {
  92. throw new \Exception('Could not establish memcached connection. Please verify your memcached configuration.');
  93. }
  94. return $memcache;
  95. }),
  96. /*
  97. |--------------------------------------------------------------------------
  98. | Laravel Session Components
  99. |--------------------------------------------------------------------------
  100. |
  101. | The following components are used by the Laravel session system.
  102. |
  103. | The framework allows the session ID to be transported via a variety
  104. | of different mechanisms by resolve the ID itself and the session
  105. | transporter instance out of the container. This allows sessions
  106. | to be used by clients who cannot receive cookies.
  107. |
  108. | The session manager is responsible for loading the session payload
  109. | from the session driver, as well as examining the payload validitiy
  110. | and things like the CSRF token.
  111. |
  112. */
  113. 'laravel.session.transporter' => array('resolver' => function($c)
  114. {
  115. return new Session\Transporters\Cookie;
  116. }),
  117. 'laravel.session.apc' => array('resolver' => function($c)
  118. {
  119. return new Session\Drivers\APC($c->core('cache.apc'));
  120. }),
  121. 'laravel.session.cookie' => array('resolver' => function($c)
  122. {
  123. return new Session\Drivers\Cookie;
  124. }),
  125. 'laravel.session.database' => array('resolver' => function($c)
  126. {
  127. return new Session\Drivers\Database(Database\Manager::connection());
  128. }),
  129. 'laravel.session.file' => array('resolver' => function($c)
  130. {
  131. return new Session\Drivers\File(SESSION_PATH);
  132. }),
  133. 'laravel.session.redis' => array('resolver' => function($c)
  134. {
  135. return new Session\Drivers\Redis($c->core('cache.redis'));
  136. }),
  137. 'laravel.session.memcached' => array('resolver' => function($c)
  138. {
  139. return new Session\Drivers\Memcached($c->core('cache.memcached'));
  140. }),
  141. );