public function run() { $app = new \Slim\Slim(); $this->app = $app; GetAllHeadersService::fixMissingFunction(); $app->add(new \Widgeto\Middleware\Authorization(getallheaders(), array('^\\/$' => 'GET', '^\\/[^.]*.html$' => 'GET', '^\\/rest\\/login\\/$' => 'POST'))); \dibi::connect(DatabaseConfigService::getConfig()); \dibi::getSubstitutes()->{''} = getenv("TABLE_PREFIX"); new \Widgeto\Rest\LoginRest($app); new \Widgeto\Rest\LogoutRest($app); new \Widgeto\Rest\PageRest($app); new \Widgeto\Rest\TemplateRest($app); new \Widgeto\Rest\FileRest($app); new \Widgeto\Rest\UserRest($app); new \Widgeto\Rest\HomeRest($app); $app->run(); }
public static function setUpDatabase() { putenv("DATABASE_URL=sqlite3://tests/test.s3db"); \dibi::connect(DatabaseConfigService::getConfig()); \dibi::getSubstitutes()->{''} = ""; }
<h1>Using Substitutions | dibi</h1> <?php require __DIR__ . '/../src/loader.php'; dibi::connect(['driver' => 'sqlite3', 'database' => 'data/sample.s3db']); // create new substitution :blog: ==> wp_ dibi::getSubstitutes()->blog = 'wp_'; dibi::test('SELECT * FROM [:blog:items]'); // -> SELECT * FROM [wp_items] // create new substitution :: (empty) ==> my_ dibi::getSubstitutes()->{''} = 'my_'; dibi::test("UPDATE ::table SET [text]='Hello World'"); // -> UPDATE my_table SET [text]='Hello World' // create substitutions using fallback callback function substFallBack($expr) { $const = 'SUBST_' . strtoupper($expr); if (defined($const)) { return constant($const); } else { throw new Exception("Undefined substitution :{$expr}:"); } } // define callback dibi::getSubstitutes()->setCallback('substFallBack'); // define substitutes as constants define('SUBST_ACCOUNT', 'eshop_'); define('SUBST_ACTIVE', 7); dibi::test("\n\tUPDATE :account:user\n\tSET name='John Doe', status=:active:\n\tWHERE id=", 7); // -> UPDATE eshop_user SET name='John Doe', status=7 WHERE id= 7