Skip to content

Commit d0cabb0

Browse files
committed
feat: switch to jenssegers/blade
1 parent fd7c5b5 commit d0cabb0

17 files changed

+49
-947
lines changed

CHANGELOG.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

composer.json

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
{
2-
"name": "leafs/blade",
3-
"description": "Leaf PHP Framework adaptation of jenssegers/blade package",
4-
"keywords": ["leaf", "leafMVC", "laravel", "blade", "template", "view", "render"],
5-
"license" : "MIT",
6-
"type": "library",
7-
"authors": [
8-
{
9-
"name": "Michael Darko",
10-
"email": "[email protected]",
11-
"homepage": "https://mychi.netlify.app",
12-
"role": "Developer"
13-
}
14-
],
15-
"require": {
16-
"php": ">=7.3|^8.0",
17-
"illuminate/view": "^8.0|^9.0|^10.0"
18-
},
19-
"require-dev": {
20-
"pestphp/pest": "^1.0|^2.25"
21-
},
22-
"autoload": {
23-
"psr-4": {
24-
"Leaf\\": "src/"
25-
}
26-
},
27-
"minimum-stability": "dev",
28-
"prefer-stable": true,
29-
"config": {
30-
"allow-plugins": {
31-
"pestphp/pest-plugin": true
32-
}
2+
"name": "leafs/blade",
3+
"description": "Leaf PHP Framework adaptation of jenssegers/blade package",
4+
"keywords": [
5+
"leaf",
6+
"leafMVC",
7+
"laravel",
8+
"blade",
9+
"template",
10+
"view",
11+
"render"
12+
],
13+
"license": "MIT",
14+
"type": "library",
15+
"authors": [
16+
{
17+
"name": "Michael Darko",
18+
"email": "[email protected]",
19+
"homepage": "https://mychi.netlify.app",
20+
"role": "Developer"
3321
}
22+
],
23+
"require": {
24+
"php": ">=7.4|^8.0",
25+
"jenssegers/blade": "^1.4"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"Leaf\\": "src/"
30+
}
31+
},
32+
"minimum-stability": "dev",
33+
"prefer-stable": true
3434
}

src/Blade.php

Lines changed: 18 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,21 @@
22

33
namespace Leaf;
44

5-
use Illuminate\Contracts\Container\Container as ContainerInterface;
6-
use Illuminate\Contracts\View\Factory as FactoryContract;
7-
use Illuminate\Contracts\View\View;
8-
use Illuminate\Events\Dispatcher;
9-
use Illuminate\Filesystem\Filesystem;
10-
use Illuminate\Support\Facades\Facade;
11-
use Illuminate\View\Compilers\BladeCompiler;
12-
use Illuminate\View\Factory;
13-
use Illuminate\View\ViewServiceProvider;
14-
15-
class Blade implements FactoryContract
5+
class Blade
166
{
17-
/**
18-
* @var BladeContainer
19-
*/
20-
protected $container;
21-
22-
/**
23-
* @var Factory
24-
*/
25-
private $factory;
7+
protected $blade;
268

27-
/**
28-
* @var BladeCompiler
29-
*/
30-
private $compiler;
31-
32-
public function __construct($viewPaths = null, string $cachePath = null, ContainerInterface $container = null)
9+
public function __construct(string $viewPaths = null, string $cachePath = null)
3310
{
34-
$this->container = $container ?: new \Leaf\BladeContainer();
35-
36-
if ($viewPaths != null && $cachePath != null) {
37-
$this->configure($viewPaths, $cachePath);
38-
}
11+
// Just to maintain compatibility with the original Leaf Blade
3912
}
4013

4114
/**
4215
* Configure your view and cache directories
4316
*/
44-
public function configure($viewPaths, $cachePath)
17+
public function configure(string $viewPaths, string $cachePath)
4518
{
46-
$this->setupContainer((array) $viewPaths, $cachePath);
47-
(new ViewServiceProvider($this->container))->register();
48-
49-
$this->factory = $this->container->get('view');
50-
$this->compiler = $this->container->get('blade.compiler');
19+
$this->blade = new \Jenssegers\Blade\Blade($viewPaths, $cachePath);
5120
}
5221

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

6433
/**
@@ -67,90 +36,25 @@ public function render(string $view, array $data = [], array $mergeData = []): s
6736
* You can optionally pass data into the view as a second parameter.
6837
* Don't forget to chain the `render` method
6938
*/
70-
public function make($view, $data = [], $mergeData = []): View
71-
{
72-
return $this->factory->make($view, $data, $mergeData);
73-
}
74-
75-
public function compiler(): BladeCompiler
39+
public function make(string $view, $data = [], $mergeData = []): string
7640
{
77-
return $this->compiler;
41+
return $this->blade->make($view, $data, $mergeData)->render();
7842
}
7943

8044
/**
81-
* Create your own custom directive
45+
* Add a new namespace to the loader
8246
*/
8347
public function directive(string $name, callable $handler)
8448
{
85-
$this->compiler->directive($name, $handler);
86-
}
87-
88-
public function if($name, callable $callback)
89-
{
90-
$this->compiler->if($name, $callback);
91-
}
92-
93-
public function exists($view): bool
94-
{
95-
return $this->factory->exists($view);
96-
}
97-
98-
public function file($path, $data = [], $mergeData = []): View
99-
{
100-
return $this->factory->file($path, $data, $mergeData);
101-
}
102-
103-
public function share($key, $value = null)
104-
{
105-
return $this->factory->share($key, $value);
106-
}
107-
108-
public function composer($views, $callback): array
109-
{
110-
return $this->factory->composer($views, $callback);
111-
}
112-
113-
public function creator($views, $callback): array
114-
{
115-
return $this->factory->creator($views, $callback);
116-
}
117-
118-
public function addNamespace($namespace, $hints): self
119-
{
120-
$this->factory->addNamespace($namespace, $hints);
121-
122-
return $this;
123-
}
124-
125-
public function replaceNamespace($namespace, $hints): self
126-
{
127-
$this->factory->replaceNamespace($namespace, $hints);
128-
129-
return $this;
130-
}
131-
132-
public function __call(string $method, array $params)
133-
{
134-
return call_user_func_array([$this->factory, $method], $params);
49+
$this->blade->directive($name, $handler);
13550
}
13651

137-
protected function setupContainer(array $viewPaths, string $cachePath)
52+
/**
53+
* Summary of blade
54+
* @return \Jenssegers\Blade\Blade
55+
*/
56+
public function blade()
13857
{
139-
$this->container->bindIf('files', function () {
140-
return new Filesystem;
141-
}, true);
142-
143-
$this->container->bindIf('events', function () {
144-
return new Dispatcher;
145-
}, true);
146-
147-
$this->container->bindIf('config', function () use ($viewPaths, $cachePath) {
148-
return new BladeConfig([
149-
'view.paths' => $viewPaths,
150-
'view.compiled' => $cachePath,
151-
]);
152-
}, true);
153-
154-
Facade::setFacadeApplication($this->container);
58+
return $this->blade;
15559
}
15660
}

0 commit comments

Comments
 (0)