|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the ramsey/collection library |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @copyright Copyright (c) Ben Ramsey <[email protected]> |
|
10
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
11
|
|
|
* @link https://benramsey.com/projects/ramsey-collection/ Documentation |
|
12
|
|
|
* @link https://packagist.org/packages/ramsey/collection Packagist |
|
13
|
|
|
* @link https://github.com/ramsey/collection GitHub |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Ramsey\Collection\Map; |
|
17
|
|
|
|
|
18
|
|
|
use Ramsey\Collection\Tool\TypeTrait; |
|
19
|
|
|
use Ramsey\Collection\Tool\ValueToStringTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* This class provides an implementation of the TypedMapInterface, to |
|
23
|
|
|
* minimize the effort required to implement this interface |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface |
|
26
|
|
|
{ |
|
27
|
|
|
use TypeTrait; |
|
28
|
|
|
use ValueToStringTrait; |
|
29
|
|
|
|
|
30
|
|
|
public function offsetSet($offset, $value) |
|
31
|
|
|
{ |
|
32
|
|
|
if (false === $this->checkType($this->getKeyType(), $offset)) { |
|
33
|
|
|
throw new \InvalidArgumentException( |
|
34
|
|
|
'Key must be of type ' . $this->getKeyType() . '; key is ' |
|
35
|
|
|
. $this->toolValueToString($offset) |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
if (false === $this->checkType($this->getValueType(), $value)) { |
|
39
|
|
|
throw new \InvalidArgumentException( |
|
40
|
|
|
'Value must be of type ' . $this->getValueType() . '; value is ' |
|
41
|
|
|
. $this->toolValueToString($value) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
parent::offsetSet($offset, $value); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|