mirror of
https://github.com/filp/whoops.git
synced 2026-09-15 20:26:44 +00:00
Changed: getEditorHref() no longer return an array or ajax/url, replaced by getEditorAjax() instead.
This commit is contained in:
@@ -8,6 +8,7 @@ namespace Whoops\Handler;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use UnexpectedValueException;
|
||||
use Whoops\Exception\Formatter;
|
||||
use Whoops\Util\Misc;
|
||||
use Whoops\Util\TemplateHelper;
|
||||
@@ -317,7 +318,7 @@ class PrettyPageHandler extends Handler
|
||||
* @throws InvalidArgumentException If editor resolver does not return a string
|
||||
* @param string $filePath
|
||||
* @param int $line
|
||||
* @return false|string|array
|
||||
* @return false|string
|
||||
*/
|
||||
public function getEditorHref($filePath, $line)
|
||||
{
|
||||
@@ -342,26 +343,45 @@ class PrettyPageHandler extends Handler
|
||||
);
|
||||
}
|
||||
|
||||
if (is_array($editor) && (!isset($editor['ajax']) || !is_bool($editor['ajax']))) {
|
||||
throw new InvalidArgumentException(
|
||||
$editor = str_replace("%line", rawurlencode($line), (is_string($editor) ? $editor : $editor['url']));
|
||||
$editor = str_replace("%file", rawurlencode($filePath), (is_string($editor) ? $editor : $editor['url']));
|
||||
|
||||
return $editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a boolean if the editor link should
|
||||
* act as an Ajax request. The editor must be a
|
||||
* valid callable function/closure
|
||||
*
|
||||
* @throws UnexpectedValueException If editor resolver does not return a boolean
|
||||
* @param string $filePath
|
||||
* @param int $line
|
||||
* @return bool
|
||||
*/
|
||||
public function getEditorAjax($filePath, $line)
|
||||
{
|
||||
if ($this->editor === null || !is_callable($this->editor)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$editor = $this->editor;
|
||||
|
||||
$editor = call_user_func($editor, $filePath, $line);
|
||||
|
||||
// Check that the editor is a string or a valid array, and replace the
|
||||
// %line and %file placeholders:
|
||||
if (!isset($editor['ajax']) || !is_bool($editor['ajax'])) {
|
||||
throw new UnexpectedValueException(
|
||||
__METHOD__ . " was unable to resolve ajax option; got something else instead"
|
||||
);
|
||||
}
|
||||
|
||||
if(is_string($editor))
|
||||
{
|
||||
$editor = str_replace("%line", rawurlencode($line), $editor);
|
||||
$editor = str_replace("%file", rawurlencode($filePath), $editor);
|
||||
}
|
||||
else
|
||||
{
|
||||
$editor['url'] = str_replace("%line", rawurlencode($line), $editor['url']);
|
||||
$editor['url'] = str_replace("%file", rawurlencode($filePath), $editor['url']);
|
||||
}
|
||||
|
||||
return $editor;
|
||||
return $editor['ajax'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return void
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<?php $filePath = $frame->getFile(); ?>
|
||||
<?php if ($filePath && $editorHref = $handler->getEditorHref($filePath, (int) $line)): ?>
|
||||
Open:
|
||||
<a href="<?php echo (is_array($editorHref) ? $editorHref['url'] : $editorHref) ?>" class="editor-link"<?php echo (is_array($editorHref) && $editorHref['ajax'] ? ' data-ajax' : '') ?>>
|
||||
<a href="<?php echo $editorHref ?>" class="editor-link"<?php echo ($handler->getEditorAjax($filePath, (int) $line) ? ' data-ajax' : '') ?>>
|
||||
<strong><?php echo $tpl->escape($filePath ?: '<#unknown>') ?></strong>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
|
||||
@@ -209,6 +209,7 @@ class PrettyPageHandlerTest extends TestCase
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::setEditor
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getEditorHref
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getEditorAjax
|
||||
*/
|
||||
public function testSetEditorCallable()
|
||||
{
|
||||
@@ -238,12 +239,15 @@ class PrettyPageHandlerTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorHref('/foo/bar.php', 10),
|
||||
array(
|
||||
'url' => 'http://google.com/search/?q=%2Ffoo%2Fbar.php:10',
|
||||
'ajax' => true
|
||||
)
|
||||
'http://google.com/search/?q=%2Ffoo%2Fbar.php:10'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorAjax('/foo/bar.php', 10),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
$handler->setEditor(function ($file, $line) {
|
||||
$file = rawurlencode($file);
|
||||
$line = rawurlencode($line);
|
||||
@@ -255,12 +259,13 @@ class PrettyPageHandlerTest extends TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorHref('/foo/bar.php', 10),
|
||||
array(
|
||||
'url' => 'http://google.com/search/?q=%2Ffoo%2Fbar.php:10',
|
||||
'ajax' => false
|
||||
)
|
||||
'http://google.com/search/?q=%2Ffoo%2Fbar.php:10'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorAjax('/foo/bar.php', 10),
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user