-
-
Save ellisgl/9086936 to your computer and use it in GitHub Desktop.
TweetMVC Returns - A PHP 5.4 MVC framework that fits in 3 tweets (A couple bytes smaller)
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\Cor\A; | |
# 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 A) | |
->set('ns', '\\SApp\\Ctrlr\\') | |
->set('tmpls', __DIR__.'/src/tmpls/') | |
->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 SApp\Ctrlr; | |
use TMVC\Core\C; | |
use TMVC\Core\V; | |
class Shout extends C | |
{ | |
# Theoretically accessed from http://{hostname}/index.php?c=Shout&a=out | |
public function out(array $params = []) | |
{ | |
$name = isset($params['name']) ? $params['name'] : 'Nobody'; | |
(new V) | |
->set('title', "Shout Out to $name") | |
->set('name', $name) | |
->set('day', $this->get('a')->get('date')->format('l')) | |
->out($this->get('a')->get('tmpls').'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
<?php namespace TMVC\Cor;trait G{public $d=[];function s($k,$v){$this->d[$k]=$v;return $this;}function g($k){return $this->d[$k]?:NULL;}} | |
class M{use G;}class V{use G;function o($_){ob_start();extract($this->d);require"$_.php";ob_end_flush();}}class C{use G;} | |
class A{use G;function run(){$r=$_GET+['c'=>'h','a'=>'i'];$c=$this->d['ns'].$r['c'];(new$c)->s('a',$this)->$r['a']($r);return $this;}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment