Skip to content

Instantly share code, notes, and snippets.

@ellisgl
Forked from jeremeamia/index.php
Last active Aug 29, 2015
Embed
What would you like to do?
TweetMVC Returns - A PHP 5.4 MVC framework that fits in 3 tweets (A couple bytes smaller)
<?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();
<?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');
}
}
<!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>
<?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