Last active
August 29, 2015 13:59
-
-
Save Diti/10598977 to your computer and use it in GitHub Desktop.
[School 42] Documentation & traits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once dirname(__FILE__) . '/Doc.trait.php'; // In same directory as class files | |
class MyClass { | |
use Doc; | |
// [...] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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