t-labs-co / formatter
The Laravel Formatter package
Fund package maintenance!
ty-huynh
Requires
- php: ^8.4||^8.3||^8.2
- illuminate/contracts: ^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- spatie/laravel-ray: ^1.35
This package is not auto-updated.
Last update: 2025-03-22 05:15:16 UTC
README
This package helps you format your PHP strings. You can use it for one string or many, and it's as simple as using Laravel validation.
Work with us
We're PHP and Laravel whizzes, and we'd love to work with you! We can:
- Design the perfect fit solution for your app.
- Make your code cleaner and faster.
- Refactoring and Optimize performance.
- Ensure Laravel best practices are followed.
- Provide expert Laravel support.
- Review code and Quality Assurance.
- Offer team and project leadership.
- Delivery Manager
Features
- Simple and intuitive syntax for defining formatting rules.
- Support for multiple built-in formatting rules (e.g., trim, replace, limit, date_format).
- Ability to create custom formatting rules.
- Integration with Laravel models and validation.
- Comprehensive unit tests for ensuring reliability.
PHP and Laravel Version Support
This package supports the following versions of PHP:
- PHP:
^8.2
Installation
You can install the package via composer:
composer require t-labs-co/formatter
Usage
use TLabsCo\Formatter\Formatter; $formatterRules = [ 'title' => 'trim|replace:Local Composer Dependencies,[Local Composer Dependencies]|replace:[Local Composer Dependencies],[Composer Dependencies]|limit:150', 'publish_date' => 'date_format:Y-m-d', ]; $data = [ 'title' => ' How to resolve missing Local Composer Dependencies on CentOS 8? ', 'publish_date' => '2024/05/02 13:00' ]; $formatted = Formatter::make($data, $formatterRules)->format()->formatted(); /* Output: $formatted = [ 'title' => 'How to resolve missing [Composer Dependencies] on CentOS 8?', 'publish_date' => '2024-05-02' ]; */
Use custom format rule
use TLabsCo\Formatter\Rules\FormatterRule; class Max100FormatRule extends FormatterRule { public function format($attribute, $value) { if (strlen($value) > 100) { return substr($value, 0, 100); } return $value; } } // Using with custom rule use TLabsCo\Formatter\Formatter; $formatterRules = [ 'title' => 'trim|replace:Local Composer Dependencies,[Local Composer Dependencies]|replace:[Local Composer Dependencies],[Composer Dependencies]|limit:150', 'publish_date' => 'date_format:Y-m-d', 'short_description' => ['trim', new Max100FormatRule()], ]; $data = [ 'title' => ' How to resolve missing Local Composer Dependencies on CentOS 8? ', 'publish_date' => '2024/05/02 13:00', 'short_description' => 'Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description ' ]; $formatted = Formatter::make($data, $formatterRules)->format()->formatted(); /* Output: $formatted = [ 'title' => 'How to resolve missing [Composer Dependencies] on CentOS 8?', 'publish_date' => '2024-05-02', 'short_description' => 'Very long description Very long description Very long description Very long description Very long de' ]; */
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.