Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f680cc

Browse files
committed
added Kernel::getProjectDir()
1 parentd662b21 commit1f680cc

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

‎src/Symfony/Component/HttpKernel/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
3.3.0
55
-----
66

7+
* Added`kernel.project_dir` and`Kernel::getProjectDir()`
8+
* Deprecated`kernel.root_dir` and`Kernel::getRootDir()`
79
* Deprecated`Kernel::getEnvParameters()`
810
* Deprecated the special`SYMFONY__` environment variables
911
* added the possibility to change the query string parameter used by`UriSigner`

‎src/Symfony/Component/HttpKernel/Kernel.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ abstract class Kernel implements KernelInterface, TerminableInterface
5959
protected$startTime;
6060
protected$loadClassCache;
6161

62+
private$projectDir;
63+
6264
constVERSION ='3.3.0-DEV';
6365
constVERSION_ID =30300;
6466
constMAJOR_VERSION =3;
@@ -80,6 +82,7 @@ public function __construct($environment, $debug)
8082
$this->environment =$environment;
8183
$this->debug = (bool)$debug;
8284
$this->rootDir =$this->getRootDir();
85+
$this->projectDir =$this->getProjectDir();
8386
$this->name =$this->getName();
8487

8588
if ($this->debug) {
@@ -306,6 +309,28 @@ public function getRootDir()
306309
return$this->rootDir;
307310
}
308311

312+
/**
313+
* Gets the application root dir (path of the project's composer file).
314+
*
315+
* @return string The project root dir
316+
*/
317+
publicfunctiongetProjectDir()
318+
{
319+
if (null ===$this->projectDir) {
320+
$r =new \ReflectionObject($this);
321+
$dir =$rootDir =dirname($r->getFileName());
322+
while (!file_exists($dir.'/composer.json')) {
323+
if ($dir ===dirname($dir)) {
324+
return$this->projectDir =$rootDir;
325+
}
326+
$dir =dirname($dir);
327+
}
328+
$this->projectDir =$dir;
329+
}
330+
331+
return$this->projectDir;
332+
}
333+
309334
/**
310335
* {@inheritdoc}
311336
*/
@@ -553,6 +578,7 @@ protected function getKernelParameters()
553578
returnarray_merge(
554579
array(
555580
'kernel.root_dir' =>realpath($this->rootDir) ?:$this->rootDir,
581+
'kernel.project_dir' =>realpath($this->projectDir) ?:$this->projectDir,
556582
'kernel.environment' =>$this->environment,
557583
'kernel.debug' =>$this->debug,
558584
'kernel.name' =>$this->name,

‎src/Symfony/Component/HttpKernel/KernelInterface.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ public function getEnvironment();
121121
publicfunctionisDebug();
122122

123123
/**
124-
* Gets the application root dir.
124+
* Gets the application root dir (path of the project's Kernel class).
125125
*
126-
* @return string Theapplication root dir
126+
* @return string TheKernel root dir
127127
*/
128128
publicfunctiongetRootDir();
129129

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp