forked from GNUsocial/gnu-social
[CORE][Entity] Replaced get_called_class() calls with static::class since the former is deprecated
This commit is contained in:
parent
14b03c7137
commit
d29e28b829
@ -42,10 +42,10 @@ abstract class Entity
|
|||||||
$prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'has'));
|
$prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'has'));
|
||||||
// https://wiki.php.net/rfc/closure_apply#proposal
|
// https://wiki.php.net/rfc/closure_apply#proposal
|
||||||
$private_property_accessor = fn ($prop) => isset($this->{$prop});
|
$private_property_accessor = fn ($prop) => isset($this->{$prop});
|
||||||
$private_property_accessor = $private_property_accessor->bindTo($this, \get_called_class());
|
$private_property_accessor = $private_property_accessor->bindTo($this, static::class);
|
||||||
return $private_property_accessor($prop);
|
return $private_property_accessor($prop);
|
||||||
}
|
}
|
||||||
throw new BadMethodCallException('Non existent method ' . \get_called_class() . "::{$name} called with arguments: " . print_r($arguments, true));
|
throw new BadMethodCallException('Non existent method ' . static::class . "::{$name} called with arguments: " . print_r($arguments, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,12 +89,14 @@ abstract class Entity
|
|||||||
/**
|
/**
|
||||||
* Create a new instance, but check for duplicates
|
* Create a new instance, but check for duplicates
|
||||||
*
|
*
|
||||||
|
* @throws \App\Util\Exception\ServerException
|
||||||
|
*
|
||||||
* @return array [$obj, $is_update]
|
* @return array [$obj, $is_update]
|
||||||
*/
|
*/
|
||||||
public static function createOrUpdate(array $args, array $find_by_keys = []): array
|
public static function createOrUpdate(array $args, array $find_by_keys = []): array
|
||||||
{
|
{
|
||||||
$table = DB::getTableForClass(\get_called_class());
|
$table = DB::getTableForClass(static::class);
|
||||||
$find_by = $find_by_keys == [] ? $args : array_intersect_key($args, array_flip($find_by_keys));
|
$find_by = $find_by_keys === [] ? $args : array_intersect_key($args, array_flip($find_by_keys));
|
||||||
try {
|
try {
|
||||||
$obj = DB::findOneBy($table, $find_by);
|
$obj = DB::findOneBy($table, $find_by);
|
||||||
} catch (NotFoundException) {
|
} catch (NotFoundException) {
|
||||||
@ -126,7 +128,7 @@ abstract class Entity
|
|||||||
public static function getByPK(mixed $values): ?self
|
public static function getByPK(mixed $values): ?self
|
||||||
{
|
{
|
||||||
$values = \is_array($values) ? $values : [$values];
|
$values = \is_array($values) ? $values : [$values];
|
||||||
$class = \get_called_class();
|
$class = static::class;
|
||||||
$keys = DB::getPKForClass($class);
|
$keys = DB::getPKForClass($class);
|
||||||
$find_by = [];
|
$find_by = [];
|
||||||
foreach ($values as $k => $v) {
|
foreach ($values as $k => $v) {
|
||||||
|
Loading…
Reference in New Issue
Block a user