getInstance() public static method

Get connection manager instance to share connections between different instances.
public static getInstance ( ) : ConnectionManager
return ConnectionManager
Example #1
0
 /**
  * register db manager
  *
  * return $this
  */
 protected function registerDbManager()
 {
     $container = $this->getContainer();
     $container->share(ConnectionManagerInterface::class, function () use($container) {
         /** @var \Pagewire\Core\Application $app */
         $manager = ConnectionManager::getInstance();
         $app = $container->get(ApplicationInterface::class);
         $connections = $app->getConfig('db.connections', []);
         if (count($connections) < 1) {
             return $manager;
         }
         $hasDefault = false;
         foreach ($connections as $name => $params) {
             if (!is_string($name)) {
                 if ($hasDefault) {
                     continue;
                 }
                 $name = $manager::DEFAULT_CONNECTION;
                 $hasDefault = true;
             }
             $manager->add($params, $name);
         }
         return $manager;
     });
     return $this;
 }
Example #2
0
 /**
  * Get table name
  *
  * Add prefix if if $withPrefix is true and a prefix exists
  *
  * @param bool $withPrefix
  * @return string
  */
 public function getTableName($withPrefix = true)
 {
     $prefix = ConnectionManager::getInstance()->get()->getPrefix();
     return (true === $withPrefix && strlen($prefix) > 0 ? rtrim($prefix, '_') . '_' : '') . $this->configuration['tableName'];
 }