Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #19826 [VarDumper] Add ClassStub for clickable & shorter PHP …
…identifiers (nicolas-grekas) This PR was merged into the 3.2-dev branch. Discussion ---------- [VarDumper] Add ClassStub for clickable & shorter PHP identifiers | Q | A | ------------- | --- | Branch? | master | New feature? | yes | Tests pass? | yes | License | MIT | Doc PR | symfony/symfony-docs#6946 Tells dumpers when PHP identifiers are used so that they can shorten the namespace and create IDE links to the source. ![capture du 2016-09-02 17-07-06](https://cloud.githubusercontent.com/assets/243674/18208461/df2c9684-712f-11e6-9fea-de13e21f86c3.png) (PR also embeds some fixes/cleanups) Commits ------- 788f7e8 [VarDumper] Add ClassStub for clickable & shorter PHP identifiers
- Loading branch information
Showing
13 changed files
with
175 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\VarDumper\Caster; | ||
|
||
/** | ||
* Represents a PHP class identifier. | ||
* | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
*/ | ||
class ClassStub extends ConstStub | ||
{ | ||
/** | ||
* Constructor. | ||
* | ||
* @param string A PHP identifier, e.g. a class, method, interface, etc. name | ||
* @param callable The callable targeted by the identifier when it is ambiguous or not a real PHP identifier | ||
*/ | ||
public function __construct($identifier, $callable = null) | ||
{ | ||
$this->value = $identifier; | ||
|
||
if (0 < $i = strrpos($identifier, '\\')) { | ||
$this->attr['ellipsis'] = strlen($identifier) - $i; | ||
} | ||
|
||
if (null !== $callable) { | ||
if ($callable instanceof \Closure) { | ||
$r = new \ReflectionFunction($callable); | ||
} elseif (is_object($callable)) { | ||
$r = new \ReflectionMethod($callable, '__invoke'); | ||
} elseif (is_array($callable)) { | ||
$r = new \ReflectionMethod($callable[0], $callable[1]); | ||
} elseif (false !== $i = strpos($callable, '::')) { | ||
$r = new \ReflectionMethod(substr($callable, 0, $i), substr($callable, 2 + $i)); | ||
} else { | ||
$r = new \ReflectionFunction($callable); | ||
} | ||
} elseif (false !== $i = strpos($identifier, '::')) { | ||
$r = new \ReflectionMethod(substr($identifier, 0, $i), substr($identifier, 2 + $i)); | ||
} else { | ||
$r = new \ReflectionClass($identifier); | ||
} | ||
|
||
if ($f = $r->getFileName()) { | ||
$this->attr['file'] = $f; | ||
$this->attr['line'] = $r->getStartLine() - substr_count($r->getDocComment(), "\n"); | ||
} | ||
} | ||
|
||
public static function wrapCallable($callable) | ||
{ | ||
if (is_object($callable) || !is_callable($callable)) { | ||
return $callable; | ||
} | ||
|
||
if (!is_array($callable)) { | ||
$callable = new static($callable); | ||
} elseif (is_string($callable[0])) { | ||
$callable[0] = new static($callable[0]); | ||
} else { | ||
$callable[1] = new static($callable[1], $callable); | ||
} | ||
|
||
return $callable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Symfony/Component/VarDumper/Tests/Fixtures/FooInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\VarDumper\Tests\Fixtures; | ||
|
||
interface FooInterface | ||
{ | ||
/** | ||
* Hello. | ||
*/ | ||
public function foo(); | ||
} |