9 class Repo
implements \IteratorAggregate
{
11 * The name of the repository
17 * The path to the repository
23 * The edit url template
29 * Path to the repository containing the name.mdref file
31 * @throws \InvalidArgumentException
33 public function __construct($path) {
34 if (!($mdref = current(glob("$path/*.mdref")))) {
35 throw new \
InvalidArgumentException(
36 sprintf("Not a reference, could not find '*.mdref': '%s'",
40 $this->path
= realpath($path);
41 $this->name
= basename($mdref, ".mdref");
42 $this->edit
= trim(file_get_contents($mdref));
46 * Get the repository's name
49 public function getName() {
54 * Get the path of the repository or a file in it
58 public function getPath($file = "") {
59 return $this->path
. "/$file";
63 * Get the edit url for a ref entry
64 * @param string $entry
67 public function getEditUrl($entry) {
68 return sprintf($this->edit
, $entry);
72 * Get the file path of an entry in this repo
73 * @param string $entry
74 * @return string file path
76 public function hasEntry($entry, &$canonical = null) {
77 $file = $this->getPath("$entry.md");
81 $file = $this->getPath($this->getName()."/$entry.md");
83 $canonical = $this->getName() . "/" . $entry;
89 * Get the canonical entry name of a file in this repo
91 * @return string entry
93 public function hasFile($file) {
94 if (($file = realpath($file))) {
95 $path = $this->getPath();
96 $plen = strlen($path);
97 if (!strncmp($file, $path, $plen)) {
98 $dirname = dirname(substr($file, $plen));
99 $basename = basename($file, ".md");
101 if ($dirname === ".") {
105 return $dirname . "/". $basename;
111 * Get an Entry instance
112 * @param string $entry
113 * @return \mdref\Entry
114 * @throws \OutOfBoundsException
116 public function getEntry($entry) {
117 return new Entry($entry, $this);
121 * Get the root Entry instance
122 * @return \mdref\Entry
124 public function getRootEntry() {
125 return new Entry($this->name
, $this);
129 * Implements \IteratorAggregate
130 * @return \mdref\Tree
132 public function getIterator() {
133 return new Tree($this->path
, $this);