Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made setttings more complete

  • Loading branch information...
commit faec97d7b0e59fc870498ff77b44be3bb8f85098 1 parent 3e0f186
@brucespang authored
View
13 frank/core.php
@@ -93,13 +93,6 @@ class Frank{
* @var array
*/
private static $middleware = array();
-
- /**
- * Template directory location
- *
- * @var string
- */
- public static $view_path = '';
/**
* Public functions
@@ -162,6 +155,8 @@ public static function call($options=array()){
public static function render_template($name, $options){
$locals = $options['locals'] ? $options['locals'] : array();
+ $view_path = settings::get('views');
+
if(isset(self::$templates[$name])){
$template = self::$templates[$name];
@@ -171,14 +166,14 @@ public static function render_template($name, $options){
self::$body .= ob_get_contents();
ob_end_clean();
- }elseif(file_exists(self::$view_path.'/'.$name.'.html')){
+ }elseif(file_exists($view_path.'/'.$name)){
$template = function($path, $locals){
require($path);
};
ob_start();
- $template(self::$view_path.'/'.$name.'.html', $locals);
+ $template($view_path.'/'.$name, $locals);
self::$body .= ob_get_contents();
ob_end_clean();
}
View
1  frank/frank.php
@@ -2,6 +2,7 @@
require('helpers.php');
require('core.php');
+ require('settings.php');
require('library.php');
/**
View
4 frank/library.php
@@ -55,8 +55,8 @@ function not_found($function){
* @param array $options Options for Frank
*/
function set($options){
- if(isset($options['views']))
- Frank::$view_path = $options['views'];
+ foreach($options as $option => $value)
+ settings::set($option, $value);
}
/**
View
38 frank/settings.php
@@ -0,0 +1,38 @@
+<?php
+
+ class settings{
+
+ /**
+ * Array of settings and their values
+ *
+ * @var array
+ */
+ private static $settings = array();
+
+ /**
+ * Set a setting
+ *
+ * @param string $setting_name Name of the setting
+ * @param mixed $value Value of the setting
+ */
+ function set($setting_name, $value){
+ self::$settings[$setting_name] = $value;
+ }
+
+ /**
+ * Get the value of a setting
+ *
+ * @param string $setting_name Name of the setting
+ * @return string Value of the setting
+ */
+ function get($setting_name){
+ if(gettype(self::$settings[$setting_name]) == 'object')
+ $value = call_user_func(self::$settings[$setting_name]);
+ else
+ $value = self::$settings[$setting_name];
+
+ return $value;
+ }
+ }
+
+?>
View
6 index.php
@@ -10,6 +10,9 @@ function hello($name){
configure(function(){
$test = 'test';
set(array('views' => dirname(__FILE__) . '/templates'));
+ set(array('extension' => function(){
+ return '.'.end(explode('.', __FILE__));
+ }));
});
after(function(){
@@ -17,7 +20,8 @@ function hello($name){
});
get("/", function(){
- echo "Welcome to Frank.php";
+ echo "Welcome to Frank";
+ echo settings::get('extension');
});
get("/template", function(){
Please sign in to comment.
Something went wrong with that request. Please try again.