4197de1afa015c8aa6d14beefd81af125018ec69
8 use function is_numeric
;
9 use function preg_replace
;
12 * The complete available reference
14 class Reference
implements IteratorAggregate
{
16 * List of mdref repositories
19 private $repos = array();
27 * @param array $refs list of mdref repository paths
29 public function __construct(array $refs, Formatter
$fmt = null) {
30 foreach ($refs as $path) {
31 $repo = new Repo($path);
32 $this->repos
[$repo->getName()] = $repo;
34 $this->fmt
= $fmt ?
: new Formatter
;
41 public function getFormatter() : Formatter
{
46 * Lookup the repo containing a ref entry
47 * @param string $entry requested reference entry, e.g. "pq/Connection/exec"
48 * @param string $canonical
49 * @return \mdref\Repo|NULL
51 public function getRepoForEntry(string $entry, string &$canonical = null) : ?Repo
{
52 foreach ($this->repos
as $repo) {
53 /** @var $repo Repo */
54 if ($repo->hasEntry($entry, $canonical)) {
62 * Implements IteratorAggregate
63 * @return ArrayIterator repository list
65 public function getIterator() : Iterator
{
66 return new ArrayIterator($this->repos
);
70 * @param string $anchor
73 public function formatAnchor(string $anchor, string $location = null) : string {
74 if (is_numeric($anchor)) {
77 return preg_replace("/[^[:alnum:]\.:_]/", ".", $anchor);
81 * @param string $string
83 * @throws \Exception, Exception
85 public function formatString(string $string, string $location = null) : string {
86 return $this->fmt
->formatString($string, $location);
92 * @throws \Exception, Exception
94 public function formatFile(string $file, string $location = null) : string {
95 return $this->fmt
->formatFile($file, $location);