承接 dominik-eller/laravel-data-normalizer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dominik-eller/laravel-data-normalizer

最新稳定版本:v1.2.1

Composer 安装命令:

composer require dominik-eller/laravel-data-normalizer

包简介

A Laravel package to normalize and format data such as phone numbers, emails, and other input into standardized formats.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package to normalize and format data such as phone numbers, emails, and other input into standardized formats.

Installation

You can install the package via composer:

composer require dominik-eller/laravel-data-normalizer
composer dump-autoload

You can publish the config file with:

php artisan vendor:publish --tag="data-normalizer-config"

This is the contents of the published config file:

return [
    'phone' => [
        'default_country' => 'DE',
        'format' => 'E164',
    ],
    'email' => [
        'trim_whitespace' => true,
        'lowercase' => true,
    ],
];

Usage

Normalize a phone number

use Deller\DataNormalizer\Facades\DataNormalizer;

$normalizedPhone = DataNormalizer::create('phone')->normalize('+49 (151) 123 45678');
// $normalizedPhone will be "+4915112345678" (E.164 format)

Format a phone number

use Deller\DataNormalizer\Facades\DataFormatter;

$formattedPhone = DataFormatter::create('phone')->format('+4915112345678', ['format' => 'INTERNATIONAL']);
// $formattedPhone will be "+49 151 1234 5678"

If parsing fails, the formatter logs the error and returns the original value.

Normalize an email address

use Deller\DataNormalizer\Facades\DataNormalizer;

$normalizedEmail = DataNormalizer::create('email')->normalize('  JohnDoe@Example.com  ');
// $normalizedEmail will be "johndoe@example.com"

Format an email address

use Deller\DataNormalizer\Facades\DataFormatter;

$formattedEmail = DataFormatter::create('email')->format('  JohnDoe@Example.com  ');
// $formattedEmail will be "johndoe@example.com"

Registering a custom formatter

use Deller\DataNormalizer\Factories\DataFormatterFactory;

class CustomFormatter extends \Deller\DataNormalizer\DataFormatter
{
    public function format($data)
    {
        return 'Formatted: ' . strtoupper($data);
    }
}

// Register the custom formatter type
DataFormatterFactory::registerType('custom', CustomFormatter::class);

// Use the custom formatter via the facade
$customFormatter = \Deller\DataNormalizer\Facades\DataFormatter::create('custom');
echo $customFormatter->format('some data'); // Output: "Formatted: SOME DATA"

Registering a custom normalizer

use Deller\DataNormalizer\Factories\DataNormalizerFactory;

class CustomNormalizer extends \Deller\DataNormalizer\DataNormalizer
{
    public function normalize($data)
    {
        return 'Normalized: ' . strtolower(trim($data));
    }
}

// Register the custom normalizer type
DataNormalizerFactory::registerType('custom', CustomNormalizer::class);

// Use the custom normalizer via the facade
$customNormalizer = \Deller\DataNormalizer\Facades\DataNormalizer::create('custom');
echo $customNormalizer->normalize('  SOME DATA  '); // Output: "Normalized: some data"

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please report security vulnerabilities by email to me@dominik-eller.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 474
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-25