Skip to content

Commit a7747e1

Browse files
committed
wip
1 parent 3b94f37 commit a7747e1

13 files changed

Lines changed: 97 additions & 104 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ composer require tempest/view-for-laravel
2828
From any controller, simply return an instance of `\Tempest\ViewForLaravel\TempestView`:
2929

3030
```php
31-
use Tempest\ViewForLaravel\TempestView;
31+
use Tempest\ViewForLaravel\GenericTempestView;
3232

3333
final readonly class HomeController
3434
{
3535
public function __invoke()
3636
{
37-
return new TempestView(__DIR__ . '/Views/home.view.php');
37+
return new GenericTempestView(__DIR__ . '/Views/home.view.php');
3838
}
3939
}
4040
```

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
"autoload": {
3434
"psr-4": {
3535
"Tempest\\ViewForLaravel\\": "src/"
36-
}
36+
},
37+
"files": [
38+
"src/functions.php"
39+
]
3740
},
3841
"autoload-dev": {
3942
"psr-4": {

src/GenericTempestView.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Tempest\ViewForLaravel;
4+
5+
final class GenericTempestView implements TempestView
6+
{
7+
use IsTempestView;
8+
}

src/IsTempestView.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Tempest\ViewForLaravel;
4+
5+
use Illuminate\Http\Response;
6+
use Tempest\View\IsView;
7+
use Tempest\View\ViewRenderer;
8+
9+
trait IsTempestView
10+
{
11+
use IsView;
12+
13+
public function __construct(
14+
string $path,
15+
array $data = [],
16+
) {
17+
if (! str_ends_with($path, '.view.php')) {
18+
$path = $path . '.view.php';
19+
}
20+
21+
$this->path = $path;
22+
$this->data = $data;
23+
}
24+
25+
public function toResponse($request): Response
26+
{
27+
$viewRenderer = app()->get(ViewRenderer::class);
28+
29+
return response($viewRenderer->render($this));
30+
}
31+
}

src/TempestView.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,9 @@
33
namespace Tempest\ViewForLaravel;
44

55
use Illuminate\Contracts\Support\Responsable;
6-
use Illuminate\Http\Response;
7-
use Tempest\View\IsView;
86
use Tempest\View\View;
9-
use Tempest\View\ViewRenderer;
107

11-
final class TempestView implements Responsable, View
8+
interface TempestView extends Responsable, View
129
{
13-
use IsView;
1410

15-
public function __construct(
16-
string $path,
17-
array $data = [],
18-
) {
19-
if (! str_ends_with($path, '.view.php')) {
20-
$path = $path . '.view.php';
21-
}
22-
23-
$this->path = $path;
24-
$this->data = $data;
25-
}
26-
27-
public function toResponse($request): Response
28-
{
29-
$viewRenderer = app()->get(ViewRenderer::class);
30-
31-
return response($viewRenderer->render($this));
32-
}
3311
}

src/functions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Tempest\ViewForLaravel\GenericTempestView;
4+
5+
if (! function_exists('tempestView')) {
6+
function tempestView(string $path, array $data = []): GenericTempestView
7+
{
8+
return new GenericTempestView($path, $data);
9+
}
10+
}

tests/Controllers/HomeController.php

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Tempest\ViewForLaravel\Tests\Controllers;
4+
5+
use Tempest\ViewForLaravel\GenericTempestView;
6+
7+
final readonly class ViewController
8+
{
9+
public function fullPath(): GenericTempestView
10+
{
11+
return new GenericTempestView(resource_path('views/home.view.php'));
12+
}
13+
14+
public function withoutExtension(): GenericTempestView
15+
{
16+
return new GenericTempestView(resource_path('views/home'));
17+
}
18+
19+
public function withoutPath(): GenericTempestView
20+
{
21+
return new GenericTempestView('home');
22+
}
23+
}

tests/Controllers/ViewFromResourceController.php

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

tests/ResourceViews/resource-home.view.php

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

0 commit comments

Comments
 (0)