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 trim($this->getFile()->readTitle());
101 if ($this->isRoot()) {
102 return trim($this->repo
->getRootEntry()->getTitle());
108 * Read the first line of the description of the ref entry file
111 public function getDescription() {
112 if ($this->isFile()) {
113 return trim($this->getFile()->readDescription());
115 if ($this->isRoot()) {
116 return trim($this->repo
->getRootEntry()->getDescription());
122 * Read the full description of the ref entry file
125 public function getFullDescription() {
126 if ($this->isFile()) {
127 return trim($this->getFile()->readFullDescription());
129 if ($this->isRoot()) {
130 return trim($this->repo
->getRootEntry()->getFullDescription());
136 * Read the intriductory section of the refentry file
139 public function getIntro() {
140 if ($this->isFile()) {
141 return trim($this->getFile()->readIntro());
143 if ($this->isRoot()) {
144 return trim($this->repo
->getRootEntry()->getIntro());
150 * Check if the refentry exists
153 public function isFile() {
154 return strlen($this->path
) > 0;
158 * Check if this is the first entry of the reference tree
161 public function isRoot() {
162 return count($this->list) === 1;
166 * Get the parent ref entry
167 * @return \mdref\Entry
169 public function getParent() {
170 switch ($dirn = dirname($this->name
)) {
175 return $this->repo
->getEntry($dirn);
180 * Get the list of parents up-down
183 public function getParents() {
185 for ($parent = $this->getParent(); $parent; $parent = $parent->getParent()) {
186 array_unshift($parents, $parent);
192 * Guess whether this ref entry is about a function or method
195 public function isFunction() {
196 $base = end($this->list);
197 return $base{0} === "_" ||
ctype_lower($base{0});
201 * Guess whether this ref entry is about a namespace, interface or class
204 public function isNsClass() {
205 $base = end($this->list);
206 return ctype_upper($base{0});
209 public function getEntryName() {
210 return end($this->list);
213 public function getNsName() {
214 if ($this->isRoot()) {
215 return $this->getName();
216 } elseif ($this->isFunction()) {
217 $parts = explode("/", trim($this->getName(), "/"));
218 $self = array_pop($parts);
219 return implode("\\", $parts) . "::" . $self;
221 return strtr($this->getName(), "/", "\\");
229 public function __toString() {
230 $parts = explode("/", trim($this->getName(), "/"));
231 $myself = array_pop($parts);
235 $parent = end($parts);
237 switch ($myself{0}) {
239 return "★" . substr($myself, 1);
242 if (!ctype_lower($myself{0}) ||
ctype_lower($parent{0})) {
246 return $parent . "::" . $myself;
251 * Get the base name of this ref entry
254 public function getBasename() {
255 return dirname($this->path
) . "/" . basename($this->path
, ".md");
259 * Guess whether there are any child nodes
260 * @param string $glob
263 function hasIterator($glob = null, $loose = false) {
265 return glob($this->getBasename() . "/$glob") ||
266 ($loose && glob($this->getBasename() . "/*/$glob"));
267 } elseif ($this->isRoot()) {
269 } elseif ($this->getBasename() !== "/") {
270 return is_dir($this->getBasename());
277 * Guess whether there are namespace/interface/class child nodes
280 function hasNsClasses() {
281 return $this->hasIterator("/[A-Z]*.md", true);
285 * Guess whether there are function/method child nodes
288 function hasFunctions() {
289 return $this->hasIterator("/[a-z_]*.md");
293 * Implements \IteratorAggregate
294 * @return \mdref\Tree child nodes
296 function getIterator() {
297 return new Tree($this->getBasename(), $this->repo
);
300 function getStructure() {
301 return new Structure($this);