PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/nooku/administrator/components/com_default/databases/adapters/mysqli.php

https://github.com/bhar1red/anahita
PHP | 118 lines | 49 code | 16 blank | 53 comment | 6 complexity | f425cce19f29a875afb94ec199181b54 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: mysqli.php 4628 2012-05-06 19:56:43Z johanjanssens $
  4. * @package Nooku_Components
  5. * @subpackage Default
  6. * @copyright Copyright (C) 2007 - 2012 Johan Janssens. All rights reserved.
  7. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
  8. * @link http://www.nooku.org
  9. */
  10. /**
  11. * Default Database MySQLi Adapter
  12. *
  13. * @author Johan Janssens <johan@nooku.org>
  14. * @category Nooku
  15. * @package Nooku_Components
  16. * @subpackage Default
  17. */
  18. class ComDefaultDatabaseAdapterMysqli extends KDatabaseAdapterMysqli implements KServiceInstantiatable
  19. {
  20. /**
  21. * The cache object
  22. *
  23. * @var JCache
  24. */
  25. protected $_cache;
  26. /**
  27. * Constructor
  28. *
  29. * Prevent creating instances of this class by making the contructor private
  30. *
  31. * @param object An optional KConfig object with configuration options
  32. */
  33. public function __construct(KConfig $config)
  34. {
  35. parent::__construct($config);
  36. if(JFactory::getConfig()->getValue('config.caching')) {
  37. $this->_cache = JFactory::getCache('database', 'output');
  38. }
  39. }
  40. /**
  41. * Force creation of a singleton
  42. *
  43. * @param object An optional KConfig object with configuration options
  44. * @param object A KServiceInterface object
  45. * @return KDatabaseTableInterface
  46. */
  47. public static function getInstance(KConfigInterface $config, KServiceInterface $container)
  48. {
  49. if (!$container->has($config->service_identifier))
  50. {
  51. $classname = $config->service_identifier->classname;
  52. $instance = new $classname($config);
  53. $container->set($config->service_identifier, $instance);
  54. }
  55. return $container->get($config->service_identifier);
  56. }
  57. /**
  58. * Initializes the options for the object
  59. *
  60. * Called from {@link __construct()} as a first step of object instantiation.
  61. *
  62. * @param object An optional KConfig object with configuration options.
  63. * @return void
  64. */
  65. protected function _initialize(KConfig $config)
  66. {
  67. $db = JFactory::getDBO();
  68. $resource = method_exists($db, 'getConnection') ? $db->getConnection() : $db->_resource;
  69. $prefix = method_exists($db, 'getPrefix') ? $db->getPrefix() : $db->_table_prefix;
  70. $config->append(array(
  71. 'connection' => $resource,
  72. 'table_prefix' => $prefix,
  73. ));
  74. parent::_initialize($config);
  75. }
  76. /**
  77. * Retrieves the table schema information about the given table
  78. *
  79. * This function try to get the table schema from the cache. If it cannot be found
  80. * the table schema will be retrieved from the database and stored in the cache.
  81. *
  82. * @param string A table name or a list of table names
  83. * @return KDatabaseSchemaTable
  84. */
  85. public function getTableSchema($table)
  86. {
  87. if(!isset($this->_table_schema[$table]) && isset($this->_cache))
  88. {
  89. $database = $this->getDatabase();
  90. $identifier = md5($database.$table);
  91. if (!$schema = $this->_cache->get($identifier))
  92. {
  93. $schema = parent::getTableSchema($table);
  94. //Store the object in the cache
  95. $this->_cache->store(serialize($schema), $identifier);
  96. }
  97. else $schema = unserialize($schema);
  98. $this->_table_schema[$table] = $schema;
  99. }
  100. return parent::getTableSchema($table);
  101. }
  102. }