Skip to content

Commit 3378080

Browse files
Merge pull request spatie#485 from andrey-helldar/patch/2023-02-28/1
Added the ability to create `data` files, `casts`, `transformers` and `rules` using Laravel Idea plugin
2 parents 1363ed8 + a192ad6 commit 3378080

File tree

5 files changed

+128
-2
lines changed

5 files changed

+128
-2
lines changed

ide.json

+82
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,87 @@
3333
}
3434
]
3535
}
36+
],
37+
"codeGenerations": [
38+
{
39+
"id": "spatie.create-laravel-data",
40+
"name": "Create Data",
41+
"classSuffix": "Data",
42+
"files": [
43+
{
44+
"directory": "/app/Data",
45+
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
46+
"template": {
47+
"type": "stub",
48+
"path": "/stubs/data.stub",
49+
"fallbackPath": "stubs/data.stub",
50+
"parameters": {
51+
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
52+
"DummyNamespace": "${INPUT_FQN|namespace}"
53+
}
54+
}
55+
}
56+
]
57+
},
58+
{
59+
"id": "spatie.create-laravel-data-cast",
60+
"name": "Create Data Cast",
61+
"classSuffix": "Cast",
62+
"files": [
63+
{
64+
"directory": "/app/Data/Casts",
65+
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
66+
"template": {
67+
"type": "stub",
68+
"path": "/stubs/data-cast.stub",
69+
"fallbackPath": "stubs/data-cast.stub",
70+
"parameters": {
71+
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
72+
"DummyNamespace": "${INPUT_FQN|namespace}"
73+
}
74+
}
75+
}
76+
]
77+
},
78+
{
79+
"id": "spatie.create-laravel-data-transformer",
80+
"name": "Create Data Transformer",
81+
"classSuffix": "Transformer",
82+
"files": [
83+
{
84+
"directory": "/app/Data/Transformers",
85+
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
86+
"template": {
87+
"type": "stub",
88+
"path": "/stubs/data-transformer.stub",
89+
"fallbackPath": "stubs/data-transformer.stub",
90+
"parameters": {
91+
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
92+
"DummyNamespace": "${INPUT_FQN|namespace}"
93+
}
94+
}
95+
}
96+
]
97+
},
98+
{
99+
"id": "spatie.create-laravel-data-rule",
100+
"name": "Create Data Rule",
101+
"classSuffix": "Rule",
102+
"files": [
103+
{
104+
"directory": "/app/Data/Rules",
105+
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
106+
"template": {
107+
"type": "stub",
108+
"path": "/stubs/data-rule.stub",
109+
"fallbackPath": "stubs/data-rule.stub",
110+
"parameters": {
111+
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
112+
"DummyNamespace": "${INPUT_FQN|namespace}"
113+
}
114+
}
115+
}
116+
]
117+
}
36118
]
37119
}

stubs/data-cast.stub

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use Spatie\LaravelData\Casts\Cast;
6+
use Spatie\LaravelData\Support\DataProperty;
7+
8+
class DummyClass implements Cast
9+
{
10+
public function cast(DataProperty $property, mixed $value, array $context): mixed
11+
{
12+
//
13+
}
14+
}

stubs/data-rule.stub

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use Spatie\LaravelData\RuleInferrers\RuleInferrer;
6+
use Spatie\LaravelData\Support\DataProperty;
7+
use Spatie\LaravelData\Support\Validation\PropertyRules;
8+
use Spatie\LaravelData\Support\Validation\ValidationContext;
9+
10+
class DummyClass implements RuleInferrer
11+
{
12+
public function handle(DataProperty $property, PropertyRules $rules, ValidationContext $context,): PropertyRules
13+
{
14+
//
15+
}
16+
}

stubs/data-transformer.stub

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use Spatie\LaravelData\Support\DataProperty;
6+
use Spatie\LaravelData\Transformers\Transformer;
7+
8+
class DummyClass implements Transformer
9+
{
10+
public function transform(DataProperty $property, mixed $value): mixed
11+
{
12+
//
13+
}
14+
}

stubs/data.stub

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace {{ namespace }};
3+
namespace DummyNamespace;
44

55
use Spatie\LaravelData\Data;
66

7-
class {{ class }} extends Data
7+
class DummyClass extends Data
88
{
99
public function __construct(
1010
//

0 commit comments

Comments
 (0)