コード例 #1
0
    public function objectFilter(&$script)
    {
        $parser = new PhpParser($script, true);
        $doUpdateMethod = $parser->findMethod('doUpdate');
        $versionPhpName = $this->getVersionColumn()->getPhpName();
        $newCode = <<<EOF
if (\$this->optimisticLockEnabled) {
    \$selectCriteria->filterBy{$versionPhpName}(\$this->locked{$versionPhpName});
}
EOF;
        $doUpdateMethod = str_replace(' return ', " {$newCode}\n       return ", $doUpdateMethod);
        $parser->replaceMethod('doUpdate', $doUpdateMethod);
        $script = $parser->getCode();
    }
コード例 #2
0
ファイル: PhpParserTest.php プロジェクト: rouffj/Propel2
    /**
     * @dataProvider basicClassCodeProvider
     */
    public function testReplaceMethodReplacesMethod($code)
    {
        $parser = new PhpParser($code);
        $newCode = <<<EOF


    public function bar1prime()
    {
        // yep, I've been replaced
        echo 'bar';
    }
EOF;
        $parser->replaceMethod('bar1', $newCode);
        $expected = <<<EOF
<?php
class Foo {

    public function bar1prime()
    {
        // yep, I've been replaced
        echo 'bar';
    }

    protected \$bar2;

    public function bar2()
    {
        // this is bar2
    }

    /**
     * This is the bar3 method
     */
    public function bar3()
    {
        // this is bar3
    }

    public function bar4()
    {
        // this is bar4 with a curly brace }
        echo '}';
    }
}
EOF;
        $this->assertEquals($expected, $parser->getCode());
    }
コード例 #3
0
 public function objectFilter(&$script)
 {
     $p = new PhpParser($script, true);
     $text = $p->findMethod('toArray');
     $matches = [];
     preg_match('/(\\$result = array\\(([^;]+)\\);)/U', $text, $matches);
     $values = rtrim($matches[2]) . "\n";
     $new_result = '';
     $indent = '        ';
     foreach ($this->delegates as $key => $value) {
         $delegateTable = $this->getDelegateTable($key);
         $tn = ($delegateTable->getSchema() ? $delegateTable->getSchema() . NameGeneratorInterface::STD_SEPARATOR_CHAR : '') . $delegateTable->getCommonName();
         $ns = $delegateTable->getNamespace() ? '\\' . $delegateTable->getNamespace() : '';
         $new_result .= "{$indent}\$keys_{$tn} = {$ns}\\Map\\{$delegateTable->getPhpName()}TableMap::getFieldNames(\$keyType);\n";
         $i = 0;
         foreach ($delegateTable->getColumns() as $column) {
             if (!$this->isColumnForeignKeyOrDuplicated($column)) {
                 $values .= "{$indent}    \$keys_{$tn}[{$i}] => \$this->get{$column->getPhpName()}(),\n";
             }
             $i++;
         }
     }
     $new_result .= "{$indent}\$result = array({$values}\n{$indent});";
     $text = str_replace($matches[1], ltrim($new_result), $text);
     $p->replaceMethod('toArray', $text);
     $script = $p->getCode();
 }