Skip to content

Commit

Permalink
[Foundation] added a way to reboot the kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 19, 2010
1 parent 257c06f commit ee50040
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Foundation/Bundle/Bundle.php
Expand Up @@ -29,4 +29,8 @@ public function buildContainer(ContainerInterface $container)
public function boot(ContainerInterface $container)
{
}

public function shutdown(ContainerInterface $container)
{
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Foundation/Bundle/BundleInterface.php
Expand Up @@ -25,4 +25,6 @@ interface BundleInterface
public function buildContainer(ContainerInterface $container);

public function boot(ContainerInterface $container);

public function shutdown(ContainerInterface $container);
}
32 changes: 31 additions & 1 deletion src/Symfony/Foundation/Kernel.php
Expand Up @@ -113,7 +113,7 @@ public function boot()
$this->container = $this->initializeContainer();
$this->container->setService('kernel', $this);

// boot bundles (in reverse order)
// boot bundles
foreach ($this->bundles as $bundle)
{
$bundle->boot($this->container);
Expand All @@ -124,6 +124,36 @@ public function boot()
return $this;
}

/**
* Shutdowns the kernel.
*
* This method is mainly useful when doing functional testing.
*/
public function shutdown()
{
$this->booted = false;

foreach ($this->bundles as $bundle)
{
$bundle->shutdown($this->container);
}

$this->container = null;
}

/**
* Reboots the kernel.
*
* This method is mainly useful when doing functional testing.
*
* It is a shortcut for the call to shutdown() and boot().
*/
public function reboot()
{
$this->shutdown();
$this->boot();
}

public function run()
{
$this->handle()->send();
Expand Down
46 changes: 36 additions & 10 deletions src/Symfony/Foundation/bootstrap.php
@@ -1,4 +1,4 @@
<?php
<?php

namespace Symfony\Foundation\Bundle;

Expand All @@ -16,6 +16,10 @@ public function buildContainer(ContainerInterface $container)
public function boot(ContainerInterface $container)
{
}

public function shutdown(ContainerInterface $container)
{
}
}


Expand All @@ -31,6 +35,8 @@ interface BundleInterface
public function buildContainer(ContainerInterface $container);

public function boot(ContainerInterface $container);

public function shutdown(ContainerInterface $container);
}


Expand Down Expand Up @@ -145,7 +151,7 @@ public function configLoad($config)
return $configuration;
}


public function getXsdValidationBasePath()
{
return false;
Expand Down Expand Up @@ -182,7 +188,7 @@ class ErrorHandler

protected $level;


public function __construct($level = null)
{
$this->level = null === $level ? error_reporting() : $level;
Expand All @@ -193,7 +199,7 @@ public function register()
set_error_handler(array($this, 'handle'));
}


public function handle($level, $message, $file, $line, $context)
{
if (0 === $this->level)
Expand All @@ -218,7 +224,7 @@ public function handle($level, $message, $file, $line, $context)

class ClassCollectionLoader
{

static public function load($classes, $cacheDir, $name, $autoReload)
{
$cache = $cacheDir.'/'.$name.'.php';
Expand Down Expand Up @@ -336,7 +342,7 @@ abstract class Kernel implements \Serializable

const VERSION = '2.0.0-DEV';


public function __construct($environment, $debug)
{
$this->debug = (Boolean) $debug;
Expand Down Expand Up @@ -373,13 +379,13 @@ abstract public function registerContainerConfiguration();

abstract public function registerRoutes();


public function isBooted()
{
return $this->booted;
}


public function boot()
{
if (true === $this->booted)
Expand All @@ -400,6 +406,26 @@ public function boot()
return $this;
}


public function shutdown()
{
$this->booted = false;

foreach ($this->bundles as $bundle)
{
$bundle->shutdown($this->container);
}

$this->container = null;
}


public function reboot()
{
$this->shutdown();
$this->boot();
}

public function run()
{
$this->handle()->send();
Expand Down Expand Up @@ -683,7 +709,7 @@ class EventDispatcher extends BaseEventDispatcher
{
protected $container;


public function __construct(ContainerInterface $container)
{
$this->container = $container;
Expand All @@ -700,7 +726,7 @@ public function __construct(ContainerInterface $container)
}
}


public function getListeners($name)
{
if (!isset($this->listeners[$name]))
Expand Down

0 comments on commit ee50040

Please sign in to comment.