Beispiel #1
0
 public function render()
 {
     // Generate the DOT source code, and write to a file.
     $dot = new \Tabulate\Template('erd/erd.twig');
     $dot->tables = $this->tables;
     $dot->selectedTables = $this->selectedTables;
     $dotCode = $dot->render();
     $tmpFilePath = Config::storageDirTmp('erd/' . uniqid());
     $dotFile = $tmpFilePath . '/erd.dot';
     $pngFile = $tmpFilePath . '/erd.png';
     file_put_contents($dotFile, $dotCode);
     // Generate the image.
     $cmd = Config::dotCommand() . ' -Tpng -o' . escapeshellarg($pngFile) . ' ' . escapeshellarg($dotFile);
     $ds = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
     $pipes = false;
     $proc = proc_open($cmd, $ds, $pipes, Config::storageDirTmp('erd'), array());
     fclose($pipes[0]);
     $out = stream_get_contents($pipes[1]);
     fclose($pipes[1]);
     $err = stream_get_contents($pipes[2]);
     fclose($pipes[2]);
     proc_close($proc);
     if (!empty($err)) {
         throw new \Exception("Error generating graph image. {$err}");
     }
     // Send the image.
     header('Content-Type:image/png');
     echo file_get_contents($pngFile);
     // Clean up.
     \Tabulate\File::rmdir($tmpFilePath);
 }
Beispiel #2
0
 public function index()
 {
     $template = new \Tabulate\Template('home.twig');
     $template->title = 'Welcome!';
     $template->tables = $this->db->getTables();
     $template->user = $this->user;
     echo $template->render();
 }
Beispiel #3
0
        case FastRoute\Dispatcher::NOT_FOUND:
            http_response_code(404);
            throw new \Exception("Not found: {$route}", 404);
            break;
        case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
            $allowedMethods = $routeInfo[1];
            // ... 405 Method Not Allowed
            break;
        case FastRoute\Dispatcher::FOUND:
            $handler = explode('::', $routeInfo[1]);
            $vars = $routeInfo[2];
            $controllerName = '\\Tabulate\\Controllers\\' . $handler[0];
            $controller = new $controllerName();
            $action = $handler[1];
            $controller->{$action}($vars);
            exit(0);
            break;
        default:
            http_response_code(500);
            echo "Something odd has happened.";
            exit(1);
            break;
    }
} catch (\Exception $e) {
    //var_dump($e);exit();
    $template = new Tabulate\Template('error_page.twig');
    $template->title = 'Error';
    $template->e = $e;
    echo $template->render();
    exit(1);
}