Skip to content

Commit

Permalink
Added the ability to create data files, casts, transformers and…
Browse files Browse the repository at this point in the history
… `rules` using Laravel Idea plugin
  • Loading branch information
andrey-helldar committed Jun 28, 2023
1 parent ce3d885 commit bd0e38a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 2 deletions.
86 changes: 86 additions & 0 deletions ide.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,91 @@
}
]
}
],
"codeGenerations": [
{
"id": "spatie.create-laravel-data",
"name": "Create Data",
"inputFilter": "data",
"classSuffix": "Data",
"files": [
{
"directory": "/app/Data",
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
"template": {
"type": "stub",
"path": "/stubs/data.stub",
"fallbackPath": "stubs/data.stub",
"parameters": {
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
"DummyNamespace": "${INPUT_FQN|namespace}"
}
}
}
]
},
{
"id": "spatie.create-laravel-data-cast",
"name": "Create Data Cast",
"inputFilter": "cast",
"classSuffix": "Cast",
"files": [
{
"directory": "/app/Data/Casts",
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
"template": {
"type": "stub",
"path": "/stubs/data-cast.stub",
"fallbackPath": "stubs/data-cast.stub",
"parameters": {
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
"DummyNamespace": "${INPUT_FQN|namespace}"
}
}
}
]
},
{
"id": "spatie.create-laravel-data-transformer",
"name": "Create Data Transformer",
"inputFilter": "data",
"classSuffix": "Transformer",
"files": [
{
"directory": "/app/Data/Transformers",
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
"template": {
"type": "stub",
"path": "/stubs/data-transformer.stub",
"fallbackPath": "stubs/data-transformer.stub",
"parameters": {
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
"DummyNamespace": "${INPUT_FQN|namespace}"
}
}
}
]
},
{
"id": "spatie.create-laravel-data-rule",
"name": "Create Data Rule",
"inputFilter": "rule",
"classSuffix": "Rule",
"files": [
{
"directory": "/app/Data/Rules",
"name": "${INPUT_CLASS|className|upperCamelCase}.php",
"template": {
"type": "stub",
"path": "/stubs/data-rule.stub",
"fallbackPath": "stubs/data-rule.stub",
"parameters": {
"DummyClass": "${INPUT_CLASS|className|upperCamelCase}",
"DummyNamespace": "${INPUT_FQN|namespace}"
}
}
}
]
}
]
}
14 changes: 14 additions & 0 deletions stubs/data-cast.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace DummyNamespace;

use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\DataProperty;

class DummyClass implements Cast
{
public function cast(DataProperty $property, mixed $value, array $context): mixed
{
//
}
}
16 changes: 16 additions & 0 deletions stubs/data-rule.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace DummyNamespace;

use Spatie\LaravelData\RuleInferrers\RuleInferrer;
use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Validation\PropertyRules;
use Spatie\LaravelData\Support\Validation\ValidationContext;

class DummyClass implements RuleInferrer
{
public function handle(DataProperty $property, PropertyRules $rules, ValidationContext $context,): PropertyRules
{
//
}
}
14 changes: 14 additions & 0 deletions stubs/data-transformer.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace DummyNamespace;

use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Transformers\Transformer;

class DummyClass implements Transformer
{
public function transform(DataProperty $property, mixed $value): mixed
{
//
}
}
4 changes: 2 additions & 2 deletions stubs/data.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace {{ namespace }};
namespace DummyNamespace;

use Spatie\LaravelData\Data;

class {{ class }} extends Data
class DummyClass extends Data
{
public function __construct(
//
Expand Down

0 comments on commit bd0e38a

Please sign in to comment.