src/Utils/Reflection/ReflectionUtil.php
public static function objToSnakeArray($object, $blackList = [])
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('Not an object');
        }

        return array_reduce(
            self::getAllProperties($object, $blackList),
            function (
                array $result,
                \ReflectionProperty $property
            ) use (
                $object
            ) {
                $property->setAccessible(true);

                $field = $property->getName();
                $value = $property->getValue($object);
                $value = self::transformValue($value);

                if ($object instanceof WithNullableFields) {
                    if (is_null($value) && !$object->isNullable($field)) {
                        return $result;
                    }

                    if ($object->isNullable($field) && !$object->isValueChanged($field)) {
                        return $result;
                    }
                } elseif (is_null($value)) {
                    return $result;
                }


                $result[Str::snake($field)] = $value;

                $property->setAccessible(false);

                return $result;
            },
            []
        );
    }
public static function objToSnakeArray($object, $blackList = [])
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('Not an object');
        }

        return array_reduce(
            self::getAllProperties($object, $blackList),
            function (
                array $result,
                \ReflectionProperty $property
            ) use (
                $object
            ) {
                $property->setAccessible(true);

                $field = $property->getName();
                $value = $property->getValue($object);
                $value = self::transformValue($value);

                if ($object instanceof WithNullableFields) {
                    if (is_null($value) && !$object->isNullable($field)) {
                        return $result;
                    }

                    if ($object->isNullable($field) && !$object->isValueChanged($field)) {
                        return $result;
                    }
                } elseif (is_null($value)) {
                    return $result;
                }


                $result[Str::snake($field)] = $value;

                $property->setAccessible(false);

                return $result;
            },
            []
        );
    }
public static function objToSnakeArray ( $ object , $ blackList = [ ] ) { if ( ! is_object ( $ object ) ) { throw new \ InvalidArgumentException ( 'Not an object' ) ; } return array_reduce ( self :: getAllProperties ( $ object , $ blackList ) , function ( array $ result , \ ReflectionProperty $ property ) use ( $ object ) { $ property -> setAccessible ( true ) ; $ field = $ property -> getName ( ) ; $ value = $ property -> getValue ( $ object ) ; $ value = self :: transformValue ( $ value ) ; if ( $ object instanceof WithNullableFields ) { if ( is_null ( $ value ) && ! $ object -> isNullable ( $ field ) ) { return $ result ; } if ( $ object -> isNullable ( $ field ) && ! $ object -> isValueChanged ( $ field ) ) { return $ result ; } } elseif ( is_null ( $ value ) ) { return $ result ; } $ result [ Str :: snake ( $ field ) ] = $ value ; $ property -> setAccessible ( false ) ; return $ result ; } , [ ] ) ; }
Take an object and return an array using all it's properties.

Don't set the null one

@param       $object    *
@param array $blackList array containing name of properties to not serialize

@throws \ReflectionException

@return array
Take an object and return an array using all it s properties .