/**
  * @param PropelPHPParser $parser
  */
 protected function replaceDoDeleteAll($parser)
 {
     $peerClassName = $this->builder->getStubPeerBuilder()->getClassname();
     $search = "\$con->commit();";
     $replace = "\$con->commit();\n            {$peerClassName}::purgeCache();";
     $script = $parser->findMethod('doDeleteAll');
     $script = str_replace($search, $replace, $script);
     $parser->replaceMethod("doDeleteAll", $script);
 }
 /**
  * @param PropelPHPParser $parser
  */
 protected function replaceFindPk(PropelPHPParser $parser)
 {
     $search = "return \$this->findPkSimple(\$key, \$con);";
     $replace = "return \$this->filterByPrimaryKey(\$key)->findOne(\$con);";
     $script = $parser->findMethod('findPk');
     $script = str_replace($search, $replace, $script);
     $parser->replaceMethod('findPk', $script);
 }
예제 #3
0
    /**
     * @dataProvider basicClassCodeProvider
     */
    public function testFindMethodWithWrongCurlyBraces($code)
    {
        $parser = new PropelPHPParser($code);
        $expected = <<<EOF


    public function bar4()
    {
        // this is bar4 with a curly brace }
        echo '}';
    }
EOF;
        $this->assertEquals($expected, $parser->findMethod('bar4'));
    }
 public function objectFilter(&$script)
 {
     $script = preg_replace('#(implements Persistent)#', '$1, EventDispatcherAwareModelInterface', $script);
     // rename the dummy_construct to __construct if __construct does not exists
     if (strpos($script, 'function __construct') === false) {
         $script = str_replace('function dummy_construct', 'function __construct', $script);
     }
     $parser = new PropelPHPParser($script, true);
     $parser->removeMethod('dummy_construct');
     $oldCode = $parser->findMethod('__construct');
     $newCode = substr_replace($oldCode, $this->addConstructHook() . '}', strrpos($oldCode, '}'));
     $parser->replaceMethod('__construct', $newCode);
     $script = $parser->getCode();
 }