Skip to content

Commit

Permalink
🎨 Use more typehinting
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed May 25, 2019
1 parent dd9895f commit 935de07
Showing 1 changed file with 61 additions and 33 deletions.
94 changes: 61 additions & 33 deletions src/Blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@

use Illuminate\Container\Container;
use Illuminate\Contracts\Container\Container as ContainerInterface;
use Illuminate\Contracts\View\Factory as FactoryContract;
use Illuminate\Contracts\View\View;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Factory;
use Illuminate\View\ViewServiceProvider;

class Blade
class Blade implements FactoryContract
{
/**
* @var array|string
*/
private $viewPaths;

/**
* @var string
*/
private $cachePath;

/**
* @var Container
*/
Expand All @@ -40,36 +31,16 @@ class Blade

public function __construct($viewPaths, string $cachePath, ContainerInterface $container = null)
{
$this->viewPaths = $viewPaths;
$this->cachePath = $cachePath;
$this->container = $container ?: new Container;

$this->setupContainer();
$this->setupContainer((array) $viewPaths, $cachePath);
(new ViewServiceProvider($this->container))->register();

$this->factory = $this->container->get('view');
$this->compiler = $this->container->get('blade.compiler');
}

protected function setupContainer()
{
$this->container->bindIf('files', function () {
return new Filesystem;
}, true);

$this->container->bindIf('events', function () {
return new Dispatcher;
}, true);

$this->container->bindIf('config', function () {
return [
'view.paths' => (array) $this->viewPaths,
'view.compiled' => $this->cachePath,
];
}, true);
}

public function make(string $view, array $data = [], array $mergeData = []): View
public function make($view, $data = [], $mergeData = []): View
{
return $this->factory->make($view, $data, $mergeData);
}
Expand All @@ -84,8 +55,65 @@ public function directive(string $name, callable $handler)
$this->compiler->directive($name, $handler);
}

public function exists($view): bool
{
return $this->factory->exists($view);
}

public function file($path, $data = [], $mergeData = []): View
{
return $this->factory->file($path, $data, $mergeData);
}

public function share($key, $value = null)
{
return $this->factory->shared($key, $value);
}

public function composer($views, $callback): array
{
return $this->factory->composer($views, $callback);
}

public function creator($views, $callback): array
{
return $this->factory->creator($views, $callback);
}

public function addNamespace($namespace, $hints): self
{
$this->factory->addNamespace($namespace, $hints);

return $this;
}

public function replaceNamespace($namespace, $hints): self
{
$this->factory->replaceNamespace($namespace, $hints);

return $this;
}

public function __call(string $method, array $params)
{
return call_user_func_array([$this->factory, $method], $params);
}

protected function setupContainer(array $viewPaths, string $cachePath)
{
$this->container->bindIf('files', function () {
return new Filesystem;
}, true);

$this->container->bindIf('events', function () {
return new Dispatcher;
}, true);

$this->container->bindIf('config', function () use ($viewPaths, $cachePath) {
return [
'view.paths' => $viewPaths,
'view.compiled' => $cachePath,
];
}, true);
}
}

0 comments on commit 935de07

Please sign in to comment.