Last active
December 20, 2015 23:48
-
-
Save bake/6215025 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Config { | |
public static $paths = [ | |
'base' => '/index.php', | |
'views' => 'views/', | |
'foo' => 'bar' | |
]; | |
public static function path($path) { | |
return static::$paths[$path]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo extends Config { | |
public static function get($result) { | |
return $result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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