tricae/dto-url

This package is abandoned and no longer maintained. No replacement package was suggested.

Library to handle and wrap URL informations

1.0.2 2018-09-21 15:47 UTC

This package is not auto-updated.

Last update: 2019-02-20 19:24:26 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version Total Downloads License Forks Stars

INTRODUCTION

Tiny library for encapsulating an URL.

EXAMPLES OF USE

<?php

use GFG\DTOUrl\Url;

$urlParts = [
    'scheme'   => 'http',
    'host'     => 'externalshop.com',
    'port'     => 80,
    'user'     => 'username',
    'pass'     => 'password',
    'path'     => ['api', 'version', 'action'],
    'query'    => ['query' => 'string'],
    'fragment' => 'first'
];
$url = new Url($urlParts);

// http://username:password@externalshop.com:80/api/version/action?query=string#first
echo $url->getFullUrl();
<?php

use GFG\DTOUrl\Url;

$urlParts = [
    'scheme'   => 'https',
    'host'     => 'www.externalshop.com',
    'path'     => ['test']
];
$url = new Url($urlParts);

// https://www.externalshop.com/test
echo $url->getFullUrl();
<?php

use GFG\DTOUrl\Url;

$urlParts = [
    'path' => [
        'api', 
        'version' => 'version',
        'partnerCode' => 'partner-code',
        'product'
    ]
];
$url = new Url($urlParts);

$replace = [
    'version'     => 2,
    'partnerCode' => 'kanui'
];
$url->replacePath($replace);

// api/2/kanui/product
echo $url->getFullUrl();
<?php

use GFG\DTOUrl\Url;

$urlParts = [
    'scheme'   => 'http',
    'host'     => 'externalshop.com',
    'port'     => 80,
    'user'     => 'username',
    'pass'     => 'password',
    'path'     => ['api', 'version', 'action'],
    'query'    => ['query' => 'string'],
    'fragment' => 'first'
];
$url = new Url($urlParts);

$paths = [
    'version' => 'version',
    'create',
    'product'
];
$replace = ['version' => '2.0'];
$url->setPath($paths)->replacePath($replace);

// http://username:password@externalshop.com:80/2.0/create/product?query=string#first
echo $this->url->getFullUrl();
<?php

use GFG\DTOUrl\Url;

$urlParts = [
    'scheme'   => 'http',
    'host'     => 'externalshop.com',
    'port'     => 80,
    'user'     => 'username',
    'pass'     => 'password',
    'path'     => ['api', 'version', 'action'],
    'query'    => ['query' => 'string'],
    'fragment' => 'first'
];
$url = new Url($urlParts);

$query = ['name' => 'name'];
$replace = ['name' => 'fullname'];
$url->setQuery($query)->replaceQuery($replace);

// http://username:password@externalshop.com:80/api/version/action?name=fullname#first
echo $url->getFullUrl();