sfContext::createInstance PHP Méthode

createInstance() public static méthode

Creates a new context instance.
public static createInstance ( sfApplicationConfiguration $configuration, string $name = null, string $class = __CLASS__ ) : sfContext
$configuration sfApplicationConfiguration An sfApplicationConfiguration instance
$name string A name for this context (application name by default)
$class string The context class to use (sfContext by default)
Résultat sfContext An sfContext instance
    public static function createInstance(sfApplicationConfiguration $configuration, $name = null, $class = __CLASS__)
    {
        if (null === $name) {
            $name = $configuration->getApplication();
        }
        self::$current = $name;
        self::$instances[$name] = new $class();
        if (!self::$instances[$name] instanceof sfContext) {
            throw new sfFactoryException(sprintf('Class "%s" is not of the type sfContext.', $class));
        }
        self::$instances[$name]->initialize($configuration);
        return self::$instances[$name];
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function boot(ContainerInterface $container)
 {
     if (empty($this->options)) {
         throw new \RuntimeException('You must provide options for the Symfony 1.4 kernel.');
     }
     if ($this->isBooted()) {
         return;
     }
     if ($this->classLoader && !$this->classLoader->isAutoloaded()) {
         $this->classLoader->autoload();
     }
     $dispatcher = $container->get('event_dispatcher');
     $event = new LegacyKernelBootEvent($container->get('request'), $this->options);
     $dispatcher->dispatch(LegacyKernelEvents::BOOT, $event);
     $this->options = $event->getOptions();
     require_once $this->rootDir . '/config/ProjectConfiguration.class.php';
     $application = $this->options['application'];
     $environment = $this->options['environment'];
     $debug = $this->options['debug'];
     $this->configuration = \ProjectConfiguration::getApplicationConfiguration($application, $environment, $debug, $this->getRootDir());
     $this->configuration->loadHelpers(array('Url'));
     // Create a context to use with some helpers like Url.
     if (!\sfContext::hasInstance()) {
         $session = $container->get('session');
         if ($session->isStarted()) {
             $session->save();
         }
         ob_start();
         \sfContext::createInstance($this->configuration);
         ob_end_flush();
         $session->migrate();
     }
     $this->isBooted = true;
 }
All Usage Examples Of sfContext::createInstance