Update.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Controllers;
  10. use ForkBB\Core\Container;
  11. use ForkBB\Models\Page;
  12. class Update
  13. {
  14. /**
  15. * Контейнер
  16. * @var Container
  17. */
  18. protected $c;
  19. public function __construct(Container $container)
  20. {
  21. $this->c = $container;
  22. }
  23. /**
  24. * Маршрутиризация
  25. */
  26. public function routing(): Page
  27. {
  28. $uri = $_SERVER['REQUEST_URI'];
  29. if (false !== ($pos = \strpos($uri, '?'))) {
  30. $uri = \substr($uri, 0, $pos);
  31. }
  32. $uri = \rawurldecode($uri);
  33. $this->c->user = $this->c->users->create(['id' => 2, 'group_id' => FORK_GROUP_ADMIN]); //???? id?
  34. $this->c->Lang->load('common');
  35. $r = $this->c->Router;
  36. $r->add(
  37. $r::GET,
  38. '/admin/update/{uid}/{stage|i:\d+}[/{start|i:\d+}]',
  39. 'AdminUpdate:stage',
  40. 'AdminUpdateStage'
  41. );
  42. $r->add(
  43. $r::DUO,
  44. '/admin/update',
  45. 'AdminUpdate:view',
  46. 'AdminUpdate'
  47. );
  48. $method = $_SERVER['REQUEST_METHOD'];
  49. $route = $r->route($method, $uri);
  50. $page = null;
  51. switch ($route[0]) {
  52. case $r::OK:
  53. // ... 200 OK
  54. list($page, $action) = \explode(':', $route[1], 2);
  55. $page = $this->c->$page->$action($route[2], $method);
  56. break;
  57. default:
  58. $page = $this->c->AdminUpdate->view([], 'GET');
  59. break;
  60. }
  61. return $page;
  62. }
  63. }