<?php

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


class ProxyConfig
{
  private $server;
  private $port;
  private $user;
  private $password;

  public function __construct($pServer = '', $pPort = '', $pUser = '', $pPassword = '')
  {
    $this->setServer($pServer);
    $this->setPort($pPort);
    $this->setUser($pUser);
    $this->setPassword($pPassword);
  }

  public static function getProxyConfigFromSettings()
  {
    $proxyConfig = new ProxyConfig();
    $proxyConfig->setServerAndPortCombined(CURL_PROXYSERVER);
    $proxyConfig->setUserAndPasswordCombined(CURL_PROXYPASS);

    return $proxyConfig;
  }

  public function setServer($pServer)
  {
    $this->server = $pServer;
  }

  public function getServer()
  {
    return $this->server;
  }

  public function setPort($pPort)
  {
    $this->port = $pPort;
  }

  public function getPort()
  {
    return $this->port;
  }

  public function setUser($pUser)
  {
    $this->user = $pUser;
  }

  public function getUser()
  {
    return $this->user;
  }

  public function setPassword($pPassword)
  {
    $this->password = $pPassword;
  }

  public function getPassword()
  {
    return $this->password;
  }

  
  public function setServerAndPortCombined($serverAndPort)
  {
    list($server, $port) = ConstantOperations::getProxyServerAndPort();
    $this->setServer($server);
    $this->setPort($port);
  }

  
  public function setUserAndPasswordCombined($userAndPassword)
  {
    $user = $passwort = '';
    $userPasswortTrenner = StringOperations::strpos($userAndPassword, ':');
    if ($userPasswortTrenner !== false) {
      $user = StringOperations::substr($userAndPassword, 0, $userPasswortTrenner);
      $passwort = StringOperations::substr($userAndPassword, $userPasswortTrenner + 1);
    } else {
      $user = $userAndPassword;
    }
    $this->setUser($user);
    $this->setPassword($passwort);
  }
}