Phundament-Packages
[ class tree: Phundament-Packages ] [ index: Phundament-Packages ] [ all elements ]

Source for file LDatabaseConfiguration.php

Documentation is available at LDatabaseConfiguration.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * LDatabaseConfiguration class file.
  6.  *
  7.  * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  8.  * @copyright 2005, diemeisterei GmbH. All rights reserved.
  9.  * @author $Author: schmunk $
  10.  * @version $Revision: 601 $  $Date: 2007-02-24 23:49:30 +0100 (Sa, 24 Feb 2007) $
  11.  * @package Phundament.Packages
  12.  * @subpackage LDatabase
  13.  */
  14.  
  15. /**
  16.  * Handles propel & creole configurations
  17.  *
  18.  * @package System.Data
  19.  */
  20. class LDatabaseConfiguration extends TControl
  21. {
  22.     /**
  23.      * Array of master config
  24.      */
  25.     public $_config;
  26.  
  27.     /**
  28.      * Returns array of master config
  29.      */
  30.     public function getConfig()
  31.     {
  32.         return $this->_config;
  33.     }
  34.  
  35.     /**
  36.      * Inits the config handler
  37.      */
  38.     public function init($config)
  39.     {
  40.         $_logdirPrado :: getPathOfAlias("Application"'/runtime/propel/propel.log';
  41.         $this->_config['log']array (
  42.             'ident' => 'propellog',
  43.             'level' => $this->Application->Parameters['PropelLogLevel'],
  44.             'name' => $_logdir,
  45.             'type' => 'file'
  46.         );
  47.         $_cpd$this->_config['propel']['datasources'];
  48.         $xmlObjs$config->getElementsByTagName('database');
  49.         foreach ($xmlObjs AS $xmlObj)
  50.         {
  51.             $attrs$xmlObj->getAttributes();
  52.             // Propel 1.2
  53.             $connection["phptype"]$attrs->itemAt("adapter");
  54.             $_hs$attrs->itemAt("hostspec");
  55.             $connection["hostspec"](!empty ($_hs)) $_hs " ";
  56.             $connection["database"]$attrs->itemAt("database");
  57.             $connection["username"]$attrs->itemAt("username");
  58.             $connection["password"]$attrs->itemAt("password");
  59.  
  60.             // Propel 1.3
  61.             #echo $connection["dsn"] = $attrs->itemAt("adapter").":".$attrs->itemAt("database");
  62.             // mysql:host=localhost;dbname=ph
  63.             #echo $attrs->itemAt("id");
  64.             #echo $connection["dsn"] = $attrs->itemAt("adapter").":host=".$attrs->itemAt("hostspec").";dbname=".$attrs->itemAt("database");
  65.             #echo "<hr>";
  66.             #$connection["user"] = $attrs->itemAt("username");
  67.  
  68.             $_cpd[$attrs->itemAt("id")]['adapter']$attrs->itemAt("adapter");
  69.             $_cpd[$attrs->itemAt("id")]['connection']$connection;
  70.         }
  71.         $_cpd['default']Prado :: getApplication()->getMode();
  72.  
  73.         #$this->_config = include ($masterConfigFile);
  74.  
  75.         $xmlObjs$config->getElementsByTagName('scan');
  76.         $pkgConfigsarray ();
  77.         foreach ($xmlObjs AS $xmlObj)
  78.         {
  79.             $attrs$xmlObj->getAttributes();
  80.             $pkgConfigsarray_merge($pkgConfigs$this->findConfigurations($attrs->itemAt("namespace")$attrs->itemAt("prefer")));
  81.         }
  82.         if (is_array($pkgConfigs))
  83.             foreach ($pkgConfigs AS $config)
  84.             {
  85.                 if (!is_array($config))
  86.                 {
  87.                     Prado :: trace("Config is not an array"'Lithron.LDatabaseConfiguration');
  88.                     continue;
  89.                 }
  90.                 $this->_configLDatabaseConfiguration :: addConfiguration($this->_config$config);
  91.             }
  92.         Prado :: trace("Propel config files parsed & merged"'Lithron.LDatabaseConfiguration');
  93.         #var_dump($this->_config);exit;
  94.     }
  95.  
  96.     /**
  97.      * Reads package configs
  98.      */
  99.     private function findConfigurations($alias$prefernull)
  100.     {
  101.         #Prado :: trace("Searching for LPropel configs ...", 'Lithron.LPropel');
  102.         $pkgConfigsarray ();
  103.         $baseDirPrado :: getPathOfNamespace($alias);
  104.         if (is_dir($baseDir))
  105.         {
  106.             $scanscandir($baseDir);
  107.             foreach ($scan AS $item)
  108.             {
  109.                 $pkgDir$baseDir "/" $item;
  110.                 if (is_dir($pkgDir))
  111.                 {
  112.                     $lPropelDir$pkgDir "/db/propel";
  113.                     if (is_dir($lPropelDir))
  114.                     {
  115.                         $scanscandir($lPropelDir);
  116.                         foreach ($scan AS $item)
  117.                         {
  118.                             #echo "-conf." . strtolower($this->Application->getModule("geo_ip")->getCountryCode()) . ".php<hr>";
  119.                             #if (!(substr($item, -9) == "-conf.php"))
  120.                             #    continue;
  121.                             #echo $item."<br>";
  122.                             if ($prefer == "geo_ip" && strstr($item"-conf." strtolower($this->Application->getModule("geo_ip")->getCountryCode()) ".php"))
  123.                             {
  124.                                 #echo "OK...";
  125.                                 $pkgConfigs[$item]include_once ($lPropelDir "/" $item);
  126.                                 Prado :: trace("Found special geo_ip conf '$itemin '$alias'"'Lithron.LDatabaseConfiguration');
  127.                                 continue 2;
  128.                             }
  129.  
  130.                             elseif (substr($item-9== "-conf.php")
  131.                             {
  132.                                 $pkgConfigs[$item]include_once ($lPropelDir "/" $item);
  133.                                 #Prado :: trace("Found conf '$item' in '$alias'", 'Lithron.LDatabaseConfiguration');
  134.                             }
  135.  
  136.                         }
  137.                     }
  138.  
  139.                 }
  140.             }
  141.         }
  142.         return $pkgConfigs;
  143.  
  144.     }
  145.  
  146.     /**
  147.      * Adds a package config to the config
  148.      */
  149.     private function addConfiguration($masterConfig$config)
  150.     {
  151.         $sources$config['propel']['datasources'];
  152.         #var_dump($sources);
  153.  
  154.         foreach ($sources AS $id => $datasource)
  155.         {
  156.             if ($id == "value")
  157.                 continue;
  158.             if ($id == "default")
  159.             {
  160.                 $_dstrim($datasource);
  161.                 if (isset ($sources[$datasource]))
  162.                 {
  163.                     continue;
  164.                 }
  165.                 elseif (!empty ($_ds&& !isset ($sources[$datasource]))
  166.                 {
  167.                     $defaultKey$masterConfig['propel']['datasources']['default'];
  168.                     Prado :: trace("Config for '$datasourcenot foundassuming '$defaultKey'"'Lithron.LDatabaseConfiguration');
  169.                     $masterConfig['propel']['datasources'][$datasource]$masterConfig['propel']['datasources'][$defaultKey];
  170.                     continue;
  171.                 }
  172.             }
  173.             #var_dump($datasource);
  174.             Prado :: trace("Config for '$idadded ()."'Lithron.LDatabaseConfiguration');
  175.             $masterConfig['propel']['datasources'][$id]$datasource;
  176.             $masterConfig['propel']['datasources']["'".$id."'"]$datasource;
  177.  
  178.             // Propel 1.3
  179.             #            $masterConfig['propel']['datasources'][$id]['connection'] = $masterConfig['propel']['datasources']["Normal"]['connection'];
  180.             #            $masterConfig['propel']['datasources'][$id]['adapter'] = $masterConfig['propel']['datasources']["Normal"]['adapter'];
  181.  
  182.             #            echo "<hr>$id";
  183.  
  184.         }
  185.         #var_dump($masterConfig);
  186.  
  187.         return $masterConfig;
  188.     }
  189.  
  190.     /**
  191.      * Returns a DSN from the config
  192.      */
  193.     public function getDsn($name)
  194.     {
  195.         $config$this->_config;
  196.         $c$config['propel']['datasources'][$name]['connection'];
  197.  
  198.         if ($c['username'])
  199.         {
  200.             $prefix$c['username'":" $c['password'"@";
  201.         }
  202.         else
  203.         {
  204.             $prefix"";
  205.         }
  206.         $dsn$c['phptype'"://" $prefix "" $c['hostspec'"/" $c['database'];
  207.         return $dsn;
  208.     }
  209.  
  210. }

Documentation generated on Sun, 25 Feb 2007 16:10:19 +0100 by phpDocumentor 1.3.1