<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ramasdev / simple-collection-transformer example snippets
use Ramasdev\SimpleCollectionTransformer\Attributes\CollectionAttribute;
use Ramasdev\SimpleCollectionTransformer\Tests\Unit\Data\Collections\ChannelCollection;
#[CollectionAttribute(ChannelCollection::class)]
class Channel
{
public function __construct(
private string $channelId,
private string $channelType,
private Carbon $lastRegistration
) {
}
public function getChannelId(): string
{
return $this->channelId;
}
public function getChannelType(): string
{
return $this->channelType;
}
public function getLastRegistration(): Carbon
{
return $this->lastRegistration;
}
}
use Ramasdev\SimpleCollectionTransformer\CollectionTransformer;
$actualCollection = $this->collectionTransformer->transform($data, function ($item) {
if ($item['channel_id'] === 'b') {
return false;
}
return new Channel($item['channel_id'], $item['channel_type'], new Carbon($item['last_registration']));
}); // Returns ChannelCollection
use Ramasdev\SimpleCollectionTransformer\CollectionTransformer;
$actualCollection = $this->collectionTransformer->transform($data, function ($item) {
return $this->decoder->decodeArray((array) $item, Channel::class);
}); // Returns ChannelCollection
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.