Passed
Push — master ( d67f1f...9f0579 )
by Aimeos
01:55
created

Typo3::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2014-2018
7
 * @package MW
8
 * @subpackage Session
9
 */
10
11
12
namespace Aimeos\MW\Session;
13
14
15
/**
16
 * Managing session data using the TYPO3 session
17
 *
18
 * @package MW
19
 * @subpackage Session
20
 */
21
class Typo3 extends Base implements \Aimeos\MW\Session\Iface
0 ignored issues
show
Bug introduced by
The type Aimeos\MW\Session\Base was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
{
23
	private $user;
24
25
26
	/**
27
	 * Initializes the Typo3 session object.
28
	 *
29
	 * @param \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $user Typo3 user object (FE or BE)
30
	 */
31
	public function __construct( \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $user )
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Authentic...tractUserAuthentication was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
	{
33
		$this->user = $user;
34
	}
35
36
37
	/**
38
	 * Sets a list of key/value pairs.
39
	 *
40
	 * @param array $values Associative list of key/value pairs
41
	 * @return \Aimeos\MW\Session\Iface Session instance for method chaining
42
	 */
43
	public function apply( array $values )
44
	{
45
		foreach( $values as $key => $value ) {
46
			$this->user->setKey( 'ses', $key, $value );
47
		}
48
49
		$this->user->storeSessionData();
50
		return $this;
51
	}
52
53
54
	/**
55
	 * Returns the value of the requested session key.
56
	 *
57
	 * If the returned value wasn't a string, it's decoded from its serialized
58
	 * representation.
59
	 *
60
	 * @param string $name Key of the requested value in the session
61
	 * @param mixed $default Value returned if requested key isn't found
62
	 * @return mixed Value associated to the requested key
63
	 */
64
	public function get( $name, $default = null )
65
	{
66
		if( ( $value = $this->user->getSessionData( $name ) ) !== null ) {
67
			return $value;
68
		}
69
70
		return $default;
71
	}
72
73
74
	/**
75
	 * Sets the value for the specified key.
76
	 *
77
	 * If the value isn't a string, it's encoded into a serialized representation
78
	 * and decoded again when using the get() method.
79
	 *
80
	 * @param string $name Key to the value which should be stored in the session
81
	 * @param mixed $value Value that should be associated with the given key
82
	 * @return \Aimeos\MW\Session\Iface Session instance for method chaining
83
	 */
84
	public function set( $name, $value )
85
	{
86
		$this->user->setAndSaveSessionData( $name, $value );
87
		return $this;
88
	}
89
}
90