Skip to content
Permalink
Browse files

added default config and separate routes config file

  • Loading branch information...
gresakg committed Oct 1, 2014
1 parent 7289cca commit 85433f99bf8f1aa6f8422e4c7582244ad32b89bc
Showing with 91 additions and 9 deletions.
  1. +54 −0 config-sample/routes.php
  2. +13 −9 index.php
  3. +24 −0 src/config-dist.php
@@ -0,0 +1,54 @@
<?php
return [
"routes" => [
[
"name" => "index",
"route" => "/",
"method" => "get",
"handler" => "frontPage",
],
[
"name" => "page",
"route" => "/p/:page+",
"method" => "get",
"handler" => "setPage",
],
//custom routes
[
"name" => "news",
"route" => "/news",
"method" => "get",
"handler" => "theNews",
],
[
"name" => "newsitem",
"route" => "/n/:segments+",
"method" => "get",
"handler" => "newsItem",
],
[
"name" => "contact",
"route" => "/contact",
"method" => "get",
"handler" => "contactForm",
],
[
"name" => "contactok",
"route" => "/contact/ok/",
"method" => "get",
"handler" => "contactOk",
],
[
"name" => "postcontact",
"route" => "/contact/:token",
"method" => "post",
"handler" => "contactForm",
],
],
// define default route conditions
"route.conditions" => [
'page+' => '[a-zA-Z0-9_-]+',
'lang' => '[\w]{2}',
],
];
@@ -8,8 +8,16 @@
// use pimple as dependency injector
$di = new \Pimple\Container();
// load basic configurations
$di['config'] = require __DIR__.'/config/config.php';
$default = require __DIR__.'/src/config-dist.php';
$config = require __DIR__.'/config/config.php';
$routes = require __DIR__.'/config/routes.php';
$di['config'] = array_merge(array_merge($default, $config),$routes);
$di['cache'] = $di->factory(function () use ($di) {
$adapter = "Gresakg\Cache\Adapter\\".$di['config']['cache.adapter'];
$cache = new $adapter();
return new Gresakg\Cache\Cache($cache);
});
// load slim as main framework
$di['slim'] = function($c) {
@@ -40,12 +48,6 @@
return new \PHaiku\Data();
});
$di['cache'] = $di->factory(function () use ($di) {
$adapter = "Gresakg\Cache\Adapter\\".$di['config']['cache.adapter'];
$cache = new $adapter();
return new Gresakg\Cache\Cache($cache);
});
//add custom services
include __DIR__.'/config/services.php';
@@ -69,12 +71,14 @@
//set the routes
\PHaiku\PHaiku::setRoutes($di);
//route for clearing the cache
if($di['config']['cache']) {
$di['slim']->get("/clearcache", function() use($di) {
$di['slim']->get($di['config']['cache.flush.url'], function() use($di) {
$di['cache']->dropCache();
$di['slim']->redirect("/");
});
}
//run slim
$di['slim']->run();
@@ -0,0 +1,24 @@
<?php
return [
"mode" => "development",
"debug" => true,
"benchmark" => true,
"cache" => true,
"cache.adapter" => "File",
"cache.time" => 120,
"cache.flush.url" => "/clearcache",
"templates.path" => "./templates/skela",
"class.name" => "\PHaiku\Haiku",
"data.store" => "./data",
"default.ext" => "html",
"contact.mail"=> "",
"mail.host" => "",
"mail.username" => "",
"mail.password" => "",
"recaptcha.publickey" => "your-recaptcha-public-key",
"recaptcha.privatekey" => "your-recaptcha-private-key",
"multilingual" => true,
"default.language" => "en",
"languages" => ["sl","en"],
];

0 comments on commit 85433f9

Please sign in to comment.
You can’t perform that action at this time.