ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
StartUpSequenceDispatcher.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ilContext;
25 use ilSession;
30 use SplQueue;
33 
40 {
41  private Container $dic;
43  private $sequence = [];
44 
45  public function __construct(Container $dic)
46  {
47  $this->dic = $dic;
48  $this->initSequence();
49  }
50 
51  protected function initSequence(): void
52  {
53  $this->sequence = new SplQueue();
54  $this->sequence->push(new StartUpStep(
55  $this->dic->ctrl(),
56  $this->dic['legalDocuments']
57  ));
58  $this->sequence->push(new ilUserProfileStartUpStep(
59  $this->dic->user(),
60  $this->dic->ctrl()
61  ));
62  $this->sequence->push(new ilForcedUserPasswordChangeStartUpStep(
63  $this->dic->user(),
64  $this->dic->ctrl(),
65  $this->dic->http()->request()
66  ));
67  }
68 
69  protected function storeRequest(): void
70  {
71  if (!ilSession::get('orig_request_target')) {
72  //#16324 don't use the complete REQUEST_URI
73 
74  $url = $_SERVER['REQUEST_URI'];
75  $short = strpos($url, StandardURIBuilder::SHORT);
76 
77  if (preg_match('@/([^/]+\\.php[?/].*)$@', $url, $matches)) {
78  $url = $matches[1];
79  } elseif ($short !== false) {
80  $url = substr($url, $short + 1);
81  } else {
82  $url = substr($url, strrpos($url, '/') + 1);
83  }
84 
85  ilSession::set('orig_request_target', $url);
86  }
87  }
88 
92  public function dispatch(): bool
93  {
94  $this->dic->logger()->init()->debug('Started request interception checks ...');
95 
96  if (defined('IL_CERT_SSO')) {
97  $this->dic->logger()->init()->debug('ApacheAuthentication request. No interception.');
98  return false;
99  } elseif (!ilContext::supportsRedirects()) {
100  $this->dic->logger()->init()->debug('Context does not support redirects. No interception.');
101  return false;
102  } elseif ($this->dic->ctrl()->isAsynch()) {
103  $this->dic->logger()->init()->debug('Async request. No interception.');
104  return false;
105  } elseif (in_array(basename($_SERVER['PHP_SELF']), array('logout.php'))) {
106  $this->dic->logger()->init()->debug('Logout request. No interception.');
107  return false;
108  } elseif (!$this->dic->user()->getId() || $this->dic->user()->isAnonymous()) {
109  $this->dic->logger()->init()->debug('Anonymous request. No interception.');
110  return false;
111  } elseif (ilSession::get(__CLASS__ . '_passed')) {
112  $this->dic->logger()->init()->debug(__CLASS__ . ' already passed in the current user session.');
113  return false;
114  }
115 
116  $this->sequence->rewind();
117  while (!$this->sequence->isEmpty()) {
118  $step = $this->sequence->shift();
119 
120  if ($step->isInFulfillment()) {
121  $this->dic->globalScreen()->tool()->context()->current()->addAdditionalData(
123  true
124  );
125 
126  $this->dic->logger()->init()->debug('Step is in fulfillment:' . get_class($step));
127  return false;
128  }
129 
130  if ($step->shouldInterceptRequest()) {
131  $this->dic->logger()->init()->debug('Step required adjustment:' . get_class($step));
132  if ($step->shouldStoreRequestTarget()) {
133  $this->storeRequest();
134  }
135  $step->execute();
136  return true;
137  }
138  }
139 
140  ilSession::set(__CLASS__ . '_passed', 1);
141  return false;
142  }
143 }
static get(string $a_var)
Class ChatMainBarProvider .
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$url
Definition: ltiregstart.php:35
static set(string $a_var, $a_val)
Set a value.
static supportsRedirects()
Are redirects supported?