Skip to content

Commit

Permalink
added default config and separate routes config file
Browse files Browse the repository at this point in the history
  • Loading branch information
gresakg committed Oct 1, 2014
1 parent 7289cca commit 85433f9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
54 changes: 54 additions & 0 deletions config-sample/routes.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}',
],
];
22 changes: 13 additions & 9 deletions index.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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';

Expand All @@ -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();

Expand Down
24 changes: 24 additions & 0 deletions src/config-dist.php
@@ -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.