mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-13 03:46:58 +01:00
* [MOD] Code refactoring
This commit is contained in:
@@ -34,10 +34,10 @@ class ArrayUtil
|
||||
/**
|
||||
* Buscar un objeto en un array según el valor de una propiedad
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param string $property Nombre de la propiedad
|
||||
* @param string $value Valor de la propiedad
|
||||
* @param object $default Valor por defecto
|
||||
* @param string $value Valor de la propiedad
|
||||
* @param object $default Valor por defecto
|
||||
* @return false|object
|
||||
*/
|
||||
public static function searchInObject(array $array, $property, $value, $default = null)
|
||||
@@ -53,4 +53,45 @@ class ArrayUtil
|
||||
|
||||
return null !== $default ? $default : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si un valor existe en un array de objetos
|
||||
*
|
||||
* @param array $objectArray
|
||||
* @param string $method
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkInObjectArrayMethod(array $objectArray, $method, $value)
|
||||
{
|
||||
foreach ($objectArray as $object) {
|
||||
if (is_callable([$object, $method]) && $object->$method() === $value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si un valor existe en un array de objetos
|
||||
*
|
||||
* @param array $objectArray
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkInObjectArray(array $objectArray, $property, $value)
|
||||
{
|
||||
foreach ($objectArray as $object) {
|
||||
if (is_object($object)
|
||||
&& isset($object->$property)
|
||||
&& $object->$property == $value
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user