boomdraw/canonicalizer

Canonicalizer package for Laravel

v2.0.0 2019-12-11 00:44 UTC

This package is auto-updated.

Last update: 2024-05-11 14:52:22 UTC


README

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