Skip to content

Instantly share code, notes, and snippets.

@Diti
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diti/10598977 to your computer and use it in GitHub Desktop.
Save Diti/10598977 to your computer and use it in GitHub Desktop.
[School 42] Documentation & traits
<?php
trait Doc {
public static function doc() {
$filler = str_repeat('-', 80 - strlen(__CLASS__) - 4);
return '<- ' . __CLASS__ . ' ' . $filler . PHP_EOL
. file_get_contents(dirname(__FILE__) . '/' . __CLASS__ . '.doc.txt') . PHP_EOL
. $filler . ' ' . __CLASS__ . ' ->' . PHP_EOL;
}
}
<?php
require_once dirname(__FILE__) . '/Doc.trait.php'; // In same directory as class files
class MyClass {
use Doc;
// [...]
}
A class that doesn't do anything.
Call its documentation (MyClass.doc.txt) with:
echo MyClass::doc();
Note that MyClass.doc.txt should not end with an empty line (Git removes them).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment