public function upgrade()
 {
     $specVersion = sfYaml::getSpecVersion();
     $queue = array();
     $success = true;
     $finder = sfFinder::type('file')->name('*.yml')->prune('vendor');
     foreach ($finder->in(sfConfig::get('sf_root_dir')) as $file) {
         // attempt to upgrade booleans
         $original = file_get_contents($file);
         $upgraded = sfToolkit::pregtr($original, array('/^([^:]+: +)(?:on|y(?:es)?|\\+)(\\s*(#.*)?)$/im' => '\\1true\\2', '/^([^:]+: +)(?:off|no?|-)(\\s*(#.*)?)$/im' => '\\1false\\2'));
         try {
             sfYaml::setSpecVersion('1.1');
             $yaml11 = sfYaml::load($original);
             sfYaml::setSpecVersion('1.2');
             $yaml12 = sfYaml::load($upgraded);
         } catch (Exception $e) {
             // unable to load the YAML
             $yaml11 = 'foo';
             $yaml12 = 'bar';
         }
         if ($yaml11 == $yaml12) {
             if ($original != $upgraded) {
                 $this->getFilesystem()->touch($file);
                 file_put_contents($file, $upgraded);
             }
         } else {
             $this->logSection('yaml', 'Unable to upgrade ' . sfDebug::shortenFilePath($file), null, 'ERROR');
             // force project to use YAML 1.1 spec
             if ('1.1' != $specVersion) {
                 $specVersion = '1.1';
                 $class = sfClassManipulator::fromFile(sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php');
                 $original = $class->getCode();
                 $modified = $class->wrapMethod('setup', 'sfYaml::setSpecVersion(\'1.1\');');
                 if ($original != $modified && $this->askConfirmation(array('Unable to convert YAML file:', sfDebug::shortenFilePath($file), '', 'Would you like to force YAML to be parsed with the 1.1 specification? (Y/n)'), 'QUESTION_LARGE')) {
                     $this->logSection('yaml', 'Forcing YAML 1.1 spec');
                     $this->getFilesystem()->touch($class->getFile());
                     $class->save();
                 } else {
                     $this->logBlock(array('Unable to either upgrade YAML files or force 1.1 spec.', '(see UPGRADE_TO_1_3 file for more information)'), 'ERROR_LARGE');
                 }
             }
             $success = false;
         }
     }
     if ($success && '1.1' == $specVersion) {
         $file = sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php';
         $original = file_get_contents($file);
         $modified = preg_replace('/^\\s*sfYaml::setSpecVersion\\(\'1\\.1\'\\);\\n/im', '', $original);
         if ($original != $modified) {
             $this->logSection('yaml', 'Removing setting of YAML 1.1 spec');
             $this->getFilesystem()->touch($file);
             file_put_contents($file, $modified);
         }
     }
 }
 /**
  * Enables a plugin in the ProjectConfiguration class.
  *
  * This is a static method that does not rely on the PEAR environment
  * as we don't want this method to have PEAR as a dependency.
  *
  * @param string $plugin    The name of the plugin
  * @param string $configDir The config directory
  */
 public static function enablePlugin($plugin, $configDir)
 {
     if (!$configDir) {
         throw new sfPluginException('You must provide a "config_dir" option.');
     }
     $manipulator = sfClassManipulator::fromFile($configDir . '/ProjectConfiguration.class.php');
     $manipulator->wrapMethod('setup', '', sprintf('$this->enablePlugins(\'%s\');', $plugin));
     $manipulator->save();
 }
$m->wrapMethod('foo', '', '// code after');
$t->is($m->getCode(), $sourceWithCodeAfter, '->getCode() returns the modified code');
// ->setFile() ->getFile()
$t->diag('->setFile() ->getFile()');
$m = new sfClassManipulator($source);
$m->setFile('foo');
$t->is($m->getFile(), 'foo', '->setFile() sets the name of the file associated with the source code');
// ::fromFile()
$t->diag('::fromFile()');
$file = sys_get_temp_dir() . '/sf_tmp.php';
file_put_contents($file, $source);
$m = sfClassManipulator::fromFile($file);
$t->is($m->getFile(), $file, '::fromFile() sets the file internally');
// ->save()
$t->diag('->save()');
$m = sfClassManipulator::fromFile($file);
$m->wrapMethod('foo', '', '// code after');
$m->save();
$t->is(file_get_contents($file), $sourceWithCodeAfter, '->save() saves the modified code if a file is associated with the instance');
unlink($file);
// ->filterMethod()
$t->diag('->filterMethod()');
class MethodFilterer
{
    public $lines = array();
    public function filter1($line)
    {
        $this->lines[] = $line;
        return $line;
    }
    public function filter2($line)
Beispiel #4
0
    $error = true;
}
if ($error) {
    $this->logBlock('SYMPAL SERVER CHECK RETURNED ERRORS', 'ERROR_LARGE');
    if (!$this->askConfirmation('The server check returned some errors and/or warnings. Do you wish to continue with the installation? (y/n)', 'QUESTION_LARGE')) {
        $this->logBlock('Sympal installation was cancelled!', 'ERROR_LARGE');
        return;
    }
} else {
    if (!$this->askConfirmation('The server check was a success! You should have no problem running Sympal. Do you wish to continue on with the installation? (y/n)', 'QUESTION_LARGE')) {
        $this->logBlock('Sympal installation was cancelled!', 'ERROR_LARGE');
        return;
    }
}
$this->logSection('sympal', '...adding Sympal code to ProjectConfiguration');
$manipulator = sfClassManipulator::fromFile(sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php');
$manipulator->wrapMethod('setup', '', 'require_once(dirname(__FILE__).\'/../plugins/sfSympalPlugin/config/sfSympalPluginConfiguration.class.php\');');
$manipulator->wrapMethod('setup', '', 'sfSympalPluginConfiguration::enableSympalPlugins($this);');
$manipulator->save();
$this->logSection('sympal', '...downloading sfSympalPlugin');
// Using SVN for now because PEAR ALWAYS FAILS FOR SOME PEOPLE
$this->getFilesystem()->execute('svn co http://svn.symfony-project.org/plugins/sfSympalPlugin/trunk plugins/sfSympalPlugin');
//@$this->runTask('plugin:install', 'sfSympalPlugin --stability=alpha');
//$this->disablePlugin('sfSympalPlugin'); // We don't want the explicit enabling of this plugin
$this->reloadTasks();
$this->logSection('sympal', '...setup initial data');
$application = $this->askAndValidate('What would you like your first application to be called?', new sfValidatorString(), array('style' => 'QUESTION_LARGE'));
$firstName = $this->askAndValidate('What is your first name?', new sfValidatorString(), array('style' => 'QUESTION_LARGE'));
$lastName = $this->askAndValidate('What is your last name?', new sfValidatorString(), array('style' => 'QUESTION_LARGE'));
$validator = new sfValidatorEmail(array(), array('invalid' => 'Invalid e-mail address!'));
$emailAddress = $this->askAndValidate('What is your e-mail address?', $validator, array('style' => 'QUESTION_LARGE'));