/** * @throws WrongArgumentException * @return PrimitiveForm * * @deprecated You should use ofProto() instead **/ public function of($className) { Assert::classExists($className); $protoClass = EntityProto::PROTO_CLASS_PREFIX . $className; Assert::classExists($protoClass); return $this->ofProto(Singleton::getInstance($protoClass)); }
public function __construct($root, $path) { Assert::isString($path, 'non-string path given'); if (is_object($root)) { $className = get_class($root); } else { Assert::classExists($root); $className = $root; } $this->root = $className; $this->path = $path; $this->fetchHelpers($className); $proto = self::$protos[$className]; $path = explode('.', $path); for ($i = 0, $size = count($path); $i < $size; ++$i) { $this->properties[$i] = $property = $proto->getPropertyByName($path[$i]); if ($className = $property->getClassName()) { $this->fetchHelpers($className); $proto = self::$protos[$className]; } elseif ($i < $size) { continue; } else { throw new WrongArgumentException('corrupted path'); } } }
/** * @throws WrongArgumentException * @return PrimitivePolymorphicIdentifier **/ public function ofBase($className) { Assert::classExists($className); Assert::isInstance($className, 'DAOConnected', "class '{$className}' must implement DAOConnected interface"); $this->baseClassName = $className; return $this; }
/** * @throws WrongArgumentException * @return PrimitiveEnum **/ public function of($class) { $className = $this->guessClassName($class); Assert::classExists($className); Assert::isInstance($className, 'Enum'); $this->className = $className; return $this; }
public function dropWith($worker) { Assert::classExists($worker); if ($this->modifiedIds) { $workerObject = new $worker($this->dao); $workerObject->uncacheByIds($this->modifiedIds); $this->modifiedIds = array(); } return $this; }
public static function setDefaultLocker($name) { Assert::classExists($name); self::$lockerName = $name; self::$locker = Singleton::getInstance($name); }
/** * @return BasePrimitive **/ public static function spawn($primitive, $name) { Assert::classExists($primitive); return new $primitive($name); }
public static function setDefaultHandler($handler) { Assert::classExists($handler); self::$defaultHandler = $handler; }
public function __construct($controllerName) { Assert::classExists($controllerName); $this->url = $controllerName; }
public function toValue(ProtoDAO $dao = null, $array, $prefix = null) { $raw = $array[$prefix . $this->columnName]; if ($this->type == 'binary') { return DBPool::getByDao($dao)->getDialect()->unquoteBinary($raw); } if ($this->className == 'HttpUrl') { return HttpUrl::create()->parse($raw); } if (!$this->identifier && $this->generic && $this->className) { return call_user_func(array($this->className, 'create'), $raw); } elseif (!$this->identifier && $this->className) { // BOVM: prevents segfault on >=php-5.2.5 Assert::classExists($this->className); if (!is_subclass_of($this->className, 'Enumeration')) { $remoteDao = call_user_func(array($this->className, 'dao')); $joinPrefix = $remoteDao->getJoinPrefix($this->columnName, $prefix); $joined = $this->strategyId == FetchStrategy::JOIN || isset($array[$joinPrefix . $remoteDao->getIdName()]); if ($joined) { return $remoteDao->makeObject($array, $joinPrefix); } else { // will be fetched later // by AbstractProtoClass::fetchEncapsulants $object = new $this->className(); $object->setId($raw); return $object; } } else { return new $this->className($raw); } } // veeeeery "special" handling, by tradition. // MySQL returns 0/1, others - t/f if ($this->type == 'boolean') { return (bool) strtr($raw, array('f' => null)); } return $raw; }
public static function setDefaultWorker($worker) { Assert::classExists($worker); self::$worker = $worker; }
private function processPath(AbstractProtoClass $proto, $probablyPath, JoinCapableQuery $query, $table, $parentRequired = true, $prefix = null) { $path = explode('.', $probablyPath); try { $property = $proto->getPropertyByName($path[0]); } catch (MissingElementException $e) { // oh, it's a value, not a property return new DBValue($probablyPath); } unset($path[0]); Assert::isTrue($property->getRelationId() != null && !$property->isGenericType()); Assert::classExists($property->getClassName()); // checking whether we're playing with value object if (!method_exists($property->getClassName(), 'dao')) { if (method_exists($property->getClassName(), 'proto') && count($path) > 1) { return $this->processPath($property->getProto(), implode('.', $path), $query, $table); } else { return $this->guessAtom(implode('.', $path), $query, $table, $prefix); } } else { $propertyDao = call_user_func(array($property->getClassName(), 'dao')); Assert::isNotNull($propertyDao, 'can not find target dao for "' . $property->getName() . '" property at "' . get_class($proto) . '"'); } $alias = $propertyDao->getJoinName($property->getColumnName(), $prefix); if ($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY) { $remoteName = $property->getClassName(); $selfName = $this->getObjectName(); $self = new $selfName(); $getter = $property->getGetter(); $dao = call_user_func(array($remoteName, 'dao')); if ($property->getRelationId() == MetaRelation::MANY_TO_MANY) { $helperTable = $self->{$getter}()->getHelperTable(); $helperAlias = $helperTable; if (!$query->hasJoinedTable($helperAlias)) { $logic = Expression::eq(DBField::create($this->getIdName(), $table), DBField::create($self->{$getter}()->getParentIdField(), $helperAlias)); if ($property->isRequired()) { $query->join($helperTable, $logic, $helperAlias); } else { $query->leftJoin($helperTable, $logic, $helperAlias); } } $logic = Expression::eq(DBField::create($propertyDao->getIdName(), $alias), DBField::create($self->{$getter}()->getChildIdField(), $helperAlias)); } else { $logic = Expression::eq(DBField::create($self->{$getter}()->getParentIdField(), $alias), DBField::create($this->getIdName(), $table)); } if (!$query->hasJoinedTable($alias)) { if ($property->isRequired() && $parentRequired) { $query->join($dao->getTable(), $logic, $alias); } else { $query->leftJoin($dao->getTable(), $logic, $alias); } } } else { // OneToOne, lazy OneToOne // prevents useless joins if (isset($path[1]) && count($path) == 1 && $path[1] == $propertyDao->getIdName()) { return new DBField($property->getColumnName(), $table); } if (!$query->hasJoinedTable($alias)) { $logic = Expression::eq(DBField::create($property->getColumnName(), $table), DBField::create($propertyDao->getIdName(), $alias)); if ($property->isRequired() && $parentRequired) { $query->join($propertyDao->getTable(), $logic, $alias); } else { $query->leftJoin($propertyDao->getTable(), $logic, $alias); } } } if ($path) { return $propertyDao->guessAtom(implode('.', $path), $query, $alias, $property->isRequired() && $parentRequired, $propertyDao->getJoinPrefix($property->getColumnName(), $prefix)); } // ok, we're done }