示例#1
0
 /**
  * {@inheritDoc}
  */
 public function render(Application &$app, $file, array $data = [])
 {
     $cdir = getcwd();
     $twig = new Twig();
     $twig->setLoader(new Loader($cdir));
     $app->initialize('twig', ['twig' => &$twig]);
     $template = $twig->loadTemplate($file);
     return $template->render($data);
 }
示例#2
0
文件: app.php 项目: minond/fabrico
 public static function create()
 {
     $app = new Application();
     $conf = new Configuration();
     $conf->setFormat(Configuration::YAML);
     $conf->setDirectory('config');
     $conf->setEnvironments(getenv('APP_ENV'));
     $app->setConfiguration($conf);
     $app->initialize('config');
     $app->initialize('config_macros');
     $conf->setCache(new RuntimeCache());
     return Application::bind($app);
 }
示例#3
0
文件: Model.php 项目: minond/fabrico
<?php

namespace Fabrico\Model;

use PDO;
use Exception;
use Fabrico\Application;
// --------------------------------------
// lasciate ogne speranza, voi ch'intrate
// --------------------------------------
Application::call(function () {
    $key = 'db:' . getenv('APP_ENV');
    // class declaration in conditional statement? yeah. I do what ever the
    // f**k I want, bitch
    switch ($this->conf->get("{$key}:type")) {
        case 'file':
            require sprintf('%s/ModelFileStorage.php', __DIR__);
            Model::setDirectory($this->conf->get("{$key}:flat"));
            break;
        case 'pdo':
            require sprintf('%s/ModelDatabaseStorage.php', __DIR__);
            Model::setConnection(new PDO($this->conf->get("{$key}:dsn"), null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]));
            break;
        default:
            throw new Exception('Invalid db configuration');
    }
});