legacy
[mdref/mdref] / mdref / Reference.php
1 <?php
2
3 namespace mdref;
4
5 /**
6 * The complete available reference
7 */
8 class Reference implements \IteratorAggregate {
9 /**
10 * List of mdref repositories
11 * @var array
12 */
13 private $repos = array();
14
15 /**
16 * @param array $refs list of mdref repository paths
17 */
18 public function __construct(array $refs) {
19 foreach ($refs as $path) {
20 $repo = new Repo($path);
21 $this->repos[$repo->getName()] = $repo;
22 }
23 }
24
25 /**
26 * Lookup the repo containing a ref entry
27 * @param string $entry requested reference entry, e.g. "pq/Connection/exec"
28 * @param type $canonical
29 * @return \mdref\Repo|NULL
30 */
31 public function getRepoForEntry($entry, &$canonical = null) {
32 foreach ($this->repos as $repo) {
33 if ($repo->hasEntry($entry, $canonical)) {
34 return $repo;
35 }
36 }
37 }
38
39 /**
40 * Implements \IteratorAggregate
41 * @return \ArrayIterator repository list
42 */
43 public function getIterator() {
44 return new \ArrayIterator($this->repos);
45 }
46
47 public function formatString($string) {
48 $md = \MarkdownDocument::createFromString($string);
49 $md->compile(\MarkdownDocument::AUTOLINK);
50 return $md->getHtml();
51 }
52
53 public function formatFile($file) {
54 $fd = fopen($file, "r");
55 $md = \MarkdownDocument::createFromStream($fd);
56 $md->compile(\MarkdownDocument::AUTOLINK | \MarkdownDocument::TOC);
57 $html = $md->getHtml();
58 fclose($fd);
59 return $html;
60 }
61 }