mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 09:26:54 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Extensions\League\Fractal\Serializers;
 | 
						|
 | 
						|
use League\Fractal\Serializer\ArraySerializer;
 | 
						|
 | 
						|
class PanelSerializer extends ArraySerializer
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Serialize an item.
 | 
						|
     */
 | 
						|
    public function item(?string $resourceKey, array $data): array
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            'object' => $resourceKey,
 | 
						|
            'attributes' => $data,
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Serialize a collection.
 | 
						|
     */
 | 
						|
    public function collection(?string $resourceKey, array $data): array
 | 
						|
    {
 | 
						|
        $response = [];
 | 
						|
        foreach ($data as $datum) {
 | 
						|
            $response[] = $this->item($resourceKey, $datum);
 | 
						|
        }
 | 
						|
 | 
						|
        return [
 | 
						|
            'object' => 'list',
 | 
						|
            'data' => $response,
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Serialize a null resource.
 | 
						|
     */
 | 
						|
    public function null(): ?array
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            'object' => 'null_resource',
 | 
						|
            'attributes' => null,
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Merge the included resources with the parent resource being serialized.
 | 
						|
     */
 | 
						|
    public function mergeIncludes(array $transformedData, array $includedData): array
 | 
						|
    {
 | 
						|
        foreach ($includedData as $key => $datum) {
 | 
						|
            $transformedData['relationships'][$key] = $datum;
 | 
						|
        }
 | 
						|
 | 
						|
        return $transformedData;
 | 
						|
    }
 | 
						|
}
 |