infusionweb / laravel-url-resolver-provider
Provides a Laravel 5 service provider and facade for URLResolver.php.
Installs: 1 501
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.5.9
- illuminate/support: ~5.0
- mdf/php-url-resolver: @dev
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: ~4.6
This package is auto-updated.
Last update: 2024-10-28 09:57:25 UTC
README
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.