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-04-11 20:58:32 UTC


README

68747470733a2f2f7374617469632e6765726d616e69612d6b672e636f6d2f6c6f676f732f67612d6c6f676f2d323031362d7765622e7376677a

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