Example #1
0
 /**
  * Constructor
  *
  * Settings are provided through the 'settings' argument. The following
  * settings are supported:
  *
  *   * baseUri
  *   * userName (optional)
  *   * password (optional)
  *   * proxy (optional)
  *   * authType (optional)
  *   * encoding (optional)
  *
  *  authType must be a bitmap, using self::AUTH_BASIC, self::AUTH_DIGEST
  *  and self::AUTH_NTLM. If you know which authentication method will be
  *  used, it's recommended to set it, as it will save a great deal of
  *  requests to 'discover' this information.
  *
  *  Encoding is a bitmap with one of the ENCODING constants.
  *
  * @param array $settings
  */
 function __construct(array $settings)
 {
     if (!isset($settings['baseUri'])) {
         throw new \InvalidArgumentException('A baseUri must be provided');
     }
     parent::__construct();
     $this->baseUri = $settings['baseUri'];
     if (isset($settings['proxy'])) {
         $this->addCurlSetting(CURLOPT_PROXY, $settings['proxy']);
     }
     if (isset($settings['userName'])) {
         $userName = $settings['userName'];
         $password = isset($settings['password']) ? $settings['password'] : '';
         if (isset($settings['authType'])) {
             $curlType = 0;
             if ($settings['authType'] & self::AUTH_BASIC) {
                 $curlType |= CURLAUTH_BASIC;
             }
             if ($settings['authType'] & self::AUTH_DIGEST) {
                 $curlType |= CURLAUTH_DIGEST;
             }
             if ($settings['authType'] & self::AUTH_NTLM) {
                 $curlType |= CURLAUTH_NTLM;
             }
         } else {
             $curlType = CURLAUTH_BASIC | CURLAUTH_DIGEST;
         }
         $this->addCurlSetting(CURLOPT_HTTPAUTH, $curlType);
         $this->addCurlSetting(CURLOPT_USERPWD, $userName . ':' . $password);
     }
     if (isset($settings['encoding'])) {
         $encoding = $settings['encoding'];
         $encodings = [];
         if ($encoding & self::ENCODING_IDENTITY) {
             $encodings[] = 'identity';
         }
         if ($encoding & self::ENCODING_DEFLATE) {
             $encodings[] = 'deflate';
         }
         if ($encoding & self::ENCODING_GZIP) {
             $encodings[] = 'gzip';
         }
         $this->addCurlSetting(CURLOPT_ENCODING, implode(',', $encodings));
     }
     $this->addCurlSetting(CURLOPT_USERAGENT, 'sabre-dav/' . Version::VERSION . ' (http://sabre.io/)');
     $this->xml = new Xml\Service();
     // BC
     $this->propertyMap =& $this->xml->elementMap;
 }
Example #2
0
 /**
  * Constructor
  *
  * Settings are provided through the 'settings' argument. The following
  * settings are supported:
  *
  *   * baseUri
  *   * userName (optional)
  *   * password (optional)
  *   * proxy (optional)
  *   * authType (optional)
  *   * encoding (optional)
  *
  *  authType must be a bitmap, using self::AUTH_BASIC and
  *  self::AUTH_DIGEST. If you know which authentication method will be
  *  used, it's recommended to set it, as it will save a great deal of
  *  requests to 'discover' this information.
  *
  *  Encoding is a bitmap with one of the ENCODING constants.
  *
  * @param array $settings
  */
 function __construct(array $settings)
 {
     if (!isset($settings['baseUri'])) {
         throw new \InvalidArgumentException('A baseUri must be provided');
     }
     $validSettings = ['baseUri', 'userName', 'password', 'proxy'];
     parent::__construct();
     $this->baseUri = $settings['baseUri'];
     if (isset($settings['proxy'])) {
         $this->addCurlSetting(CURLOPT_PROXY, $settings['proxy']);
     }
     if (isset($settings['userName'])) {
         $userName = $settings['userName'];
         $password = isset($settings['password']) ? $settings['password'] : '';
         if (isset($settings['authType'])) {
             $curlType = 0;
             if ($settings['authType'] & self::AUTH_BASIC) {
                 $curlType |= CURLAUTH_BASIC;
             }
             if ($settings['authType'] & self::AUTH_DIGEST) {
                 $curlType |= CURLAUTH_DIGEST;
             }
         } else {
             $curlType = CURLAUTH_BASIC | CURLAUTH_DIGEST;
         }
         $this->addCurlSetting(CURLOPT_HTTPAUTH, $curlType);
         $this->addCurlSetting(CURLOPT_USERPWD, $userName . ':' . $password);
     }
     if (isset($settings['encoding'])) {
         $encoding = $settings['encoding'];
         $encodings = [];
         if ($encoding & self::ENCODING_IDENTITY) {
             $encodings[] = 'identity';
         }
         if ($encoding & self::ENCODING_DEFLATE) {
             $encodings[] = 'deflate';
         }
         if ($encoding & self::ENCODING_GZIP) {
             $encodings[] = 'gzip';
         }
         $this->addCurlSetting(CURLOPT_ENCODING, implode(',', $encodings));
     }
     $this->propertyMap['{DAV:}resourcetype'] = 'Sabre\\DAV\\Property\\ResourceType';
 }