Skip to content

[Kernel] Get rid of Kernel::registerRootDir() #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Mar 16, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class Kernel extends BaseKernel
{
public function __construct()
{
$this->tmpDir = sys_get_temp_dir().'/sf2_'.rand(1, 9999);
if (!is_dir($this->tmpDir)) {
if (false === @mkdir($this->tmpDir)) {
die(sprintf('Unable to create a temporary directory (%s)', $this->tmpDir));
$this->rootDir = sys_get_temp_dir().'/sf2_'.rand(1, 9999);
if (!is_dir($this->rootDir)) {
if (false === @mkdir($this->rootDir)) {
die(sprintf('Unable to create a temporary directory (%s)', $this->rootDir));
}
} elseif (!is_writable($this->tmpDir)) {
die(sprintf('Unable to write in a temporary directory (%s)', $this->tmpDir));
} elseif (!is_writable($this->rootDir)) {
die(sprintf('Unable to write in a temporary directory (%s)', $this->rootDir));
}

parent::__construct('env', true);
Expand All @@ -42,12 +42,7 @@ public function __construct()
public function __destruct()
{
$fs = new Filesystem();
$fs->remove($this->tmpDir);
}

public function registerRootDir()
{
return $this->tmpDir;
$fs->remove($this->rootDir);
}

public function registerBundles()
Expand Down
14 changes: 13 additions & 1 deletion src/Symfony/Component/HttpKernel/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
}

/**
* {@inheritdoc}
* Handles a Request to convert it to a Response.
*
* When $catch is true, the implementation must catch all exceptions
* and do its best to convert them to a Response instance.
*
* @param Request $request A Request instance
* @param integer $type The type of the request
* (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
* @param Boolean $catch Whether to catch exceptions or not
*
* @return Response A Response instance
*
* @throws \Exception When an Exception occurs during processing
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
Expand Down
56 changes: 50 additions & 6 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public function __construct($environment, $debug)
$this->environment = $environment;
$this->debug = (Boolean) $debug;
$this->booted = false;
$this->rootDir = realpath($this->registerRootDir());
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->getRootDir()));

if ($this->debug) {
ini_set('display_errors', 1);
Expand Down Expand Up @@ -262,6 +261,11 @@ public function locateResource($name, $dir = null, $first = true)
throw new \InvalidArgumentException(sprintf('Unable to find file "@%s".', $name));
}

/**
* Gets the name of the kernel
*
* @return string The kernel name
*/
public function getName()
{
return $this->name;
Expand Down Expand Up @@ -294,6 +298,11 @@ public function isDebug()
*/
public function getRootDir()
{
if (null === $this->rootDir) {
$r = new \ReflectionObject($this);
$this->rootDir = dirname($r->getFileName());
}

return $this->rootDir;
}

Expand Down Expand Up @@ -324,7 +333,7 @@ public function getStartTime()
*/
public function getCacheDir()
{
return $this->rootDir.'/cache/'.$this->environment;
return $this->getRootDir().'/cache/'.$this->environment;
}

/**
Expand All @@ -334,7 +343,7 @@ public function getCacheDir()
*/
public function getLogDir()
{
return $this->rootDir.'/logs';
return $this->getRootDir().'/logs';
}

/**
Expand All @@ -345,7 +354,6 @@ public function getLogDir()
* @throws \LogicException if two bundles share a common name
* @throws \LogicException if a bundle tries to extend a non-registered bundle
* @throws \LogicException if two bundles extend the same ancestor
*
*/
protected function initializeBundles()
{
Expand Down Expand Up @@ -396,6 +404,12 @@ protected function initializeBundles()

}

/**
* Initializes the DI container
*
* The cached version of the DI container is used when fresh, otherwise the
* container is built.
*/
protected function initializeContainer()
{
$class = $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
Expand All @@ -418,6 +432,11 @@ protected function initializeContainer()
}
}

/**
* Returns the kernel parameters
*
* @return array An array of kernel parameters
*/
protected function getKernelParameters()
{
$bundles = array();
Expand All @@ -427,7 +446,7 @@ protected function getKernelParameters()

return array_merge(
array(
'kernel.root_dir' => $this->rootDir,
'kernel.root_dir' => $this->getRootDir(),
'kernel.environment' => $this->environment,
'kernel.debug' => $this->debug,
'kernel.name' => $this->name,
Expand All @@ -440,6 +459,13 @@ protected function getKernelParameters()
);
}

/**
* Gets the environment parameters
*
* Only the parameters starting with "SYMFONY__" are considered
*
* @return array An array of parameters
*/
protected function getEnvParameters()
{
$parameters = array();
Expand All @@ -452,6 +478,11 @@ protected function getEnvParameters()
return $parameters;
}

/**
* Builds the DI container
*
* @return ContainerBuilder The compiled DI container
*/
protected function buildContainer()
{
$parameterBag = new ParameterBag($this->getKernelParameters());
Expand All @@ -474,6 +505,13 @@ protected function buildContainer()
return $container;
}

/**
* Dumps the DI container to PHP code in the cache
*
* @param ConfigCache $cache The config cache
* @param ContainerBuilder $container The DI container
* @param string $class The name of the class to generate
*/
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class)
{
foreach (array('cache', 'logs') as $name) {
Expand All @@ -497,6 +535,12 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
$cache->write($content, $container->getResources());
}

/**
* Returns a loader for the container
*
* @param ContainerInterface $container The DI container
* @return DelegatingLoader The loader
*/
protected function getContainerLoader(ContainerInterface $container)
{
$resolver = new LoaderResolver(array(
Expand Down
20 changes: 8 additions & 12 deletions src/Symfony/Component/HttpKernel/KernelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
*/
interface KernelInterface extends HttpKernelInterface, \Serializable
{
/**
* Returns the root directory of this application.
*
* Most of the time, this is just __DIR__.
*
* @return string A directory path
*/
function registerRootDir();

/**
* Returns an array of bundles to registers.
*
Expand Down Expand Up @@ -77,12 +68,12 @@ function getBundles();
function isClassInActiveBundle($class);

/**
* Returns a bundle by its name.
* Returns a bundle and optionally its descendants by its name.
*
* @param string $name Bundle name
* @param Boolean $first Whether to return the first bundle or all bundles matching this name
* @param Boolean $first Whether to return the first bundle only or together with its descendants
*
* @return BundleInterface A BundleInterface instance
* @return BundleInterface|Array A BundleInterface instance or an array of BundleInterface instances if $first is false
*
* @throws \InvalidArgumentException when the bundle is not enabled
*/
Expand Down Expand Up @@ -116,6 +107,11 @@ function getBundle($name, $first = true);
*/
function locateResource($name, $dir = null, $first = true);

/**
* Gets the name of the kernel
*
* @return string The kernel name
*/
function getName();

/**
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy