generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollback to typescript transformer 2
- Loading branch information
1 parent
a0a163b
commit c7a4be1
Showing
23 changed files
with
380 additions
and
327 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/Support/TypeScriptTransformer/DataTypeScriptCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelData\Support\TypeScriptTransformer; | ||
|
||
use ReflectionClass; | ||
use Spatie\LaravelData\Contracts\BaseData; | ||
use Spatie\TypeScriptTransformer\Collectors\Collector; | ||
use Spatie\TypeScriptTransformer\Structures\TransformedType; | ||
|
||
class DataTypeScriptCollector extends Collector | ||
{ | ||
public function getTransformedType(ReflectionClass $class): ?TransformedType | ||
{ | ||
if (! $class->isSubclassOf(BaseData::class)) { | ||
return null; | ||
} | ||
|
||
$transformer = new DataTypeScriptTransformer($this->config); | ||
|
||
return $transformer->transform($class, $class->getShortName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 0 additions & 139 deletions
139
src/Support/TypeScriptTransformer/DataUtilitiesClassPropertyProcessor.php
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
src/Support/TypeScriptTransformer/RemoveLazyTypeProcessor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelData\Support\TypeScriptTransformer; | ||
|
||
use Exception; | ||
use phpDocumentor\Reflection\Type; | ||
use phpDocumentor\Reflection\Types\Compound; | ||
use phpDocumentor\Reflection\Types\Object_; | ||
use ReflectionMethod; | ||
use ReflectionParameter; | ||
use ReflectionProperty; | ||
use Spatie\LaravelData\Lazy; | ||
use Spatie\TypeScriptTransformer\Structures\MissingSymbolsCollection; | ||
use Spatie\TypeScriptTransformer\TypeProcessors\TypeProcessor; | ||
|
||
class RemoveLazyTypeProcessor implements TypeProcessor | ||
{ | ||
public function process( | ||
Type $type, | ||
ReflectionParameter | ReflectionMethod | ReflectionProperty $reflection, | ||
MissingSymbolsCollection $missingSymbolsCollection | ||
): ?Type { | ||
if (! $type instanceof Compound) { | ||
return $type; | ||
} | ||
|
||
/** @var \Illuminate\Support\Collection $types */ | ||
$types = collect(iterator_to_array($type->getIterator())) | ||
->reject(function (Type $type) { | ||
if (! $type instanceof Object_) { | ||
return false; | ||
} | ||
|
||
return is_a((string)$type->getFqsen(), Lazy::class, true); | ||
}); | ||
|
||
if ($types->isEmpty()) { | ||
throw new Exception("Type {$reflection->getDeclaringClass()->name}:{$reflection->getName()} cannot be only Lazy"); | ||
} | ||
|
||
if ($types->count() === 1) { | ||
return $types->first(); | ||
} | ||
|
||
return new Compound($types->all()); | ||
} | ||
} |
Oops, something went wrong.