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
);
86 * Read the title of the ref entry file
89 public function getTitle() {
90 if ($this->isFile()) {
91 return $this->getFile()->readTitle();
93 if ($this->isRoot()) {
94 return $this->repo
->getRootEntry()->getTitle();
100 * Read the description of the ref entry file
103 public function getDescription() {
104 if ($this->isFile()) {
105 return $this->getFile()->readDescription();
107 if ($this->isRoot()) {
108 return $this->repo
->getRootEntry()->getDescription();
114 * Read the intriductory section of the refentry file
117 public function getIntro() {
118 if ($this->isFile()) {
119 return $this->getFile()->readIntro();
121 if ($this->isRoot()) {
122 return $this->repo
->getRootEntry()->getIntro();
128 * Check if the refentry exists
131 public function isFile() {
132 return strlen($this->path
) > 0;
136 * Check if this is the first entry of the reference tree
139 public function isRoot() {
140 return count($this->list) === 1;
144 * Get the parent ref entry
145 * @return \mdref\Entry
147 public function getParent() {
148 if ("." !== ($dirn = dirname($this->name
))) {
149 return $this->repo
->getEntry($dirn);
154 * Get the list of parents up-down
157 public function getParents() {
159 for ($parent = $this->getParent(); $parent; $parent = $parent->getParent()) {
160 array_unshift($parents, $parent);
166 * Guess whether this ref entry is about a function or method
169 public function isFunction() {
170 $base = end($this->list);
171 return $base{0} === "_" ||
ctype_lower($base{0});
175 * Guess whether this ref entry is about a namespace, interface or class
178 public function isNsClass() {
179 $base = end($this->list);
180 return ctype_upper($base{0});
187 public function __toString() {
188 $parts = explode("/", trim($this->getName(), "/"));
189 $myself = array_pop($parts);
193 $parent = end($parts);
195 switch ($myself{0}) {
197 return "★" . substr($myself, 1);
200 if (!ctype_lower($myself{0}) ||
ctype_lower($parent{0})) {
204 return $parent . "::" . $myself;
209 * Get the base name of this ref entry
212 public function getBasename() {
213 return dirname($this->path
) . "/" . basename($this->path
, ".md");
217 * Guess whether there are any child nodes
218 * @param string $glob
221 function hasIterator($glob = null) {
223 return glob($this->getBasename() . "/$glob");
224 } elseif ($this->isRoot()) {
227 return is_dir($this->getBasename());
232 * Guess whether there are namespace/interface/class child nodes
235 function hasNsClasses() {
236 return $this->hasIterator("/[A-Z]*.md");
240 * Guess whether there are function/method child nodes
243 function hasFunctions() {
244 return $this->hasIterator("/[a-z_]*.md");
248 * Implements \IteratorAggregate
249 * @return \mdref\Tree child nodes
251 function getIterator() {
252 return new Tree($this->getBasename(), $this->repo
, $this->isRoot());