Fixing remaining static bugs

This commit is contained in:
Dennis Eichhorn 2016-05-14 16:22:25 +02:00
parent f18d9e953a
commit 5a854ce1c9
2 changed files with 33 additions and 31 deletions

View File

@ -55,7 +55,7 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function update($obj);
public static function update($obj);
/**
* Save data.
@ -65,7 +65,7 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function save();
public static function save();
/**
* Delete data.
@ -75,7 +75,7 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function delete();
public static function delete();
/**
* Find data.
@ -99,7 +99,7 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function listResults(Builder $query);
public static function listResults(Builder $query);
/**
* Populate data.
@ -111,7 +111,7 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function populate(array $result);
public static function populate(array $result);
/**
* Populate data.
@ -123,7 +123,7 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function populateIterable(array $result) : array;
public static function populateIterable(array $result) : array;
/**
* Load.
@ -135,7 +135,7 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function with(...$objects);
public static function with(...$objects);
/**
* Get object.
@ -147,6 +147,6 @@ interface DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get($primaryKey);
public static function get($primaryKey);
}

View File

@ -32,10 +32,8 @@ use phpOMS\DataStorage\DataMapperInterface;
* @link http://orange-management.com
* @since 1.0.0
*/
class DataMapperAbstract //implements DataMapperInterface
class DataMapperAbstract implements DataMapperInterface
{
protected static $CLASS = __CLASS__;
/**
* Database connection.
*
@ -163,7 +161,9 @@ class DataMapperAbstract //implements DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function __construct() {}
private function __construct()
{
}
/**
* Clone.
@ -171,7 +171,9 @@ class DataMapperAbstract //implements DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function __clone() {}
private function __clone()
{
}
/**
* Set database connection.
@ -280,19 +282,19 @@ class DataMapperAbstract //implements DataMapperInterface
public static function clear()
{
self::$overwrite = true;
self::$overwrite = true;
self::$primaryField = '';
self::$createdAt = '';
self::$columns = [];
self::$hasMany = [];
self::$ownsMany = [];
self::$hasOne = [];
self::$isExtending = [];
self::$extends = [];
self::$ownsOne = [];
self::$table = '';
self::$fields = [];
self::$collection = [
self::$createdAt = '';
self::$columns = [];
self::$hasMany = [];
self::$ownsMany = [];
self::$hasOne = [];
self::$isExtending = [];
self::$extends = [];
self::$ownsOne = [];
self::$table = '';
self::$fields = [];
self::$collection = [
'primaryField' => [],
'createdAt' => [],
'columns' => [],
@ -332,7 +334,7 @@ class DataMapperAbstract //implements DataMapperInterface
* Create object in db.
*
* @param mixed $obj Object reference (gets filled with insert id)
* @param bool $relations Create all relations as well
* @param int $relations Create all relations as well
*
* @return mixed
*
@ -341,7 +343,7 @@ class DataMapperAbstract //implements DataMapperInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function create($obj, bool $relations = true)
public static function create($obj, int $relations = RelationType::ALL)
{
self::extend(__CLASS__);
@ -421,7 +423,7 @@ class DataMapperAbstract //implements DataMapperInterface
$objId = self::$db->con->lastInsertId();
// handle relations
if ($relations) {
if ($relations === RelationType::ALL) {
foreach (static::$hasMany as $member => $rel) {
/* is a has many property */
$property = $reflectionClass->getProperty($member); // throws ReflectionException
@ -664,7 +666,7 @@ class DataMapperAbstract //implements DataMapperInterface
foreach ($result as $member => $values) {
if ($reflectionClass->hasProperty($member)) {
$mapper = static::$hasMany[$member]['mapper'];
$mapper = static::$hasMany[$member]['mapper'];
$reflectionProperty = $reflectionClass->getProperty($member);
if (!($accessible = $reflectionProperty->isPublic())) {
@ -899,14 +901,14 @@ class DataMapperAbstract //implements DataMapperInterface
* Get all by custom query.
*
* @param Builder $query Query
* @param bool $relations Relations
* @param int $relations Relations
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getAllByQuery(Builder $query, bool $relations = true) : array
public static function getAllByQuery(Builder $query, int $relations = RelationType::ALL) : array
{
$sth = self::$db->con->prepare($query->toSql());
$sth->execute();