Exemplo n.º 1
0
 /**
  * Sets all the required parameters to configure a given Source instance.
  *
  * @param SourceConfig $sourceConfig
  *
  * @throws \Msl\ResourceProxy\Exception\BadSourceConfigurationException
  *
  * @return void
  */
 public function setConfig(SourceConfig $sourceConfig)
 {
     // FILTERS
     // 1. Setting message status filter
     $filters = $sourceConfig->getFilter();
     if (isset($filters[self::MESSAGES_STATUS_FILTER])) {
         $messageStatus = $filters[self::MESSAGES_STATUS_FILTER];
         if ($messageStatus === self::UNREAD_ONLY_MESSAGES_FILTER) {
             $this->unreadOnly = true;
         }
     }
     // 2. Setting folder filter
     if (isset($filters[self::FOLDER_FILTER])) {
         $this->folder = $filters[self::FOLDER_FILTER];
     }
     // Calling parent method to set the rest of the required configuration
     parent::setConfig($sourceConfig);
 }
Exemplo n.º 2
0
 /**
  * Returns an instance of SourceConfig object to wrap all required configuration for any Source instance.
  *
  * @param string $name              The Source name
  * @param string $type              The Source type (e.g. 'imap')
  * @param array $parameters         Required configuration array to create a Source instance
  * @param array $globalParameters   Global configuration array: if required parameters are not specified in the parameters array, then we check if they are defined in this array
  *
  * @throws \Msl\ResourceProxy\Exception\BadSourceConfigConfigurationException
  *
  * @return SourceConfig
  */
 protected function getSourceConfig($name, $type, array $parameters, array $globalParameters = array())
 {
     // Initializing result object
     $sourceConfig = new SourceConfig();
     // Checking connection parameters
     if (!isset($parameters['connection'])) {
         throw new Exception\BadSourceConfigConfigurationException(sprintf("Missing parameters 'connection' for source configuration '{$name}'", $name));
     } else {
         // Checking host parameter
         if (!isset($parameters['connection']['host'])) {
             // We check the global configuration parameter
             if (!isset($globalParameters['host'])) {
                 throw new Exception\BadSourceConfigConfigurationException(sprintf("Missing global or local parameters 'host' for source configuration '{$name}.connection'", $name));
             } else {
                 $host = $globalParameters['host'];
             }
         } else {
             $host = $parameters['connection']['host'];
         }
         // Checking port parameter
         if (!isset($parameters['connection']['port'])) {
             // We check the global configuration parameter
             if (!isset($globalParameters['port'])) {
                 throw new Exception\BadSourceConfigConfigurationException(sprintf("Missing global or local parameters 'port' for source configuration '{$name}.connection'", $name));
             } else {
                 $port = $globalParameters['port'];
             }
         } else {
             $port = $parameters['connection']['port'];
         }
         // Checking ssl parameter
         if (!isset($parameters['connection']['ssl'])) {
             // We check the global configuration parameter
             if (!isset($globalParameters['ssl'])) {
                 throw new Exception\BadSourceConfigConfigurationException(sprintf("Missing global or local parameters 'ssl' for source configuration '{$name}.connection'", $name));
             } else {
                 $ssl = $globalParameters['ssl'];
             }
         } else {
             $ssl = $parameters['connection']['ssl'];
         }
         // Checking username parameter
         if (!isset($parameters['connection']['username'])) {
             throw new Exception\BadSourceConfigConfigurationException(sprintf("Missing parameters 'username' for source configuration '{$name}.username'", $name));
         }
         $username = $parameters['connection']['username'];
         // Checking password parameter
         if (!isset($parameters['connection']['password'])) {
             throw new Exception\BadSourceConfigConfigurationException(sprintf("Missing parameters 'password' for source configuration '{$name}.password'", $name));
         }
         $password = $parameters['connection']['password'];
         // Populating SourceConfig object
         $sourceConfig->setName($name);
         $sourceConfig->setHost($host);
         $sourceConfig->setUsername($username);
         $sourceConfig->setPassword($password);
         $sourceConfig->setCryptProtocol($ssl);
         $sourceConfig->setPort($port);
         $sourceConfig->setType($type);
         if (isset($parameters['connection']['filter'])) {
             $sourceConfig->setFilter($parameters['connection']['filter']);
         }
     }
     // Returning SourceConfig object
     return $sourceConfig;
 }
Exemplo n.º 3
0
 /**
  * Returns a string representation for the source object
  *
  * @return string
  */
 public function toString()
 {
     return sprintf('Storage Source Object [host:\'%s\'][port:\'%s\'][user:\'%s\']', $this->sourceConfig->getHost(), $this->sourceConfig->getPort(), $this->sourceConfig->getUsername());
 }