<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
use Illuminate\Support\Facades\Log;

/**
 * Class TrimStrings.
 */
class TrimStrings extends Middleware
{
    /**
     * The names of the attributes that should not be trimmed.
     *
     * @var array
     */
    protected $except = [
        'current_password',
        'password',
        'new_password',
        'new_password_confirm',
        'image.top_left',
        'image.top',
        'image.top_right',
        'image.left',
        'image.center',
        'image.right',
        'image.bottom_left',
        'image.bottom',
        'image.bottom_right',
        'face_image'
    ];

    /**
     * Transform the given value.
     *
     * @param  string $key   key
     * @param  mixed  $value value
     * @return mixed
     */
    protected function transform($key, $value)
    {
        if (in_array($key, $this->except, true)) {
            return $value;
        }

        return is_string($value) ? trimSpaceTwoByte($value) : $value;
    }
}
