germania-kg/mergequery_urifactory

URI factory decorator for merging query parameters

1.0.3 2021-01-11 13:39 UTC

This package is auto-updated.

Last update: 2024-10-11 22:17:56 UTC


README

Germania KG ยท MergeQueryUriFactory

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation

$ composer require germania-kg/mergequery_urifactory

Usage:

The MergeQueryUriFactoryDecorator adds a createUriMergeQuery method to any given PSR-17 UriFactory. It also itself implements Psr\Http\Message\UriFactoryInterface and can also be used as callable.

The createUriMergeQuery accepts both string and UriInterface URIs.

<?php
use Germania\MergeQueryUriFactory\MergeQueryUriFactoryDecorator;
use Nyholm\Psr7\Factory\Psr17Factory;  

$decoratee = new Psr17Factory();
$uri_factory = new MergeQueryUriFactoryDecorator( $decoratee );

// You know the UriFactoryInterface:
$uri = $uri_factory->createUri( 'http://httpbin.org' );

// Programmatically merge query parameters,
// either to a string or UriInterface:
$uri2 = $uri_factory->createUriMergeQuery( 'http://httpbin.org', ['foo' => 'bar']);
$uri3 = $uri_factory->createUriMergeQuery( $uri, ['foo' => 'bar']);

echo $uri3;
// http://httpbin.org?foo=bar