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 ?
: Formatter
::factory();
38 * Lookup the repo containing a ref entry
39 * @param string $entry requested reference entry, e.g. "pq/Connection/exec"
40 * @param string $canonical
41 * @return \mdref\Repo|NULL
43 public function getRepoForEntry(string $entry, string &$canonical = null) : ?Repo
{
44 foreach ($this->repos
as $repo) {
45 /** @var $repo Repo */
46 if ($repo->hasEntry($entry, $canonical)) {
54 * Implements IteratorAggregate
55 * @return ArrayIterator repository list
57 public function getIterator() : Iterator
{
58 return new ArrayIterator($this->repos
);
62 * @param string $anchor
65 public function formatAnchor(string $anchor) : string {
66 if (is_numeric($anchor)) {
69 return preg_replace("/[^[:alnum:]\.:_]/", ".", $anchor);
73 * @param string $string
75 * @throws \Exception, Exception
77 public function formatString(string $string) : string {
78 return $this->fmt
->formatString($string);
84 * @throws \Exception, Exception
86 public function formatFile(string $file) : string {
87 return $this->fmt
->formatFile($file);