index.php 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // Copyright (C) 2010-2015 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Required constants :
  20. * - PORTAL_MODULE_ID : Name of the portal instance module
  21. * - PORTAL_ID : Name of the portal instance module design (Configuration)
  22. */
  23. // Silex framework and components
  24. require_once APPROOT . '/lib/silex/vendor/autoload.php';
  25. // iTop application requirements
  26. //require_once __DIR__.'/../../../../approot.inc.php'; // Required by the instanciation module
  27. //require_once APPROOT.'/application/startup.inc.php'; // Required by the instanciation module
  28. require_once APPROOT . '/core/moduledesign.class.inc.php';
  29. require_once APPROOT . '/application/loginwebpage.class.inc.php';
  30. require_once APPROOT . '/sources/autoload.php';
  31. // Portal
  32. require_once __DIR__ . '/../src/providers/urlgeneratorserviceprovider.class.inc.php';
  33. require_once __DIR__ . '/../src/helpers/urlgeneratorhelper.class.inc.php';
  34. require_once __DIR__ . '/../src/providers/contextmanipulatorserviceprovider.class.inc.php';
  35. require_once __DIR__ . '/../src/helpers/contextmanipulatorhelper.class.inc.php';
  36. require_once __DIR__ . '/../src/providers/scopevalidatorserviceprovider.class.inc.php';
  37. require_once __DIR__ . '/../src/helpers/scopevalidatorhelper.class.inc.php';
  38. require_once __DIR__ . '/../src/helpers/securityhelper.class.inc.php';
  39. require_once __DIR__ . '/../src/helpers/applicationhelper.class.inc.php';
  40. // Forms
  41. require_once __DIR__ . '/../src/forms/objectformmanager.class.inc.php';
  42. use \Exception;
  43. use \Symfony\Component\HttpFoundation\Response;
  44. use \Combodo\iTop\Portal\Helper\ApplicationHelper;
  45. // Checking user rights and prompt if needed
  46. LoginWebPage::DoLoginEx(PORTAL_ID);
  47. // Initializing Silex framework
  48. $oApp = new Silex\Application();
  49. // Registring optional silex components
  50. $oApp->register(new Combodo\iTop\Portal\Provider\UrlGeneratorServiceProvider());
  51. $oApp->register(new Combodo\iTop\Portal\Provider\ContextManipulatorServiceProvider());
  52. $oApp->register(new Combodo\iTop\Portal\Provider\ScopeValidatorServiceProvider(), array(
  53. 'scope_validator.scopes_path' => utils::GetCachePath(),
  54. 'scope_validator.scopes_filename' => PORTAL_ID . '.scopes.php',
  55. 'scope_validator.instance_name' => PORTAL_ID
  56. ));
  57. $oApp->register(new Silex\Provider\TwigServiceProvider(), array(
  58. 'twig.path' => APPROOT . 'env-' . utils::GetCurrentEnvironment()
  59. ));
  60. // Configuring Silex application
  61. $oApp['debug'] = false;
  62. $oApp['combodo.absolute_url'] = utils::GetAbsoluteUrlAppRoot();
  63. $oApp['combodo.portal.base.absolute_url'] = utils::GetAbsoluteUrlAppRoot() . 'env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/web/';
  64. $oApp['combodo.portal.instance.absolute_url'] = utils::GetAbsoluteUrlAppRoot() . 'env-' . utils::GetCurrentEnvironment() . '/' . PORTAL_MODULE_ID . '/';
  65. $oApp['combodo.portal.instance.id'] = PORTAL_MODULE_ID;
  66. $oApp['combodo.portal.instance.conf'] = array();
  67. $oApp['combodo.portal.instance.routes'] = array();
  68. // Registering error/exception handler in order to transform php error to exception
  69. ApplicationHelper::RegisterExceptionHandler($oApp);
  70. // Preparing portal foundations (Can't use Silex autoload through composer as we don't follow PSR conventions -filenames, functions-)
  71. ApplicationHelper::LoadControllers();
  72. ApplicationHelper::LoadRouters();
  73. ApplicationHelper::RegisterRoutes($oApp);
  74. ApplicationHelper::LoadBricks();
  75. ApplicationHelper::RegisterTwigExtensions($oApp);
  76. // Loading portal configuration from the module design
  77. ApplicationHelper::LoadPortalConfiguration($oApp);
  78. // Loading current user
  79. ApplicationHelper::LoadCurrentUser($oApp);
  80. // Running application
  81. $oApp->run();