/**
  * Executes this configuration handler.
  *
  * @param array $configFiles An array of absolute filesystem path to a configuration file
  *
  * @return string Data to be written to a cache file
  *
  * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  * @throws sfParseException If a requested configuration file is improperly formatted
  */
 public function execute($configFiles)
 {
     // parse the yaml
     $config = self::getConfiguration($configFiles);
     // init our data
     $data = '';
     // let's do our fancy work
     foreach ($config as $file) {
         if (!is_readable($file)) {
             // file doesn't exist
             throw new sfParseException(sprintf('Configuration file "%s" specifies nonexistent or unreadable file "%s".', $configFiles[0], $file));
         }
         $contents = file_get_contents($file);
         // strip comments (not in debug mode)
         if (!sfConfig::get('sf_debug')) {
             $contents = sfToolkit::stripComments($contents);
         }
         // strip php tags
         $contents = sfToolkit::pregtr($contents, array('/^\\s*<\\?(php\\s*)?/m' => '', '/^\\s*\\?>/m' => ''));
         // replace windows and mac format with unix format
         $contents = str_replace("\r", "\n", $contents);
         // replace multiple new lines with a single newline
         $contents = preg_replace(array('/\\s+$/Sm', '/\\n+/S'), "\n", $contents);
         // append file data
         $data .= "\n" . $contents;
     }
     // compile data
     return sprintf("<?php\n" . "// auto-generated by sfCompileConfigHandler\n" . "// date: %s\n" . "%s\n", date('Y/m/d H:i:s'), $data);
 }
 /**
  * Executes this configuration handler.
  *
  * @param array $configFiles An array of absolute filesystem path to a configuration file
  *
  * @return string Data to be written to a cache file
  *
  * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  * @throws sfParseException If a requested configuration file is improperly formatted
  */
 public function execute($configFiles)
 {
     // parse the yaml
     $config = self::getConfiguration($configFiles);
     // init our data
     $data = '';
     // let's do our fancy work
     foreach ($config as $file) {
         if (!is_readable($file)) {
             // file doesn't exist
             throw new sfParseException(sprintf('Configuration file "%s" specifies nonexistent or unreadable file "%s".', $configFiles[0], $file));
         }
         $contents = file_get_contents($file);
         // strip comments (not in debug mode)
         if (!sfConfig::get('sf_debug')) {
             $contents = sfToolkit::stripComments($contents);
         }
         // insert configuration files
         /*      $contents = preg_replace_callback(array('#(require|include)(_once)?\((sfContext::getInstance\(\)\->getConfigCache\(\)|\$configCache)->checkConfig\(\'config/([^\']+)\'\)\);#m',
                                                   '#()()(sfContext::getInstance\(\)\->getConfigCache\(\)|\$configCache)->import\(\'config/([^\']+)\'(, false)?\);#m'),
                                                 array($this, 'insertConfigFileCallback'), $contents);
         */
         // strip php tags
         $contents = sfToolkit::pregtr($contents, array('/^\\s*<\\?(php)?/m' => '', '/^\\s*\\?>/m' => ''));
         // replace windows and mac format with unix format
         $contents = str_replace("\r", "\n", $contents);
         // replace multiple new lines with a single newline
         $contents = preg_replace(array('/\\s+$/Sm', '/\\n+/S'), "\n", $contents);
         // append file data
         $data .= "\n" . $contents;
     }
     // compile data
     $retval = sprintf("<?php\n" . "// auto-generated by sfCompileConfigHandler\n" . "// date: %s\n%s\n", date('Y/m/d H:i:s'), $data);
     return $retval;
 }
Example #3
0
 public function build()
 {
     if (!DataModelBuilder::getBuildProperty('builderAddComments')) {
         return sfToolkit::stripComments(parent::build());
     }
     return parent::build();
 }
  protected function addClassBody(&$script)
  {
    parent::addClassBody($script);

    // remove comments and fix coding standards
    $script = str_replace(array("\t", "{\n  \n"), array('  ', "{\n"), sfToolkit::stripComments($script));
  }
 public function build()
 {
     $objectCode = parent::build();
     if (!$this->getBuildProperty('builderAddComments')) {
         $objectCode = sfToolkit::stripComments($objectCode);
     }
     return $objectCode;
 }
 public function build()
 {
     $code = parent::build();
     if (!DataModelBuilder::getBuildProperty('builderAddComments')) {
         $code = sfToolkit::stripComments($code);
     }
     return $code;
 }
Example #7
0
 public function build()
 {
     $peerCode = parent::build();
     if (!$this->getBuildProperty('builderAddComments')) {
         $peerCode = sfToolkit::stripComments($peerCode);
     }
     // change Propel::import() calls to sfPropel::import()
     $peerCode = str_replace('Propel::import(', 'sfPropel::import(', $peerCode);
     return $peerCode;
 }
Example #8
0
 public function build()
 {
     $objectCode = parent::build();
     if (!DataModelBuilder::getBuildProperty('builderAddComments')) {
         $objectCode = sfToolkit::stripComments($objectCode);
     }
     if (!DataModelBuilder::getBuildProperty('builderAddIncludes')) {
         // remove all inline includes: object classes include the peers
         $objectCode = preg_replace("/include_once\\s*.*Base.*Peer\\.php.*\\s*/", "", $objectCode);
     }
     return $objectCode;
 }
Example #9
0
 public function build()
 {
     $peerCode = parent::build();
     if (!DataModelBuilder::getBuildProperty('builderAddComments')) {
         $peerCode = sfToolkit::stripComments($peerCode);
     }
     if (!DataModelBuilder::getBuildProperty('builderAddIncludes')) {
         //remove all inline includes: peer class include inline the mapbuilder classes
         $peerCode = preg_replace("/(include|require)_once\\s*.*MapBuilder\\.php.*\\s*/", "", $peerCode);
     }
     return $peerCode;
 }
 public function validate()
 {
     $found = array();
     $files = sfFinder::type('file')->name('*.php')->prune('vendor')->in(array(sfConfig::get('sf_apps_dir'), sfConfig::get('sf_lib_dir'), sfConfig::get('sf_test_dir'), sfConfig::get('sf_plugins_dir')));
     foreach ($files as $file) {
         $content = sfToolkit::stripComments(file_get_contents($file));
         if (preg_match('#\\b(get|has|remove)(Request)*Parameter\\(\\s*[\'"][^\\),]*?\\[[^\\),]#', $content)) {
             $found[$file] = true;
         }
     }
     return $found;
 }
Example #11
0
 public function build()
 {
     $peerCode = parent::build();
     if (!DataModelBuilder::getBuildProperty('builderAddComments')) {
         $peerCode = sfToolkit::stripComments($peerCode);
     }
     if (!DataModelBuilder::getBuildProperty('builderAddIncludes')) {
         // remove all inline includes: peer class include inline the mapbuilder classes
         $peerCode = preg_replace("/(include|require)_once\\s*.*Base.*Peer\\.php.*\\s*/", "", $peerCode);
         $peerCode = preg_replace("/(include|require)_once\\s*.*MapBuilder\\.php.*\\s*/", "", $peerCode);
     }
     // change Propel::import() calls to sfPropel::import()
     $peerCode = str_replace('Propel::import(', 'sfPropel::import(', $peerCode);
     return $peerCode;
 }
 public function doValidate($methods, $dir)
 {
     $found = array();
     $files = sfFinder::type('file')->name('*.php')->prune('vendor')->in($dir);
     foreach ($files as $file) {
         $content = sfToolkit::stripComments(file_get_contents($file));
         $matches = array();
         foreach ($methods as $method) {
             if (preg_match('#\\b' . preg_quote($method, '#') . '\\b#', $content)) {
                 $matches[] = $method;
             }
         }
         if ($matches) {
             $found[$file] = implode(', ', $matches);
         }
     }
     return $found;
 }
 public function validate()
 {
     $settings = array('sf_check_symfony_version', 'sf_max_forwards', 'sf_lazy_cache_key', 'sf_strip_comments', 'sf_lazy_routes_deserialize', 'sf_calendar_web_dir', 'sf_rich_text_js_dir', 'sf_validation_error_prefix', 'sf_validation_error_suffix', 'sf_validation_error_class', 'sf_validation_error_id_prefix', '_is_internal', 'sf_doc_dir');
     $found = array();
     $files = sfFinder::type('file')->name('*.php')->prune('vendor')->in(array(sfConfig::get('sf_apps_dir'), sfConfig::get('sf_lib_dir'), sfConfig::get('sf_test_dir'), sfConfig::get('sf_plugins_dir')));
     foreach ($files as $file) {
         $content = sfToolkit::stripComments(file_get_contents($file));
         $matches = array();
         foreach ($settings as $setting) {
             if (false !== stripos($content, $setting)) {
                 $matches[] = $setting;
             }
         }
         if ($matches) {
             $found[$file] = implode(', ', $matches);
         }
     }
     return $found;
 }
 public function validate()
 {
     $helpers = array('select_day_tag', 'select_month_tag', 'select_year_tag', 'select_date_tag', 'select_second_tag', 'select_minute_tag', 'select_hour_tag', 'select_ampm_tag', 'select_time_tag', 'select_datetime_tag', 'select_number_tag', 'select_timezone_tag', 'options_for_select', 'select_tag', 'select_country_tag', 'select_language_tag', 'select_currency_tag', 'input_tag', 'input_hidden_tag', 'input_file_tag', 'input_password_tag', 'textarea_tag', 'checkbox_tag', 'radiobutton_tag', 'input_date_range_tag', 'input_date_tag', 'submit_tag', 'reset_tag', 'submit_image_tag', 'label_for', 'object_admin_input_file_tag', 'object_admin_double_list', 'object_admin_select_list', 'object_admin_check_list', 'object_input_date_tag', 'object_textarea_tag', 'objects_for_select', 'object_select_tag', 'object_select_country_tag', 'object_select_language_tag', 'object_input_hidden_tag', 'object_input_tag', 'object_checkbox_tag', 'form_has_error', 'form_error', 'get_callbacks', 'get_ajax_options', 'button_to_remote', 'link_to_remote', 'periodically_call_remote', 'form_remote_tag', 'submit_to_remote', 'submit_image_to_remote', 'update_element_function', 'evaluate_remote_response', 'remote_function', 'observe_field', 'observe_form', 'visual_effect', 'sortable_element', 'draggable_element', 'drop_receiving_element', 'input_auto_complete_tag', 'input_in_place_editor_tag');
     $found = array();
     $files = sfFinder::type('file')->name('*.php')->prune('vendor')->in(array(sfConfig::get('sf_apps_dir'), sfConfig::get('sf_lib_dir'), sfConfig::get('sf_test_dir'), sfConfig::get('sf_plugins_dir')));
     foreach ($files as $file) {
         $content = sfToolkit::stripComments(file_get_contents($file));
         $matches = array();
         foreach ($helpers as $helper) {
             if (preg_match('#\\b' . preg_quote($helper, '#') . '\\b#', $content)) {
                 $matches[] = $helper;
             }
         }
         if ($matches) {
             $found[$file] = implode(', ', $matches);
         }
     }
     return $found;
 }
 public function validate()
 {
     $classes = array('sfDoctrineLogger', 'sfNoRouting', 'sfPathInfoRouting', 'sfRichTextEditor', 'sfRichTextEditorFCK', 'sfRichTextEditorTinyMCE', 'sfCrudGenerator', 'sfAdminGenerator', 'sfPropelCrudGenerator', 'sfPropelAdminGenerator', 'sfPropelUniqueValidator', 'sfDoctrineUniqueValidator', 'sfLoader', 'sfConsoleRequest', 'sfConsoleResponse', 'sfConsoleController', 'sfDoctrineDataRetriever', 'sfPropelDataRetriever', 'sfWidgetFormI18nSelectLanguage', 'sfWidgetFormI18nSelectCurrency', 'sfWidgetFormI18nSelectCountry', 'sfWidgetFormChoiceMany', 'sfWidgetFormPropelChoiceMany', 'sfWidgetFormDoctrineChoiceMany', 'sfValidatorChoiceMany', 'sfValidatorPropelChoiceMany', 'sfValidatorPropelDoctrineMany', 'SfExtensionObjectBuilder', 'SfExtensionPeerBuilder', 'SfMultiExtendObjectBuilder', 'SfNestedSetBuilder', 'SfNestedSetPeerBuilder', 'SfObjectBuilder', 'SfPeerBuilder', 'sfWidgetFormPropelSelect', 'sfWidgetFormPropelSelectMany', 'sfWidgetFormDoctrineSelect', 'sfWidgetFormDoctrineSelectMany', 'sfEzComponentsBridge', 'sfZendFrameworkBridge', 'sfProcessCache', 'sfValidatorConfigHandler', 'sfActionException', 'sfValidatorException', 'sfFillInFormFilter', 'sfValidationExecutionFilter', 'sfRequestCompat10', 'sfFillInForm', 'sfCallbackValidator', 'sfCompareValidator', 'sfDateValidator', 'sfEmailValidator', 'sfFileValidator', 'sfNumberValidator', 'sfRegexValidator', 'sfStringValidator', 'sfUrlValidator', 'sfValidator', 'sfValidatorManager', 'sfMailView', 'sfMail');
     $found = array();
     $files = sfFinder::type('file')->name('*.php')->prune('vendor')->in(array(sfConfig::get('sf_apps_dir'), sfConfig::get('sf_lib_dir'), sfConfig::get('sf_test_dir'), sfConfig::get('sf_plugins_dir')));
     foreach ($files as $file) {
         $content = sfToolkit::stripComments(file_get_contents($file));
         $matches = array();
         foreach ($classes as $class) {
             if (preg_match('#\\b' . preg_quote($class, '#') . '\\b#', $content)) {
                 $matches[] = $class;
             }
         }
         if ($matches) {
             $found[$file] = implode(', ', $matches);
         }
     }
     return $found;
 }
 public function validate()
 {
     $found = array();
     $files = sfFinder::type('file')->name('*Configuration.class.php')->in($this->getProjectConfigDirectories());
     foreach ($files as $file) {
         $content = sfToolkit::stripComments(file_get_contents($file));
         $matches = array();
         if (false !== strpos($content, 'sfCompat10Plugin')) {
             $matches[] = 'sfCompat10Plugin';
         }
         if (false !== strpos($content, 'sfProtoculousPlugin')) {
             $matches[] = 'sfProtoculousPlugin';
         }
         if ($matches) {
             $found[$file] = implode(', ', $matches);
         }
     }
     return $found;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $config = $this->getCliConfig();
     $this->logSection('doctrine', sprintf('generating migration class named "%s"', $arguments['name']));
     if (!is_dir($config['migrations_path'])) {
         $this->getFilesystem()->mkdirs($config['migrations_path']);
     }
     $this->callDoctrineCli('generate-migration', array('name' => $arguments['name']));
     $finder = sfFinder::type('file')->sort_by_name()->name('*.php');
     if ($files = $finder->in($config['migrations_path'])) {
         $file = array_pop($files);
         $contents = file_get_contents($file);
         $contents = strtr(sfToolkit::stripComments($contents), array("{\n\n" => "{\n", "\n}" => "\n}\n", '    ' => '  '));
         file_put_contents($file, $contents);
         if (isset($options['editor-cmd'])) {
             $this->getFilesystem()->execute($options['editor-cmd'] . ' ' . escapeshellarg($file));
         }
     }
 }
 /**
  * Executes this configuration handler.
  *
  * @param array An array of absolute filesystem path to a configuration file
  *
  * @return string Data to be written to a cache file
  *
  * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  * @throws sfParseException If a requested configuration file is improperly formatted
  */
 public function execute($configFiles)
 {
     // parse the yaml
     $config = array();
     foreach ($configFiles as $configFile) {
         $config = array_merge($config, $this->parseYaml($configFile));
     }
     // init our data
     $data = '';
     // let's do our fancy work
     foreach ($config as $file) {
         $file = $this->replaceConstants($file);
         $file = $this->replacePath($file);
         if (!is_readable($file)) {
             // file doesn't exist
             $error = sprintf('Configuration file "%s" specifies nonexistent or unreadable file "%s"', $configFiles[0], $file);
             throw new sfParseException($error);
         }
         $contents = file_get_contents($file);
         // strip comments (not in debug mode)
         if (!sfConfig::get('sf_debug')) {
             $contents = sfToolkit::stripComments($contents);
         }
         // insert configuration files
         $contents = preg_replace_callback(array('#(require|include)(_once)?\\((sfConfigCache::getInstance\\(\\)|\\$configCache)->checkConfig\\([^_]+sf_app_config_dir_name[^\\.]*\\.\'/([^\']+)\'\\)\\);#m', '#()()(sfConfigCache::getInstance\\(\\)|\\$configCache)->import\\(.sf_app_config_dir_name\\.\'/([^\']+)\'(, false)?\\);#m'), array($this, 'insertConfigFileCallback'), $contents);
         // strip php tags
         $contents = sfToolkit::pregtr($contents, array('/^\\s*<\\?(php)?/m' => '', '/^\\s*\\?>/m' => ''));
         // replace windows and mac format with unix format
         $contents = str_replace("\r", "\n", $contents);
         // replace multiple new lines with a single newline
         $contents = preg_replace(array('/\\s+$/Sm', '/\\n+/S'), "\n", $contents);
         // append file data
         $data .= "\n" . $contents;
     }
     // compile data
     $retval = sprintf("<?php\n" . "// auto-generated by sfCompileConfigHandler\n" . "// date: %s\n%s\n", date('Y/m/d H:i:s'), $data);
     // save current symfony release
     file_put_contents(sfConfig::get('sf_config_cache_dir') . '/VERSION', file_get_contents(sfConfig::get('sf_symfony_lib_dir') . '/VERSION'));
     return $retval;
 }
    /**
     * @see sfTask
     */
    protected function execute($arguments = array(), $options = array())
    {
        $this->logSection('doctrine', 'generating model classes');
        $config = $this->getCliConfig();
        $builderOptions = $this->configuration->getPluginConfiguration('sfDoctrinePlugin')->getModelBuilderOptions();
        $stubFinder = sfFinder::type('file')->prune('base')->name('*' . $builderOptions['suffix']);
        $before = $stubFinder->in($config['models_path']);
        $schema = $this->prepareSchemaFile($config['yaml_schema_path']);
        $import = new Doctrine_Import_Schema();
        $import->setOptions($builderOptions);
        $import->importSchema($schema, 'yml', $config['models_path']);
        $listFiles = array();
        $listDir = array();
        $bI = array('package' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 'subpackage' => 'model', 'author' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here');
        $baseRecordFile = sprintf("%s/BaseDoctrineRecord.class.php", $config['models_path']);
        $baseRecordFileContent = <<<EOF
<?php

/**
 * Base doctrin record.
 *
 * @package    {$bI['package']}
 * @subpackage {$bI['subpackage']}
 * @author     {$bI['author']}
 */


##class## BaseDoctrineRecord extends sfPostgresDoctrineRecord
{
}

EOF;
        if (!file_exists($baseRecordFile)) {
            file_put_contents($baseRecordFile, str_replace('##class##', 'class', $baseRecordFileContent));
        }
        // markup base classes with magic methods
        foreach (sfYaml::load($schema) as $model => $definition) {
            $file = sprintf('%s%s/%s/Base%s%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $builderOptions['baseClassesDirectory'], $model, $builderOptions['suffix']);
            $code = file_get_contents($file);
            // introspect the model without loading the class
            if (preg_match_all('/@property (\\w+) \\$(\\w+)/', $code, $matches, PREG_SET_ORDER)) {
                $properties = array();
                foreach ($matches as $match) {
                    $properties[$match[2]] = $match[1];
                }
                $typePad = max(array_map('strlen', array_merge(array_values($properties), array($model))));
                $namePad = max(array_map('strlen', array_keys(array_map(array('sfInflector', 'camelize'), $properties))));
                $setters = array();
                $getters = array();
                foreach ($properties as $name => $type) {
                    $camelized = sfInflector::camelize($name);
                    $collection = 'Doctrine_Collection' == $type;
                    $getters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Returns the current record\'s "%s" %s', $type, 'get', $camelized . '()', $name, $collection ? 'collection' : 'value');
                    $setters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Sets the current record\'s "%s" %s', $model, 'set', $camelized . '()', $name, $collection ? 'collection' : 'value');
                }
                // use the last match as a search string
                $code = str_replace($match[0], $match[0] . PHP_EOL . ' * ' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', array_merge($getters, $setters)), $code);
                $newfile = sprintf('%s%s%s/%s/Base%s%s', $config['models_path'], isset($definition['package']) && false !== stripos($definition['package'], 'plugin') && 0 !== stripos($definition['package'], 'plugin') ? '/plugins' : '/project', isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $builderOptions['baseClassesDirectory'], $model, $builderOptions['suffix']);
                $newtablefile = sprintf('%s%s%s/%sTable%s', $config['models_path'], isset($definition['package']) && false !== stripos($definition['package'], 'plugin') && 0 !== stripos($definition['package'], 'plugin') ? '/plugins' : '/project', isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $model, $builderOptions['suffix']);
                $newdir = sprintf('%s%s%s/%s', $config['models_path'], isset($definition['package']) && false !== stripos($definition['package'], 'plugin') && 0 !== stripos($definition['package'], 'plugin') ? '/plugins' : '/project', isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $builderOptions['baseClassesDirectory']);
                if (!file_exists($newdir)) {
                    mkdir($newdir, 0777, true);
                }
                $listDir[sprintf('%s%s/%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $builderOptions['baseClassesDirectory'])] = true;
                $listDir[sprintf('%s%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '')] = true;
                if (!file_exists(str_replace(sprintf('%s/Base', $builderOptions['baseClassesDirectory']), '', $newfile))) {
                    $listFiles[sprintf('%s%s/%s%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $model, $builderOptions['suffix'])] = str_replace(sprintf('%s/Base', $builderOptions['baseClassesDirectory']), '', $newfile);
                } else {
                    unlink(sprintf('%s%s/%s%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $model, $builderOptions['suffix']));
                }
                if (!file_exists($newtablefile)) {
                    $listFiles[sprintf('%s%s/%sTable%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $model, $builderOptions['suffix'])] = $newtablefile;
                } else {
                    unlink(sprintf('%s%s/%sTable%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $model, $builderOptions['suffix']));
                }
                $code = str_replace(" extends sfDoctrineRecord", " extends BaseDoctrineRecord", $code);
                file_put_contents($newfile, $code);
                unlink($file);
            }
        }
        $properties = parse_ini_file(sfConfig::get('sf_config_dir') . '/properties.ini', true);
        $tokens = array('##PACKAGE##' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', '##SUBPACKAGE##' => 'model', '##NAME##' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here', ' <##EMAIL##>' => '', "{\n\n}" => "{\n}\n");
        // cleanup new stub classes
        $after = $stubFinder->in($config['models_path']);
        $this->getFilesystem()->replaceTokens(array_diff($after, $before), '', '', $tokens);
        // cleanup base classes
        $baseFinder = sfFinder::type('file')->name('Base*' . $builderOptions['suffix']);
        $baseDirFinder = sfFinder::type('dir')->name('base');
        $this->getFilesystem()->replaceTokens($baseFinder->in($baseDirFinder->in($config['models_path'])), '', '', $tokens);
        // cleanup new table classes
        $tableFinder = sfFinder::type('file')->prune('base')->name('*Table' . $builderOptions['suffix']);
        foreach (array_diff($tableFinder->in($config['models_path']), $before) as $file) {
            $contents = file_get_contents($file);
            file_put_contents($file, sfToolkit::stripComments($contents));
        }
        foreach ($listFiles as $old => $new) {
            rename($old, $new);
        }
        foreach ($listDir as $dir => $val) {
            if (file_exists($dir)) {
                if (($files = @scandir($dir)) && count($files) <= 2) {
                    rmdir($dir);
                }
            }
        }
        $this->reloadAutoload();
    }
$php = <<<EOF
<?php

# A perl like comment
// Another comment
/* A very long
comment
on several lines
*/

\$i = 1; // A comment on a PHP line
EOF;
$stripped_php = '<?php $i = 1; ';
$t->is(preg_replace('/\\s*(\\r?\\n)+/', ' ', sfToolkit::stripComments($php)), $stripped_php, '::stripComments() strip all comments from a php string');
sfConfig::set('sf_strip_comments', false);
$t->is(sfToolkit::stripComments($php), $php, '::stripComments() do nothing if "sf_strip_comments" is false');
// ::stripslashesDeep()
$t->diag('::stripslashesDeep()');
$t->is(sfToolkit::stripslashesDeep('foo'), 'foo', '::stripslashesDeep() strip slashes on string');
$t->is(sfToolkit::stripslashesDeep(addslashes("foo's bar")), "foo's bar", '::stripslashesDeep() strip slashes on array');
$t->is(sfToolkit::stripslashesDeep(array(addslashes("foo's bar"), addslashes("foo's bar"))), array("foo's bar", "foo's bar"), '::stripslashesDeep() strip slashes on deep arrays');
$t->is(sfToolkit::stripslashesDeep(array(array('foo' => addslashes("foo's bar")), addslashes("foo's bar"))), array(array('foo' => "foo's bar"), "foo's bar"), '::stripslashesDeep() strip slashes on deep arrays');
// ::clearDirectory()
$t->diag('::clearDirectory()');
$tmp_dir = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . 'symfony_tests_' . rand(1, 999);
mkdir($tmp_dir);
file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'test', 'ok');
mkdir($tmp_dir . DIRECTORY_SEPARATOR . 'foo');
file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'bar', 'ok');
sfToolkit::clearDirectory($tmp_dir);
$t->ok(!is_dir($tmp_dir . DIRECTORY_SEPARATOR . 'foo'), '::clearDirectory() removes all directories from the directory parameter');
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->logSection('doctrine', 'generating model classes');
     $config = $this->getCliConfig();
     $builderOptions = $this->configuration->getPluginConfiguration('sfDoctrinePlugin')->getModelBuilderOptions();
     $stubFinder = sfFinder::type('file')->prune('base')->name('*' . $builderOptions['suffix']);
     $before = $stubFinder->in($config['models_path']);
     $schema = $this->prepareSchemaFile($config['yaml_schema_path']);
     $import = new Doctrine_Import_Schema();
     $import->setOptions($builderOptions);
     $import->importSchema($schema, 'yml', $config['models_path']);
     // markup base classes with magic methods
     foreach (sfYaml::load($schema) as $model => $definition) {
         $file = sprintf('%s%s/%s/Base%s%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $builderOptions['baseClassesDirectory'], $model, $builderOptions['suffix']);
         $code = file_get_contents($file);
         // introspect the model without loading the class
         if (preg_match_all('/@property (\\w+) \\$(\\w+)/', $code, $matches, PREG_SET_ORDER)) {
             $properties = array();
             foreach ($matches as $match) {
                 $properties[$match[2]] = $match[1];
             }
             $typePad = max(array_map('strlen', array_merge(array_values($properties), array($model))));
             $namePad = max(array_map('strlen', array_keys(array_map(array('sfInflector', 'camelize'), $properties))));
             $setters = array();
             $getters = array();
             foreach ($properties as $name => $type) {
                 $camelized = sfInflector::camelize($name);
                 $collection = 'Doctrine_Collection' == $type;
                 $getters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Returns the current record\'s "%s" %s', $type, 'get', $camelized . '()', $name, $collection ? 'collection' : 'value');
                 $setters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Sets the current record\'s "%s" %s', $model, 'set', $camelized . '()', $name, $collection ? 'collection' : 'value');
             }
             // use the last match as a search string
             $code = str_replace($match[0], $match[0] . PHP_EOL . ' * ' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', array_merge($getters, $setters)), $code);
             file_put_contents($file, $code);
         }
     }
     $properties = parse_ini_file(sfConfig::get('sf_config_dir') . '/properties.ini', true);
     $tokens = array('##PACKAGE##' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', '##SUBPACKAGE##' => 'model', '##NAME##' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here', ' <##EMAIL##>' => '', "{\n\n}" => "{\n}\n");
     // cleanup new stub classes
     $after = $stubFinder->in($config['models_path']);
     $this->getFilesystem()->replaceTokens(array_diff($after, $before), '', '', $tokens);
     // cleanup base classes
     $baseFinder = sfFinder::type('file')->name('Base*' . $builderOptions['suffix']);
     $baseDirFinder = sfFinder::type('dir')->name('base');
     $this->getFilesystem()->replaceTokens($baseFinder->in($baseDirFinder->in($config['models_path'])), '', '', $tokens);
     // cleanup new table classes
     $tableFinder = sfFinder::type('file')->prune('base')->name('*Table' . $builderOptions['suffix']);
     foreach (array_diff($tableFinder->in($config['models_path']), $before) as $file) {
         $contents = file_get_contents($file);
         file_put_contents($file, sfToolkit::stripComments($contents));
     }
     $this->reloadAutoload();
 }
Example #22
0
\$i = 1; // A comment on a PHP line
EOF;

$stripped_php = '<?php $i = 1; ';

$t->is(preg_replace('/\s*(\r?\n)+/', ' ', sfToolkit::stripComments($php)), $stripped_php, '::stripComments() strip all comments from a php string');

$php = <<<EOF
<?php
  \$pluginDirs = '/*/modules/lib/helper';
  \$pluginDirs = '/*/lib/helper';

EOF;

$t->is(sfToolkit::stripComments($php), $php, '::stripComments() correctly handles comments within strings');


// ::stripslashesDeep()
$t->diag('::stripslashesDeep()');
$t->is(sfToolkit::stripslashesDeep('foo'), 'foo', '::stripslashesDeep() strip slashes on string');
$t->is(sfToolkit::stripslashesDeep(addslashes("foo's bar")), "foo's bar", '::stripslashesDeep() strip slashes on array');
$t->is(sfToolkit::stripslashesDeep(array(addslashes("foo's bar"), addslashes("foo's bar"))), array("foo's bar", "foo's bar"), '::stripslashesDeep() strip slashes on deep arrays');
$t->is(sfToolkit::stripslashesDeep(array(array('foo' => addslashes("foo's bar")), addslashes("foo's bar"))), array(array('foo' => "foo's bar"), "foo's bar"), '::stripslashesDeep() strip slashes on deep arrays');

// ::clearDirectory()
$t->diag('::clearDirectory()');
$tmp_dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'symfony_tests_'.rand(1, 999);
mkdir($tmp_dir);
file_put_contents($tmp_dir.DIRECTORY_SEPARATOR.'test', 'ok');
mkdir($tmp_dir.DIRECTORY_SEPARATOR.'foo');