public function objectFilter(&$script)
 {
     if ($this->isDisabled()) {
         return;
     }
     $class = new sfClassManipulator($script);
     $class->filterMethod('doSave', array($this, 'filterDoSave'));
     $script = $class->getCode();
 }
 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();
 }
    public function peerFilter(&$script)
    {
        if ($this->isDisabled()) {
            return;
        }
        $doInsertPre = <<<EOF
// symfony_behaviors behavior
    foreach (sfMixer::getCallables('Base{$this->getTable()->getPhpName()}Peer:doInsert:pre') as \$sf_hook)
    {
      if (false !== \$sf_hook_retval = call_user_func(\$sf_hook, 'Base{$this->getTable()->getPhpName()}Peer', \$values, \$con))
      {
        return \$sf_hook_retval;
      }
    }

EOF;
        $doUpdatePre = <<<EOF
// symfony_behaviors behavior
    foreach (sfMixer::getCallables('Base{$this->getTable()->getPhpName()}Peer:doUpdate:pre') as \$sf_hook)
    {
      if (false !== \$sf_hook_retval = call_user_func(\$sf_hook, 'Base{$this->getTable()->getPhpName()}Peer', \$values, \$con))
      {
        return \$sf_hook_retval;
      }
    }

EOF;
        // add doInsert and doUpdate hooks
        $class = new sfClassManipulator($script);
        $class->filterMethod('doInsert', array($this, 'filterDoInsert'));
        $class->wrapMethod('doInsert', $doInsertPre);
        $class->filterMethod('doUpdate', array($this, 'filterDoUpdate'));
        $class->wrapMethod('doUpdate', $doUpdatePre);
        $script = $class->getCode();
        // add symfony behavior configuration file
        if ($this->createBehaviorsFile()) {
            $script .= $this->getBehaviorsInclude();
        }
    }
    }
}
$f = new MethodFilterer();
$sourceFiltered = <<<EOF
<?php

class Foo
{
  function foo(\$arg)
  {
    if (false)
    {
      return;
    }
  }

  function baz()
  {
    if (true)
    {
      return;
    }
  }
}
EOF;
$m = new sfClassManipulator($source);
$m->filterMethod('foo', array($f, 'filter1'));
$t->is($m->getCode(), $source, '->filterMethod() does not change the code if the filter does nothing');
$t->is_deeply($f->lines, array('  function foo()' . PHP_EOL, '  {' . PHP_EOL, '    if (true)' . PHP_EOL, '    {' . PHP_EOL, '      return;' . PHP_EOL, '    }' . PHP_EOL, '  }'), '->filterMethod() filters each line of the method');
$m->filterMethod('foo', array($f, 'filter2'));
$t->is($m->getCode(), $sourceFiltered, '->filterMethod() modifies the method');
示例#6
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'));
示例#7
0
$m = new sfClassManipulator($sourceCRLF);
$f->lines = array();
$m->filterMethod('foo', array($f, 'filter1'));
$t->is($m->getCode(), $sourceCRLF, '->filterMethod() does not change the code if the filter does nothing');
$t->is_deeply($f->lines, array("  function foo()\r\n", "  {\r\n", "    if (true)\r\n", "    {\r\n", "      return;\r\n", "    }\r\n", "  }"), '->filterMethod() filters each line of the method');
$m->filterMethod('foo', array($f, 'filter2'));
$t->is($m->getCode(), $sourceFilteredCRLF, '->filterMethod() modifies the method');
// LF
$t->diag('LF');
$m = new sfClassManipulator($sourceLF);
$f->lines = array();
$m->filterMethod('foo', array($f, 'filter1'));
$t->is($m->getCode(), $sourceLF, '->filterMethod() does not change the code if the filter does nothing');
$t->is_deeply($f->lines, array("  function foo()\n", "  {\n", "    if (true)\n", "    {\n", "      return;\n", "    }\n", "  }"), '->filterMethod() filters each line of the method');
$m->filterMethod('foo', array($f, 'filter2'));
$t->is($m->getCode(), $sourceFilteredLF, '->filterMethod() modifies the method');
// no EOL
$t->diag('no EOL');
$sourceFlat = '<?php class Foo { function foo() { if (true) { return; } } function baz() { if (true) { return; } } }';
$m = new sfClassManipulator($sourceFlat);
$f->lines = array();
$m->filterMethod('foo', array($f, 'filter1'));
$t->is_deeply($f->lines, array('function foo() { if (true) { return; } }'), '->filterMethod() works when there are no line breaks');
$t->is($m->getCode(), $sourceFlat, '->filterMethod() works when there are no line breaks');
// mixed EOL
$t->diag('mixed EOL');
$sourceMixed = "<?php\r\n\nclass Foo\r\n{\n  function foo()\r\n  {\n    if (true)\r\n    {\n      return;\r\n    }\n  }\r\n\n  function baz()\r\n  {\n    if (true)\r\n    {\n      return;\r\n    }\n  }\r\n}";
$m = new sfClassManipulator($sourceMixed);
$f->lines = array();
$m->filterMethod('foo', array($f, 'filter1'));
$t->is_deeply($f->lines, array("  function foo()\r\n", "  {\n", "    if (true)\r\n", "    {\n", "      return;\r\n", "    }\n", "  }"), '->filterMethod() filters each line of a mixed EOL-style method');