source: Dev/branches/jos-branch/server/tonic/examples/examples.php @ 298

Last change on this file since 298 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.8 KB
Line 
1<?php
2
3require_once 'helloworld/helloworld.php';
4require_once 'filesystem/filesystem.php';
5require_once 'filesystem/filesystemcollection.php';
6require_once 'smarty/smarty.php';
7require_once 'htmlform/htmlform.php';
8require_once 'auth/auth.php';
9require_once 'multirep/multirep.php';
10
11/**
12 * Examples listing
13 * @namespace Tonic\Examples
14 * @uri /
15 */
16class 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>
52END;
53        $response->body .= '<ul>'.$examples.'</ul>';
54       
55        return $response;
56       
57    }
58   
59}
60
Note: See TracBrowser for help on using the repository browser.