All Projects → michael-rubel → laravel-formatters

michael-rubel / laravel-formatters

Licence: MIT license
«‎Formatter» pattern for Laravel

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-formatters

AutoFormatInputWatcher
This repository contains input watcher for auto formatting digits in edit text
Stars: ✭ 15 (-82.56%)
Mutual labels:  formatter, formatting
kirai
String formatting library for Java, Android, Web and Unix Terminal
Stars: ✭ 69 (-19.77%)
Mutual labels:  formatter, formatting
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-80.23%)
Mutual labels:  formatter, formatting
Golite
Add essential language support for the Go language to Sublime Text 3.
Stars: ✭ 14 (-83.72%)
Mutual labels:  formatter, formatting
Nginx Config Formatter
nginx config file formatter/beautifier written in Python.
Stars: ✭ 222 (+158.14%)
Mutual labels:  formatter, formatting
ufmt
Safe, atomic formatting with black and µsort
Stars: ✭ 46 (-46.51%)
Mutual labels:  formatter, formatting
formatting
源码格式自动化调整工具
Stars: ✭ 37 (-56.98%)
Mutual labels:  formatter, formatting
unicode-formatter
Convert portions of text to fancy text using unicode fonts for use on Twitter and other sites that don't support rich text
Stars: ✭ 31 (-63.95%)
Mutual labels:  formatter, formatting
Juliaformatter.jl
An opinionated code formatter for Julia. Plot twist - the opinion is your own.
Stars: ✭ 217 (+152.33%)
Mutual labels:  formatter, formatting
Editorconfig Netbeans
A NetBeans IDE plugin supporting the EditorConfig standard. ⛺
Stars: ✭ 123 (+43.02%)
Mutual labels:  formatter, formatting
teks
Easily get custom go template based outputs to your command-line tool. Like in docker/kubernetes
Stars: ✭ 41 (-52.33%)
Mutual labels:  formatter, formatting
idea-uroborosql-formatter
Beautiful SQL Formatter for IntelliJ Platform
Stars: ✭ 18 (-79.07%)
Mutual labels:  formatter, formatting
Vse Formatdocumentonsave
Visual Studio - Format Document on Save
Stars: ✭ 61 (-29.07%)
Mutual labels:  formatter, formatting
Sublime-uroboroSQL-formatter
Beautiful SQL Formatter for Sublime Text 3
Stars: ✭ 25 (-70.93%)
Mutual labels:  formatter, formatting
awesome-python-code-formatters
A curated list of awesome Python code formatters
Stars: ✭ 168 (+95.35%)
Mutual labels:  formatter, formatting
json-lua
JSON encoder/decoder
Stars: ✭ 47 (-45.35%)
Mutual labels:  formatter
address-format
A PHP library to parse street addresses to localized formats
Stars: ✭ 76 (-11.63%)
Mutual labels:  formatter
sf
Simple Bash framework which provides argument parsing, usage output and text formatting variables
Stars: ✭ 16 (-81.4%)
Mutual labels:  formatting
IPTV
M3U Playlist for free TV channels
Stars: ✭ 1,016 (+1081.4%)
Mutual labels:  looking-for-contributors
configs
Trunk.io default linter configs
Stars: ✭ 69 (-19.77%)
Mutual labels:  formatters

Laravel Formatters

Laravel Formatters

Latest Version on Packagist Total Downloads Code Quality Code Coverage GitHub Tests Action Status PHPStan

This package introduces the Formatter pattern you can use to standardize data formats in your Laravel application. You can write your own formatters and put them in app/Formatters folder, then apply them everywhere in your application through format helper. The package uses the Service Container under the hood to easily extend or override the formatter classes.


Latest version of the package requires PHP ^8.0 and Laravel ^9.7. If you're looking for older versions, check release history.

#StandWithUkraine

SWUbanner

Installation

Install the package via composer:

composer require michael-rubel/laravel-formatters
php artisan vendor:publish --tag="formatters-config"

Usage

format(DateTimeFormatter::class, now());

You can use a shorter version of the string as an alternative:

format('date-time', now());

Available built-in formatters

Artisan command

To make the programmer's life easier, we also added the Artisan command. You can use make:formatter command to generate formatter classes. It will put the class with the given name into app/Formatters folder and auto-inject the stub.

Extending formatters

Since the formatters are resolved through the Service Container they can be easily overridden by extending bindings.

For example in your Service Provider:

$this->app->extend(DateTimeFormatter::class, function ($formatter) {
    $formatter->datetime_format = 'Y.m.d H:i';

    return $formatter;
});

Adding custom/overriding package formatters

To add a custom formatter you should create the class that implements the MichaelRubel\Formatters\Formatter interface and put it to the app/Formatters folder. You can put formatter with the same name as the package's to override the formatter from the package. You can customize the folder in the config file.

Examples

You can discover examples of the usage here.

Contributing

If you have written your own formatter and want to add it to this package, PRs are welcomed. But take care of the extendability of the formatter you want to make as built-in and remember to write tests for your use cases.

Testing

composer test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].