Compare commits

...

5 Commits

  1. 4
      Model/DbDriver.php
  2. 4
      Model/MySQLiStatement.php
  3. 19
      Model/SqlModel.php
  4. 4
      Model/SqlResultCollection.php

4
Model/DbDriver.php

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

4
Model/MySQLiStatement.php

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

19
Model/SqlModel.php

@ -164,9 +164,10 @@ abstract class SqlModel extends Model
* @param string $data Request
* @param array $params Request parameters
* @param CacheKey $cache_key Key for caching in
* @param bool $returnNewInstance Return the instance of this filled from query
* @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()) {
$result = $this->query($data, $params)->fetch();
@ -174,6 +175,20 @@ abstract class SqlModel extends Model
$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;
}
@ -250,4 +265,4 @@ abstract class SqlModel extends Model
{
return new SqlCriteria($this, $sql_expression, $sql_expression_params);
}
}
}

4
Model/SqlResultCollection.php

@ -1,8 +1,8 @@
<?php namespace Majestic\Model;
use Illuminate\Support\Contracts\ArrayableInterface;
use Illuminate\Contracts\Support\Arrayable;
class SqlResultCollection extends \ArrayIterator implements iSqlResultItems, ArrayableInterface
class SqlResultCollection extends \ArrayIterator implements iSqlResultItems, Arrayable
{
private $items;

Loading…
Cancel
Save