From 5a854ce1c9706e81937d5c6a0dd238125361a21b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 14 May 2016 16:22:25 +0200 Subject: [PATCH] Fixing remaining static bugs --- DataStorage/DataMapperInterface.php | 16 +++---- DataStorage/Database/DataMapperAbstract.php | 48 +++++++++++---------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/DataStorage/DataMapperInterface.php b/DataStorage/DataMapperInterface.php index bf31723ad..0df484e62 100644 --- a/DataStorage/DataMapperInterface.php +++ b/DataStorage/DataMapperInterface.php @@ -55,7 +55,7 @@ interface DataMapperInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public function update($obj); + public static function update($obj); /** * Save data. @@ -65,7 +65,7 @@ interface DataMapperInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public function save(); + public static function save(); /** * Delete data. @@ -75,7 +75,7 @@ interface DataMapperInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public function delete(); + public static function delete(); /** * Find data. @@ -99,7 +99,7 @@ interface DataMapperInterface * @since 1.0.0 * @author Dennis Eichhorn */ - 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 */ - 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 */ - 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 */ - public function with(...$objects); + public static function with(...$objects); /** * Get object. @@ -147,6 +147,6 @@ interface DataMapperInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public function get($primaryKey); + public static function get($primaryKey); } diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 30cbc1de0..9f9a995ca 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -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 */ - private function __construct() {} + private function __construct() + { + } /** * Clone. @@ -171,7 +171,9 @@ class DataMapperAbstract //implements DataMapperInterface * @since 1.0.0 * @author Dennis Eichhorn */ - 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 */ - 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 */ - 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();