2016-01-08 09:00:28 -06:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* Request.php
|
2017-10-21 01:40:00 -05:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-20 05:41:23 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* This file is part of Firefly III.
|
2016-10-04 23:52:15 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 07:44:05 -06:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 05:41:23 -05:00
|
|
|
*/
|
2017-04-09 00:44:22 -05:00
|
|
|
declare(strict_types=1);
|
2016-01-08 09:00:28 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2017-01-21 01:32:23 -06:00
|
|
|
use Carbon\Carbon;
|
2015-02-05 21:39:52 -06:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
2016-01-09 01:20:55 -06:00
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class Request.
|
2016-01-09 01:20:55 -06:00
|
|
|
*/
|
2017-01-20 12:49:35 -06:00
|
|
|
class Request extends FormRequest
|
2015-02-11 00:35:10 -06:00
|
|
|
{
|
2017-01-21 01:32:23 -06:00
|
|
|
/**
|
|
|
|
* @param string $field
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-08-18 07:45:42 -05:00
|
|
|
public function boolean(string $field): bool
|
2017-01-21 01:32:23 -06:00
|
|
|
{
|
2018-04-13 10:28:11 -05:00
|
|
|
if ((string)$this->input($field) === 'true') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((string)$this->input($field) === 'false') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:10:40 -05:00
|
|
|
return 1 === (int)$this->input($field);
|
2017-01-21 01:32:23 -06:00
|
|
|
}
|
|
|
|
|
2018-02-09 12:11:55 -06:00
|
|
|
/**
|
|
|
|
* @param string $field
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function integer(string $field): int
|
|
|
|
{
|
2018-04-02 08:10:40 -05:00
|
|
|
return (int)$this->get($field);
|
2018-02-09 12:11:55 -06:00
|
|
|
}
|
|
|
|
|
2017-01-20 12:49:35 -06:00
|
|
|
/**
|
|
|
|
* @param string $field
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-08-21 00:13:03 -05:00
|
|
|
public function string(string $field): string
|
2017-01-20 12:49:35 -06:00
|
|
|
{
|
2017-02-16 23:42:36 -06:00
|
|
|
$string = $this->get($field) ?? '';
|
2017-01-20 12:49:35 -06:00
|
|
|
$search = [
|
2017-01-21 02:07:10 -06:00
|
|
|
"\u{0001}", // start of heading
|
|
|
|
"\u{0002}", // start of text
|
|
|
|
"\u{0003}", // end of text
|
|
|
|
"\u{0004}", // end of transmission
|
|
|
|
"\u{0005}", // enquiry
|
|
|
|
"\u{0006}", // ACK
|
|
|
|
"\u{0007}", // BEL
|
|
|
|
"\u{0008}", // backspace
|
|
|
|
"\u{000E}", // shift out
|
|
|
|
"\u{000F}", // shift in
|
|
|
|
"\u{0010}", // data link escape
|
|
|
|
"\u{0011}", // DC1
|
|
|
|
"\u{0012}", // DC2
|
|
|
|
"\u{0013}", // DC3
|
|
|
|
"\u{0014}", // DC4
|
|
|
|
"\u{0015}", // NAK
|
|
|
|
"\u{0016}", // SYN
|
|
|
|
"\u{0017}", // ETB
|
|
|
|
"\u{0018}", // CAN
|
|
|
|
"\u{0019}", // EM
|
|
|
|
"\u{001A}", // SUB
|
|
|
|
"\u{001B}", // escape
|
|
|
|
"\u{001C}", // file separator
|
|
|
|
"\u{001D}", // group separator
|
|
|
|
"\u{001E}", // record separator
|
|
|
|
"\u{001F}", // unit separator
|
|
|
|
"\u{007F}", // DEL
|
2017-01-20 12:49:35 -06:00
|
|
|
"\u{00A0}", // non-breaking space
|
2017-01-21 02:07:10 -06:00
|
|
|
"\u{1680}", // ogham space mark
|
|
|
|
"\u{180E}", // mongolian vowel separator
|
|
|
|
"\u{2000}", // en quad
|
|
|
|
"\u{2001}", // em quad
|
|
|
|
"\u{2002}", // en space
|
|
|
|
"\u{2003}", // em space
|
|
|
|
"\u{2004}", // three-per-em space
|
|
|
|
"\u{2005}", // four-per-em space
|
|
|
|
"\u{2006}", // six-per-em space
|
|
|
|
"\u{2007}", // figure space
|
|
|
|
"\u{2008}", // punctuation space
|
|
|
|
"\u{2009}", // thin space
|
|
|
|
"\u{200A}", // hair space
|
|
|
|
"\u{200B}", // zero width space
|
|
|
|
"\u{202F}", // narrow no-break space
|
|
|
|
"\u{3000}", // ideographic space
|
|
|
|
"\u{FEFF}", // zero width no -break space
|
2017-01-20 12:49:35 -06:00
|
|
|
];
|
|
|
|
$replace = "\x20"; // plain old normal space
|
|
|
|
$string = str_replace($search, $replace, $string);
|
|
|
|
|
|
|
|
return trim($string);
|
|
|
|
}
|
2017-09-08 23:41:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $field
|
|
|
|
*
|
|
|
|
* @return Carbon|null
|
|
|
|
*/
|
|
|
|
protected function date(string $field)
|
|
|
|
{
|
|
|
|
return $this->get($field) ? new Carbon($this->get($field)) : null;
|
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
}
|