/**
   * Constructor.
   *
   * @param string              $rootDir    The project root directory
   * @param sfEventDispatcher   $dispatcher The event dispatcher
   */
  public function __construct($rootDir = null, sfEventDispatcher $dispatcher = null)
  {
    if (null === self::$active || $this instanceof sfApplicationConfiguration)
    {
      self::$active = $this;
    }

    $this->rootDir = null === $rootDir ? self::guessRootDir() : realpath($rootDir);
    $this->symfonyLibDir = realpath(dirname(__FILE__).'/..');
    $this->dispatcher = null === $dispatcher ? new sfEventDispatcher() : $dispatcher;

    ini_set('magic_quotes_runtime', 'off');

    sfConfig::set('sf_symfony_lib_dir', $this->symfonyLibDir);

    $this->setRootDir($this->rootDir);

    // provide forms the dispatcher
    sfFormSymfony::setEventDispatcher($this->dispatcher);

    $this->setup();

    $this->loadPlugins();
    $this->setupPlugins();
  }
Ejemplo n.º 2
0
    public function filter(sfEvent $event, $value)
    {
        $this->events[] = func_get_args();
        return $value;
    }
    public function reset()
    {
        $this->events = array();
    }
}
$listener = new FormListener();
$dispatcher = new sfEventDispatcher();
$dispatcher->connect('form.post_configure', array($listener, 'listen'));
$dispatcher->connect('form.filter_values', array($listener, 'filter'));
$dispatcher->connect('form.validation_error', array($listener, 'listen'));
sfFormSymfony::setEventDispatcher($dispatcher);
class TestForm extends sfFormSymfony
{
    public function configure()
    {
        $this->setValidators(array('first_name' => new sfValidatorString(), 'last_name' => new sfValidatorString()));
    }
}
// ->__construct()
$t->diag('->__construct()');
$listener->reset();
$form = new TestForm();
$t->is(count($listener->events), 1, '->__construct() notifies one event');
$t->is($listener->events[0][0]->getName(), 'form.post_configure', '->__construct() notifies the "form.post_configure" event');
// ->bind()
$t->diag('->bind()');