/**
  * {@inheritdoc}
  */
 public function objectFilter(&$script)
 {
     $columName = ucfirst($this->camelize($this->behavior->getParameter('column_name')));
     $parser = new PropelPHPParser($script, true);
     $parser->replaceMethod('get' . $columName, $this->behavior->renderTemplate('objectGetHstore', $this->getTemplateData()));
     $parser->replaceMethod('set' . $columName, $this->behavior->renderTemplate('objectSetHstore', $this->getTemplateData()));
     $script = $parser->getCode();
 }
 /**
  * @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);
 }
コード例 #3
0
    /**
     * The object builder adds a first __toString() method,
     * and this behavior adds a second one in objectMethods(),
     * so the first one must be removed.
     */
    public function objectFilter(&$script)
    {
        if (!$this->hasPrimaryString($this->getTable()) && $this->hasPrimaryString($this->getI18nTable())) {
            $foreignKey = $this->getI18nTable()->getBehavior('symfony_i18n_translation')->getForeignKey();
            $refPhpName = $foreignKey->getRefPhpName() ? $foreignKey->getRefPhpName() : $this->getI18nTable()->getPhpName();
            $toString .= <<<EOF


\t/**
\t * Uses the primaryString column from the related i18n model
\t * @see {$this->getI18nTable()->getPhpName()}
\t */
\tpublic function __toString()
\t{
  \treturn (string) \$this->getCurrent{$refPhpName}();
\t}

EOF;
            $parser = new PropelPHPParser($script, true);
            $parser->replaceMethod('__toString', $toString);
            $script = $parser->getCode();
        }
        $table = $this->getTable();
        $i18nTable = $this->getI18nTable();
        $tablePhpName = $this->getTable()->getPhpName();
        $i18nTablePhpName = $this->getI18nTable()->getPhpName();
        $pattern = '/foreach \\(\\$this->coll' . $i18nTablePhpName . 's as \\$referrerFK\\) \\{/';
        $addition = "\n          \$referrerFK->set" . $tablePhpName . "(\$this);";
        $replacement = "\$0{$addition}";
        $script = preg_replace($pattern, $replacement, $script);
    }
コード例 #4
0
    /**
     * @dataProvider basicClassCodeProvider
     */
    public function testReplaceMethodReplacesMethod($code)
    {
        $parser = new PropelPHPParser($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());
    }
コード例 #5
0
    /**
     * @dataProvider basicClassCodeProvider
     */
    public function testReplaceMethodReplacesMethod($code)
    {
        $parser = new PropelPHPParser($code);
        $newCode = <<<EOF


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

\tpublic function bar1prime()
\t{
\t\t// yep, I've been replaced
\t\techo 'bar';
\t}
\t
\tprotected \$bar2;
\t
\tpublic function bar2()
\t{
\t\t// this is bar2
\t}

\t/**
\t * This is the bar3 method
\t */
\tpublic function bar3()
\t{
\t\t// this is bar3
\t}

\tpublic function bar4()
\t{
\t\t// this is bar4 with a curly brace }
\t\techo '}';
\t}
}
EOF;
        $this->assertEquals($expected, $parser->getCode());
    }
コード例 #6
0
    public function objectFilter(&$script, $builder)
    {
        $behaviors = $this->getTable()->getBehaviors();
        if (isset($behaviors['i18n'])) {
            $table = $this->getTable();
            $tablePhpName = $this->getTable()->getPhpName();
            $i18nTable = $behaviors['i18n']->getI18nTable();
            $i18nTablePhpName = $behaviors['i18n']->getI18nTable()->getPhpName();
            $pattern = '/foreach \\(\\$this->coll' . $i18nTablePhpName . 's as \\$referrerFK\\) \\{/';
            $addition = "\r\n        \$referrerFK->set" . $tablePhpName . "(\$this);";
            $replacement = "\$0{$addition}";
            $script = preg_replace($pattern, $replacement, $script);
            $pattern = '/protected \\$currentLocale = \'.*\';/';
            $replacement = 'protected \\$currentLocale = null;';
            $script = preg_replace($pattern, $replacement, $script);
            $pattern = '/\\(\\$locale = \'.*\'/';
            $replacement = '(\\$locale';
            $script = preg_replace($pattern, $replacement, $script);
            $getLocale .= <<<EOF
                
            
/**
 * Gets the locale for translations
 *
 * @return    string {$locale} Locale to use for the translation, e.g. 'fr_FR'
 */
public function getLocale()
{
  if(null == \$this->currentLocale)
  {
    return sfPropel::getDefaultCulture();
  }
  else
  {
    return \$this->currentLocale;
  }
}
EOF;
            $parser = new PropelPHPParser($script, true);
            $parser->replaceMethod('getLocale', $getLocale);
            $script = $parser->getCode();
            $setLocale .= <<<EOF
   
   
/**
 * Sets the locale for translations
 *
 * @param     string \$locale Locale to use for the translation, e.g. 'fr_FR'
 *
 * @return    {$tablePhpName} The current object (for fluent API support)
 */
public function setLocale(\$locale)
{
  if(null == \$this->currentLocale)
  {
    \$this->currentLocale =  sfPropel::getDefaultCulture();
  }
  else
  {
    \$this->currentLocale = \$locale;
  }
  return \$this;
}
EOF;
            $parser = new PropelPHPParser($script, true);
            $parser->replaceMethod('setLocale', $setLocale);
            //$script = $parser->getCode();
        }
    }
コード例 #7
0
 public function queryFilter(&$script, $builder)
 {
     $useI18nQueryMethod = $this->getUseI18nQueryMethod($builder);
     $parser = new \PropelPHPParser($script, true);
     $parser->replaceMethod('useI18nQuery', $useI18nQueryMethod);
     $script = $parser->getCode();
 }
 /**
  * @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);
 }
 /**
  * {@inheritdoc}
  */
 public function queryFilter(&$script)
 {
     $parser = new PropelPHPParser($script, true);
     $parser->replaceMethod($this->getCamelizedColumnName(), $this->addQueryFilterByHstore());
     $script = $parser->getCode();
 }
 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();
 }