-
-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:phpDocumentor/phpDocumentor2 int…
…o develop
- Loading branch information
Showing
20 changed files
with
402 additions
and
142 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
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
77 changes: 77 additions & 0 deletions
77
src/phpDocumentor/Plugin/Core/Transformer/Writer/Pathfinder.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,77 @@ | ||
<?php | ||
|
||
namespace phpDocumentor\Plugin\Core\Transformer\Writer; | ||
|
||
class Pathfinder | ||
{ | ||
/** | ||
* Combines the query and an object to retrieve a list of nodes that are to be used as node-point in a template. | ||
* | ||
* This method interprets the provided query string and walks through the given object to find the correct | ||
* element. This method will silently fail if an invalid query was provided; in such a case the given object | ||
* is returned. | ||
* | ||
* @param object $object | ||
* @param string $query | ||
* | ||
* @return \Traversable|mixed[] | ||
*/ | ||
public function find($object, $query) | ||
{ | ||
if ($query) { | ||
$node = $this->walkObjectTree($object, $query); | ||
|
||
if (!is_array($node) && (!$node instanceof \Traversable)) { | ||
$node = array($node); | ||
} | ||
|
||
return $node; | ||
} | ||
|
||
return array($object); | ||
} | ||
|
||
/** | ||
* Walks an object graph and/or array using a twig query string. | ||
* | ||
* @param \Traversable|mixed $objectOrArray | ||
* @param string $query A path to walk separated by dots, i.e. `namespace.namespaces`. | ||
* | ||
* @return mixed | ||
*/ | ||
private function walkObjectTree($objectOrArray, $query) | ||
{ | ||
$node = $objectOrArray; | ||
$objectPath = explode('.', $query); | ||
|
||
// walk through the tree | ||
foreach ($objectPath as $pathNode) { | ||
if (is_array($node)) { | ||
if (isset($node[$pathNode])) { | ||
$node = $node[$pathNode]; | ||
continue; | ||
} | ||
} elseif (is_object($node)) { | ||
if (isset($node->$pathNode) || (method_exists($node, '__get') && $node->$pathNode)) { | ||
$node = $node->$pathNode; | ||
continue; | ||
} elseif (method_exists($node, $pathNode)) { | ||
$node = $node->$pathNode(); | ||
continue; | ||
} elseif (method_exists($node, 'get' . $pathNode)) { | ||
$pathNode = 'get' . $pathNode; | ||
$node = $node->$pathNode(); | ||
continue; | ||
} elseif (method_exists($node, 'is' . $pathNode)) { | ||
$pathNode = 'is' . $pathNode; | ||
$node = $node->$pathNode(); | ||
continue; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return $node; | ||
} | ||
} |
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
Oops, something went wrong.