public static function getContainerClassOfMetaProperty(MetaClassProperty $property, $addBackslash = false)
 {
     if (!$property->getType() instanceof ObjectType || is_null($property->getRelationId())) {
         throw new WrongArgumentException();
     }
     $className = ($addBackslash ? '\\' : '') . $property->getClass()->getDaoNamespace() . '\\' . $property->getClass()->getName() . ucfirst($property->getName()) . 'DAO';
     return $className;
 }
 public function equals(MetaClassProperty $property)
 {
     return $property->getName() == $this->getName() && $property->getColumnName() == $this->getColumnName() && $property->getType() == $this->getType() && $property->getSize() == $this->getSize() && $property->getRelation() == $this->getRelation() && $property->isRequired() == $this->isRequired() && $property->isIdentifier() == $this->isIdentifier();
 }
 private function checkRecursion(MetaClassProperty $property, MetaClass $holder, $paths = [])
 {
     Assert::isTrue($property->getRelationId() == MetaRelation::ONE_TO_ONE);
     if ($property->getFetchStrategy() && $property->getFetchStrategy()->getId() != FetchStrategy::JOIN) {
         return false;
     }
     $remote = $property->getType()->getClass();
     if (isset($paths[$holder->getName()][$remote->getName()])) {
         return true;
     } else {
         $paths[$holder->getName()][$remote->getName()] = true;
         foreach ($remote->getProperties() as $remoteProperty) {
             if ($remoteProperty->getRelationId() == MetaRelation::ONE_TO_ONE) {
                 if ($this->checkRecursion($remoteProperty, $holder, $paths)) {
                     $remoteProperty->setFetchStrategy(FetchStrategy::cascade());
                 }
             }
         }
     }
     return false;
 }
Exemple #4
0
    public function toSetter(MetaClass $class, MetaClassProperty $property, MetaClassProperty $holder = null)
    {
        if ($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY) {
            // we don't need setter in such cases
            return null;
        }
        $name = $property->getName();
        $methodName = 'set' . ucfirst($name);
        if ($holder) {
            return <<<EOT

/**
 * @return {$holder->getClass()->getName()}
**/
public function {$methodName}({$property->getType()->getClassName()} \${$name})
{
\t\$this->{$holder->getName()}->{$methodName}(\${$name});
\t
\treturn \$this;
}

EOT;
        } else {
            $defaultValue = $property->isOptional() ? ' = null' : '';
            if ($property->getFetchStrategyId() == FetchStrategy::LAZY) {
                $method = <<<EOT

/**
 * @return {$property->getClass()->getName()}
**/
public function {$methodName}({$this->className} \${$name}{$defaultValue})
{
\t\$this->{$name} = \${$name};
\t\$this->{$name}Id = \${$name} ? \${$name}->getId() : null;

\treturn \$this;
}

/**
 * @return {$property->getClass()->getName()}
**/
public function {$methodName}Id(\$id{$defaultValue})
{
\t\$this->{$name} = null;
\t\$this->{$name}Id = \$id;

\treturn \$this;
}

EOT;
            } else {
                $method = <<<EOT

/**
 * @return {$property->getClass()->getName()}
**/
public function {$methodName}({$this->className} \${$name}{$defaultValue})
{
\t\$this->{$name} = \${$name};

\treturn \$this;
}

EOT;
            }
        }
        return $method;
    }