6 * The complete available reference
8 class Reference
implements \IteratorAggregate
{
10 * List of mdref repositories
13 private $repos = array();
16 * @param array $refs list of mdref repository paths
18 public function __construct(array $refs) {
19 foreach ($refs as $path) {
20 $repo = new Repo($path);
21 $this->repos
[$repo->getName()] = $repo;
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
31 public function getRepoForEntry($entry, &$canonical = null) {
32 foreach ($this->repos
as $repo) {
33 /** @var $repo Repo */
34 if ($repo->hasEntry($entry, $canonical)) {
41 * Implements \IteratorAggregate
42 * @return \ArrayIterator repository list
44 public function getIterator() {
45 return new \
ArrayIterator($this->repos
);
48 public function formatAnchor($anchor) {
49 if (is_numeric($anchor)) {
52 return preg_replace("/[^[:alnum:]\.:_]/", ".", $anchor);
55 public function formatString($string) {
56 if (extension_loaded("discount")) {
57 $md = \MarkdownDocument
::createFromString($string);
58 $md->compile(\MarkdownDocument
::AUTOLINK
);
59 return $md->getHtml();
61 if (extension_loaded("cmark")) {
62 $node = \CommonMark\
Parse($string);
63 return \CommonMark\Render\
HTML($node);
65 throw new \
Exception("No Markdown implementation found");
68 public function formatFile($file) {
69 if (extension_loaded("discount")) {
70 $fd = fopen($file, "r");
71 $md = \MarkdownDocument
::createFromStream($fd);
72 $md->compile(\MarkdownDocument
::AUTOLINK | \MarkdownDocument
::TOC
);
73 $html = $md->getHtml();
77 if (extension_loaded("cmark")) {
78 $node = \CommonMark\
Parse(file_get_contents($file));
79 return \CommonMark\Render\
HTML($node);
81 throw new \
Exception("No Markdown implementation found");