Last active
August 29, 2015 14:08
-
-
Save devosc/5b66b7080a6736d8d9d5 to your computer and use it in GitHub Desktop.
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 Micro; | |
use Framework\Route\Definition\Builder\Builder; | |
use Framework\Route\Definition\Definition; | |
use Framework\Service\Config\Router\Router; | |
class Micro | |
implements MicroApplication | |
{ | |
/** | |
* | |
*/ | |
use Base; | |
/** | |
* @link https://github.com/mvc5/framework/blob/master/src/Route/Definition/Builder/Builder.php#L28 | |
* @param array $definition | |
* @return Definition | |
*/ | |
public function route(array $definition) | |
{ | |
return Builder::add( | |
$this->routes[Args::DEFINITIONS], | |
$definition, | |
explode( | |
'/', | |
$definition[Definition::NAME] | |
), | |
function(Definition $parent, Definition $definition, $path, $root) { | |
$parent->add($path, $definition); | |
$root && $this->routes[Args::EVENTS]->add(Args::ROUTE_DISPATCH, new Router($definition)); | |
return $definition; | |
}, | |
true | |
); | |
} | |
/** | |
* @param array $args | |
* @param callable $callback | |
* @return callable|mixed|null|object | |
*/ | |
public function __invoke(array $args = [], callable $callback = null) | |
{ | |
return $this->call(Args::MICRO, $args, $callback); | |
} | |
} |
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 | |
/** | |
* | |
*/ | |
use Micro\Micro; | |
use Framework\View\Model\Model; | |
use Framework\View\Manager\ViewManager; | |
include __DIR__ . '/../vendor/autoload.php'; | |
$app = new Micro(); | |
//services via ArrayAccess | |
//var_dump($app['Request']); | |
//configuration via property access | |
//$app->templates['layout'] = '../view/layout.phtml'; | |
//$app->templates['home'] = '../view/index.phtml'; | |
$app->route([ | |
'name' => 'home', | |
'route' => '/', | |
'controller' => function(ViewManager $vm, array $args = []) { | |
$args['micro_route'] = 'micro:home'; | |
//$vm is a named argument plugin | |
$args['demo_time'] = $vm->call('time'); | |
return new Model('home', ['args' => $args]); | |
} | |
]); | |
$app->route([ | |
'name' => 'application', | |
'route' => '/application', | |
'controller' => function(array $args = []) { | |
$args['micro_route'] = 'micro:application'; | |
return new Model('home', ['args' => $args]); | |
} | |
]); | |
$app->route([ | |
'name' => 'application/default', | |
//'route' => '[/:controller[/:action]]', | |
'controller' => function(array $args = []) { | |
/** @var $this Framework\Controller\Manager\Manager */ | |
$args['micro_route'] = 'micro:application:default'; | |
$args['demo_time'] = $this->call('time'); | |
return new Model('home', ['args' => $args]); | |
} | |
]); | |
$app->route([ | |
'name' => 'application/default/three', | |
'route' => '[/:controller[/:action]]', | |
'controller' => function(array $args = []) { | |
/** @var $this Framework\Controller\Manager\Manager */ | |
$args['micro_route'] = 'micro:application:default:three'; | |
$args['demo_time'] = $this->call('time'); | |
return new Model('home', ['args' => $args]); | |
} | |
]); | |
call_user_func($app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I may end up folding the array and property access into the main repo classes (Application and Web). I don't see much point in hiding the configuration and I'm thinking about a putting in a /framework/config directory at the same level as /src so the application can choose which defaults to use and for them to be easier to merge. Thanks for the feedback.