Refactoring and cleanup
* Moved logic from entrypoint to a dedicated class. * Disabled automatic flush of state. * Added locking support to prevent multiple instances. * Added logging * Added base interface for CredentialsLoader
This commit is contained in:
		
							
								
								
									
										33
									
								
								src/Configuration/ComposeConfiguration.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/Configuration/ComposeConfiguration.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace NoccyLabs\FreshDocker\Configuration;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Yaml\Yaml;
 | 
			
		||||
 | 
			
		||||
class ComposeConfiguration
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    private array $checks = [];
 | 
			
		||||
 | 
			
		||||
    public function __construct(string $configfile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->loadComposeFile($configfile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function loadComposeFile($configfile)
 | 
			
		||||
    {
 | 
			
		||||
        $config = Yaml::parseFile($configfile);
 | 
			
		||||
        $services = $config['services']??[];
 | 
			
		||||
        foreach ($services as $name=>$service) {
 | 
			
		||||
            $image = $service['image']??null;
 | 
			
		||||
            if ($image && !in_array($image,$this->checks)) {
 | 
			
		||||
                $this->checks[] = $image;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getChecks(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->checks;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user