Skip to content

Commit

Permalink
global upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Dec 22, 2017
1 parent 00ee5d0 commit 9fd45c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 72 deletions.
24 changes: 0 additions & 24 deletions src/FlowNative/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ protected function exists($name): bool
*/
public function &__get($name)
{
if (!$this->exists($name))
{
throw new NotFound\Data('Variable `' . $name . '` not found');
}

return $this->___data___[$name];
}

Expand All @@ -109,23 +104,4 @@ public function __isset($name)
return $this->exists($name);
}

/**
* @param string $name
* @param array $arguments
*
* @return mixed
*/
public function __call($name, array $arguments)
{
return $this->helper->$name($this, ...$arguments);
}

/**
* @return array
*/
public function &exports(): array
{
return $this->___data___;
}

}
13 changes: 1 addition & 12 deletions src/FlowNative/Extensions/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ public function getExtends()
*/
public function extends(string $layout, string $from = null)
{
if (!$from)
{
$debug = \debug_backtrace();
$from = $debug[0]['file'];
}

if ($from === $this->from)
{
throw new Runtime('Double extends layout from `' . $from . '`');
}

$this->from = $from;
$this->extends = $layout;
}
Expand All @@ -76,7 +65,7 @@ public function extends(string $layout, string $from = null)
*/
public function start(string $name, string $option = self::RESET)
{
ob_start();
\ob_start();

if (empty($this->blocks[$name]))
{
Expand Down
18 changes: 11 additions & 7 deletions src/FlowNative/FlowNative.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ class FlowNative
*/
public function __construct(Context $context = null)
{
$this->content = $context;
if ($context)
{
$this->setContent($context);
}
}

// set flow
$this->content()->setFlow($this);
protected function setContent(Context $context)
{
$this->content = $context;
$this->content->setFlow($this);
}

/**
Expand All @@ -45,12 +51,10 @@ public function content(): Context
{
if (!$this->content)
{
$this->content = new Context(
$this->setContent(new Context(
new Helper(),
new Extensions()
);

$this->content->setFlow($this);
));
}

return $this->content;
Expand Down
31 changes: 2 additions & 29 deletions src/FlowNative/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,13 @@ class Helper
*
* @return $this
*/
public function add($name, callable $callable)
public function addHelper($name, callable $callable)
{
$this->helpers[$name] = $callable;

return $this;
}

/**
* @param string $name
*
* @return bool
*/
public function exists($name): bool
{
return isset($this->helpers[$name]);
}

/**
* @param string $name
* @param array $arguments
Expand All @@ -83,24 +73,7 @@ public function exists($name): bool
*/
public function __call($name, array $arguments)
{
$newThis = \array_shift($arguments);

if (!$this->exists($name))
{
throw new NotFound\Data('Helper `' . $name . '` not found!');
}

$callable = $this->helpers[$name];

if (\method_exists($callable, 'call'))
{
/**
* @var \Closure $callable
*/
return $callable->call($newThis, ...$arguments);
}

return $callable(...$arguments);
return \call_user_func($this->helpers[$name], ...$arguments);
}

}

0 comments on commit 9fd45c1

Please sign in to comment.