use http\Controller\Observer;
+/**
+ * The sole action controller of mdref
+ */
class Action extends Observer
{
private function serveReference(\http\Controller $ctl) {
}
}
+ /**
+ * Implements \SplObserver
+ * @param \SplSubject $ctl
+ */
function update(\SplSubject $ctl) {
/* @var \http\Controller $ctl */
try {
use http\Env as HTTP;
+/**
+ * mdref exception handler
+ */
class ExceptionHandler
{
function __construct() {
return true;
}
+ /**
+ * Format an exception as HTML and send appropriate exception info as HTTP headers
+ * @param \Exception $e
+ * @param array $title_tag
+ * @param array $message_tag
+ * @param array $trace_tag
+ * @return string
+ */
static function html(\Exception $e, array $title_tag = ["h1"], array $message_tag = ["p"], array $trace_tag = ["pre", "style='font-size:smaller'"]) {
if ($e instanceof \http\Controller\Exception) {
$code = $e->getCode() ?: 500;
namespace mdref;
+/**
+ * The RefEntry class represents a reference entry, i.e. a .md file
+ */
class RefEntry
{
/**
*/
protected $file;
+ /**
+ * @param \mdref\Path $path
+ * @param type $entry
+ */
function __construct(Path $path, $entry = null) {
$this->path = $path;
$this->entry = trim($entry ?: $path->getPathName(), DIRECTORY_SEPARATOR);
}
+ /**
+ * Clean up the file handle
+ */
function __destruct() {
if (is_resource($this->file)) {
fclose($this->file);
}
}
+ /**
+ * Format as URL
+ * @return string
+ */
function formatUrl() {
return htmlspecialchars($this->entry);
}
return $link;
}
+ /**
+ * Format as link text
+ * @param bool $basename whether to use the basename only
+ * @return string
+ */
function formatLink($basename = false) {
$link = "";
if (strlen($this->entry)) {
return htmlspecialchars($link);
}
+ /**
+ * Create a consolidated Path of this entry
+ * @return \mdref\Path
+ */
function getPath() {
$path = $this->path;
$file = $path($this->entry);
}
}
+ /**
+ * Read the title of the refentry
+ * @return string
+ */
function readTitle() {
$this->openFile();
fseek($this->file, 1, SEEK_SET);
return htmlspecialchars(fgets($this->file));
}
+ /**
+ * Read the description of the refentry
+ * @return string
+ */
function readDescription() {
$this->openFile();
fseek($this->file, 0, SEEK_SET);
return htmlspecialchars(fgets($this->file));
}
+ /**
+ * Format a "Edit me" URL. The project reference top directory needs a
+ * »name«.mdref file besides its »name«.md entry point with the edit URL
+ * printf template as content. The sole printf argument is the relative
+ * path of the entry.
+ * @return string
+ */
function formatEditUrl() {
$path = $this->path;
$base = current(explode(DIRECTORY_SEPARATOR, $path->getPathName()));
}
}
+ /**
+ * Recurse into the reference tree
+ * @param \mdref\Finder $refs
+ * @param string $pattern
+ * @param callable $cb
+ */
function recurse(Finder $refs, $pattern, callable $cb) {
$path = $refs->find($refs->getBaseUrl()->mod($this->entry));
foreach (new RefListing($path, $refs->glob($path, $pattern)) as $entry) {
});
}
}
-}
\ No newline at end of file
+}
namespace mdref;
+/**
+ * A list of markdown reference files
+ */
class RefListing implements \Countable, \Iterator
{
/**
}, $files);
}
+ /**
+ * Implements \Countable
+ * @return int
+ */
function count() {
return count($this->entries);
}
+ /**
+ * Implements \Iterator
+ */
function rewind() {
reset($this->entries);
}
+ /**
+ * Implements \Iterator
+ * @return bool
+ */
function valid() {
return null !== key($this->entries);
}
+ /**
+ * Implements \Iterator
+ * @return string
+ */
function key() {
return $this->path->getSubPath(current($this->entries));
}
+ /**
+ * Implements \Iterator
+ */
function next() {
next($this->entries);
}
-
+
+ /**
+ * Implements \Iterator
+ * @return \mdref\RefEntry
+ */
function current() {
return new RefEntry($this->path, $this->key());//$this->format($this->key());
}
+ /**
+ * Get the parent reference entry
+ * @return null|\mdref\RefEntry
+ */
function getParent() {
switch ($parent = dirname($this->path->getPathName())) {
case ".":
}
}
+ /**
+ * Get the reference entry this reflist is based of
+ * @return \mdref\RefEntry
+ */
function getSelf() {
return new RefEntry($this->path);
}