Skip to content

Instantly share code, notes, and snippets.

@jeremeamia
Created May 17, 2012 16:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeremeamia/2720020 to your computer and use it in GitHub Desktop.
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
<?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
Copy link

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
Copy link

This is awesome :)

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