8000 added KernelInterface · alexfilatov/symfony@fb4e7fb · GitHub
[go: up one dir, main page]

Skip to content

Commit fb4e7fb

Browse files
committed
added KernelInterface
1 parent 935c82e commit fb4e7fb

File tree

5 files changed

+291
-57
lines changed

5 files changed

+291
-57
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
* @author Fabien Potencier <fabien.potencier@symfony-project.org>
3737
*/
38-
abstract class Kernel implements HttpKernelInterface, \Serializable
38+
abstract class Kernel implements KernelInterface
3939
{
4040
protected $bundles;
4141
protected $bundleMap;
@@ -61,7 +61,7 @@ public function __construct($environment, $debug)
6161
$this->debug = (Boolean) $debug;
6262
$this->booted = false;
6363
$this->rootDir = realpath($this->registerRootDir());
64-
$this->name = basename($this->rootDir);
64+
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
6565

6666
if ($this->debug) {
6767
ini_set('display_errors', 1);
@@ -83,29 +83,6 @@ public function __clone()
8383
$this->container = null;
8484
}
8585

86-
/**
87-
* Returns the root directory of this application.
88-
*
89-
* Most of the time, this is just __DIR__.
90-
*
91-
* @return string A directory path
92-
*/
93-
abstract public function registerRootDir();
94-
95-
/**
96-
* Returns an array of bundles to registers.
97-
*
98-
* @return array An array of bundle instances.
99-
*/
100-
abstract public function registerBundles();
101-
102-
/**
103-
* Loads the container configuration
104-
*
105-
* @param LoaderInterface $loader A LoaderInterface instance
106-
*/
107-
abstract public function registerContainerConfiguration(LoaderInterface $loader);
108-
10986
/**
11087
* Boots the current kernel.
11188
*
@@ -308,11 +285,6 @@ public function getName()
308285
return $this->name;
309286
}
310287

311-
public function getSafeName()
312-
{
313-
return preg_replace('/[^a-zA-Z0-9_]+/', '', $this->name);
314-
}
315-
316288
/**
317289
* Gets the environment.
318290
*
@@ -421,7 +393,7 @@ protected function initializeBundles()
421393

422394
protected function initializeContainer()
423395
{
424-
$class = $this->getSafeName().ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
396+
$class = $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
425397
$location = $this->getCacheDir().'/'.$class;
426398
$reload = $this->debug ? $this->needsReload($class, $location) : false;
427399

@@ -443,7 +415,7 @@ protected function initializeContainer()
443415
}
444416
}
445417

446-
public function getKernelParameters()
418+
protected function getKernelParameters()
447419
{
448420
$bundles = array();
449421
foreach ($this->bundles as $name => $bundle) {
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel;
13+
14+
use Symfony\Component\DependencyInjection\ContainerInterface;
15+
use Symfony\Component\DependencyInjection\Loader\LoaderInterface;
16+
use Symfony\Component\HttpKernel\HttpKernelInterface;
17+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
18+
19+
/**
20+
* The Kernel is the heart of the Symfony system.
21+
*
22+
* It manages an environment made of bundles.
23+
*
24+
* @author Fabien Potencier <fabien.potencier@symfony-project.org>
25+
*/
26+
interface KernelInterface extends HttpKernelInterface, \Serializable
27+
{
28+
/**
29+
* Returns the root directory of this application.
30+
*
31+
* Most of the time, this is just __DIR__.
32+
*
33+
* @return string A directory path
34+
*/
35+
function registerRootDir();
36+
37+
/**
38+
* Returns an array of bundles to registers.
39+
*
40+
* @return array An array of bundle instances.
41+
*/
42+
function registerBundles();
43+
44+
/**
45+
* Loads the container configuration
46+
*
47+
* @param LoaderInterface $loader A LoaderInterface instance
48+
*/
49+
function registerContainerConfiguration(LoaderInterface $loader);
50+
51+
/**
52+
* Boots the current kernel.
53+
*
54+
* This method boots the bundles, which MUST set
55+
* the DI container.
56+
*
57+
* @throws \LogicException When the Kernel is already booted
58+
*/
59+
function boot();
60+
61+
/**
62+
* Shutdowns the kernel.
63+
*
64+
* This method is mainly useful when doing functional testing.
65+
*/
66+
function shutdown();
67+
68+
/**
69+
* Reboots the kernel.
70+
*
71+
* This method is mainly useful when doing functional testing.
72+
*
73+
* It is a shortcut for the call to shutdown() and boot().
74+
*/
75+
function reboot();
76+
77+
/**
78+
* Gets the registered bundle instances.
79+
*
80+
* @return array An array of registered bundle instances
81+
*/
82+
function getBundles();
83+
84+
/**
85+
* Checks if a given class name belongs to an active bundle.
86+
*
87+
* @param string $class A class name
88+
*
89+
* @return Boolean true if the class belongs to an active bundle, false otherwise
90+
*/
91+
function isClassInActiveBundle($class);
92+
93+
/**
94+
* Returns a bundle by its name.
95+
*
96+
* @param string $name Bundle name
97+
* @param Boolean $first Whether to return the first bundle or all bundles matching this name
98+
*
99+
* @return BundleInterface A BundleInterface instance
100+
*
101+
* @throws \InvalidArgumentException when the bundle is not enabled
102+
*/
103+
function getBundle($name, $first = true);
104+
105+
/**
106+
* Returns the file path for a given resource.
107+
*
108+
* A Resource can be a file or a directory.
109+
*
110+
* The resource name must follow the following pattern:
111+
*
112+
* @BundleName/path/to/a/file.something
113+
*
114+
* where BundleName is the name of the bundle
115+
* and the remaining part is the relative path in the bundle.
116+
*
117+
* If $dir is passed, and the first segment of the path is Resources,
118+
* this method will look for a file named:
119+
*
120+
* $dir/BundleName/path/without/Resources
121+
*
122+
* @param string $name A resource name to locate
123+
* @param string $dir A directory where to look for the resource first
124+
* @param Boolean $first Whether to return the first path or paths for all matching bundles
125+
*
126+
* @return string|array The absolute path of the resource or an array if $first is false
127+
*
128+
* @throws \InvalidArgumentException if the file cannot be found or the name is not valid
129+
* @throws \RuntimeException if the name contains invalid/unsafe characters
130+
*/
131+
function locateResource($name, $dir = null, $first = true);
132+
133+
function getName();
134+
135+
/**
136+
* Gets the environment.
137+
*
138+
* @return string The current environment
139+
*/
140+
function getEnvironment();
141+
142+
/**
143+
* Checks if debug mode is enabled.
144+
*
145+
* @return Boolean true if debug mode is enabled, false otherwise
146+
*/
147+
function isDebug();
148+
149+
/**
150+
* Gets the application root dir.
151+
*
152+
* @return string The application root dir
153+
*/
154+
function getRootDir();
155+
156+
/**
157+
* Gets the current container.
158+
*
159+
* @return ContainerInterface A ContainerInterface instance
160+
*/
161+
function getContainer();
162+
163+
/**
164+
* Gets the request start time (not available if debug is disabled).
165+
*
166+
* @return integer The request start timestamp
167+
*/
168+
function getStartTime();
169+
170+
/**
171+
* Gets the cache directory.
172+
*
173+
* @return string The cache directory
174+
*/
175+
function getCacheDir();
176+
177+
/**
178+
* Gets the log directory.
179+
*
180+
* @return string The log directory
181+
*/
182+
function getLogDir();
183+
}

src/Symfony/Component/HttpKernel/Resources/bin/packager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
'Symfony\\Component\\HttpKernel\\Debug\\ErrorHandler',
3737
'Symfony\\Component\\HttpKernel\\ClassCollectionLoader',
3838
'Symfony\\Component\\HttpKernel\\HttpKernelInterface',
39+
'Symfony\\Component\\HttpKernel\\HttpKernel',
40+
'Symfony\\Component\\HttpKernel\\KernelInterface',
3941
'Symfony\\Component\\HttpKernel\\Kernel',
4042

4143
'Symfony\\Component\\HttpFoundation\\ParameterBag',

0 commit comments

Comments
 (0)
0