2 require_once __DIR__ . '/../src/anoweco/autoload.php';
4 \Twig_Autoloader::register();
6 $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../data/templates/');
7 $twig = new \Twig_Environment(
10 //'cache' => '/path/to/compilation_cache',
14 //$twig->addExtension(new Twig_Extension_Debug());
16 function verifyParameter($givenParams, $paramName)
18 if (!isset($givenParams[$paramName])) {
19 error('"' . $paramName . '" parameter missing');
21 return $givenParams[$paramName];
24 function verifyUrlParameter($givenParams, $paramName)
26 verifyParameter($givenParams, $paramName);
27 $url = parse_url($givenParams[$paramName]);
28 if (!isset($url['scheme'])) {
29 error('Invalid URL in "' . $paramName . '" parameter: scheme missing');
31 if (!isset($url['host'])) {
32 error('Invalid URL in "' . $paramName . '" parameter: host missing');
35 return $givenParams[$paramName];
38 function getOptionalParameter($givenParams, $paramName, $default)
40 if (!isset($givenParams[$paramName])) {
43 return $givenParams[$paramName];
49 * @param string $status HTTP status code line
50 * @param string $code One of the allowed status types:
52 * - insufficient_scope
55 * @param string $description
57 function error($description, $status = 'HTTP/1.0 400 Bad Request')
60 header('Content-Type: text/plain');
61 echo $description . "\n";
65 function render($tplname, $vars = array(), $return = false)
67 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
70 return $template->render($vars);
72 echo $template->render($vars);