KD2 Framework  Check-in [7950636c25]

Overview
Comment:UserSession: save session data from time to time
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7950636c258d2dccda1856bd8ca9224a2bc0e4f0
User & Date: bohwaz on 2023-05-10 18:50:57
Other Links: manifest | tags
Context
2023-05-11
09:03
AbstractEntity: Fix typo check-in: eb5d6ed18f user: bohwaz tags: trunk
2023-05-10
18:50
UserSession: save session data from time to time check-in: 7950636c25 user: bohwaz tags: trunk
17:41
AbstractEntity: Normalize line breaks to UNIX lines check-in: 99de2b85cf user: bohwaz tags: trunk
Changes

Modified src/lib/KD2/UserSession.php from [133c80c427] to [6315766967].

261
262
263
264
265
266
267
268
269
270
271
272
273
274








275
276
277
278
279
280
281

		if (null === $this->cookie_domain && isset($_SERVER['SERVER_NAME']))
		{
			$this->cookie_domain = $_SERVER['SERVER_NAME'];
		}
	}

	public function __destruct()
	{
		// Save data
		if ($this->modified) {
			$this->start(true);
			$_SESSION['userSessionData'] = $this->data;
			$this->close();








		}
	}

	protected function getSessionOptions()
	{
		return [
			'name'            => $this->cookie_name,







|






>
>
>
>
>
>
>
>







261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

		if (null === $this->cookie_domain && isset($_SERVER['SERVER_NAME']))
		{
			$this->cookie_domain = $_SERVER['SERVER_NAME'];
		}
	}

	public function save()
	{
		// Save data
		if ($this->modified) {
			$this->start(true);
			$_SESSION['userSessionData'] = $this->data;
			$this->close();
			$this->modified = false;
		}
	}

	public function __destruct()
	{
		if ($this->modified) {
			throw new \LogicException('Session data has been modified but not saved');
		}
	}

	protected function getSessionOptions()
	{
		return [
			'name'            => $this->cookie_name,
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443




444


445
446
447
448
449
450
451
		}

		if (empty($_SESSION['userSession']))
		{
			return false;
		}

		$this->user =& $_SESSION['userSession'];
		return true;
	}

	public function getUser()
	{
		if (!$this->isLogged())
		{
			throw new \LogicException('User is not logged in.');
		}

		return $this->user;
	}

	public function set($key, $value)
	{
		if (array_key_exists($key, $this->data) && $this->data[$key] === $value) {
			return;
		}





		$this->data[$key] = $value;


		$this->modified = true;
	}

	public function get($key)
	{
		$this->start();
		return $this->data[$key] ?? null;







|



















>
>
>
>
|
>
>







425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
		}

		if (empty($_SESSION['userSession']))
		{
			return false;
		}

		$this->user = $_SESSION['userSession'];
		return true;
	}

	public function getUser()
	{
		if (!$this->isLogged())
		{
			throw new \LogicException('User is not logged in.');
		}

		return $this->user;
	}

	public function set($key, $value)
	{
		if (array_key_exists($key, $this->data) && $this->data[$key] === $value) {
			return;
		}

		if ($value === null) {
			unset($this->data[$key]);
		}
		else {
			$this->data[$key] = $value;
		}

		$this->modified = true;
	}

	public function get($key)
	{
		$this->start();
		return $this->data[$key] ?? null;