<commit_before><?php

require_once 'propel/engine/builder/om/php5/PHP5ComplexObjectBuilder.php';

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * @package    symfony
 * @subpackage addon
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class SfObjectBuilder extends PHP5ComplexObjectBuilder
{
  public function build()
  {
    if (!DataModelBuilder::getBuildProperty('builderAddComments'))
    {
      return sfToolkit::stripComments(parent::build());
    }
    
    return parent::build();
  }

  protected function addIncludes(&$script)
  {
    if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
    {
      return;
    }

    parent::addIncludes($script);

    // include the i18n classes if needed
    if ($this->getTable()->getAttribute('isI18N'))
    {
      $relatedTable   = $this->getDatabase()->getTable($this->getTable()->getAttribute('i18nTable'));

      $script .= '
require_once \''.$this->getFilePath($this->getStubObjectBuilder()->getPackage().'.'.$relatedTable->getPhpName().'Peer').'\';
require_once \''.$this->getFilePath($this->getStubObjectBuilder()->getPackage().'.'.$relatedTable->getPhpName()).'\';
';
    }
  }

  protected function addClassBody(&$script)
  {
    parent::addClassBody($script);

    if ($this->getTable()->getAttribute('isI18N'))
    {
      if (count($this->getTable()->getPrimaryKey()) > 1)
      {
        throw new Exception('i18n support only works with a single primary key');
      }

      $this->addCultureAccessorMethod($script);
      $this->addCultureMutatorMethod($script);

      $this->addI18nMethods($script);
    }

    if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
    {
      $this->addCall($script);
    }
  }

  protected function addCall(&$script)
  {
    $script .= "

  public function __call(\$method, \$parameters)
  {
    if (!\$callable = sfMixer::getCallable('{$this->getClassname()}:'.\$method))
    {
      throw new sfException(sprintf('Call to undefined method {$this->getClassname()}::%s', \$method));
    }

    array_unshift(\$arguments, \$this);

    return call_user_func_array(\$callable, \$arguments);
  }

";
  }
  
  protected function addConstants(&$script)
  {
    parent::addConstants($script);
    $script .= "
	/** the default database name for this class */
	const DATABASE_NAME = '{$this->getDatabase()->getName()}';
";
  }

  protected function addAttributes(&$script)
  {
    parent::addAttributes($script);

    if ($this->getTable()->getAttribute('isI18N'))
    {<commit_msg>fixed typo in propel builder that prevented complete usage of behaviors<commit_after><?php

require_once 'propel/engine/builder/om/php5/PHP5ComplexObjectBuilder.php';

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * @package    symfony
 * @subpackage addon
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class SfObjectBuilder extends PHP5ComplexObjectBuilder
{
  public function build()
  {
    if (!DataModelBuilder::getBuildProperty('builderAddComments'))
    {
      return sfToolkit::stripComments(parent::build());
    }
    
    return parent::build();
  }

  protected function addIncludes(&$script)
  {
    if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
    {
      return;
    }

    parent::addIncludes($script);

    // include the i18n classes if needed
    if ($this->getTable()->getAttribute('isI18N'))
    {
      $relatedTable   = $this->getDatabase()->getTable($this->getTable()->getAttribute('i18nTable'));

      $script .= '
require_once \''.$this->getFilePath($this->getStubObjectBuilder()->getPackage().'.'.$relatedTable->getPhpName().'Peer').'\';
require_once \''.$this->getFilePath($this->getStubObjectBuilder()->getPackage().'.'.$relatedTable->getPhpName()).'\';
';
    }
  }

  protected function addClassBody(&$script)
  {
    parent::addClassBody($script);

    if ($this->getTable()->getAttribute('isI18N'))
    {
      if (count($this->getTable()->getPrimaryKey()) > 1)
      {
        throw new Exception('i18n support only works with a single primary key');
      }

      $this->addCultureAccessorMethod($script);
      $this->addCultureMutatorMethod($script);

      $this->addI18nMethods($script);
    }

    if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
    {
      $this->addCall($script);
    }
  }

  protected function addCall(&$script)
  {
    $script .= "

  public function __call(\$method, \$arguments)
  {
    if (!\$callable = sfMixer::getCallable('{$this->getClassname()}:'.\$method))
    {
      throw new sfException(sprintf('Call to undefined method {$this->getClassname()}::%s', \$method));
    }

    array_unshift(\$arguments, \$this);

    return call_user_func_array(\$callable, \$arguments);
  }

";
  }
  
  protected function addConstants(&$script)
  {
    parent::addConstants($script);
    $script .= "
	/** the default database name for this class */
	const DATABASE_NAME = '{$this->getDatabase()->getName()}';
";
  }

  protected function addAttributes(&$script)
  {
    parent::addAttributes($script);

    if ($this->getTable()->getAttribute('isI18N'))
    {
{'fraction_non_alphanumeric': 0.16823117982698324, 'fraction_numerical': 0.009571139333701455, 'mean_word_length': 3.704761904761905, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '403813', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1652, 'n_words': 310}