public static function forceString($value)
    {
        if (is_string($value)) {
            return [sprintf("'%s'", $value), []];
        }

        if (is_array($value)) {
            $import = [];
            $assoc = [];

            foreach ($value as $key => $val) {
                if (!is_int($key)) {
                    $key_arr = static::forceString($key);
                    $val_arr = static::forceString($val);

                    array_push(
                        $assoc,
                        sprintf(
                            '%1$s=> %2$s',
                            $key_arr[0],
                            $val_arr[0]
                        )
                    );

                    if (!empty($key_arr[1])) {
                        $import = array_merge($import, $key_arr[1]);
                    }

                    if (!empty($val_arr[1])) {
                        $import = array_merge($import, $val_arr[1]);
                    }
                } else {
                    $val_arr = static::forceString($val);
                    array_push($assoc, $val_arr[0]);

                    if (!empty($val_arr[1])) {
                        $import = array_merge($import, $val_arr[1]);
                    }
                }
            }

            return [sprintf('[%s]', implode(', ', $assoc)), $import];
        }

        if (is_object($value) && $value instanceof DeConstructableInterface) {
            $skel = $value->deconstruct();

            $import = [$skel['path']];

            $class = $skel['name'];

            $constructor_args = [$skel['constructorArgs']];
            $cons_args = [];
            foreach ($constructor_args as $arg) {
                $val_array = static::forceString($arg);

                array_push($cons_args, $val_array[0]);

                if (!empty($val_array[1])) {
                    $import = array_merge($import, $val_array[1]);
                }
            }

            if (empty($constructor_args[0])) {
                $cons_args = '';
            } else {
                $cons_args = implode(',', $cons_args);
            }

            return [
                sprintf(
                    '%s(%s)',
                    $class,
                    $cons_args
                ),
                $import,
            ];
        }

        if (true === $value) {
            return ['true', []];
        }

        if (false === $value) {
            return ['false', []];
        }

        if (null === $value) {
            return ['null', []];
        }

        return [$value, []];
    }
public static function forceString($value)
    {
        if (is_string($value)) {
            return [sprintf("'%s'", $value), []];
        }

        if (is_array($value)) {
            $import = [];
            $assoc = [];

            foreach ($value as $key => $val) {
                if (!is_int($key)) {
                    $key_arr = static::forceString($key);
                    $val_arr = static::forceString($val);

                    array_push(
                        $assoc,
                        sprintf(
                            '%1$s=> %2$s',
                            $key_arr[0],
                            $val_arr[0]
                        )
                    );

                    if (!empty($key_arr[1])) {
                        $import = array_merge($import, $key_arr[1]);
                    }

                    if (!empty($val_arr[1])) {
                        $import = array_merge($import, $val_arr[1]);
                    }
                } else {
                    $val_arr = static::forceString($val);
                    array_push($assoc, $val_arr[0]);

                    if (!empty($val_arr[1])) {
                        $import = array_merge($import, $val_arr[1]);
                    }
                }
            }

            return [sprintf('[%s]', implode(', ', $assoc)), $import];
        }

        if (is_object($value) && $value instanceof DeConstructableInterface) {
            $skel = $value->deconstruct();

            $import = [$skel['path']];

            $class = $skel['name'];

            $constructor_args = [$skel['constructorArgs']];
            $cons_args = [];
            foreach ($constructor_args as $arg) {
                $val_array = static::forceString($arg);

                array_push($cons_args, $val_array[0]);

                if (!empty($val_array[1])) {
                    $import = array_merge($import, $val_array[1]);
                }
            }

            if (empty($constructor_args[0])) {
                $cons_args = '';
            } else {
                $cons_args = implode(',', $cons_args);
            }

            return [
                sprintf(
                    '%s(%s)',
                    $class,
                    $cons_args
                ),
                $import,
            ];
        }

        if (true === $value) {
            return ['true', []];
        }

        if (false === $value) {
            return ['false', []];
        }

        if (null === $value) {
            return ['null', []];
        }

        return [$value, []];
    }
public static function forceString ( $ value ) { if ( is_string ( $ value ) ) { return [ sprintf ( "'%s'" , $ value ) , [ ] ] ; } if ( is_array ( $ value ) ) { $ import = [ ] ; $ assoc = [ ] ; foreach ( $ value as $ key => $ val ) { if ( ! is_int ( $ key ) ) { $ key_arr = static :: forceString ( $ key ) ; $ val_arr = static :: forceString ( $ val ) ; array_push ( $ assoc , sprintf ( '%1$s=> %2$s' , $ key_arr [ 0 ] , $ val_arr [ 0 ] ) ) ; if ( ! empty ( $ key_arr [ 1 ] ) ) { $ import = array_merge ( $ import , $ key_arr [ 1 ] ) ; } if ( ! empty ( $ val_arr [ 1 ] ) ) { $ import = array_merge ( $ import , $ val_arr [ 1 ] ) ; } } else { $ val_arr = static :: forceString ( $ val ) ; array_push ( $ assoc , $ val_arr [ 0 ] ) ; if ( ! empty ( $ val_arr [ 1 ] ) ) { $ import = array_merge ( $ import , $ val_arr [ 1 ] ) ; } } } return [ sprintf ( '[%s]' , implode ( ', ' , $ assoc ) ) , $ import ] ; } if ( is_object ( $ value ) && $ value instanceof DeConstructableInterface ) { $ skel = $ value -> deconstruct ( ) ; $ import = [ $ skel [ 'path' ] ] ; $ class = $ skel [ 'name' ] ; $ constructor_args = [ $ skel [ 'constructorArgs' ] ] ; $ cons_args = [ ] ; foreach ( $ constructor_args as $ arg ) { $ val_array = static :: forceString ( $ arg ) ; array_push ( $ cons_args , $ val_array [ 0 ] ) ; if ( ! empty ( $ val_array [ 1 ] ) ) { $ import = array_merge ( $ import , $ val_array [ 1 ] ) ; } } if ( empty ( $ constructor_args [ 0 ] ) ) { $ cons_args = '' ; } else { $ cons_args = implode ( ',' , $ cons_args ) ; } return [ sprintf ( '%s(%s)' , $ class , $ cons_args ) , $ import , ] ; } if ( true === $ value ) { return [ 'true' , [ ] ] ; } if ( false === $ value ) { return [ 'false' , [ ] ] ; } if ( null === $ value ) { return [ 'null' , [ ] ] ; } return [ $ value , [ ] ] ; }
Converts a value to a string ready for writing on a file.

@param $value

@return array

@since  1.1.0

@author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
Converts a value to a string ready for writing on a file .