-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for OrgId fields ID and BicOrBei.
- Loading branch information
1 parent
ec669b2
commit 89fd61e
Showing
2 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* SepaUtilities | ||
* | ||
* @license GNU LGPL v3.0 - For details have a look at the LICENSE file | ||
* @copyright ©2017 Alexander Schickedanz | ||
* @copyright ©2018 Alexander Schickedanz | ||
* @link https://github.com/AbcAeffchen/SepaUtilities | ||
* | ||
* @author Alexander Schickedanz <[email protected]> | ||
|
@@ -114,6 +114,13 @@ class SepaUtilities | |
*/ | ||
const BIC_REQUIRED_THRESHOLD = 20160131; | ||
|
||
/** | ||
* Valid maximal text length | ||
*/ | ||
const TEXT_LENGTH_VERY_SHORT = 35; | ||
const TEXT_LENGTH_SHORT = 70; | ||
const TEXT_LENGTH_LONG = 140; | ||
|
||
private static $ibanPatterns = ['EG' => 'EG[0-9]{2}[0-9A-Z]{23}', | ||
'AL' => 'AL[0-9]{10}[0-9A-Z]{16}', | ||
'DZ' => 'DZ[0-9]{2}[0-9A-Z]{20}', | ||
|
@@ -655,14 +662,27 @@ public static function check($field, $input, array $options = null, $version = n | |
: self::checkRestrictedIdentificationSEPA2($input); | ||
case 'initgpty': // cannot be empty (and the following things also) | ||
case 'cdtr': // cannot be empty (and the following things also) | ||
case 'dbtr': if(empty($input)) return false; // cannot be empty | ||
case 'dbtr': | ||
if(empty($input)) | ||
return false; // cannot be empty | ||
case 'orgid_id': | ||
return ( self::checkLength($input, self::TEXT_LENGTH_VERY_SHORT) | ||
&& self::checkCharset($input) ) | ||
? $input : false; | ||
case 'orgnlcdtrschmeid_nm': | ||
case 'ultmtcdtr': | ||
case 'ultmtdbtr': return (self::checkLength($input, 70) && self::checkCharset($input)) ? $input : false; | ||
case 'rmtinf': return (self::checkLength($input, 140) && self::checkCharset($input)) ? $input : false; | ||
case 'ultmtdbtr': | ||
return ( self::checkLength($input, self::TEXT_LENGTH_SHORT) | ||
&& self::checkCharset($input) ) | ||
? $input : false; | ||
case 'rmtinf': | ||
return ( self::checkLength($input, self::TEXT_LENGTH_LONG) | ||
&& self::checkCharset($input) ) | ||
? $input : false; | ||
case 'orgnldbtracct_iban': | ||
case 'iban': return self::checkIBAN($input,$options); | ||
case 'orgnldbtragt_bic': | ||
case 'orgid_bob': | ||
case 'bic': return self::checkBIC($input,$options); | ||
case 'ccy': return self::checkActiveOrHistoricCurrencyCode($input); | ||
case 'amdmntind': | ||
|
@@ -787,24 +807,38 @@ public static function checkAndSanitizeAll(array &$inputs, $flags = 0, array $op | |
return implode(', ', $fieldsWithErrors); | ||
} | ||
|
||
public static function sanitizeShortText($input,$allowEmpty = false, $flags = 0) | ||
public static function sanitizeText($length, $input, $allowEmpty = false, $flags = 0) | ||
{ | ||
$res = self::sanitizeLength(self::replaceSpecialChars($input, $flags), 70); | ||
$res = self::sanitizeLength(self::replaceSpecialChars($input, $flags), $length); | ||
|
||
if($allowEmpty || !empty($res)) | ||
return $res; | ||
|
||
return false; | ||
} | ||
|
||
public static function sanitizeLongText($input,$allowEmpty = false, $flags = 0) | ||
/** | ||
* @deprecated | ||
* @param $input | ||
* @param bool $allowEmpty | ||
* @param int $flags | ||
* @return bool|string | ||
*/ | ||
public static function sanitizeShortText($input,$allowEmpty = false, $flags = 0) | ||
{ | ||
$res = self::sanitizeLength(self::replaceSpecialChars($input, $flags), 140); | ||
|
||
if($allowEmpty || !empty($res)) | ||
return $res; | ||
return self::sanitizeText(self::TEXT_LENGTH_SHORT, $input, $allowEmpty, $flags); | ||
} | ||
|
||
return false; | ||
/** | ||
* @deprecated1111 | ||
* @param $input | ||
* @param bool $allowEmpty | ||
* @param int $flags | ||
* @return bool|string | ||
*/ | ||
public static function sanitizeLongText($input,$allowEmpty = false, $flags = 0) | ||
{ | ||
return self::sanitizeText(self::TEXT_LENGTH_LONG, $input, $allowEmpty, $flags); | ||
} | ||
|
||
/** | ||
|
@@ -822,15 +856,20 @@ public static function sanitize($field, $input, $flags = 0) | |
$field = strtolower($field); | ||
switch($field) // fall-through's are on purpose | ||
{ | ||
case 'orgid_id': | ||
return self::sanitizeText(self::TEXT_LENGTH_VERY_SHORT, $input, true, $flags); | ||
case 'ultmtcdrt': | ||
case 'ultmtdebtr': return self::sanitizeShortText($input,true,$flags); | ||
case 'ultmtdebtr': | ||
return self::sanitizeText(self::TEXT_LENGTH_SHORT, $input, true, $flags); | ||
case 'orgnlcdtrschmeid_nm': | ||
case 'initgpty': | ||
case 'cdtr': | ||
case 'dbtr': | ||
return self::sanitizeShortText($input,false,$flags); | ||
case 'rmtinf': return self::sanitizeLongText($input,true,$flags); | ||
default: return false; | ||
return self::sanitizeText(self::TEXT_LENGTH_SHORT, $input, false, $flags); | ||
case 'rmtinf': | ||
return self::sanitizeText(self::TEXT_LENGTH_LONG, $input, true, $flags); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
|