6 * A single reference entry
8 class Entry
implements \IteratorAggregate
{
22 * The containing repository
28 * The file path, if the refentry exists
34 * The file instance of this entry
40 * @param string $name the compound name of the ref entry, e.g. "pq/Connection/exec"
41 * @param \mdref\Repo $repo the containing repository
43 public function __construct($name, Repo
$repo) {
46 $this->list = explode("/", $name);
47 $this->path
= $repo->hasEntry($name);
51 * Get the compound name, e.g. "pq/Connection/exec"
54 public function getName() {
59 * Get the containing repository
62 public function getRepo() {
67 * Get the file path, if any
70 public function getPath() {
75 * Get the file instance of this entry
78 public function getFile() {
80 $this->file
= new File($this->path
);
89 public function getEditUrl() {
90 return $this->repo
->getEditUrl($this->name
);
94 * Read the title of the ref entry file
97 public function getTitle() {
98 if ($this->isFile()) {
99 return $this->getFile()->readTitle();
101 if ($this->isRoot()) {
102 return $this->repo
->getRootEntry()->getTitle();
108 * Read the description of the ref entry file
111 public function getDescription() {
112 if ($this->isFile()) {
113 return $this->getFile()->readDescription();
115 if ($this->isRoot()) {
116 return $this->repo
->getRootEntry()->getDescription();
122 * Read the intriductory section of the refentry file
125 public function getIntro() {
126 if ($this->isFile()) {
127 return $this->getFile()->readIntro();
129 if ($this->isRoot()) {
130 return $this->repo
->getRootEntry()->getIntro();
136 * Check if the refentry exists
139 public function isFile() {
140 return strlen($this->path
) > 0;
144 * Check if this is the first entry of the reference tree
147 public function isRoot() {
148 return count($this->list) === 1;
152 * Get the parent ref entry
153 * @return \mdref\Entry
155 public function getParent() {
156 switch ($dirn = dirname($this->name
)) {
161 return $this->repo
->getEntry($dirn);
166 * Get the list of parents up-down
169 public function getParents() {
171 for ($parent = $this->getParent(); $parent; $parent = $parent->getParent()) {
172 array_unshift($parents, $parent);
178 * Guess whether this ref entry is about a function or method
181 public function isFunction() {
182 $base = end($this->list);
183 return $base{0} === "_" ||
ctype_lower($base{0});
187 * Guess whether this ref entry is about a namespace, interface or class
190 public function isNsClass() {
191 $base = end($this->list);
192 return ctype_upper($base{0});
199 public function __toString() {
200 $parts = explode("/", trim($this->getName(), "/"));
201 $myself = array_pop($parts);
205 $parent = end($parts);
207 switch ($myself{0}) {
209 return "★" . substr($myself, 1);
212 if (!ctype_lower($myself{0}) ||
ctype_lower($parent{0})) {
216 return $parent . "::" . $myself;
221 * Get the base name of this ref entry
224 public function getBasename() {
225 return dirname($this->path
) . "/" . basename($this->path
, ".md");
229 * Guess whether there are any child nodes
230 * @param string $glob
233 function hasIterator($glob = null, $loose = false) {
235 return glob($this->getBasename() . "/$glob") ||
236 ($loose && glob($this->getBasename() . "/*/$glob"));
237 } elseif ($this->isRoot()) {
240 return is_dir($this->getBasename());
245 * Guess whether there are namespace/interface/class child nodes
248 function hasNsClasses() {
249 return $this->hasIterator("/[A-Z]*.md", true);
253 * Guess whether there are function/method child nodes
256 function hasFunctions() {
257 return $this->hasIterator("/[a-z_]*.md");
261 * Implements \IteratorAggregate
262 * @return \mdref\Tree child nodes
264 function getIterator() {
265 return new Tree($this->getBasename(), $this->repo
);