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 if ("." !== ($dirn = dirname($this->name
))) {
157 return $this->repo
->getEntry($dirn);
162 * Get the list of parents up-down
165 public function getParents() {
167 for ($parent = $this->getParent(); $parent; $parent = $parent->getParent()) {
168 array_unshift($parents, $parent);
174 * Guess whether this ref entry is about a function or method
177 public function isFunction() {
178 $base = end($this->list);
179 return $base{0} === "_" ||
ctype_lower($base{0});
183 * Guess whether this ref entry is about a namespace, interface or class
186 public function isNsClass() {
187 $base = end($this->list);
188 return ctype_upper($base{0});
195 public function __toString() {
196 $parts = explode("/", trim($this->getName(), "/"));
197 $myself = array_pop($parts);
201 $parent = end($parts);
203 switch ($myself{0}) {
205 return "★" . substr($myself, 1);
208 if (!ctype_lower($myself{0}) ||
ctype_lower($parent{0})) {
212 return $parent . "::" . $myself;
217 * Get the base name of this ref entry
220 public function getBasename() {
221 return dirname($this->path
) . "/" . basename($this->path
, ".md");
225 * Guess whether there are any child nodes
226 * @param string $glob
229 function hasIterator($glob = null, $loose = false) {
231 return glob($this->getBasename() . "/$glob") ||
232 ($loose && glob($this->getBasename() . "/*/$glob"));
233 } elseif ($this->isRoot()) {
236 return is_dir($this->getBasename());
241 * Guess whether there are namespace/interface/class child nodes
244 function hasNsClasses() {
245 return $this->hasIterator("/[A-Z]*.md", true);
249 * Guess whether there are function/method child nodes
252 function hasFunctions() {
253 return $this->hasIterator("/[a-z_]*.md");
257 * Implements \IteratorAggregate
258 * @return \mdref\Tree child nodes
260 function getIterator() {
261 return new Tree($this->getBasename(), $this->repo
);