4a8f921e5888c426c9a74f824d6839b19d5f82e6
5 use pq\Mapper\Property\All
;
6 use pq\Mapper\Property\Field
;
7 use pq\Mapper\Property\Ref
;
8 use ReflectionProperty
;
9 use UnexpectedValueException
;
19 * @var ReflectionProperty[]
25 * @param MapInterface $map
28 function register(MapInterface
$map) {
29 $this->maps
[$map->getClass()] = $map;
34 * Get a property reflector
35 * @param string $class
37 * @return ReflectionProperty
39 function getReflector($class, $prop) {
40 if (is_object($class)) {
41 $class = get_class($class);
43 $hash = "$class::$prop";
44 if (!isset($this->refp
[$hash])) {
45 $this->refp
[$hash] = new ReflectionProperty($class, $prop);
46 $this->refp
[$hash]->setAccessible(true);
48 return $this->refp
[$hash];
52 * Get the mapping of $class
53 * @param string $class
54 * @return MapInterface
55 * @throws UnexpectedValueException
57 function mapOf($class) {
58 if (is_object($class)) {
59 $class = get_class($class);
61 if (!isset($this->maps
[$class])) {
62 if (!is_callable([$class, "mapAs"])) {
63 throw new UnexpectedValueException("Not a mapped class: '$class'");
65 $this->register($class::mapAs($this));
67 return $this->maps
[$class];
71 * Create a storage for $class
72 * @param string $class
75 function createStorage($class) {
76 return new Storage($this->mapOf($class));
80 * Create a simple field mapping
81 * @param string $property
82 * @param string $field
85 function mapField($property, $field = null) {
86 return new Field($this, $property, $field);
90 * Create a child rows mapping by foreign key
91 * @param string $property
94 function mapAll($property) {
95 return new All($this, $property);
99 * Create a parent row mapping by foreign key
100 * @param string $property
103 function mapRef($property) {
104 return new Ref($this, $property);