initialize.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. |-------------------------------------------------------------------
  4. | Register Composer PSR Auto Loader
  5. |-------------------------------------------------------------------
  6. |
  7. | Composer is the convenient way to auto load all dependencies and
  8. | classes. We will simple require it here, so that we don't need
  9. | worry about importing classes manually.
  10. */
  11. require __DIR__ . "/../vendor/autoload.php";
  12. /*
  13. | -------------------------------------------------------------------
  14. | Check if script is running via cli and return false
  15. | -------------------------------------------------------------------
  16. */
  17. $filename = preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
  18. if (php_sapi_name() === 'cli-server' && is_file($filename)) {
  19. return false;
  20. }
  21. /*
  22. |--------------------------------------------------------------------------
  23. | Create The Application
  24. |--------------------------------------------------------------------------
  25. |
  26. | To boot framework first thing we will create a new application instance
  27. | which serves glue for all the components, and binding components
  28. | with the IoC container
  29. */
  30. $app = \Cygnite\Foundation\Application::instance();
  31. $app->importHelpers();
  32. /*
  33. |--------------------------------------------------------------------------
  34. | Attach Exception handler to Event Listener
  35. |--------------------------------------------------------------------------
  36. |
  37. | We will attach exception handler to event listener, so that if anything
  38. | goes wrong it will catch exceptions.
  39. */
  40. $app['app.event'] = function () use($app) {
  41. $event = $app->singleton('event', '\Cygnite\Base\EventHandler\Event');
  42. $event->attach("exception", '\\Cygnite\\Exception\\Handler@handleException');
  43. return $event;
  44. };
  45. $config = \Cygnite\Helpers\Config::load();
  46. /**
  47. | ---------------------------------------------------
  48. | Application booting process
  49. | --------------------------------------------------
  50. *
  51. * Set configuration and services and boot-up application
  52. */
  53. return $app->setConfiguration($config)->boot();