I've implemented an abstract class in PHP which manages all my database connections. This class has all basic methods I need like writing, reading, deleting...
To use this class now, I'm creating a special class for each database table:
class Data_Store_Snacks extends Data_Store_Abstract {
public function __construct() {
$this->table = Install::SNACKS_TABLE_NAME;
$this->primary_key = 'id';
$this->model = Data_Store_Snacks_Model::class;
parent::__construct();
}
}
In the above class I'm setting the table, primary key and model which should be returned. The problem is that in the abstract class above this class, I have this method for example:
/**
* Retrieves multiple table rows as an array, filtered by the where
*
* @param array $where
* @param array|null $order_by
* @param int|null $limit
* @param int|null $offset
*
* @return array|false
*/
public function find_all_by( array $where, array $order_by = null, int $limit = null, int $offset = null ) {
Currently, it's returning an array or false. Instead of the array, I want to return the model as an array like:
@return Data_Store_Snacks_Model[]|false
This works, but not for more than one table! Instead, I need something dynamic like:
@return $this->model[]|false
But as far as I know this is not possible. Currently, I'm using a @var
definition within a foreach
but I don't like doing this to just have my methods available in my IDE
Any ideas?