Пример #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;
 }
Пример #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();
     }
 }