SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/Pdb.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13. namespace Sprout\Helpers;
  14.  
  15. use karmabunny\pdb\Compat\StaticPdb;
  16. use karmabunny\pdb\PdbConfig;
  17. use Kohana;
  18.  
  19. /**
  20.  * Class for doing database queries via PDO (PDO Database => Pdb)
  21.  */
  22. class Pdb extends StaticPdb
  23. {
  24. protected static $prefix = 'sprout_';
  25.  
  26. /** @inheritdoc */
  27. public static function getConfig(string $name = null): PdbConfig
  28. {
  29. $name = $name ?? 'default';
  30. $config = Kohana::config('database.' . $name);
  31.  
  32. $conf = $config['connection'];
  33. $conf['type'] = str_replace('mysqli', 'mysql', $conf['type']);
  34. $conf['character_set'] = $config['character_set'];
  35. $conf['prefix'] = $config['prefix'] ?? self::$prefix;
  36. $conf['hacks'] = $config['hacks'] ?? [];
  37.  
  38. return new PdbConfig($conf);
  39. }
  40. }
  41.