Skip to content

Commit

Permalink
lib
Browse files Browse the repository at this point in the history
  • Loading branch information
schpill committed Apr 5, 2017
1 parent 7395913 commit 671d6d7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
8 changes: 6 additions & 2 deletions lib/bus.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@

class Bus
{
public function set($event, callable $closure)
public function set($event, $closure)
{
if (is_string($closure)) {
$closure = resolverClass($closure);
}

$bus = Registry::get('core.bus', []);
$bus[$event] = $closure;
Registry::set('core.bus', $bus);

return $this;
}

public function push($event, callable $closure)
public function push($event, $closure)
{
return $this->set($event, $closure);
}
Expand Down
13 changes: 11 additions & 2 deletions lib/ghost.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function rowing()

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

public function __get($k)
Expand Down Expand Up @@ -145,7 +145,16 @@ public function __call($m, $a)

return $this;
} else {
$this->$m = $closure;
if (is_string($closure) && fnmatch('*@*', $closure)) {
$resolver = resolverClass($closure);
$macros[$m] = $resolver;

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

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

return $this;
}
Expand Down
45 changes: 25 additions & 20 deletions lib/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

spl_autoload_register(function ($class) {
if (!class_exists($class)) {
$status = aliases($class);
// $status = aliases($class);

if (!$status) {
// if (!$status) {
$tab = explode('\\', $class);
$ns = array_shift($tab);
$lib = array_shift($tab);
Expand All @@ -47,7 +47,9 @@
$humanized = Inflector::uncamelize($class);
list($dbTable, $dummy) = explode($humanized, '_model', 2);
}
}

aliases($class);
// }
}
});

Expand Down Expand Up @@ -1357,6 +1359,17 @@ function str()
return $stringInstance;
}

function reg()
{
static $registryInstance;

if (!$registryInstance) {
$registryInstance = new Now;
}

return $registryInstance;
}

function factory()
{
$factory = lib('OctaliaFactory')->construct(\Faker\Factory::create('fr_FR'));
Expand Down Expand Up @@ -1501,14 +1514,6 @@ function systemBoot($dir = null)
staticFacade('\\Octo\\Now', 'Registry');
}

if (!class_exists('Octo\Stubber')) {
staticFacade('\\Kahlan\\Plugin\\Stub', 'Stubber');
}

if (!class_exists('Octo\Refactor')) {
staticFacade('\\Kahlan\\Plugin\\Monkey', 'Refactor');
}

$dirs = Arrays::last(
explode(
DS,
Expand Down Expand Up @@ -2104,7 +2109,7 @@ function middlewares($when = 'before')

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

if (in_array($method, $methods)) {
Expand All @@ -2115,11 +2120,11 @@ function middlewares($when = 'before')

function aliases($className)
{
$aliases = Registry::get('core.aliases', []);
static $aliases = [];

$aliasesFile = path('app') . '/config/aliases.php';

if (File::exists($aliasesFile)) {
if (file_exists($aliasesFile)) {
$aliasesFromConfig = include $aliasesFile;
$aliases = array_merge($aliases, $aliasesFromConfig);
}
Expand Down Expand Up @@ -2160,11 +2165,11 @@ function subscribers()
$subscribersFile = path('app') . '/config/subscribers.php';

if (File::exists($subscribersFile)) {
$ubscribers = include $subscribersFile;
}
$subscribers = include $subscribersFile;

foreach ($ubscribers as $subscriberClass) {
subscriber($subscriberClass);
foreach ($subscribers as $subscriberClass) {
subscriber($subscriberClass);
}
}
}

Expand Down Expand Up @@ -4990,8 +4995,8 @@ function resolverClass($class, $sep = '@')
{
return function() use ($class, $sep) {
$segments = explode($sep, $class);
$method = count($segments) == 2 ? end($segments) : 'supply';
$callable = [app()->make(current($segments)), $method];
$method = count($segments) == 2 ? $segments[1] : 'supply';
$callable = [app($segments[0]), $method];
$data = func_get_args();

return call_user_func_array($callable, $data);
Expand Down
5 changes: 5 additions & 0 deletions lib/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public static function url($baseRoute = '')
}
}

public static function path($baseRoute = '')
{
return static::uri($baseRoute);
}

public static function uri($baseRoute = '')
{
$uri = substr($_SERVER['REQUEST_URI'], strlen($baseRoute));
Expand Down

0 comments on commit 671d6d7

Please sign in to comment.