PHP code example of dominik-eller / laravel-data-normalizer

1. Go to this page and download the library: Download dominik-eller/laravel-data-normalizer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dominik-eller / laravel-data-normalizer example snippets


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

use Deller\DataNormalizer\Facades\PhoneNormalizer;

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

use Deller\DataNormalizer\Facades\PhoneFormatter;

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

use Deller\DataNormalizer\Facades\EmailNormalizer;

$normalizedEmail = EmailNormalizer::create('email')->normalize('  [email protected]  ');
// $normalizedEmail will be "[email protected]"

use Deller\DataNormalizer\Facades\EmailFormatter;

$formattedEmail = DataFormatter::create('email')->format('  [email protected]  ');
// $formattedEmail will be "[email protected]"

use Deller\DataNormalizer\Factories\DataFormatterFactory;

class CustomFormatter implements \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"

use Deller\DataNormalizer\Factories\DataNormalizerFactory;

class CustomNormalizer implements \Deller\DataNormalizer\DataFormatter
{
    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"