generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82f1983
commit 7cc6e0e
Showing
10 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelData\Attributes; | ||
|
||
use Attribute; | ||
use Spatie\LaravelData\Casts\Cast; | ||
use Spatie\LaravelData\Exceptions\CannotCreateCastAttribute; | ||
use Spatie\LaravelData\Exceptions\CannotCreateTransformerAttribute; | ||
use Spatie\LaravelData\Transformers\Transformer; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] | ||
class WithCastAndTransformer implements GetsCast | ||
{ | ||
public array $arguments; | ||
|
||
public function __construct( | ||
/** @var class-string<Transformer&Cast> $class */ | ||
public string $class, | ||
mixed ...$arguments | ||
) { | ||
if (! is_a($this->class, Transformer::class, true)) { | ||
throw CannotCreateTransformerAttribute::notATransformer(); | ||
} | ||
|
||
if (! is_a($this->class, Cast::class, true)) { | ||
throw CannotCreateCastAttribute::notACast(); | ||
} | ||
|
||
$this->arguments = $arguments; | ||
} | ||
|
||
public function get(): Cast&Transformer | ||
{ | ||
return new ($this->class)(...$this->arguments); | ||
} | ||
} |
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
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
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
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 |
---|---|---|
|
@@ -49,9 +49,11 @@ public function __construct( | |
} | ||
|
||
/** | ||
* @param Closure(TValue, TKey): TValue $through | ||
* @template TOtherValue | ||
* | ||
* @return static | ||
* @param Closure(TValue, TKey): TOtherValue $through | ||
* | ||
* @return static<TKey, TOtherValue> | ||
*/ | ||
public function through(Closure $through): static | ||
Check failure on line 58 in src/CursorPaginatedDataCollection.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 |
---|---|---|
|
@@ -48,9 +48,11 @@ public function __construct( | |
} | ||
|
||
/** | ||
* @param Closure(TValue, TKey): TValue $through | ||
* @template TOtherValue | ||
* | ||
* @return static | ||
* @param Closure(TValue, TKey): TOtherValue $through | ||
* | ||
* @return static<TKey, TOtherValue> | ||
*/ | ||
public function through(Closure $through): static | ||
Check failure on line 57 in src/PaginatedDataCollection.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
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,24 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelData\Tests\Fakes\CastTransformers; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\LaravelData\Casts\Cast; | ||
use Spatie\LaravelData\Support\Creation\CreationContext; | ||
use Spatie\LaravelData\Support\DataProperty; | ||
use Spatie\LaravelData\Support\Transformation\TransformationContext; | ||
use Spatie\LaravelData\Transformers\Transformer; | ||
|
||
class FakeCastTransformer implements Cast, Transformer | ||
{ | ||
|
||
public function cast(DataProperty $property, mixed $value, Collection $properties, CreationContext $context): mixed | ||
{ | ||
return $value; | ||
} | ||
|
||
public function transform(DataProperty $property, mixed $value, TransformationContext $context): mixed | ||
{ | ||
return $value; | ||
} | ||
} |
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