/**
  * constructor
  */
 private function __construct()
 {
     if (Syncroton_Registry::isRegistered('loggerBackend')) {
         $this->_logger = Syncroton_Registry::get('loggerBackend');
     }
 }
Пример #2
0
 /**
  * get existing device of owner or create new device for owner
  *
  * @param unknown_type $ownerId
  * @param unknown_type $deviceId
  * @param unknown_type $deviceType
  * @param unknown_type $userAgent
  * @param unknown_type $protocolVersion
  * @return Syncroton_Model_Device
  */
 protected function _getUserDevice($ownerId, $requestParameters)
 {
     try {
         $device = $this->_deviceBackend->getUserDevice($ownerId, $requestParameters['deviceId']);
         $device->useragent = $requestParameters['userAgent'];
         $device->acsversion = $requestParameters['protocolVersion'];
         if ($device->isDirty()) {
             $device = $this->_deviceBackend->update($device);
         }
     } catch (Syncroton_Exception_NotFound $senf) {
         $device = $this->_deviceBackend->create(new Syncroton_Model_Device(array('owner_id' => $ownerId, 'deviceid' => $requestParameters['deviceId'], 'devicetype' => $requestParameters['deviceType'], 'useragent' => $requestParameters['userAgent'], 'acsversion' => $requestParameters['protocolVersion'], 'policyId' => Syncroton_Registry::isRegistered(Syncroton_Registry::DEFAULT_POLICY) ? Syncroton_Registry::get(Syncroton_Registry::DEFAULT_POLICY) : null)));
     }
     return $device;
 }
Пример #3
0
 /**
  * the constructor
  *
  * @param  mixed				   $requestBody
  * @param  Syncroton_Model_Device  $device
  * @param  array				   $requestParameters
  */
 public function __construct($requestBody, Syncroton_Model_IDevice $device, $requestParameters)
 {
     $this->_requestBody = $requestBody;
     $this->_device = $device;
     $this->_requestParameters = $requestParameters;
     $this->_policyKey = $requestParameters['policyKey'];
     $this->_deviceBackend = Syncroton_Registry::getDeviceBackend();
     $this->_folderBackend = Syncroton_Registry::getFolderBackend();
     $this->_syncStateBackend = Syncroton_Registry::getSyncStateBackend();
     $this->_contentStateBackend = Syncroton_Registry::getContentStateBackend();
     $this->_policyBackend = Syncroton_Registry::getPolicyBackend();
     if (Syncroton_Registry::isRegistered('loggerBackend')) {
         $this->_logger = Syncroton_Registry::get('loggerBackend');
     }
     $this->_syncTimeStamp = new DateTime(null, new DateTimeZone('UTC'));
     // set default content type
     $this->_headers['Content-Type'] = 'application/vnd.ms-sync.wbxml';
     if ($this->_logger instanceof Syncroton_Log) {
         $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " sync timestamp: " . $this->_syncTimeStamp->format('Y-m-d H:i:s'));
     }
     if (isset($this->_defaultNameSpace) && isset($this->_documentElement)) {
         // Creates an instance of the DOMImplementation class
         $imp = new DOMImplementation();
         // Creates a DOMDocumentType instance
         $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
         // Creates a DOMDocument instance
         $this->_outputDom = $imp->createDocument($this->_defaultNameSpace, $this->_documentElement, $dtd);
         $this->_outputDom->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Syncroton', 'uri:Syncroton');
         $this->_outputDom->formatOutput = false;
         $this->_outputDom->encoding = 'utf-8';
     }
     if ($this->_skipValidatePolicyKey != true) {
         if (!empty($this->_device->policyId)) {
             $policy = $this->_policyBackend->get($this->_device->policyId);
             if ((int) $policy->policyKey != (int) $this->_policyKey) {
                 $this->_outputDom->documentElement->appendChild($this->_outputDom->createElementNS($this->_defaultNameSpace, 'Status', 142));
                 $sepn = new Syncroton_Exception_ProvisioningNeeded();
                 $sepn->domDocument = $this->_outputDom;
                 throw $sepn;
             }
             // should we wipe the mobile phone?
             if ($this->_device->remotewipe >= Syncroton_Command_Provision::REMOTEWIPE_REQUESTED) {
                 $this->_outputDom->documentElement->appendChild($this->_outputDom->createElementNS($this->_defaultNameSpace, 'Status', 140));
                 $sepn = new Syncroton_Exception_ProvisioningNeeded();
                 $sepn->domDocument = $this->_outputDom;
                 throw $sepn;
             }
         }
     }
 }