mirror of
https://github.com/filp/whoops.git
synced 2026-09-11 18:26:22 +00:00
allow to change the application root path
This commit is contained in:
@@ -97,6 +97,11 @@ class PrettyPageHandler extends Handler
|
||||
"idea" => "idea://open?file=%file&line=%line",
|
||||
];
|
||||
|
||||
/**
|
||||
* @var TemplateHelper
|
||||
*/
|
||||
private $templateHelper;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
@@ -114,6 +119,27 @@ class PrettyPageHandler extends Handler
|
||||
|
||||
// blacklist php provided auth based values
|
||||
$this->blacklist('_SERVER', 'PHP_AUTH_PW');
|
||||
|
||||
$this->templateHelper = new TemplateHelper();
|
||||
|
||||
if (class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) {
|
||||
$cloner = new VarCloner();
|
||||
// Only dump object internals if a custom caster exists.
|
||||
$cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) {
|
||||
$class = $stub->class;
|
||||
$classes = [$class => $class] + class_parents($class) + class_implements($class);
|
||||
|
||||
foreach ($classes as $class) {
|
||||
if (isset(AbstractCloner::$defaultCasters[$class])) {
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all internals
|
||||
return [];
|
||||
}]);
|
||||
$this->templateHelper->setCloner($cloner);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,28 +164,6 @@ class PrettyPageHandler extends Handler
|
||||
}
|
||||
}
|
||||
|
||||
// @todo: Make this more dynamic
|
||||
$helper = new TemplateHelper();
|
||||
|
||||
if (class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) {
|
||||
$cloner = new VarCloner();
|
||||
// Only dump object internals if a custom caster exists.
|
||||
$cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) {
|
||||
$class = $stub->class;
|
||||
$classes = [$class => $class] + class_parents($class) + class_implements($class);
|
||||
|
||||
foreach ($classes as $class) {
|
||||
if (isset(AbstractCloner::$defaultCasters[$class])) {
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all internals
|
||||
return [];
|
||||
}]);
|
||||
$helper->setCloner($cloner);
|
||||
}
|
||||
|
||||
$templateFile = $this->getResource("views/layout.html.php");
|
||||
$cssFile = $this->getResource("css/whoops.base.css");
|
||||
$zeptoFile = $this->getResource("js/zepto.min.js");
|
||||
@@ -256,8 +260,8 @@ class PrettyPageHandler extends Handler
|
||||
$plainTextHandler->setInspector($this->getInspector());
|
||||
$vars["preface"] = "<!--\n\n\n" . $plainTextHandler->generateResponse() . "\n\n\n\n\n\n\n\n\n\n\n-->";
|
||||
|
||||
$helper->setVariables($vars);
|
||||
$helper->render($templateFile);
|
||||
$this->templateHelper->setVariables($vars);
|
||||
$this->templateHelper->render($templateFile);
|
||||
|
||||
return Handler::QUIT;
|
||||
}
|
||||
@@ -630,6 +634,16 @@ class PrettyPageHandler extends Handler
|
||||
$this->applicationPaths = $applicationPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the application root path.
|
||||
*
|
||||
* @param string $applicationRootPath
|
||||
*/
|
||||
public function setApplicationRootPath($applicationRootPath)
|
||||
{
|
||||
$this->templateHelper->setApplicationRootPath($applicationRootPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* blacklist a sensitive value within one of the superglobal arrays.
|
||||
*
|
||||
|
||||
@@ -38,6 +38,17 @@ class TemplateHelper
|
||||
*/
|
||||
private $cloner;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $applicationRootPath;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// root path for ordinary composer projects
|
||||
$this->applicationRootPath = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a string for output in an HTML document
|
||||
*
|
||||
@@ -61,7 +72,7 @@ class TemplateHelper
|
||||
}
|
||||
|
||||
$raw = str_replace(chr(9), ' ', $raw);
|
||||
|
||||
|
||||
return htmlspecialchars($raw, $flags, "UTF-8");
|
||||
}
|
||||
|
||||
@@ -106,9 +117,8 @@ class TemplateHelper
|
||||
*/
|
||||
public function shorten($path)
|
||||
{
|
||||
$dirname = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
|
||||
if ($dirname != "/") {
|
||||
$path = str_replace($dirname, '…', $path);
|
||||
if ($this->applicationRootPath != "/") {
|
||||
$path = str_replace($this->applicationRootPath, '…', $path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
@@ -318,4 +328,24 @@ class TemplateHelper
|
||||
}
|
||||
return $this->cloner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the application root path.
|
||||
*
|
||||
* @param string $applicationRootPath
|
||||
*/
|
||||
public function setApplicationRootPath($applicationRootPath)
|
||||
{
|
||||
$this->applicationRootPath = $applicationRootPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the application root path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApplicationRootPath()
|
||||
{
|
||||
return $this->applicationRootPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,19 @@ class TemplateHelperTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Util\TemplateHelper::shorten
|
||||
*/
|
||||
public function testShorten()
|
||||
{
|
||||
$path = '/foo/bar/baz/abc.def';
|
||||
|
||||
$this->assertSame($path, $this->helper->shorten($path));
|
||||
|
||||
$this->helper->setApplicationRootPath('/foo/bar');
|
||||
$this->assertSame('…/baz/abc.def', $this->helper->shorten($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Util\TemplateHelper::slug
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user