[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Database Package 4 * 5 * @copyright Copyright (C) 2022 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Database; 10 11 use Joomla\Database\Exception\DatabaseNotFoundException; 12 13 /** 14 * Defines the trait for a Database Aware Class. 15 * 16 * @since 2.1.0 17 */ 18 trait DatabaseAwareTrait 19 { 20 /** 21 * Database 22 * 23 * @var DatabaseInterface 24 * @since 2.1.0 25 */ 26 private $databaseAwareTraitDatabase; 27 28 /** 29 * Get the database. 30 * 31 * @return DatabaseInterface 32 * 33 * @since 2.1.0 34 * @throws DatabaseNotFoundException May be thrown if the database has not been set. 35 */ 36 protected function getDatabase(): DatabaseInterface 37 { 38 if ($this->databaseAwareTraitDatabase) 39 { 40 return $this->databaseAwareTraitDatabase; 41 } 42 43 throw new DatabaseNotFoundException('Database not set in ' . \get_class($this)); 44 } 45 46 /** 47 * Set the database. 48 * 49 * @param DatabaseInterface $db The database. 50 * 51 * @return void 52 * 53 * @since 2.1.0 54 */ 55 public function setDatabase(DatabaseInterface $db): void 56 { 57 $this->databaseAwareTraitDatabase = $db; 58 } 59 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |