Skip to content

Commit 3ee136d

Browse files
committed
wip
Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 6a9a226 commit 3ee136d

File tree

6 files changed

+102
-9
lines changed

6 files changed

+102
-9
lines changed

src/Console/FilterCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\Console\Attribute\AsCommand;
99

1010
/**
11-
* @see https://github.com/laravel/nova/blob/4.0/src/Console/FilterCommand.php
11+
* @see Laravel\Nova\Console\FilterCommand
1212
*/
1313
#[AsCommand(name: 'nova:filter', description: 'Create a new filter class')]
1414
class FilterCommand extends Command

src/Console/LensCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\Console\Attribute\AsCommand;
99

1010
/**
11-
* @see https://github.com/laravel/nova/blob/4.0/src/Console/LensCommand.php
11+
* @see Laravel\Nova\Console\LensCommand
1212
*/
1313
#[AsCommand(name: 'nova:lens', description: 'Create a new lens class')]
1414
class LensCommand extends Command

src/Console/PolicyMakeCommand.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Laravel\Nova\DevTool\Console;
4+
5+
use Laravel\Nova\Console\PolicyMakeCommand as Command;
6+
use Orchestra\Canvas\Core\Concerns\CodeGenerator;
7+
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
8+
use Symfony\Component\Console\Attribute\AsCommand;
9+
10+
/**
11+
* @see Laravel\Nova\Console\PolicyMakeCommand
12+
*/
13+
#[AsCommand(name: 'nova:policy', description: 'Create a new policy class')]
14+
class PolicyMakeCommand extends Command
15+
{
16+
use CodeGenerator;
17+
use UsesGeneratorOverrides;
18+
19+
/** {@inheritDoc} */
20+
#[\Override]
21+
protected function configure()
22+
{
23+
$this->addGeneratorPresetOptions();
24+
}
25+
26+
/** {@inheritDoc} */
27+
#[\Override]
28+
public function handle()
29+
{
30+
return $this->generateCode() ? self::SUCCESS : self::FAILURE;
31+
}
32+
33+
/** {@inheritDoc} */
34+
#[\Override]
35+
protected function getPath($name)
36+
{
37+
return $this->getPathUsingCanvas($name);
38+
}
39+
40+
/** {@inheritDoc} */
41+
#[\Override]
42+
protected function rootNamespace()
43+
{
44+
return $this->rootNamespaceUsingCanvas();
45+
}
46+
}

src/Console/ResourceCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
88
use Symfony\Component\Console\Attribute\AsCommand;
99

10+
/**
11+
* @see Laravel\Nova\Console\ResourceCommand
12+
*/
1013
#[AsCommand(name: 'nova:resource', description: 'Create a new resource class')]
1114
class ResourceCommand extends Command
1215
{

src/DevToolServiceProvider.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
use Laravel\Nova\Console\DashboardCommand;
1010
use Laravel\Nova\Console\FilterCommand;
1111
use Laravel\Nova\Console\LensCommand;
12+
use Laravel\Nova\Console\PolicyMakeCommand;
1213
use Laravel\Nova\Console\ResourceCommand;
1314
use Orchestra\Workbench\Events\InstallEnded;
1415
use Orchestra\Workbench\Events\InstallStarted;
1516
use Orchestra\Workbench\Workbench;
16-
1717
use function Illuminate\Filesystem\join_paths;
1818

1919
class DevToolServiceProvider extends ServiceProvider
@@ -42,6 +42,7 @@ public function register()
4242
$this->registerDashboardCommand();
4343
$this->registerFilterCommand();
4444
$this->registerLensCommand();
45+
$this->registerPolicyMakeCommand();
4546
$this->registerResourceCommand();
4647

4748
$this->commands([
@@ -50,13 +51,14 @@ public function register()
5051
Console\DashboardCommand::class,
5152
Console\FilterCommand::class,
5253
Console\LensCommand::class,
54+
Console\PolicyMakeCommand::class,
5355
Console\ResourceCommand::class,
5456
]);
5557
}
5658
}
5759

5860
/**
59-
* Register the command.
61+
* Register the `nova:action` command.
6062
*
6163
* @return void
6264
*/
@@ -68,7 +70,7 @@ protected function registerActionCommand()
6870
}
6971

7072
/**
71-
* Register the command.
73+
* Register the `nova:dashboard` command.
7274
*
7375
* @return void
7476
*/
@@ -80,7 +82,7 @@ protected function registerDashboardCommand()
8082
}
8183

8284
/**
83-
* Register the command.
85+
* Register the `nova:base-resource` command.
8486
*
8587
* @return void
8688
*/
@@ -92,7 +94,7 @@ protected function registerBaseResourceCommand()
9294
}
9395

9496
/**
95-
* Register the command.
97+
* Register the `nova:filter` command.
9698
*
9799
* @return void
98100
*/
@@ -104,7 +106,7 @@ protected function registerFilterCommand()
104106
}
105107

106108
/**
107-
* Register the command.
109+
* Register the `nova:lens` command.
108110
*
109111
* @return void
110112
*/
@@ -116,7 +118,19 @@ protected function registerLensCommand()
116118
}
117119

118120
/**
119-
* Register the command.
121+
* Register the `nova:policy` command.
122+
*
123+
* @return void
124+
*/
125+
protected function registerPolicyMakeCommand()
126+
{
127+
$this->app->singleton(PolicyMakeCommand::class, function ($app) {
128+
return new Console\PolicyMakeCommand($app['files']);
129+
});
130+
}
131+
132+
/**
133+
* Register the `nova:resource` command.
120134
*
121135
* @return void
122136
*/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
4+
5+
use function Orchestra\Testbench\Pest\setUp;
6+
use function Pest\Laravel\artisan;
7+
8+
uses(InteractsWithPublishedFiles::class);
9+
10+
setUp(function ($parent) {
11+
defineTestbenchPackagePath();
12+
13+
$parent();
14+
15+
$this->files = [
16+
'app/Nova/Policies/*.php',
17+
];
18+
});
19+
20+
it('can generate policy file', function () {
21+
artisan('nova:policy', ['name' => 'UserPolicy', '--preset' => 'laravel'])
22+
->assertSuccessful();
23+
24+
$this->assertFileContains([
25+
'namespace App\Nova\Policies;',
26+
'use Illuminate\Auth\Access\Response;',
27+
'use Illuminate\Foundation\Auth\User;',
28+
'class UserPolicy',
29+
], 'app/Nova/Policies/UserPolicy.php');
30+
});

0 commit comments

Comments
 (0)