[6019] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require_once 'helloworld/helloworld.php'; |
---|
| 4 | require_once 'filesystem/filesystem.php'; |
---|
| 5 | require_once 'filesystem/filesystemcollection.php'; |
---|
| 6 | require_once 'smarty/smarty.php'; |
---|
| 7 | require_once 'htmlform/htmlform.php'; |
---|
| 8 | require_once 'auth/auth.php'; |
---|
| 9 | require_once 'multirep/multirep.php'; |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * Examples listing |
---|
| 13 | * @namespace Tonic\Examples |
---|
| 14 | * @uri / |
---|
| 15 | */ |
---|
| 16 | class ExamplesListResource extends Resource { |
---|
| 17 | |
---|
| 18 | function get($request) { |
---|
| 19 | |
---|
| 20 | $response = new Response($request); |
---|
| 21 | |
---|
| 22 | $examples = ''; |
---|
| 23 | $dirs = glob(dirname(__FILE__).DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR); |
---|
| 24 | if ($dirs) { |
---|
| 25 | foreach ($dirs as $path) { |
---|
| 26 | $location = basename($path); |
---|
| 27 | $readme = $path.DIRECTORY_SEPARATOR.$location.'.php'; |
---|
| 28 | if (file_exists($readme)) { |
---|
| 29 | preg_match('|/\*\*\s*\*\s*(.+?)\*/|s', file_get_contents($readme), $match); |
---|
| 30 | $comment = preg_replace('|\s*\*\s*(@.+)?|', "\n", $match[1]); |
---|
| 31 | $parts = explode("\n\n", $comment); |
---|
| 32 | $name = array_shift($parts); |
---|
| 33 | $description = join(' ', $parts); |
---|
| 34 | } else { |
---|
| 35 | $name = $location; |
---|
| 36 | $description = ''; |
---|
| 37 | } |
---|
| 38 | $examples .= |
---|
| 39 | '<li>'. |
---|
| 40 | '<h3><a href="'.$location.'">'.$name.'</a></h3>'. |
---|
| 41 | '<p>'.$description.'</p>'. |
---|
| 42 | '</li>'; |
---|
| 43 | } |
---|
| 44 | } else { |
---|
| 45 | $examples .= '<li>No examples</li>'; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | $response->body = <<<END |
---|
| 49 | <h1>Welcome to Tonic</h1> |
---|
| 50 | <p>Below is a list of example uses of the Tonic library. View each example to see it in action.</p> |
---|
| 51 | <h2>Examples</h2> |
---|
| 52 | END; |
---|
| 53 | $response->body .= '<ul>'.$examples.'</ul>'; |
---|
| 54 | |
---|
| 55 | return $response; |
---|
| 56 | |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | } |
---|
| 60 | |
---|