<?php
final class core {
/**
* Database Interface
* @var databaseInterface
*/
private $databaseInterface;
...
...
/**
* Get Database Interface
* @return databaseInterface
*/
public function databaseInterface() {
if (!$this->databaseInterface instanceof databaseInterface) {
$this->databaseInterface = new databaseInterface();
}
return $this->databaseInterface;
}
...
...
...
<?php
class databaseInterface {
/**
* MySQL cnt
* @var MySQL
*/
private $MySQL;
/**
* Return MySQL object
* @return MySQL
*/
public function MySQL() {
if (!$this->MySQL instanceof MySQL) {
$this->MySQL = new MySQL(
core::getInstance()->cfg()->MySQLServer,
core::getInstance()->cfg()->MySQLPort,
core::getInstance()->cfg()->MySQLUsername,
core::getInstance()->cfg()->MySQLPassword,
core::getInstance()->cfg()->MySQLDb
);
}
return clone $this->MySQL;
}
}
?>
...
...
<?php
class hotelsAggregator {
/**
* Array of hotel items
* @var array Array of hotel
*/
private $items = array();
public function loadHotels(MySQL $MySQL, $parentCity = false) {
if ($parentCity !== false && !$parentCity instanceof city) {
throw new Exception("Ошибка аггрератора ".__CLASS__." (".__METHOD__.") - \$parentCity не является типом city");
}
$MySQL->query("SELECT * FROM `toursHotels` ORDER BY `position`");
while ($result = $MySQL->next_row_assoc()) {
$item = new hotel($parentCity instanceof city ? $parentCity : false);
$item->setAttributes($result);
$this->items[$result['id']] = $item;
}
}