infusionweb/laravel-url-resolver-provider

Provides a Laravel 5 service provider and facade for URLResolver.php.

0.1.0 2016-05-18 23:23 UTC

This package is auto-updated.

Last update: 2024-11-28 10:07:46 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

A simple wrapper for using URLResolver.php in Laravel

This package provides a Laravel 5 service provider and facade for mdf/php-url-resolver, which is a fork of mattwright/URLResolver.php, which seems to no longer be maintained.

URLResolver.php is a PHP class that attempts to resolve URLs to a final, canonical link. On the web today, link shorteners, tracking codes and more can result in many different links that ultimately point to the same resource. By following HTTP redirects and parsing web pages for open graph and canonical URLs, URLResolver.php attempts to solve this issue.

When enabled and configured, all this package does is allow more convenient use of the URLResolver.php functionality, through a Laravel facade.

Installation

Step 1: Composer

Via Composer command line:

$ composer require infusionweb/laravel-url-resolver-provider

Or add the package to your composer.json:

{
    "require": {
        "infusionweb/laravel-url-resolver-provider": "~0.1.0"
    }
}

Step 2: Register the Service Provider

Add the service provider to your config/app.php:

'providers' => [
    //
    InfusionWeb\Laravel\Providers\UrlResolver::class,
];

Step 3: Enable the Facade

Add the facade to your config/app.php:

'aliases' => [
    //
    'Resolver' => InfusionWeb\Laravel\Facades\UrlResolver::class,
];

Usage

Simple case

<?php

use Resolver;

$url = 'http://bit.ly/1R6M0uY';

$resolved = Resolver::resolveURL($url)->getURL();

With additional setup

<?php

use Resolver;

// Change the default user agent.
Resolver::setUserAgent('Mozilla/5.0 (compatible; YourAppName/1.0; +http://www.example.com)');

// Set a temporary file for session cookie storage.
Resolver::setCookieJar('/tmp/url_resolver.cookies');

// Test result object for additional information.
$url = 'http://goo.gl/0GMP1';
$url_result = $resolver->resolveURL($url);
if ($url_result->didErrorOccur()) {
    print "Error resolving $url:\n  ".$url_result->getErrorMessageString();
}
else {
    print $url_result->getHTTPStatusCode().': '.$url_result->getURL();
}

For additional documentation, see the URLResolver.php documentation.

Credits

License

The MIT License (MIT). Please see License File for more information.