Skip to content

Instantly share code, notes, and snippets.

@bake
Last active December 20, 2015 23:48
Show Gist options
  • Save bake/6215025 to your computer and use it in GitHub Desktop.
Save bake/6215025 to your computer and use it in GitHub Desktop.
<?php
class Config {
public static $paths = [
'base' => '/index.php',
'views' => 'views/',
'foo' => 'bar'
];
public static function path($path) {
return static::$paths[$path];
}
}
<?php
class Foo extends Config {
public static function get($result) {
return $result;
}
}
<?php
function __autoload($class) {
include('./classes/'.$class.'.php');
}
Bob::get('/', function() {
/**
* just imagine there would be views/head.php, views/blog.php and views/foot.php
*/
View::add('head');
View::add('blog', ['foo' => Foo::get('bar')]);
View::add('foot');
/**
* this route would result in something like this:
*
* <?php
* include('views/head.php');
* $foo = Foo::get('bar'); // => 'bar'
* include('views/blog.php');
* unset($foo);
* include('views/foot.php');
* ?>
*/
});
Bob::go(Config::path('base'));
<?php
class View extends Config {
public static function add($view, $data = []) {
if(!is_array($data))
$data = ['data' => $data];
/**
* $data['foo'] = 'bar'; => $foo = 'bar';
*/
foreach($data as $key => $var)
${$key} = $var;
include(Config::path('views').$view.'.php');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment