Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(ParamString $args)
 {
     $dsn = new DSN($args->value(0));
     $this->adapter = self::$adapters[$dsn->getDriver()]->newInstance(DriverManager::getInstance()->getConnection($dsn->dsn));
     $this->package = $args->value('package', 'p', 'db');
     $this->host = $args->value('host', 'h', $dsn->getHost());
     $this->naming = $args->value('nstrategy', 'n', '');
     if ('' != $this->naming) {
         DBXMLNamingContext::setStrategy(XPClass::forName($this->naming)->newInstance());
     }
     $this->prefix = $args->value('prefix', 'pv', '');
     $this->ptargets = explode('|', $args->value('ptargets', 'pt', ''));
     $this->pexclude = $args->value('pexclude', 'pe', FALSE);
     $xsls = array();
     $lang = $args->value('lang', 'l', 'xp5.php');
     if ($this->getClass()->getPackage()->providesPackage(strtr($lang, '.', '_'))) {
         $resources = $this->getClass()->getPackage()->getPackage(strtr($lang, '.', '_'))->getResources();
         foreach ($resources as $resource) {
             $filename = substr($resource, strrpos($resource, DIRECTORY_SEPARATOR) + 1);
             if (substr($filename, -8, 8) !== '.php.xsl') {
                 continue;
             }
             $xsls[] = $resource;
         }
     } else {
         $packagepath = strtr($this->getClass()->getPackage()->getName(), '.', DIRECTORY_SEPARATOR);
         $xsls[] = $packagepath . DIRECTORY_SEPARATOR . $lang . '.xsl';
     }
     foreach ($xsls as $resource) {
         $processor = new DomXSLProcessor();
         $processor->setBase(__DIR__);
         $processor->setXSLBuf(ClassLoader::getDefault()->getResource($resource));
         $processor->setParam('package', $this->package);
         if ($this->prefix) {
             $processor->setParam('prefix', $this->prefix);
             $processor->setParam($this->pexclude ? 'exprefix' : 'incprefix', implode(',', $this->ptargets));
         }
         $this->processor[] = $processor;
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(ParamString $args)
 {
     $dsn = new DSN($args->value(0));
     $this->adapter = self::$adapters[$dsn->getDriver()]->newInstance(DriverManager::getInstance()->getConnection($dsn->dsn));
     $this->package = $args->value('package', 'p', 'db');
     $this->host = $args->value('host', 'h', $dsn->getHost());
     $this->naming = $args->value('nstrategy', 'n', '');
     if ('' != $this->naming) {
         DBXMLNamingContext::setStrategy(XPClass::forName($this->naming)->newInstance());
     }
     $this->prefix = $args->value('prefix', 'pv', '');
     $this->ptargets = explode('|', $args->value('ptargets', 'pt', ''));
     $this->pexclude = $args->value('pexclude', 'pe', FALSE);
     // Setup generator
     $this->processor = new DomXSLProcessor();
     $this->processor->setXSLBuf($this->getClass()->getPackage()->getResource($args->value('lang', 'l', 'xp5.php') . '.xsl'));
     $this->processor->setParam('package', $this->package);
     if ($this->prefix) {
         $this->processor->setParam('prefix', $this->prefix);
         $this->processor->setParam($this->pexclude ? 'exprefix' : 'incprefix', implode(',', $this->ptargets));
     }
 }
 /**
  * Get a connection by a DSN string
  *
  * @param   string str
  * @return  rdbms.DBConnection
  * @throws  rdbms.DriverNotSupportedException
  */
 public static function getConnection($str)
 {
     $dsn = new DSN((string) $str);
     $driver = $dsn->getDriver();
     // Lookup driver by identifier, if no direct match is found, choose from
     // the drivers with the same driver identifier. If no implementation can
     // be found that way, ask available rdbms.DriverImplementationsProviders
     if (!isset(self::$instance->lookup[$driver])) {
         if (isset(self::$instance->drivers[$driver])) {
             self::$instance->lookup[$driver] = self::$instance->drivers[$driver];
         } else {
             $provider = self::$instance->provider;
             // Normalize driver, then query providers for available implementations
             if (FALSE === ($p = strpos($driver, '+'))) {
                 $family = $driver;
                 $search = $driver . '+';
             } else {
                 $family = substr($driver, 0, $p);
                 $search = $driver;
             }
             foreach ($provider->implementationsFor($family) as $impl) {
                 XPClass::forName($impl);
             }
             // Not every implementation may be registered (e.g., due to a missing
             // prerequisite), so now search the registered implementations for a
             // suitable driver.
             $l = strlen($search);
             do {
                 foreach (self::$instance->drivers as $name => $class) {
                     if (0 !== strncmp($name, $search, $l)) {
                         continue;
                     }
                     self::$instance->lookup[$driver] = $class;
                     break 2;
                 }
                 throw new DriverNotSupportedException(sprintf('No driver registered for "%s" or provided by any of %s', $driver, xp::stringOf($provider)));
             } while (0);
         }
     }
     return self::$instance->lookup[$driver]->newInstance($dsn);
 }
 /**
  * Queue a connection string for registering on demand.
  *
  * @param   string dsn The connection's DSN
  * @return  rdbms.DSN
  * @param   string hostAlias default NULL
  * @param   string userAlias default NULL
  */
 public function queue($str, $hostAlias = NULL, $userAlias = NULL)
 {
     $dsn = new DSN($str);
     $host = NULL == $hostAlias ? $dsn->getHost() : $hostAlias;
     $user = NULL == $userAlias ? $dsn->getUser() : $userAlias;
     $this->pool[$user . '@' . $host] = $str;
     return $dsn;
 }