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

Appearance settings

Commit 1f680cc

Browse filesBrowse files
committed
added Kernel::getProjectDir()
1 parent d662b21 commit 1f680cc
Copy full SHA for 1f680cc

File tree

3 files changed

+30
-2
lines changed
Filter options

3 files changed

+30
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CHANGELOG.md
+2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Kernel.php
+26Lines 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
const VERSION = '3.3.0-DEV';
6365
const VERSION_ID = 30300;
6466
const MAJOR_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+
public function getProjectDir()
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
return array_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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/KernelInterface.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ public function getEnvironment();
121121
public function isDebug();
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 The application root dir
126+
* @return string The Kernel root dir
127127
*/
128128
public function getRootDir();
129129

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.