Пример #1
0
    public function testSomething()
    {
        $class = new PhpClass('Spanner', 'Fish', false);
        $class->addUses('Goat', ['Monkey', 'Bananna']);
        $class->addExtends('Wibble');
        $class->addImplements('FunTime');
        $class->classComponents[] = new FunctionDeclaration('hello', 'public function hello(){ return "hello"; }');
        $class->classComponents[] = new FunctionDeclaration('goodbye', 'public function goodbye(){ return "goodbye"; }');
        $class->classComponents[] = new FunctionDeclaration('__construct', 'public function __construct(){}');
        $class->classComponents[] = new FunctionDeclaration('multiLineDeclaration', <<<'PHP'
/**
 * Some multiline comment
 */
public function multiLineDeclaration ()
{
    return array(
        'monkey' => 'goat',
    );
}
PHP
);
        $class->classComponents[] = new VariableDeclaration('size', 'public $size = "big";');
        $class->classComponents[] = new VariableDeclaration('age', 'public $age;');
        $class->classComponents[] = new ClassConstant('t-rex', 'const T_REX = 100;');
        $php = $class->render();
        $php = new Php($class->render());
        $isValid = $php->isValid($error);
        //        echo $class->render()->addLineNumbers();
    }
Пример #2
0
    /**
     * Produce the static entity function data
     * @return array $lines
     */
    private function getSqlInterfaceFunction()
    {
        if (count($this->keyProperties) !== 1) {
            $content = "    throw new \\LogicException('Normality can\\'t (yet) handle tables without a primary key or multi-column primary keys.\\n" . "Please extend the generator or overload {$this->pgClass->getEntityName()}->parse().');";
        } else {
            $primaryKey = $this->keyProperties[0];
            $dataType = $this->dataTypes[$primaryKey];
            // if datatype inheritied we don't need to do anything
            if ($dataType->isInherited()) {
                return array();
            }
            // we're doing something
            $content = '';
            $this->class->addImplements("SqlInterface");
            $this->class->addUses('Bond\\Sql\\QuoteInterface');
            $this->class->addUses('Bond\\Sql\\SqlInterface');
            if ($dataType->getType() === 'int') {
                // can this property be a entity?
                if ($dataType->isEntity()) {
                    $content .= <<<PHP
    if( is_object( \$this->data['{$primaryKey}'] ) and \$this->data['{$primaryKey}'] instanceof SqlInterface ) {
        return \$this->data['{$primaryKey}']->parse( \$quoting );
    }

PHP;
                }
                // cast integer datatype to int if not null
                $content .= <<<PHP
    return \$this->data['{$primaryKey}'] !== null ? (string) (int) \$this->data['{$primaryKey}'] : 'NULL';
PHP;
            } else {
                $content .= <<<PHP
    return \$quoting->quote( \$this->data['{$primaryKey}'] );
PHP;
            }
        }
        $fn = new Sformatf(<<<'PHP'
/**
 * Impementation of interface \Bond\Pg\Query->Validate()
 * @return scalar
 */
public function parse( QuoteInterface $quoting )
{
%s
}

PHP
, $content);
        $this->class->classComponents[] = new FunctionDeclaration("parse", $fn);
    }