/**
  * @param string $email
  * @param string $password
  * @param string $username
  */
 protected function newAPI($email, $password, $username = null, $options = [])
 {
     $options = array_replace_recursive(['httpPlayback' => ['mode' => null]], $options);
     $this->httpPlayback = Factory::getInstance($options['httpPlayback']);
     if (!$username) {
         $username = $email;
     }
     $settings = $this->discover($email, $password, $username);
     if (!$settings) {
         throw new AutodiscoverFailed();
     }
     $server = $this->getServerFromResponse($settings);
     $version = $this->getServerVersionFromResponse($settings);
     if (!$server) {
         throw new AutodiscoverFailed();
     }
     $options = [];
     if ($version) {
         $options['version'] = $version;
     }
     return API::withUsernameAndPassword($server, $email, $password, $options);
 }
Beispiel #2
0
 /**
  * @param string $location
  * @param string $wsdl
  * @param array $options
  */
 public function __construct($location, $auth, $wsdl, $options = array())
 {
     $this->auth = $auth;
     $options = array_replace_recursive(['httpPlayback' => ['mode' => null]], $options);
     $options['location'] = $location;
     // If a version was set then add it to the headers.
     if (!empty($options['version'])) {
         $this->ewsHeaders['version'] = new SoapHeader('http://schemas.microsoft.com/exchange/services/2006/types', 'RequestServerVersion Version="' . $options['version'] . '"');
     }
     // If impersonation was set then add it to the headers.
     if (!empty($options['impersonation'])) {
         $impersonation = $options['impersonation'];
         if (is_string($impersonation)) {
             $impersonation = ExchangeImpersonation::fromEmailAddress($options['impersonation']);
         }
         $this->ewsHeaders['impersonation'] = new SoapHeader('http://schemas.microsoft.com/exchange/services/2006/types', 'ExchangeImpersonation', $impersonation->toXmlObject());
     }
     if (!empty($options['timezone'])) {
         $this->ewsHeaders['timezone'] = new SoapHeader('http://schemas.microsoft.com/exchange/services/2006/types', 'TimeZoneContext', array('TimeZoneDefinition' => array('Id' => $options['timezone'])));
     }
     $this->httpClient = Factory::getInstance($options['httpPlayback']);
     parent::__construct($wsdl, $options);
 }