Skip to content

Commit

Permalink
Merge pull request #3 from mauricius/feature/php83
Browse files Browse the repository at this point in the history
Upgrade dependencies
  • Loading branch information
mauricius authored Dec 22, 2024
2 parents d83b07f + 70191f7 commit e0064f9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
vendor
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ First of all, you need to install both Wireframe and WireframeRenderBlade.

Then you have to install the dependencies of WireframeRenderBlade by running

```
```bash
composer install
```

in the module folder.

Finally you can set up Wireframe (as instructed at https://wireframe-framework.com/getting-started/). Once that's done, you can open the bootstrap file (`wireframe.php`) and instruct Wireframe to use the Blade renderer:
Finally, you can set up Wireframe (as instructed at https://wireframe-framework.com/getting-started/). Once that's done, you can open the bootstrap file (`wireframe.php`) and instruct Wireframe to use the Blade renderer:

```php
// during Wireframe init (this is the preferred way):
Expand Down Expand Up @@ -55,7 +55,7 @@ Note that if a Blade file can't be found, Wireframe will automatically fall back

Blade allows you to extend a parent layout using the Blade `@extends` directive, to specify which layout the child view should "inherit". By default all layouts are referenced from the `views` folder

```
```bladehtml
@extends('layout')
```

Expand All @@ -66,9 +66,9 @@ Blade allows you to extend a parent layout using the Blade `@extends` directive,
| └-- child.blade.php
```

Otherwise you can keep the Wireframe concept of layout and use a Blade file from the `layouts` folder, by prefixing the layout with the `layout::` namespace
Otherwise, you can keep the Wireframe concept of layout and use a Blade file from the `layouts` folder, by prefixing the layout with the `layout::` namespace

```
```bladehtml
@extends('layout::layout')
```

Expand Down Expand Up @@ -100,7 +100,7 @@ $wire->addHookAfter('WireframeRendererBlade::initBlade', function(HookEvent $eve

```

```
```bladehtml
@hello('World')
```

Expand All @@ -116,7 +116,7 @@ $wire->addHookAfter('WireframeRendererBlade::initBlade', function(HookEvent $eve

```

```
```bladehtml
@superuser
<h2>Hello</h2>
@else
Expand Down Expand Up @@ -158,7 +158,7 @@ $wire->addHookAfter('WireframeRendererBlade::initBlade', function(HookEvent $eve
});
```

```
```bladehtml
@cache('my-cache-key', 3600)
{{-- heavy stuff here --}}
@endcache
Expand Down Expand Up @@ -188,7 +188,7 @@ $wire->addHookAfter('WireframeRendererBlade::initBlade', function(HookEvent $eve
});
```

```
```bladehtml
@cacheInclude('my-partial', 3600)
```

Expand Down Expand Up @@ -230,7 +230,7 @@ $wireframe->view->getRenderer()->getBladeInstance()->composer('*', function($vie

Finally you can use the `$textdomain` variable wherever you need to translate strings

```
```bladehtml
{{ __("Translate me", $textdomain) }}
```

Expand Down
4 changes: 2 additions & 2 deletions WireframeRendererBlade.info.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"title": "Wireframe Renderer: Blade",
"summary": "Blade renderer for the Wireframe output framework.",
"version": "0.2.0",
"version": "0.3.0",
"author": "Maurizio Bonani",
"href": "https://wireframe-framework.com",
"requires": [
"ProcessWire>=3.0.123",
"Wireframe>=0.9.0",
"PHP>=7.1.0"
"PHP>=8.1.0"
],
"singular": true,
"autoload": false
Expand Down
19 changes: 11 additions & 8 deletions WireframeRendererBlade.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
namespace ProcessWire;

use Jenssegers\Blade\Blade;
use Jenssegers\Blade\Container;

/**
* Wireframe Renderer Blade
*
* @version 0.2.0
* @version 0.3.0
* @author Maurizio Bonani <[email protected]>
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/
*/
Expand All @@ -20,14 +21,14 @@ class WireframeRendererBlade extends Wire implements Module
*
* @var Blade
*/
protected $blade;
protected Blade $blade;

/**
* Default extension.
*
* @var string
*/
protected $ext = 'blade.php';
protected string $ext = 'blade.php';

/**
* Init method
Expand All @@ -52,6 +53,7 @@ public function ___init(array $settings = []): WireframeRendererBlade
*
* @param array $settings Blade settings.
* @return Blade
* @throws WireException
*/
public function ___initBlade(array $settings = []): Blade
{
Expand All @@ -62,7 +64,8 @@ public function ___initBlade(array $settings = []): Blade
$views = $settings['views'] ?? $viewPaths['view'];
$cache = $settings['cache'] ?? $this->wire('config')->paths->cache . 'WireframeRendererBlade';

$blade = new Blade($views, $cache);
// see https://github.com/jenssegers/blade/issues/74
$blade = new Blade($views, $cache, Container::getInstance());

$blade->addNamespace('layout', $viewPaths['layout']);
$blade->addNamespace('partial', $viewPaths['partial']);
Expand All @@ -82,7 +85,7 @@ public function ___initBlade(array $settings = []): Blade
*/
public function render(string $type, string $view, array $context = []): string
{
if (! in_array($type, array_keys($this->wire('modules')->get('Wireframe')->getViewPaths()))) {
if (! in_array($type, array_keys($this->wire('modules')->get('Wireframe')->getViewPaths()), true)) {
throw new WireException(sprintf('Unexpected type (%s).', $type));
}

Expand All @@ -102,18 +105,18 @@ public function render(string $type, string $view, array $context = []): string
* @param string $view
* @return string
*/
protected function namespaceView(string $type, string $view)
protected function namespaceView(string $type, string $view): string
{
return $type . '::' . $view;
}

/**
* Adapt view path to Blade notation.
*
* @param string $view
* @param string $view
* @return string
*/
protected function adaptView($view)
protected function adaptView(string $view): string
{
return preg_replace('/.'. $this->ext . '$/', '', str_replace('/', '.', $view));
}
Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=8.1",
"wireframe-framework/processwire-composer-installer": "^1.0.0",
"jenssegers/blade": "^1.3"
"jenssegers/blade": "^2.0",
"phpunit/phpunit": "^9.4"
},
"autoload": {
"files" : ["helpers.php"]
},
"config": {
"allow-plugins": {
"hari/pw-module": true,
"wireframe-framework/processwire-composer-installer": true
}
}
}

0 comments on commit e0064f9

Please sign in to comment.