Beispiel #1
0
    public static function build(MetaClass $class)
    {
        $out = self::getHead();
        $out .= <<<EOT
namespace {$class->getDaoNamespace()};

use {$class->getAutoDaoClass()};


EOT;
        $type = $class->getType();
        if ($type) {
            switch ($type->getId()) {
                case MetaClassType::CLASS_ABSTRACT:
                    $abstract = 'abstract ';
                    $notes = 'nothing here yet';
                    break;
                case MetaClassType::CLASS_FINAL:
                    $abstract = 'final ';
                    $notes = 'last chance for customization';
                    break;
                default:
                    throw new WrongStateException('unknown class type');
            }
        } else {
            $abstract = null;
            $notes = 'your brilliant stuff goes here';
        }
        $out .= <<<EOT
{$abstract}class {$class->getName()}DAO extends Auto{$class->getName()}DAO
{
\t// {$notes}
}

EOT;
        return $out . self::getHeel();
    }
    public static function buildContainer(MetaClass $class, MetaClassProperty $holder)
    {
        $out = self::getHead();
        $out .= <<<EOT
namespace {$class->getDaoNamespace()};


EOT;
        $containerName = $class->getName() . ucfirst($holder->getName()) . 'DAO';
        $containerType = $holder->getRelation()->toString() . 'Linked';
        $uses = ['Hesper\\Main\\UnifiedContainer\\' . $containerType, MetaClassNameBuilder::getClassOfMetaClass($class), MetaClassNameBuilder::getClassOfMetaProperty($holder)];
        foreach ($uses as $import) {
            $out .= <<<EOT
use {$import};

EOT;
        }
        $out .= <<<EOT


EOT;
        $out .= 'final class ' . $containerName . ' extends ' . $containerType . "\n{\n";
        $className = $class->getName();
        $propertyName = strtolower($className[0]) . substr($className, 1);
        $remoteColumnName = $holder->getType()->getClass()->getTableName();
        $out .= <<<EOT
public function __construct({$className} \${$propertyName}, \$lazy = false)
{
\tparent::__construct(
\t\t\${$propertyName},
\t\t{$holder->getType()->getClassName()}::dao(),
\t\t\$lazy
\t);
}

/**
 * @return {$containerName}
**/
public static function create({$className} \${$propertyName}, \$lazy = false)
{
\treturn new self(\${$propertyName}, \$lazy);
}

EOT;
        if ($holder->getRelation()->getId() == MetaRelation::MANY_TO_MANY) {
            $out .= <<<EOT

public function getHelperTable()
{
\treturn '{$class->getTableName()}_{$remoteColumnName}';
}

public function getChildIdField()
{
\treturn '{$remoteColumnName}_id';
}

EOT;
        }
        $out .= <<<EOT

public function getParentIdField()
{
\treturn '{$class->getTableName()}_id';
}

EOT;
        $out .= "}\n";
        $out .= self::getHeel();
        return $out;
    }