mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			177 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			177 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
class Mage_Config
 | 
						|
{
 | 
						|
    private $_environment = null;
 | 
						|
    private $_scm = null;
 | 
						|
    private $_general = null;
 | 
						|
    private $_host = null;
 | 
						|
    private $_releaseId = null;
 | 
						|
    
 | 
						|
    public function loadEnvironment($environment)
 | 
						|
    {
 | 
						|
        if (($environment != '') && file_exists('.mage/config/environment/' . $environment . '.yaml')) {
 | 
						|
            $this->_environment = @yaml_parse_file('.mage/config/environment/' . $environment . '.yaml');            
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function loadSCM()
 | 
						|
    {
 | 
						|
        if (file_exists('.mage/config/scm.yaml')) {
 | 
						|
            $this->_scm = @yaml_parse_file('.mage/config/scm.yaml');            
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function loadGeneral()
 | 
						|
    {
 | 
						|
        if (file_exists('.mage/config/general.yaml')) {
 | 
						|
            $this->_general = @yaml_parse_file('.mage/config/general.yaml');
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getEnvironment()
 | 
						|
    {
 | 
						|
        return $this->_environment;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getSCM()
 | 
						|
    {
 | 
						|
        return $this->_scm;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getGlobal()
 | 
						|
    {
 | 
						|
        return $this->_global;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getHosts()
 | 
						|
    {
 | 
						|
        $config = $this->getEnvironment();
 | 
						|
        $hosts = array();
 | 
						|
        
 | 
						|
        if (isset($config['hosts'])) {
 | 
						|
            $hosts = (array) $config['hosts'];
 | 
						|
        }
 | 
						|
        
 | 
						|
        return $hosts;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function setHost($host)
 | 
						|
    {
 | 
						|
        $this->_host = $host;
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getHost()
 | 
						|
    {
 | 
						|
        return $this->_host;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function setReleaseId($id)
 | 
						|
    {
 | 
						|
        $this->_releaseId = $id;
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getReleaseId()
 | 
						|
    {
 | 
						|
        return $this->_releaseId;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getTasks($stage = 'on-deploy')
 | 
						|
    {
 | 
						|
        switch ($stage) {
 | 
						|
            case 'pre-deploy':
 | 
						|
                $type = 'tasks';
 | 
						|
                $stage = 'pre-deploy';
 | 
						|
                break;
 | 
						|
                
 | 
						|
            case 'post-deploy':
 | 
						|
                $type = 'tasks';
 | 
						|
                $stage = 'post-deploy';
 | 
						|
                break;
 | 
						|
                
 | 
						|
            case 'post-release':
 | 
						|
                $type = 'releases';
 | 
						|
                $stage = 'post-release';
 | 
						|
                break;
 | 
						|
                
 | 
						|
            case 'on-deploy':
 | 
						|
            default:
 | 
						|
                $type = 'tasks';
 | 
						|
                $stage = 'on-deploy';
 | 
						|
                break;
 | 
						|
        }
 | 
						|
        
 | 
						|
        $tasks = array();
 | 
						|
        $config = $this->getEnvironment();
 | 
						|
 | 
						|
        if (isset($config[$type]) && isset($config[$type][$stage])) {
 | 
						|
            $tasks = (array) $config[$type][$stage];
 | 
						|
        }
 | 
						|
 | 
						|
        return $tasks;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getConfig($host = false)
 | 
						|
    {
 | 
						|
        $taskConfig = array();
 | 
						|
        $taskConfig['deploy'] = $this->getEnvironment();
 | 
						|
        $taskConfig['deploy']['host'] = $host;
 | 
						|
        $taskConfig['scm'] = $this->getSCM();
 | 
						|
        
 | 
						|
        unset($taskConfig['deploy']['tasks']);
 | 
						|
        unset($taskConfig['deploy']['hosts']);
 | 
						|
        
 | 
						|
        return $taskConfig;
 | 
						|
    }
 | 
						|
 | 
						|
    public function deployment($option, $default = false)
 | 
						|
    {
 | 
						|
        $options = $this->getEnvironment();
 | 
						|
        if (isset($options['deployment'][$option])) {
 | 
						|
            return $options['deployment'][$option];
 | 
						|
        } else {
 | 
						|
            return $default;
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function release($option, $default = false)
 | 
						|
    {
 | 
						|
        $options = $this->getEnvironment();
 | 
						|
        if (isset($options['releases'][$option])) {
 | 
						|
            return $options['releases'][$option];
 | 
						|
        } else {
 | 
						|
            return $default;
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function scm($option, $default = false)
 | 
						|
    {
 | 
						|
        $options = $this->_scm;
 | 
						|
        if (isset($options[$option])) {
 | 
						|
            return $options[$option];
 | 
						|
        } else {
 | 
						|
            return $default;
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function general($option, $default = false)
 | 
						|
    {
 | 
						|
        $options = $this->_general;
 | 
						|
        if (isset($options[$option])) {
 | 
						|
            return $options[$option];
 | 
						|
        } else {
 | 
						|
            return $default;
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function mail($option, $default = false)
 | 
						|
    {
 | 
						|
        $options = $this->_general;
 | 
						|
        if (isset($options['mail'][$option])) {
 | 
						|
            return $options['mail'][$option];
 | 
						|
        } else {
 | 
						|
            return $default;
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |