Skip to content

Commit

Permalink
feat: switch to jenssegers/blade
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Aug 17, 2024
1 parent fd7c5b5 commit d0cabb0
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 947 deletions.
29 changes: 0 additions & 29 deletions CHANGELOG.md

This file was deleted.

62 changes: 31 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"name": "leafs/blade",
"description": "Leaf PHP Framework adaptation of jenssegers/blade package",
"keywords": ["leaf", "leafMVC", "laravel", "blade", "template", "view", "render"],
"license" : "MIT",
"type": "library",
"authors": [
{
"name": "Michael Darko",
"email": "[email protected]",
"homepage": "https://mychi.netlify.app",
"role": "Developer"
}
],
"require": {
"php": ">=7.3|^8.0",
"illuminate/view": "^8.0|^9.0|^10.0"
},
"require-dev": {
"pestphp/pest": "^1.0|^2.25"
},
"autoload": {
"psr-4": {
"Leaf\\": "src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
"name": "leafs/blade",
"description": "Leaf PHP Framework adaptation of jenssegers/blade package",
"keywords": [
"leaf",
"leafMVC",
"laravel",
"blade",
"template",
"view",
"render"
],
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Michael Darko",
"email": "[email protected]",
"homepage": "https://mychi.netlify.app",
"role": "Developer"
}
],
"require": {
"php": ">=7.4|^8.0",
"jenssegers/blade": "^1.4"
},
"autoload": {
"psr-4": {
"Leaf\\": "src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
132 changes: 18 additions & 114 deletions src/Blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,21 @@

namespace Leaf;

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\Support\Facades\Facade;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Factory;
use Illuminate\View\ViewServiceProvider;

class Blade implements FactoryContract
class Blade
{
/**
* @var BladeContainer
*/
protected $container;

/**
* @var Factory
*/
private $factory;
protected $blade;

/**
* @var BladeCompiler
*/
private $compiler;

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

if ($viewPaths != null && $cachePath != null) {
$this->configure($viewPaths, $cachePath);
}
// Just to maintain compatibility with the original Leaf Blade
}

/**
* Configure your view and cache directories
*/
public function configure($viewPaths, $cachePath)
public function configure(string $viewPaths, string $cachePath)
{
$this->setupContainer((array) $viewPaths, $cachePath);
(new ViewServiceProvider($this->container))->register();

$this->factory = $this->container->get('view');
$this->compiler = $this->container->get('blade.compiler');
$this->blade = new \Jenssegers\Blade\Blade($viewPaths, $cachePath);
}

/**
Expand All @@ -56,9 +25,9 @@ public function configure($viewPaths, $cachePath)
* A shorter version of the original `make` command.
* You can optionally pass data into the view as a second parameter
*/
public function render(string $view, array $data = [], array $mergeData = []): string
public function render(string $view, $data = [], $mergeData = [])
{
return $this->make($view, $data, $mergeData)->render();
return $this->make($view, $data, $mergeData);
}

/**
Expand All @@ -67,90 +36,25 @@ public function render(string $view, array $data = [], array $mergeData = []): s
* You can optionally pass data into the view as a second parameter.
* Don't forget to chain the `render` method
*/
public function make($view, $data = [], $mergeData = []): View
{
return $this->factory->make($view, $data, $mergeData);
}

public function compiler(): BladeCompiler
public function make(string $view, $data = [], $mergeData = []): string
{
return $this->compiler;
return $this->blade->make($view, $data, $mergeData)->render();
}

/**
* Create your own custom directive
* Add a new namespace to the loader
*/
public function directive(string $name, callable $handler)
{
$this->compiler->directive($name, $handler);
}

public function if($name, callable $callback)
{
$this->compiler->if($name, $callback);
}

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->share($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);
$this->blade->directive($name, $handler);
}

protected function setupContainer(array $viewPaths, string $cachePath)
/**
* Summary of blade
* @return \Jenssegers\Blade\Blade
*/
public function blade()
{
$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 new BladeConfig([
'view.paths' => $viewPaths,
'view.compiled' => $cachePath,
]);
}, true);

Facade::setFacadeApplication($this->container);
return $this->blade;
}
}
Loading

0 comments on commit d0cabb0

Please sign in to comment.