protected function getExistingVariable($name, $level = null, $messages = true)
    {
        $output = $messages ? $this->stdErr : new NullOutput();

        if ($level === self::LEVEL_ENVIRONMENT || ($this->hasSelectedEnvironment() && $level === null)) {
            $variable = $this->getSelectedEnvironment()->getVariable($name);
            if ($variable !== false) {
                if ($level === null && $this->getSelectedProject()->getVariable($name)) {
                    $output->writeln('Variable found at both project and environment levels: <error>' . $name . '</error>');
                    $output->writeln("To select a variable, use the --level option ('" . self::LEVEL_PROJECT . "' or '" . self::LEVEL_ENVIRONMENT . "').");

                    return false;
                }

                return $variable;
            }
        }
        if ($level !== self::LEVEL_ENVIRONMENT) {
            $variable = $this->getSelectedProject()->getVariable($name);
            if ($variable !== false) {
                return $variable;
            }
        }
        $output->writeln('Variable not found: <error>' . $name . '</error>');

        return false;
    }
protected function getExistingVariable($name, $level = null, $messages = true)
    {
        $output = $messages ? $this->stdErr : new NullOutput();

        if ($level === self::LEVEL_ENVIRONMENT || ($this->hasSelectedEnvironment() && $level === null)) {
            $variable = $this->getSelectedEnvironment()->getVariable($name);
            if ($variable !== false) {
                if ($level === null && $this->getSelectedProject()->getVariable($name)) {
                    $output->writeln('Variable found at both project and environment levels: <error>' . $name . '</error>');
                    $output->writeln("To select a variable, use the --level option ('" . self::LEVEL_PROJECT . "' or '" . self::LEVEL_ENVIRONMENT . "').");

                    return false;
                }

                return $variable;
            }
        }
        if ($level !== self::LEVEL_ENVIRONMENT) {
            $variable = $this->getSelectedProject()->getVariable($name);
            if ($variable !== false) {
                return $variable;
            }
        }
        $output->writeln('Variable not found: <error>' . $name . '</error>');

        return false;
    }
protected function getExistingVariable ( $ name , $ level = null , $ messages = true ) { $ output = $ messages ? $ this -> stdErr : new NullOutput ( ) ; if ( $ level === self :: LEVEL_ENVIRONMENT || ( $ this -> hasSelectedEnvironment ( ) && $ level === null ) ) { $ variable = $ this -> getSelectedEnvironment ( ) -> getVariable ( $ name ) ; if ( $ variable !== false ) { if ( $ level === null && $ this -> getSelectedProject ( ) -> getVariable ( $ name ) ) { $ output -> writeln ( 'Variable found at both project and environment levels: <error>' . $ name . '</error>' ) ; $ output -> writeln ( "To select a variable, use the --level option ('" . self :: LEVEL_PROJECT . "' or '" . self :: LEVEL_ENVIRONMENT . "')." ) ; return false ; } return $ variable ; } } if ( $ level !== self :: LEVEL_ENVIRONMENT ) { $ variable = $ this -> getSelectedProject ( ) -> getVariable ( $ name ) ; if ( $ variable !== false ) { return $ variable ; } } $ output -> writeln ( 'Variable not found: <error>' . $ name . '</error>' ) ; return false ; }
Finds an existing variable by name.

@param string      $name
@param string|null $level
@param bool        $messages Whether to print error messages to
$this->stdErr if the variable is not found.

@return \Platformsh\Client\Model\ProjectLevelVariable|\Platformsh\Client\Model\Variable|false
Finds an existing variable by name .