transact($function); } /** * @param $id int */ public static function checkIdExists($id) { static::getSingleById($id); } /** * @param $id int * @return LuDbo */ public static function getSingleById($id) { $data = static::getDataAccess()->getSingleById($id); if (is_null($data)) { self::notFound(); } return $data; } /** * @param $id int * @return LuDbo */ public static function deleteSingleById($id) { $dbo = static::getSingleById($id); static::getDataAccess()->deleteSingleById($id); return $dbo; } /** * @param $dbo LuDbo * @return LuDbo */ public static function addSingleId($dbo) { $id = static::getDataAccess()->addSingleId($dbo); return static::getSingleById($id); } /** * @param $id int * @param $dbo LuDbo * @return LuDbo */ public static function editSingleById($id, $dbo) { static::checkIdExists($id); static::getDataAccess()->editSingleById($dbo, $id); return static::getSingleById($id); } /** * @return LuDataAccess */ protected static function getDataAccess() { return null; } public static function getResourceName() { $res = static::$_resourceName; if ($res == null) { $match = []; $className = get_called_class(); preg_match('/([^\\\\]*)Business$/', get_called_class(), $match); if (count($match) < 2) { $res = $className; } else { $res = $match[1]; } if (static::$_resourceNameUnPluralize) { if (LuStringUtils::endsWith($res, "ies")) { $res = substr($res, 0, strlen($res) - 3) . "y"; } else if (LuStringUtils::endsWith($res, "s")) { $res = substr($res, 0, strlen($res) - 1); } } } return $res; } }