5 Commits

Author SHA1 Message Date
d8031c497b 10_ballov-1452 10_ballov-174 Параметр возврата нового заполненногоq из запроса собственного экземпляра в SqlModel::fetch(). 2020-04-09 21:41:44 +03:00
984e9aa716 * make majestic models as orm-objects (only on single fetch record)
10_ballov-1431 Авторизация и вывод 3-й цены на мобильной версии зеленого моря
2020-03-27 21:39:45 +03:00
89ececaef2 Fix GeneralException namespace used in DbDriver 2020-01-10 00:16:20 +03:00
bb2d713ab3 count fix 2018-04-20 13:24:30 +03:00
e475484f5a ArraybleInterface - Arrayble 2016-01-25 08:52:48 +03:00
4 changed files with 26 additions and 21 deletions

18
Config.php Executable file → Normal file
View File

@ -14,26 +14,12 @@ class Config extends Registry
private static $_class_name = 'Config'; private static $_class_name = 'Config';
/** static public function set($name, $value)
* Метод устанавливает параметры конфигурации
* @param mixed $param
* Имя параметра или параметры в массиве
* @param mixed $value
* Значение параметра. Не требуется, если передаются параметры в массиве
*/
static public function set($param, $value = null)
{ {
// Разбираю массив, если параметры переданы в массиве
if (is_array($param)) {
foreach ($param as $paramItem => $value) {
self::set($paramItem, $value);
}
return;
}
if (is_array($value)) { if (is_array($value)) {
$value = new ConfigArray($value); $value = new ConfigArray($value);
} }
self::getInstance()->offsetSet($param, $value); self::getInstance()->offsetSet($name, $value);
} }
} }

View File

@ -1,4 +1,6 @@
<?php namespace Majestic\Model; <?php namespace Majestic\Model;
use Majestic\Exception\GeneralException;
/** /**
* @copyright NetMonsters <team@netmonsters.ru> * @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru * @link http://netmonsters.ru
@ -36,7 +38,7 @@ abstract class DbDriver
$required = array('database', 'username', 'password', 'hostname'); $required = array('database', 'username', 'password', 'hostname');
foreach ($required as $option) { foreach ($required as $option) {
if (!isset($config[$option])) { if (!isset($config[$option])) {
throw new \GeneralException('Configuration must have a "' . $option . '".'); throw new GeneralException('Configuration must have a "' . $option . '".');
} }
} }
} }

View File

@ -21,7 +21,8 @@ class MySQLiStatement extends DbStatement
if ($this->map === null) { if ($this->map === null) {
$this->mapPlaceholders(); $this->mapPlaceholders();
} }
if (is_array($this->map) && count($this->map) > 0) {
if ($this->map) {
if (!is_string($param) && !is_int($param)) { if (!is_string($param) && !is_int($param)) {
throw new \Majestic\Exception\GeneralException('Placeholder must be an integer or string'); throw new \Majestic\Exception\GeneralException('Placeholder must be an integer or string');
} }
@ -33,6 +34,7 @@ class MySQLiStatement extends DbStatement
return true; return true;
} }
} }
return false; return false;
} }
protected function mapPlaceholders() protected function mapPlaceholders()

View File

@ -164,9 +164,10 @@ abstract class SqlModel extends Model
* @param string $data Request * @param string $data Request
* @param array $params Request parameters * @param array $params Request parameters
* @param CacheKey $cache_key Key for caching in * @param CacheKey $cache_key Key for caching in
* @param bool $returnNewInstance Return the instance of this filled from query
* @return mixed * @return mixed
*/ */
protected function fetch($data, $params = array(), $cache_key = null) protected function fetch($data, $params = array(), $cache_key = null, $returnFilledInstance = true)
{ {
if (!$cache_key || !$result = $cache_key->get()) { if (!$cache_key || !$result = $cache_key->get()) {
$result = $this->query($data, $params)->fetch(); $result = $this->query($data, $params)->fetch();
@ -174,6 +175,20 @@ abstract class SqlModel extends Model
$cache_key->set($result); $cache_key->set($result);
} }
} }
if ($result && $returnFilledInstance) {
$instance = new $this;
foreach (get_object_vars($result) as $key => $value) {
if ($key == 'table') {
$key = 'table_field';
}
$instance->$key = $value;
}
return $instance;
}
return $result; return $result;
} }