src/Collection.php
public static function formats($format = null, $handler = null)
    {
        if ($format === null) {
            return static::$_formats;
        }
        if ($format === false) {
            return static::$_formats = ['array' => 'Lead\Collection\Collection::toArray'];
        }
        if ($handler === false) {
            unset(static::$_formats[$format]);
            return;
        }
        return static::$_formats[$format] = $handler;
    }
public static function formats($format = null, $handler = null)
    {
        if ($format === null) {
            return static::$_formats;
        }
        if ($format === false) {
            return static::$_formats = ['array' => 'Lead\Collection\Collection::toArray'];
        }
        if ($handler === false) {
            unset(static::$_formats[$format]);
            return;
        }
        return static::$_formats[$format] = $handler;
    }
public static function formats ( $ format = null , $ handler = null ) { if ( $ format === null ) { return static :: $ _formats ; } if ( $ format === false ) { return static :: $ _formats = [ 'array' => 'Lead\Collection\Collection::toArray' ] ; } if ( $ handler === false ) { unset ( static :: $ _formats [ $ format ] ) ; return ; } return static :: $ _formats [ $ format ] = $ handler ; }
Accessor method for adding format handlers to `Collection` instances.

The values assigned are used by `Collection::to()` to convert `Collection` instances into
different formats, i.e. JSON.

This can be accomplished in two ways. First, format handlers may be registered on a
case-by-case basis, as in the following:

```php
Collection::formats('json', function($collection, $options) {
return json_encode($collection->to('array'));
});

// You can also implement the above as a static class method, and register it as follows:
Collection::formats('json', 'my\custom\Formatter::toJson');
```

@see    Lead\Collection\Collection::to()
@param  string $format  A string representing the name of the format that a `Collection`
can be converted to. If `false`, reset the `$_formats` attribute.
If `null` return the content of the `$_formats` attribute.
@param  mixed  $handler The function that handles the conversion, either an anonymous function,
a fully namespaced class method or `false` to remove the `$format` handler.
@return mixed
Accessor method for adding format handlers to Collection instances .