mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 14:56:52 +01:00 
			
		
		
		
	 da195fd2fe
			
		
	
	
		da195fd2fe
		
			
		
	
	
	
	
		
			
			* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Controllers\Api\Client;
 | |
| 
 | |
| use Webmozart\Assert\Assert;
 | |
| use App\Transformers\Api\Client\BaseClientTransformer;
 | |
| use App\Http\Controllers\Api\Application\ApplicationApiController;
 | |
| 
 | |
| abstract class ClientApiController extends ApplicationApiController
 | |
| {
 | |
|     /**
 | |
|      * Returns only the includes which are valid for the given transformer.
 | |
|      *
 | |
|      * @param  array<mixed>  $merge
 | |
|      * @return array<array-key, mixed>
 | |
|      */
 | |
|     protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = []): array
 | |
|     {
 | |
|         $filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
 | |
|             return in_array($datum, $transformer->getAvailableIncludes());
 | |
|         });
 | |
| 
 | |
|         return array_merge($filtered, $merge);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Returns the parsed includes for this request.
 | |
|      *
 | |
|      * @return array<array-key, mixed>
 | |
|      */
 | |
|     protected function parseIncludes(): array
 | |
|     {
 | |
|         $includes = $this->request->query('include') ?? [];
 | |
| 
 | |
|         if (!is_string($includes)) {
 | |
|             return $includes;
 | |
|         }
 | |
| 
 | |
|         return array_map(function ($item) {
 | |
|             return trim($item);
 | |
|         }, explode(',', $includes));
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Return an instance of an application transformer.
 | |
|      *
 | |
|      * @template T of \App\Transformers\Api\Client\BaseClientTransformer
 | |
|      *
 | |
|      * @param  class-string<T>  $abstract
 | |
|      * @return T
 | |
|      *
 | |
|      * @noinspection PhpDocSignatureInspection
 | |
|      */
 | |
|     public function getTransformer(string $abstract)
 | |
|     {
 | |
|         Assert::subclassOf($abstract, BaseClientTransformer::class);
 | |
| 
 | |
|         return $abstract::fromRequest($this->request);
 | |
|     }
 | |
| }
 |