Skip to content

Commit

Permalink
Laravel Facade (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreyrose authored Nov 17, 2024
1 parent f735dcc commit fa02765
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,43 @@
[![License](https://img.shields.io/github/license/geoffreyrose/url-helper?style=flat-square)](https://github.com/geoffreyrose/url-helper/blob/main/LICENSE)
</div>

# PHP URL Helper
An easy-to-use PHP helper to parse out different parts of a URL
# PHP URL Helper + Laravel Facade
An easy-to-use PHP helper (and Laravel Facade) to parse out different parts of a URL


### Requirements
* PHP 8.0+

### Usage

### Install
```
$ composer require geoffreyrose/url-helper
composer require geoffreyrose/url-helper
```

```php
<?php

require 'vendor/autoload.php';
### With Plain PHP

```php
use UrlHelper\UrlHelper;

...

$urlHelper = new UrlHelper();
```


### With Laravel Facade
Laravel uses Package Auto-Discovery, which doesn't require you to manually add the ServiceProvider and Facade.

```php
$rootHostname = URLHelper::getRootHostname('https://github.com/geoffreyrose/url-helper/')
```


### Methods

**Note all examples below use Plain PHP (use UrlHelper\UrlHelper) but can be swapped with Laravel Facade (URLHelper)**

#### isValidDomainName()
```
isValidDomainName(string $domain): bool
Expand Down Expand Up @@ -141,9 +151,9 @@ $urlHelper->getPathname('Dark Lord Sauron'); // null
### Run Tests

```
$ ./vendor/bin/phpunit
./vendor/bin/phpunit
// or with coverage
$ XDEBUG_MODE=coverage ./vendor/bin/phpunit
XDEBUG_MODE=coverage ./vendor/bin/phpunit
```
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
"phpunit/phpunit": "^9.0|^10.0|^11.0",
"php-coveralls/php-coveralls": "^2.5"
},
"config": {
"discard-changes": true
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"UrlHelper\\ServiceProvider"
],
"aliases": {
"URLHelper": "UrlHelper\\Facades\\URLHelper"
}
}
}
}
11 changes: 11 additions & 0 deletions src/UrlHelper/Facades/URLHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace UrlHelper\Facades;

class URLHelper extends \Illuminate\Support\Facades\Facade
{
protected static function getFacadeAccessor()
{
return \UrlHelper\UrlHelper::class;
}
}
20 changes: 20 additions & 0 deletions src/UrlHelper/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace UrlHelper;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton(\UrlHelper\UrlHelper::class, function ($app) {
return new \UrlHelper\UrlHelper();
});

$this->app->alias(\UrlHelper\UrlHelper::class, 'urlhelper');
}
}

0 comments on commit fa02765

Please sign in to comment.