private function checkRecursion(MetaClassProperty $property, MetaClass $holder, $paths = array())
 {
     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;
 }
Exemplo n.º 2
0
    public function toDropper(MetaClass $class, MetaClassProperty $property, MetaClassProperty $holder = null)
    {
        if ($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY) {
            // we don't need dropper in such cases
            return null;
        }
        $name = $property->getName();
        $methodName = 'drop' . ucfirst($name);
        if ($holder) {
            $method = <<<EOT

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

\treturn \$this;
}

EOT;
        } else {
            if ($property->getFetchStrategyId() == FetchStrategy::LAZY) {
                $method = <<<EOT

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

\treturn \$this;
}

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

/**
 * @return {$class->getName()}
**/
public function {$methodName}()
{
\t\$this->{$name} = null;

\treturn \$this;
}

EOT;
            }
        }
        return $method;
    }