Ejemplo n.º 1
0
 public function loadForSource($url)
 {
     $datasrc = dirname(dirname(__FILE__)) . '/Resources/data/databases/DataSources.xml';
     if (extension_loaded('apc') && ini_get('apc.enabled')) {
         $xml = $this->loadFileFromCache($url);
         $simulator = new \SimpleXMLElement($xml, LIBXML_NOWARNING, false);
         $xml = $this->loadFileFromCache($datasrc);
         $datasources = new \SimpleXMLElement($xml, LIBXML_NOWARNING, false);
     } else {
         $simulator = new \SimpleXMLElement($url, LIBXML_NOWARNING, true);
         $datasources = new \SimpleXMLElement($datasrc, LIBXML_NOWARNING, true);
     }
     foreach ($datasources->DataSource as $datasource) {
         $datasourceObj = new DataSource($this, (int) $datasource['id'], (string) $datasource['name'], (string) $datasource['type']);
         $datasourceObj->setUri((string) $datasource['uri']);
         $datasourceObj->setMethod((string) $datasource['method']);
         $datasourceObj->setDatabase((int) $datasource['database']);
         $datasourceObj->setDescription((string) $datasource->Description);
         $this->datasources[] = $datasourceObj;
     }
     if ($datasources->Databases) {
         foreach ($datasources->Databases->Database as $database) {
             $databaseObj = new Database($this, (int) $database['id'], (string) $database['type'], (string) $database['name']);
             $databaseObj->setLabel((string) $database['label']);
             $databaseObj->setHost((string) $database['host']);
             $databaseObj->setPort((int) $database['port']);
             $databaseObj->setUser((string) $database['user']);
             if ((string) $database['password'] != '') {
                 $databaseObj->setPassword((string) $database['password']);
             } elseif ((string) $database['user'] != '') {
                 try {
                     $user = $this->controller->get('kernel')->getContainer()->getParameter('database_user');
                     if ((string) $database['user'] == $user) {
                         $databaseObj->setPassword($this->controller->get('kernel')->getContainer()->getParameter('database_password'));
                     }
                 } catch (\Exception $e) {
                 }
             }
             $this->databases[] = $databaseObj;
         }
     }
     if ($simulator->DataSet) {
         foreach ($simulator->DataSet->children() as $child) {
             if ($child->getName() == "DataGroup") {
                 foreach ($child->Data as $data) {
                     $dataObj = new Data($this, (int) $data['id'], (string) $data['name']);
                     $dataObj->setLabel((string) $data['label']);
                     $dataObj->setType((string) $data['type']);
                     $this->datas[] = $dataObj;
                 }
             } elseif ($child->getName() == "Data") {
                 $dataObj = new Data($this, (int) $child['id'], (string) $child['name']);
                 $dataObj->setLabel((string) $child['label']);
                 $dataObj->setType((string) $child['type']);
                 $this->datas[] = $dataObj;
             }
         }
     }
     if ($simulator->Sources) {
         foreach ($simulator->Sources->Source as $source) {
             $sourceObj = new Source($this, (int) $source['id'], (string) $source['datasource'], (string) $source['returnType']);
             $sourceObj->setRequest((string) $source['request']);
             $sourceObj->setSeparator((string) $source['separator']);
             $sourceObj->setDelimiter((string) $source['delimiter']);
             $sourceObj->setReturnPath((string) $source['returnPath']);
             foreach ($source->Parameter as $parameter) {
                 $parameterObj = new Parameter($sourceObj, (string) $parameter['type']);
                 $parameterObj->setName((string) $parameter['name']);
                 $parameterObj->setFormat((string) $parameter['format']);
                 $parameterObj->setData((int) $parameter['data']);
                 $sourceObj->addParameter($parameterObj);
             }
             $this->sources[] = $sourceObj;
         }
     }
 }