Skip to content

Commit

Permalink
correctifs
Browse files Browse the repository at this point in the history
  • Loading branch information
schpill committed Mar 15, 2017
1 parent c3cf974 commit 30f6063
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 8 deletions.
29 changes: 29 additions & 0 deletions lib/ghost.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ public function __construct(array $data = [], $instance = null)
}
}

public function __invoke()
{
return $this->_instance;
}

public function rowing()
{
$collection = [];
$rows = Registry::pattern('ghost.*.' . $this->_instance);

foreach ($rows as $k => $v) {
if (!fnmatch('*__macros*', $k)) {
$key = str_replace(['ghost.', '.' . $this->_instance], '', $k);
$collection[$key] = $v;
}
}

return $collection;
}

public function __toString()
{
return json_encode($this->rowing($collection));
}

public function __get($k)
{
$key = 'ghost.' . $k . '.' . $this->_instance;
Expand Down Expand Up @@ -112,6 +137,10 @@ public function __call($m, $a)

Registry::set($key, $macros);

return $this;
} else {
$this->$m = $closure;

return $this;
}
}
Expand Down
79 changes: 76 additions & 3 deletions lib/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1555,11 +1555,81 @@ function systemBoot($dir = null)
middlewares();
}

function getRow($instance)
{
return make([], $instance);
}

function collectify(array $rows = [])
{
$collection = [];

foreach ($rows as $row) {
$collection[] = make($row);
}

return coll($collection);
}

function make(array $array = [], $instance = null)
{
return lib('ghost', [$array, $instance]);
}

function classify($instance, array $array = [])
{
$class = Strings::camelize('octo_' . Strings::uncamelize($instance));

if (!class_exists($class)) {
$code = 'class ' . $class . ' extends \\Octo\\Ghost {}';
eval($code);
}

$class = '\\' . $class;

return new $class($array, sha1($class));
}

function objectify($instance, array $array = [])
{
return single($instance, function () use ($array) {
return classify($instance, $array);
});
}

function resolve($class, array $args = [])
{
return single($class, null, $args);
}

function single($class, $resolver = null, array $args = [])
{
$key = sha1($class);
$singletons = Registry::get('core.singletons', []);

if ($resolver && is_callable($resolver)) {
$single = call_user_func_array($resolver, $args);

$singletons[$key] = $single;

Registry::set('core.singletons', $singletons);
} else {
$single = isAke($singletons, $key, null);

if (!$single) {
$single = app($class);

if ($single) {
$singletons[$key] = $single;

Registry::set('core.singletons', $singletons);
}
}
}

return $single;
}

function ionly()
{
$keys = func_get_args();
Expand All @@ -1582,17 +1652,20 @@ function middlewares($when = 'before')

foreach ($middlewares as $middlewareClass) {
$middleware = app($middlewareClass);
$methods = get_class_methods($middlewareClass);
$method = lcfirst(Strings::camelize('apply_' . $when));

if ($middleware->$when) {
$middleware->apply($request, app());
if (in_array($method, $methods)) {
call_user_func_array([$middleware, $method], [$request, app()]);
}
}
}
}

function services()
{
lib('serviceprovider');
require_once __DIR__ . DS . 'serviceprovider.php';

$servicesFile = path('app') . '/config/services.php';

if (File::exists($servicesFile)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/now.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function __construct($ns = 'core', array $data = [])
}
}

public function pattern($pattern = '*')
{
return Arrays::pattern(self::$data[$this->ns], $pattern);
}

public function flush()
{
self::$data[$this->ns] = [];
Expand Down
6 changes: 1 addition & 5 deletions lib/serviceprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ public function __construct($app = null)
$this->app = $app;
}

public function before() {}

abstract public function register();
abstract public function register();

public function services() {return [];}

public function after() {}
}

0 comments on commit 30f6063

Please sign in to comment.