Created
May 17, 2012 16:33
-
-
Save jeremeamia/2720020 to your computer and use it in GitHub Desktop.
TweetMVC Returns - A PHP 5.4 MVC framework that fits in 3 tweets
This file contains 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 # TweetMVC Example App Bootstrap | |
# Import TweetMVC using error suppression to hide notices and warnings from the cold golfing | |
@include 'tmvc.php'; | |
use TMVC\Core\App; | |
# Basic namespaced autoloader, nothing too fancy | |
spl_autoload_register(function($class) {return @include __DIR__.'/src/'.strtr($class, '\\', '/').'.php';}); | |
# Instantiate, configure, and execute the app | |
(new App) | |
->set('namespace', '\\ShoutApp\\Controller\\') | |
->set('templates', __DIR__.'/src/templates/') | |
->set('date', new DateTime()) | |
->run(); |
This file contains 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 # TweetMVC Example Controller | |
namespace ShoutApp\Controller; | |
use TMVC\Core\C as Controller; | |
use TMVC\Core\V as View; | |
class Shout extends Controller | |
{ | |
# Theoretically accessed from http://{hostname}/index.php?c=Shout&a=out | |
public function out(array $params = []) | |
{ | |
$name = isset($params['name']) ? $params['name'] : 'Nobody'; | |
(new View) | |
->set('title', "Shout Out to $name") | |
->set('name', $name) | |
->set('day', $this->get('app')->get('date')->format('l')) | |
->out($this->get('app')->get('templates').'shout/out'); | |
} | |
} |
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<title><?= $title ?></title> | |
</head> | |
<body> | |
<h1><?= $title ?></h1> | |
<p>It's <?= $day ?>, and I just wanted to give a shout out to my friend, <?= $name ?>!</p> | |
</body> | |
</html> |
This file contains 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
<?namespace TMVC\Core;trait GS{protected$d=[];function set($k,$v){$this->d[$k]=$v;return$this;}function get($k){return$this->d[$k]?:null;}} | |
class M{use GS;}class V{use GS;function out($_){ob_start();extract($this->d);require"$_.php";ob_end_flush();}}class C{use GS;}#MadeByJeremyL | |
class App{use GS;function run(){$r=$_GET+[c=>home,a=>index];$c=$this->d['namespace'].$r[c];(new$c)->set(app,$this)->$r[a]($r);return$this;}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No warnings: