<commit_before><?php

class sfDoctrineRestGenerateModuleTask extends sfBaseTask
{
  /**
   * @see sfTask
   */
  protected function configure()
  {
    $this->addArguments(array(
      new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
      new sfCommandArgument('module', sfCommandArgument::REQUIRED, 'The module name'),
      new sfCommandArgument('model', sfCommandArgument::REQUIRED, 'The model class'),
    ));

    $this->namespace = 'doctrine';
    $this->name = 'generate-rest-module';
    $this->briefDescription = 'Generates a REST module';

    $this->detailedDescription = <<<EOF
The [doctrine:generate-rest-module|INFO] task generates a Doctrine module:

  [./symfony doctrine:generate-rest-module frontend article Article|INFO]

The task creates [%article%|COMMENT] module in the [%frontend%|COMMENT]
application for the [%Article%|COMMENT] model.

The task creates routes for you in the application [routing.yml|COMMENT].
EOF;
  }

  /**
   * @see sfTask
   */
  protected function execute($arguments = array(), $options = array())
  {
    $r = new ReflectionClass($arguments['model']);

    if (!$r->isSubclassOf('Doctrine_Record'))
    {
      throw new sfCommandException(sprintf('"%s" is not a Doctrine class.', $arguments['model']));
    }

    // create a route
    $model = $arguments['model'];
    $module = $arguments['module'];
    $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model));

    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml';
    $content = file_get_contents($routing);
    $routesArray = sfYaml::load($content);

    if (!isset($routesArray[$name]))
    {
      $databaseManager = new sfDatabaseManager($this->configuration);
      $primaryKey = Doctrine_Core::getTable($model)->getIdentifier();
      $content = sprintf(<<<EOF
%s:
  class:   sfObjectRouteCollection
  options:
    model:   %s
    actions: [ create, list, delete ]
    module:  %s
    column:  id
    format:  xml


EOF
      , $name, $model, $module).$content;

      $this->logSection('file+', $routing);
      file_put_contents($routing, $content);
    }

    return $this->generate($module, $model);
  }

  protected function generate($module, $model)
  {
    $moduleDir = sfConfig::get('sf_app_module_dir').'/'.$module;

    // create basic application structure
    $finder = sfFinder::type('any')->discard('.sf');
    $dirs = $this->configuration->getGeneratorSkeletonDirs('sfDoctrineRestGenerator', $options['theme']);

    foreach ($dirs as $dir)
    {
      if (is_dir($dir))
      {
        $this->getFilesystem()->mirror($dir, $moduleDir, $finder);
        break;
      }
    }
<commit_msg>[sfDoctrineRestGeneratorPlugin]: Fixed module's routecollection generation when model's name as a Capital letter inside it.<commit_after><?php

class sfDoctrineRestGenerateModuleTask extends sfBaseTask
{
  /**
   * @see sfTask
   */
  protected function configure()
  {
    $this->addArguments(array(
      new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
      new sfCommandArgument('module', sfCommandArgument::REQUIRED, 'The module name'),
      new sfCommandArgument('model', sfCommandArgument::REQUIRED, 'The model class'),
    ));

    $this->namespace = 'doctrine';
    $this->name = 'generate-rest-module';
    $this->briefDescription = 'Generates a REST module';

    $this->detailedDescription = <<<EOF
The [doctrine:generate-rest-module|INFO] task generates a Doctrine module:

  [./symfony doctrine:generate-rest-module frontend article Article|INFO]

The task creates [%article%|COMMENT] module in the [%frontend%|COMMENT]
application for the [%Article%|COMMENT] model.

The task creates routes for you in the application [routing.yml|COMMENT].
EOF;
  }

  /**
   * @see sfTask
   */
  protected function execute($arguments = array(), $options = array())
  {
    $r = new ReflectionClass($arguments['model']);

    if (!$r->isSubclassOf('Doctrine_Record'))
    {
      throw new sfCommandException(sprintf('"%s" is not a Doctrine class.', $arguments['model']));
    }

    // create a route
    $model = $arguments['model'];
    $module = $arguments['module'];

    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml';
    $content = file_get_contents($routing);
    $routesArray = sfYaml::load($content);

    if (!isset($routesArray[$name]))
    {
      $databaseManager = new sfDatabaseManager($this->configuration);
      $primaryKey = Doctrine_Core::getTable($model)->getIdentifier();
      $content = sprintf(<<<EOF
%s:
  class:   sfObjectRouteCollection
  options:
    model:   %s
    actions: [ create, list, delete ]
    module:  %s
    column:  id
    format:  xml


EOF
      , $model, $model, $module).$content;

      $this->logSection('file+', $routing);
      file_put_contents($routing, $content);
    }

    return $this->generate($module, $model);
  }

  protected function generate($module, $model)
  {
    $moduleDir = sfConfig::get('sf_app_module_dir').'/'.$module;

    // create basic application structure
    $finder = sfFinder::type('any')->discard('.sf');
    $dirs = $this->configuration->getGeneratorSkeletonDirs('sfDoctrineRestGenerator', $options['theme']);

    foreach ($dirs as $dir)
    {
      if (is_dir($dir))
      {
        $this->getFilesystem()->mirror($dir, $moduleDir, $finder);
        break;
      }
    }

{'fraction_non_alphanumeric': 0.1593962819804896, 'fraction_numerical': 0.0003681207436039021, 'mean_word_length': 3.8216503992901507, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4886788', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1663, 'n_words': 362}