Esempio n. 1
0
 /**
  * Create an appropriate POIConnector for a layer definition
  *
  * @param LayerDefinition $layerDefinition
  *
  * @return POIConnector
  */
 protected static function getPOIConnectorFromDefinition(LayerDefinition $layerDefinition)
 {
     switch ($layerDefinition->getSourceType()) {
         case LayerDefinition::DSN:
             $poiConnector = new $layerDefinition->connector($layerDefinition->source["dsn"], $layerDefinition->source["username"], $layerDefinition->source["password"]);
             break;
         case LayerDefinition::FILE:
             $poiConnector = new $layerDefinition->connector($layerDefinition->source);
             break;
         default:
             throw new Exception(sprintf("Invalid source type: %d", $layerDefinition->getSourceType()));
     }
     foreach ($layerDefinition->connectorOptions as $optionName => $option) {
         $poiConnector->setOption($optionName, $option);
     }
     return $poiConnector;
 }
Esempio n. 2
0
 /**
  * initialize private User persistence object
  * @return void
  * @param LayerDefinition $definition
  */
 protected function userInit(LayerDefinition $definition)
 {
     // get data source.
     // NOTE: only Database persistence implemented for now
     if ($definition->getSourceType() === LayerDefinition::DSN) {
         $source = $definition->source;
         $this->user = new DbUser($source['dsn'], $source['username'], $source['password']);
     } else {
         $this->user = new DummyUser();
     }
     // try session
     if (isset($_SESSION[$this->layerName . 'User'])) {
         $this->user->fromJson($_SESSION[$this->layerName . 'User']);
         return;
     } elseif (isset($_COOKIE[$this->layerName . 'Id'])) {
         // restore user data from persistent storage keyed by cookie
         $this->user->getById($_COOKIE[$this->layerName . 'Id']);
         $_SESSION[$this->layerName . 'User'] = $this->user->toJson();
     } elseif (isset($_REQUEST['userId'])) {
         // restore user data from persistent storage keyed by Layar UID
         $this->user->getById($_REQUEST['userId']);
         $_SESSION[$this->layerName . 'User'] = $this->user->toJson();
     }
 }
Esempio n. 3
0
 /**
  * Load config from XML
  *
  * @param string $source Filename or XML string
  * @param bool $fromString $source is an XML string, not a filename. Default FALSE
  *
  * @return void
  * @throws Exception on XML failure
  */
 public function load($source, $fromString = FALSE)
 {
     $this->source = $source;
     $config = new SimpleXMLElement($this->source, 0, !$fromString);
     if (!empty($config->{"developer-id"})) {
         $this->developerID = (string) $config->{"developer-id"};
     }
     if (!empty($config->{"developer-key"})) {
         $this->developerKey = (string) $config->{"developer-key"};
     }
     /* load the names of connector classes and which files they are in */
     foreach ($config->xpath("connectors/connector") as $node) {
         $this->connectors[(string) $node->name] = (string) $node->file;
     }
     /* load layers */
     foreach ($config->xpath("layers/layer") as $node) {
         $def = new LayerDefinition();
         $def->name = (string) $node->name;
         $def->connector = trim((string) $node->connector);
         if (!empty($node->connector->options)) {
             foreach ($node->connector->options->children() as $optionNode) {
                 $def->connectorOptions[$optionNode->getName()] = (string) $optionNode;
             }
         }
         /* check to see if we need to load the connector */
         if (!class_exists($def->connector)) {
             /* include the connector's definition if it exists*/
             if (!empty($this->connectors[$def->connector])) {
                 require_once $this->connectors[$def->connector];
             } else {
                 throw new Exception(sprintf("Unknown connector: %s", $def->connector));
             }
         }
         /* load the data source information */
         if (isset($node->source->dsn)) {
             $def->setSourceType(LayerDefinition::DSN);
             $def->source["dsn"] = (string) $node->source->dsn;
             if (isset($node->source->username)) {
                 $def->source["username"] = (string) $node->source->username;
             }
             if (isset($node->source->password)) {
                 $def->source["password"] = (string) $node->source->password;
             }
         } else {
             $def->source = (string) $node->source;
         }
         /* web app configuration */
         if (isset($node->web_app)) {
             $def->web_app["name"] = (string) $node->web_app->name;
             $def->web_app["file"] = (string) $node->web_app->file;
         }
         /* load OAuth settings */
         if (isset($node->oauth)) {
             $oauth = $def->oauth;
             $oauth->setConsumerKey((string) $node->oauth->consumer_key);
             $oauth->setSecretKey((string) $node->oauth->secret_key);
             $baseUrl = (string) $node->oauth->baseUrl;
             $oauth->setRequestTokenUrl($baseUrl . (string) $node->oauth->tokenPath->request);
             $oauth->setAccessTokenUrl($baseUrl . (string) $node->oauth->tokenPath->access);
             $oauth->setAuthorizeTokenUrl($baseUrl . (string) $node->oauth->tokenPath->authorize);
         }
         $this->layerDefinitions[] = $def;
     }
 }