mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 17:26:53 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Extensions\Captcha;
 | |
| 
 | |
| use App\Extensions\Captcha\Schemas\CaptchaSchemaInterface;
 | |
| use Illuminate\Support\Collection;
 | |
| use Illuminate\Support\Str;
 | |
| 
 | |
| class CaptchaService
 | |
| {
 | |
|     /** @var array<string, CaptchaSchemaInterface> */
 | |
|     private array $schemas = [];
 | |
| 
 | |
|     /**
 | |
|      * @return CaptchaSchemaInterface[]
 | |
|      */
 | |
|     public function getAll(): array
 | |
|     {
 | |
|         return $this->schemas;
 | |
|     }
 | |
| 
 | |
|     public function get(string $id): ?CaptchaSchemaInterface
 | |
|     {
 | |
|         return array_get($this->schemas, $id);
 | |
|     }
 | |
| 
 | |
|     public function register(CaptchaSchemaInterface $schema): void
 | |
|     {
 | |
|         if (array_key_exists($schema->getId(), $this->schemas)) {
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         config()->set('captcha.' . Str::lower($schema->getId()), $schema->getConfig());
 | |
|         $this->schemas[$schema->getId()] = $schema;
 | |
|     }
 | |
| 
 | |
|     /** @return Collection<CaptchaSchemaInterface> */
 | |
|     public function getActiveSchemas(): Collection
 | |
|     {
 | |
|         return collect($this->schemas)
 | |
|             ->filter(fn (CaptchaSchemaInterface $schema) => $schema->isEnabled());
 | |
|     }
 | |
| 
 | |
|     public function getActiveSchema(): ?CaptchaSchemaInterface
 | |
|     {
 | |
|         return $this->getActiveSchemas()->first();
 | |
|     }
 | |
| }
 | 
