Created
June 4, 2014 20:00
-
-
Save mayoralito/0d4a6f3bc629a62227c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Copyright (c) 2013 Roman Ožana (http://omdesign.cz) | |
* | |
* For the full copyright and license information, please view | |
* the file license.txt that was distributed with this source code. | |
* | |
* @author Roman Ozana <[email protected]> | |
* @method Homepage() | |
* @method Homepage_actiom() | |
*/ | |
class App extends Slim { | |
public function __construct() { | |
parent::__construct(); | |
$this->container->singleton( | |
'mysuperclass', function ($container) { | |
return new MySuperClass(); | |
} | |
); | |
} | |
public function __call($name, $params) { | |
return function () use ($name, $params) { | |
list($class, $action) = explode('_', $name . '_handle'); // default method is handle | |
$args = []; | |
$class = new \ReflectionClass($class); | |
$constructor = $class->getConstructor(); | |
foreach ($constructor->getParameters() as $param) { | |
$args[] = ($param->name === 'app') ? $this : $this->container->get($param->name); | |
} | |
$controller = $class->newInstanceArgs($args); | |
return call_user_func([$controller, $action], func_get_args() + $params); | |
}; | |
} | |
} |
This file contains hidden or 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 | |
class Homepage { | |
public $app; | |
public $router; | |
public $mysuperclass; | |
public function __construct(\App $app, \Slim\Router $router, \MySuperClass $mysuperclass) { | |
$this->app = $app; | |
$this->router = $router; | |
$this->mysuperclass = $mysuperclass; | |
} | |
public function handle() { | |
var_dump($this->app); // have something | |
} | |
public function action() { | |
// call action | |
} | |
} |
This file contains hidden or 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 | |
$app = new App(); | |
$app->map('/', $app->Homepage())->via('GET', 'POST'); | |
$app->map('/action', $app->Homepage_action())->via('GET', 'POST'); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment