/home/mip/www/img/credit/datatables/Aspects.tar
PhoneNumberType.php000064400000002632151520662360010352 0ustar00<?php

namespace Propaganistas\LaravelPhone\Aspects;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use libphonenumber\PhoneNumberType as libPhoneNumberType;
use ReflectionClass;

class PhoneNumberType
{
    public static function all(): array
    {
        return (new ReflectionClass(libPhoneNumberType::class))->getConstants();
    }

    public static function isValid($type): bool
    {
        return ! is_null($type) && in_array($type, static::all(), true);
    }

    public static function isValidName($type): bool
    {
        return ! is_null($type) && in_array($type, array_keys(static::all()), true);
    }

    public static function getHumanReadableName($type): string|null
    {
        $name = array_search($type, static::all(), true);

        return $name ? strtolower($name) : null;
    }

    public static function sanitize($types): int|array|null
    {
        $sanitized = Collection::make(is_array($types) ? $types : [$types])
            ->map(function ($format) {
                // If the type equals a constant's name, return its value.
                // Otherwise just return the value.
                return Arr::get(static::all(), strtoupper($format), $format);
            })
            ->filter(function ($format) {
                return static::isValid($format);
            })->unique();

        return is_array($types) ? $sanitized->toArray() : $sanitized->first();
    }
}
PhoneNumberCountry.php000064400000001574151520662360011100 0ustar00<?php

namespace Propaganistas\LaravelPhone\Aspects;

use Illuminate\Support\Collection;
use libphonenumber\PhoneNumberUtil;

class PhoneNumberCountry
{
    public static function all(): array
    {
        return array_map('strtoupper', PhoneNumberUtil::getInstance()->getSupportedRegions());
    }

    public static function isValid($code): bool
    {
        return ! is_null($code) && in_array(strtoupper($code), static::all());
    }

    public static function sanitize($countries): string|array|null
    {
        $sanitized = Collection::make(is_array($countries) ? $countries : [$countries])
            ->filter(function ($value) {
                return static::isValid($value);
            })->map(function ($value) {
                return strtoupper($value);
            })->unique();

        return is_array($countries) ? $sanitized->toArray() : $sanitized->first();
    }
}
PhoneNumberFormat.php000064400000002676151520662360010671 0ustar00<?php

namespace Propaganistas\LaravelPhone\Aspects;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use libphonenumber\PhoneNumberFormat as libPhoneNumberFormat;
use ReflectionClass;

class PhoneNumberFormat
{
    public static function all(): array
    {
        return (new ReflectionClass(libPhoneNumberFormat::class))->getConstants();
    }

    public static function isValid($format): bool
    {
        return ! is_null($format) && in_array($format, static::all(), true);
    }

    public static function isValidName($format): bool
    {
        return ! is_null($format) && in_array($format, array_keys(static::all()), true);
    }

    public static function getHumanReadableName($format): string|null
    {
        $name = array_search($format, static::all(), true);

        return $name ? strtolower($name) : null;
    }

    public static function sanitize($formats): int|array|null
    {
        $sanitized = Collection::make(is_array($formats) ? $formats : [$formats])
            ->map(function ($format) {
                // If the format equals a constant's name, return its value.
                // Otherwise just return the value.
                return Arr::get(static::all(), strtoupper($format), $format);
            })
            ->filter(function ($format) {
                return static::isValid($format);
            })->unique();

        return is_array($formats) ? $sanitized->toArray() : $sanitized->first();
    }
}