Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TweetMVC Returns - A PHP 5.4 MVC framework that fits in 3 tweets
<?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();
<?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');
}
}
<!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>
<?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;}}
@ellisgl

This comment has been minimized.

Copy link

@ellisgl ellisgl commented Aug 24, 2012

No warnings:

<?php namespace TMVC\Core;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;}}
@noodlehaus

This comment has been minimized.

Copy link

@noodlehaus noodlehaus commented Feb 19, 2014

This is awesome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment