Install.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace ForkBB\Controllers;
  3. use ForkBB\Core\Container;
  4. use ForkBB\Models\User;
  5. class Install
  6. {
  7. /**
  8. * Контейнер
  9. * @var Container
  10. */
  11. protected $c;
  12. /**
  13. * Конструктор
  14. * @param Container $container
  15. */
  16. public function __construct(Container $container)
  17. {
  18. $this->c = $container;
  19. }
  20. /**
  21. * Маршрутиризация
  22. * @return Page
  23. */
  24. public function routing()
  25. {
  26. $uri = $_SERVER['REQUEST_URI'];
  27. if (($pos = strpos($uri, '?')) !== false) {
  28. $uri = substr($uri, 0, $pos);
  29. }
  30. $uri = rawurldecode($uri);
  31. $this->c->BASE_URL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://'
  32. . preg_replace('%:(80|443)$%', '', $_SERVER['HTTP_HOST'])
  33. . substr($uri, 0, (int) strrpos($uri, '/'));
  34. $this->c->Lang->load('common', $this->c->config['o_default_lang']);
  35. $this->c->user = new User(['id' => 2, 'group_id' => $this->c->GROUP_ADMIN], $this->c);
  36. $r = $this->c->Router;
  37. $r->add('GET', '/install', 'Install:install', 'Install');
  38. $r->add('POST', '/install', 'Install:installPost');
  39. $route = $r->route($_SERVER['REQUEST_METHOD'], $uri);
  40. $page = null;
  41. switch ($route[0]) {
  42. case $r::OK:
  43. // ... 200 OK
  44. list($page, $action) = explode(':', $route[1], 2);
  45. $page = $this->c->$page->$action($route[2]);
  46. break;
  47. default:
  48. $page = $this->c->Redirect->setPage('Install')->setMessage('Redirect to install');
  49. break;
  50. }
  51. return $page;
  52. }
  53. }