container.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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' => function($c)
  46. {
  47. return new Database\Connectors\SQLite;
  48. },
  49. 'laravel.database.connectors.mysql' => function($c)
  50. {
  51. return new Database\Connectors\MySQL;
  52. },
  53. 'laravel.database.connectors.pgsql' => 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
  63. | caching system. Each driver is resolved through the container.
  64. |
  65. | New cache drivers may be added to the framework by simply registering
  66. | them into the container.
  67. |
  68. */
  69. 'laravel.cache.apc' => array('resolver' => function($c)
  70. {
  71. return new Cache\Drivers\APC(Config::get('cache.key'));
  72. }),
  73. 'laravel.cache.file' => array('resolver' => function($c)
  74. {
  75. return new Cache\Drivers\File(CACHE_PATH);
  76. }),
  77. 'laravel.cache.memcached' => array('resolver' => function($c)
  78. {
  79. return new Cache\Drivers\Memcached($c->core('cache.memcache.connection'), Config::get('cache.key'));
  80. }),
  81. 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($c)
  82. {
  83. $memcache = new \Memcache;
  84. foreach (Config::get('cache.servers') as $server)
  85. {
  86. $memcache->addServer($server['host'], $server['port'], true, $server['weight']);
  87. }
  88. if ($memcache->getVersion() === false)
  89. {
  90. throw new \Exception('Could not establish memcached connection. Please verify your memcached configuration.');
  91. }
  92. return $memcache;
  93. }),
  94. /*
  95. |--------------------------------------------------------------------------
  96. | Laravel Session Components
  97. |--------------------------------------------------------------------------
  98. |
  99. | The following components are used by the Laravel session system.
  100. |
  101. | The framework allows the session ID to be transported via a variety
  102. | of different mechanisms by resolve the ID itself and the session
  103. | transporter instance out of the container. This allows sessions
  104. | to be used by clients who cannot receive cookies.
  105. |
  106. | The session manager is responsible for loading the session payload
  107. | from the session driver, as well as examining the payload validitiy
  108. | and things like the CSRF token.
  109. |
  110. | Like the caching components, each session driver is resolved via the
  111. | container and new drivers may be added by registering them into the
  112. | container. Several session drivers are "driven" by the cache drivers.
  113. |
  114. */
  115. 'laravel.session.transporter' => array('resolver' => function($c)
  116. {
  117. return new Session\Transporters\Cookie;
  118. }),
  119. 'laravel.session.apc' => array('resolver' => function($c)
  120. {
  121. return new Session\Drivers\APC($c->core('cache.apc'));
  122. }),
  123. 'laravel.session.cookie' => array('resolver' => function($c)
  124. {
  125. return new Session\Drivers\Cookie;
  126. }),
  127. 'laravel.session.database' => array('resolver' => function($c)
  128. {
  129. return new Session\Drivers\Database(Database\Manager::connection());
  130. }),
  131. 'laravel.session.file' => array('resolver' => function($c)
  132. {
  133. return new Session\Drivers\File(SESSION_PATH);
  134. }),
  135. 'laravel.session.memcached' => array('resolver' => function($c)
  136. {
  137. return new Session\Drivers\Memcached($c->core('cache.memcached'));
  138. }),
  139. );