-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathType.php
More file actions
37 lines (30 loc) · 873 Bytes
/
Copy pathType.php
File metadata and controls
37 lines (30 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace ScriptFUSION\Mapper\Strategy;
use ScriptFUSION\Mapper\DataType;
/**
* Casts data to the specified type.
*/
class Type extends Decorator
{
private $type;
/**
* @param DataType $type Type to cast to.
* @param Strategy $strategy Strategy.
*/
public function __construct(DataType $type, Strategy $strategy)
{
parent::__construct($strategy);
$this->type = $type;
}
public function __invoke($data, $context = null)
{
$data = parent::__invoke($data, $context);
/**
* settype() only returns false when the type specifier is invalid or
* "resource". Since the enumeration guarantees valid type specifiers
* this function call never returns false, so we do not check it.
*/
settype($data, $this->type->name);
return $data;
}
}