boomdraw/canonicalizer

Canonicalizer package for Laravel
1,053 1
Install
composer require boomdraw/canonicalizer
Latest Version:v2.0.0
PHP:^7.2
License:MIT
Last Updated:Dec 11, 2019
Links: GitHub  ·  Packagist
Maintainer: boomdraw

Canonicalizer

Canonicalizer package for Laravel

Build Status StyleCI Code Coverage Quality Score Latest Version on Packagist Total Downloads PHP Version License

Installation

Via Composer

$ composer require boomdraw/canonicalizer

Laravel

The package will automatically register itself.

Lumen

Uncomment the following line in the bootstrap file:

// bootstrap/app.php:
$app->withFacades();

Register CanonicalizerServiceProvider

// bootstrap/app.php:
$app->register(Boomdraw\Canonicalizer\CanonicalizerServiceProvider::class);

Usage examples

use Boomdraw\Canonicalizer\Facades\Canonicalizer;

or

use Canonicalizer;

Methods

Canonicalizer

Canonicalizer::canonicalize()

Args string $string, bool $nullEmpty = true

Returns canonicalized string or null if $nullEmpty = true and the string is empty.

Canonicalizer::email()

Args: string $email

Returns canonicalized email without dots before @ or null if the string does not contain @

Canonicalizer::slug()

Args: string $title, string $separator = '-', ?string $language = 'en'

\Illuminate\Support\Str::slug() alias

Canonicalizer::url()

Args: string $url, string $separator = '-'

The function calls trim() function with slash (/) and backslash (\) added to charlist and slugs url path items with specified separator.

Canonicalizer::uri()

Args: sstring $url, string $separator = '-'

Canonicalizer::url() alias

Canonicalizer::macro()

Args string $name, object|callable $macro = true

Canonicalizer uses Macroable trait, so you can add methods to a class dynamically.

Canonicalizer::macro('replaceSpaces', function(string $string) {
    return str_replace(' ', '', $string);  
});

Canonicalizer::replaceSpaces('Hello World!') === 'HelloWorld!';

Testing

You can run the tests with:

composer test

Contributing

Please see CONTRIBUTING for details and a todo list.

Security

If you discover any security-related issues, please email pkgsecurity@boomdraw.com instead of using the issue tracker.

License

MIT

Related Packages

boomdraw/laravel-dummy-image

Laravel dummy image generator based on kingkool68/dummyimage

1,557 1
php-tmdb/laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the...

53,312 160
laravel-ja/laravel

The Laravel Framework.

5,667 17
kavenegar/laravel

laravel 4 and 5 kavenegar integration

366,462 86
reliese/laravel

Reliese Components for Laravel Framework code generation.

3,954,390 1,705