1. Go to this page and download the library: Download strucura/transpose library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
strucura / transpose example snippets
use Illuminate\Http\Resources\Json\JsonResource;
use Spatie\StructureDiscoverer\Support\Conditions\ConditionBuilder;
use Strucura\Transpose\Builders\TranspositionBuilder;
use Strucura\Transpose\Transformers\BackedEnumDataTypeTransformer;
use Strucura\Transpose\Transformers\JsonResourceDataTypeTransformer;
use Strucura\Transpose\Writers\TypeScriptWriter;
return [
'transpositions' => [
TranspositionBuilder::make('TypeScript')
->discoveryPaths([
app_path(''),
])
->discoveryConditions([
ConditionBuilder::create()->enums(),
ConditionBuilder::create()
->classes()
->extending(JsonResource::class),
])
->transformers([
BackedEnumDataTypeTransformer::class,
JsonResourceDataTypeTransformer::class,
])
->writer(TypeScriptWriter::class)
->writesTo(base_path('resources/js/types.ts')),
],
];
use Strucura\Transpose\Attributes\DefineProperties;
use Strucura\Transpose\Properties\PrimitiveProperty;
use Strucura\Transpose\Enums\PrimitivesEnum;
#[DefineProperties([
new PrimitiveProperty('property1', PrimitivesEnum::String),
new PrimitiveProperty('property2', PrimitivesEnum::Integer),
])]
class MyClass
{
// Class implementation
}
use Strucura\Transpose\Attributes\DerivePropertiesFromModel;
#[DerivePropertiesFromModel(MyModel::class)]
class MyClass
{
// Class implementation
}