-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMapping.php
More file actions
61 lines (54 loc) · 1.36 KB
/
Mapping.php
File metadata and controls
61 lines (54 loc) · 1.36 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace ScriptFUSION\Mapper;
use ScriptFUSION\Mapper\Strategy\Strategy;
/**
* Represents a mapping of keys and mappable values.
*/
abstract class Mapping
{
/**
* @var array
*/
private $mapping;
private $wrapped = false;
/**
* Initializes this mapping.
*/
public function __construct()
{
/* Array-based mapping. */
if (is_array($mapping = $this->createMapping())) {
$this->mapping = $mapping;
} /* Strategy-based mapping. */
elseif ($mapping instanceof Strategy) {
$this->mapping = [$mapping];
$this->wrapped = true;
} else {
throw new InvalidMappingException('Invalid mapping: must be array or an instance of Strategy.');
}
}
/**
* Creates a mapping of key names and expressions or a straegy.
*
* @return array|Strategy Mapping.
*/
abstract protected function createMapping();
/**
* Converts the mapping to an array.
*
* @return array
*/
public function toArray()
{
return $this->mapping;
}
/**
* Gets a value indicating whether the mapping has been wrapped in an array.
*
* @return boolean True if the mapping is wrapped in an outer array, otherwise false.
*/
public function isWrapped()
{
return $this->wrapped;
}
}