00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class PropertyPath
00017 {
00018 private $root = null;
00019 private $path = null;
00020
00021 private static $daos = array();
00022 private static $protos = array();
00023
00024 private $properties = array();
00025
00026 public function __construct($root, $path)
00027 {
00028 Assert::isString($path, 'non-string path given');
00029
00030 if (is_object($root))
00031 $className = get_class($root);
00032 else {
00033 Assert::isTrue(
00034 class_exists($root, true),
00035 'inexistant class given'
00036 );
00037 $className = $root;
00038 }
00039
00040 $this->root = $className;
00041 $this->path = $path;
00042
00043 $this->fetchHelpers($className);
00044
00045 $proto = self::$protos[$className];
00046
00047 $path = explode('.', $path);
00048
00049 for ($i = 0, $size = count($path); $i < $size; ++$i) {
00050 $this->properties[$i]
00051 = $property
00052 = $proto->getPropertyByName($path[$i]);
00053
00054 if ($className = $property->getClassName()) {
00055 $this->fetchHelpers($className);
00056 $proto = self::$protos[$className];
00057 } elseif ($i < $size) {
00058 continue;
00059 } else {
00060 throw new WrongArgumentException('corrupted path');
00061 }
00062 }
00063 }
00064
00065 public function getPath()
00066 {
00067 return $this->path;
00068 }
00069
00070 public function getRoot()
00071 {
00072 return $this->root;
00073 }
00074
00078 public function getFinalProto()
00079 {
00080 return self::$protos[$this->getFinalProperty()->getClassName()];
00081 }
00082
00086 public function getFinalDao()
00087 {
00088 return self::$daos[$this->getFinalProperty()->getClassName()];
00089 }
00090
00094 public function getFinalProperty()
00095 {
00096 return end($this->properties);
00097 }
00098
00099 private function fetchHelpers($className)
00100 {
00101 if (isset(self::$protos[$className], self::$daos[$className]))
00102 return ;
00103
00104 self::$protos[$className] = call_user_func(array($className, 'proto'));
00105 self::$daos[$className] = call_user_func(array($className, 'dao'));
00106
00107 Assert::isTrue(
00108 (self::$protos[$className] instanceof AbstractProtoClass)
00109 && (self::$daos[$className] instanceof ComplexBuilderDAO)
00110 );
00111 }
00112 }
00113 ?>