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;
 }
Esempio n. 2
0
    public function toSetter(MetaClass $class, MetaClassProperty $property, MetaClassProperty $holder = null)
    {
        $name = $property->getName();
        $methodName = 'set' . ucfirst($name);
        if ($holder) {
            return <<<EOT

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

\treturn \$this;
}

EOT;
        } else {
            return <<<EOT

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

\treturn \$this;
}

EOT;
        }
    }
Esempio n. 3
0
 private static function doPropertyBuild(MetaClass $class, MetaClassProperty $property, $isNamed)
 {
     if ($parentProperty = $class->isRedefinedProperty($property->getName())) {
         // check wheter property fetch strategy becomes lazy
         if ($parentProperty->getFetchStrategyId() != $property->getFetchStrategyId() && $property->getFetchStrategyId() === FetchStrategy::LAZY) {
             return true;
         }
         return false;
     }
     if ($isNamed && $property->getName() == 'name') {
         return false;
     }
     if ($property->getName() == 'id' && !$property->getClass()->getParent()) {
         return false;
     }
     // do not redefine parent's properties
     if ($property->getClass()->getParent() && array_key_exists($property->getName(), $property->getClass()->getAllParentsProperties())) {
         return false;
     }
     return true;
 }
Esempio n. 4
0
    public function toSetter(MetaClass $class, MetaClassProperty $property, MetaClassProperty $holder = null)
    {
        $name = $property->getName();
        $methodName = 'set' . ucfirst($name);
        if ($holder) {
            return <<<EOT

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

\treturn \$this;
}

EOT;
        } else {
            if ($property->isRequired()) {
                $method = <<<EOT

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

\treturn \$this;
}

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

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

\treturn \$this;
}

EOT;
            }
        }
        return $method;
    }
Esempio n. 5
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;
    }