当前位置: 首页>>代码示例>>PHP>>正文


PHP DataSource::setDatabase方法代码示例

本文整理汇总了PHP中DataSource::setDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP DataSource::setDatabase方法的具体用法?PHP DataSource::setDatabase怎么用?PHP DataSource::setDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataSource的用法示例。


在下文中一共展示了DataSource::setDatabase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadForSource

 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;
         }
     }
 }
开发者ID:eureka2,项目名称:g6k,代码行数:76,代码来源:Simulator.php


注:本文中的DataSource::setDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。