16 private static function getSet(
string $propertyName):array{
17 $propertyName=\ucfirst($propertyName);
18 return [
'get'.$propertyName,
'set'.$propertyName];
25 public static function toggleProperty(
object $object,
string $propertyName):void{
26 list($getter,$setter)=self::getSet($propertyName);
27 $object->$setter(!($object->$getter()));
35 public static function incProperty(
object $object,
string $propertyName,$val=1):void{
36 list($getter,$setter)=self::getSet($propertyName);
37 $object->$setter($object->$getter()+$val);
45 public static function decProperty(
object $object,
string $propertyName,$val=1):void{
46 list($getter,$setter)=self::getSet($propertyName);
47 $object->$setter($object->$getter()-$val);
56 public static function concatProperty(
object $object,
string $propertyName,$val,
bool $after=
true):void{
57 list($getter,$setter)=self::getSet($propertyName);
59 $object->$setter($object->$getter().$val);
61 $object->$setter($val.($object->$getter()));
70 public static function addTo(
object $object,
string $propertyName,$val):void{
71 list($getter,$setter)=self::getSet($propertyName);
72 $array=$object->$getter();
74 $object->$setter($array);
83 public static function removeFrom(
object $object,
string $propertyName,$val){
84 list($getter,$setter)=self::getSet($propertyName);
85 $array=$object->$getter();
86 if(($index=\array_search($val, $array))!==
false){
88 unset($array[$index]);
89 $object->$setter($array);
102 list($getter,$setter)=self::getSet($propertyName);
103 $array=$object->$getter();
104 if(isset($array[$index])){
106 unset($array[$index]);
107 $object->$setter($array);
117 public static function asArray(
object $object):array{
118 return $object->_rest??[];
126 public static function asJson(
object $object,
int $options=0):string{
127 return \json_encode($object->_rest??[],$options);
137 foreach ($properties as $property){
138 $get=
'get'.\ucfirst($property);
139 $res[$property]=$object->$get();
150 public static function asJsonProperties(
object $object,array $properties,
int $options=0):string{
151 return \json_encode(self::asArrayProperties($object, $properties),$options);
161 public static function equals(
object $object,?
object $toObject,
string $property=
'id'){
165 $get=
'get'.\ucfirst($property);
166 return $object->$get()===$toObject->$get();
Ubiquity\utils\models$UModel This class is part of Ubiquity.
static removeFromByIndex(object $object, string $propertyName, $index)
static asArray(object $object)
static asArrayProperties(object $object, array $properties)
static toggleProperty(object $object, string $propertyName)
static addTo(object $object, string $propertyName, $val)
static removeFrom(object $object, string $propertyName, $val)
static asJson(object $object, int $options=0)
static asJsonProperties(object $object, array $properties, int $options=0)
static getSet(string $propertyName)
static decProperty(object $object, string $propertyName, $val=1)
static concatProperty(object $object, string $propertyName, $val, bool $after=true)
static equals(object $object,?object $toObject, string $property='id')
Determines if 2 objects are equal.
static incProperty(object $object, string $propertyName, $val=1)