X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpq%2FMapper%2FMapper.php;fp=lib%2Fpq%2FMapper%2FMapper.php;h=725a50c9ce28eb605bb4f9ef145832bda196e3bc;hb=e6da4c7430e5c5b4ba482206e42aeebb4363d2b3;hp=0000000000000000000000000000000000000000;hpb=0861b6cd0d8f86add1a068fd3d9740428c8418cd;p=m6w6%2Fpq-gateway diff --git a/lib/pq/Mapper/Mapper.php b/lib/pq/Mapper/Mapper.php new file mode 100644 index 0000000..725a50c --- /dev/null +++ b/lib/pq/Mapper/Mapper.php @@ -0,0 +1,83 @@ +maps[$map->getClass()] = $map; + return $this; + } + + function getReflector($class, $prop) { + if (is_object($class)) { + $class = get_class($class); + } + $hash = "$class::$prop"; + if (!isset($this->refp[$hash])) { + $this->refp[$hash] = new \ReflectionProperty($class, $prop); + $this->refp[$hash]->setAccessible(true); + } + return $this->refp[$hash]; + } + + /** + * @param string $class + * @return \pq\Mapper\MapInterface + * @throws UnexpectedValueException + */ + function mapOf($class) { + if (is_object($class)) { + $class = get_class($class); + } + if (!isset($this->maps[$class])) { + if (!is_callable([$class, "mapAs"])) { + throw new UnexpectedValueException("Not a mapped class: '$class'"); + } + $this->register($class::mapAs($this)); + } + return $this->maps[$class]; + } + + /** + * @param string $class + * @return \pq\Mapper\Storage + */ + function createStorage($class) { + return new Storage($this, $class); + } + + /** + * @param string $property + * @param string $field + * @return \pq\Mapper\Property\Field + */ + function mapField($property, $field = null) { + return new Property\Field($this, $property, $field); + } + + /** + * @param string $property + * @return \pq\Mapper\Property\All + */ + function mapAll($property) { + return new Property\All($this, $property); + } + + /** + * @param string $property + * @return \pq\Mapper\Property\Ref + */ + function mapRef($property) { + return new Property\Ref($this, $property); + } +}