public function expandAll (array $urls, callable $callback = null)
    {
        $urls = array_values($urls);
        $expanded = [];

        // Request builder.
        $requests = function ($urls) {
            foreach ($urls as $url) {
                yield new Request('HEAD', $url);
            }
        };

        if (! is_callable($callback)) {
            $expanded = array_combine($urls, array_pad([], count($urls), null));
            $callback = function ($error, $long, $short) use (&$expanded) {
                if (! $error) {
                    $expanded[$short] = $long;
                }
            };
        }

        $client = clone $this->client;
        $client->setAccessToken(null);

        (new Pool(
            $client,
            $requests($urls),
            [
                'fulfilled' => function (ResponseInterface $response, $index) use ($urls, $callback) {
                    $short = $urls[$index];
                    $long = $response->hasHeader('Location') ? $response->getHeaderLine('Location') : null;

                    call_user_func($callback, null, $long, $short);
                },
                'rejected'  => function (RequestException $reason) use ($callback) {
                    call_user_func($callback, $reason, null, null);
                },
            ]
        ))->promise()->wait();

        return $expanded;
    }
public function expandAll (array $urls, callable $callback = null)
    {
        $urls = array_values($urls);
        $expanded = [];

        // Request builder.
        $requests = function ($urls) {
            foreach ($urls as $url) {
                yield new Request('HEAD', $url);
            }
        };

        if (! is_callable($callback)) {
            $expanded = array_combine($urls, array_pad([], count($urls), null));
            $callback = function ($error, $long, $short) use (&$expanded) {
                if (! $error) {
                    $expanded[$short] = $long;
                }
            };
        }

        $client = clone $this->client;
        $client->setAccessToken(null);

        (new Pool(
            $client,
            $requests($urls),
            [
                'fulfilled' => function (ResponseInterface $response, $index) use ($urls, $callback) {
                    $short = $urls[$index];
                    $long = $response->hasHeader('Location') ? $response->getHeaderLine('Location') : null;

                    call_user_func($callback, null, $long, $short);
                },
                'rejected'  => function (RequestException $reason) use ($callback) {
                    call_user_func($callback, $reason, null, null);
                },
            ]
        ))->promise()->wait();

        return $expanded;
    }
public function expandAll ( array $ urls , callable $ callback = null ) { $ urls = array_values ( $ urls ) ; $ expanded = [ ] ; // Request builder. $ requests = function ( $ urls ) { foreach ( $ urls as $ url ) { yield new Request ( 'HEAD' , $ url ) ; } } ; if ( ! is_callable ( $ callback ) ) { $ expanded = array_combine ( $ urls , array_pad ( [ ] , count ( $ urls ) , null ) ) ; $ callback = function ( $ error , $ long , $ short ) use ( & $ expanded ) { if ( ! $ error ) { $ expanded [ $ short ] = $ long ; } } ; } $ client = clone $ this -> client ; $ client -> setAccessToken ( null ) ; ( new Pool ( $ client , $ requests ( $ urls ) , [ 'fulfilled' => function ( ResponseInterface $ response , $ index ) use ( $ urls , $ callback ) { $ short = $ urls [ $ index ] ; $ long = $ response -> hasHeader ( 'Location' ) ? $ response -> getHeaderLine ( 'Location' ) : null ; call_user_func ( $ callback , null , $ long , $ short ) ; } , 'rejected' => function ( RequestException $ reason ) use ( $ callback ) { call_user_func ( $ callback , $ reason , null , null ) ; } , ] ) ) -> promise ( ) -> wait ( ) ; return $ expanded ; }
Expands the given URLs into their long version. This is done dirtily, by issuing a HEAD request to the given
short URL, and using the contents of the `Location` header.

If a callback is given, it needs to have the following signature:
`function ($long = '', $short = '')`

If a callback isn't specified, an array containing a mapping of short => long URLs is returned.

@param array         $urls
@param callable|null $callback

@return array
Expands the given URLs into their long version . This is done dirtily by issuing a HEAD request to the given short URL and using the contents of the Location header .