I wanna to define a base class for all my db table class. It is like the following:
namespace Application\Model\LocalBase;
use Laminas\Db\TableGateway\TableGatewayInterface;
class TableBase
{
protected TableGatewayInterface $tableGateway;
public function __construct(TableGatewayInterface $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function fetchRecord($whereArr)
{
$rowset = $this->tableGateway->select($whereArr);
return $rowset->current();
}
public function deleteRecord($whereArr)
{
return $this->tableGateway->delete($whereArr);
}
/** this method I wanna just limit the fuction name, no limit to the parameters */
public function getPaginator(...$args)
{
//
}
public function insertRecord(array $data): int
{
return $this->tableGateway->insert($data);
}
public function updateRecord(array $whereArr,array $data): int
{
return $this->tableGateway->update($data,$whereArr);
}
/** this method, just limit func name, no limit to parameters, one or two or three, whatever the parameter type is */
public function saveRecord(...$args)
{
//
}
}
When I extend the above base class. I wanna it looks like.
namespace Member\Model;
use Application\Model\LocalBase\TableBase;
use Application\Model\UtilsFuncs;
use Laminas\Http\Request;
class MessageboardTable extends TableBase
{
// when I overwrite this method like this, the phpstorm editor raise error, not compatible...
public function saveRecord(Messageboard $messageboard, UtilsFuncs $utilsFuncs, Request $request)
{
$ip = $utilsFuncs->getIp($request);
if (!$ip) return $utilsFuncs->uniformJson(false, 'can not get ip');
// ... save data into database logic here...
}
}
Is it possible to reach such requirement? Base class limit the function name, and make other workmate not to name the saving record logic fucntion. But it wonât limit the parameter. And allow the sub class who extent the base class can format the input parameterâs type. Like the above MessageboardTable class, the first parameter must be Messageboard entity.
Or it is possible to fulfil. Any kind people can give me a certain answer?