boomdraw / canonicalizer
Canonicalizer package for Laravel
Installs: 1 024
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.2
- illuminate/support: 5.5.*|5.6.*|5.7.*|5.8.*|^6.0
Requires (Dev)
- orchestra/testbench: 3.5.*|3.6.*|3.7.*|3.8.*|^4.0
This package is auto-updated.
Last update: 2024-12-11 16:09:37 UTC
README
Canonicalizer package for Laravel
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.