Skip to content

Commit 89fd61e

Browse files
committed
Support for OrgId fields ID and BicOrBei.
1 parent ec669b2 commit 89fd61e

File tree

2 files changed

+64
-16
lines changed

2 files changed

+64
-16
lines changed

CHANGE_LOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Sephpa - Change Log
22
===============
33

4+
## 1.2.5 - Feb 21, '18
5+
- added support for `OrgId` fields `ID` and `BicOrBei`. They can be used in check and sanitize
6+
functions using the keys `orgid_id` and `orgid_bob`.
7+
- added constants for max text lengths `SepaUtilities::TEXT_LENGTH_VERY_SHORT`,
8+
`SepaUtilities::TEXT_LENGTH_SHORT` and `SepaUtilities::TEXT_LENGTH_LONG`
9+
- The functions `sanitizeShortText()` and `sanitizeLongText()` are now deprecated and will be
10+
removed in the next major version. The replacemant is `sanitizeText()` using the `TEXT_LENGTH_*`
11+
constants.
12+
413
## 1.2.4 - Oct 22, '17
514
- Added the function `version2string` to get a string representation
615
of a SEPA file version.

src/SepaUtilities.php

+55-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SepaUtilities
44
*
55
* @license GNU LGPL v3.0 - For details have a look at the LICENSE file
6-
* @copyright ©2017 Alexander Schickedanz
6+
* @copyright ©2018 Alexander Schickedanz
77
* @link https://github.com/AbcAeffchen/SepaUtilities
88
*
99
* @author Alexander Schickedanz <[email protected]>
@@ -114,6 +114,13 @@ class SepaUtilities
114114
*/
115115
const BIC_REQUIRED_THRESHOLD = 20160131;
116116

117+
/**
118+
* Valid maximal text length
119+
*/
120+
const TEXT_LENGTH_VERY_SHORT = 35;
121+
const TEXT_LENGTH_SHORT = 70;
122+
const TEXT_LENGTH_LONG = 140;
123+
117124
private static $ibanPatterns = ['EG' => 'EG[0-9]{2}[0-9A-Z]{23}',
118125
'AL' => 'AL[0-9]{10}[0-9A-Z]{16}',
119126
'DZ' => 'DZ[0-9]{2}[0-9A-Z]{20}',
@@ -655,14 +662,27 @@ public static function check($field, $input, array $options = null, $version = n
655662
: self::checkRestrictedIdentificationSEPA2($input);
656663
case 'initgpty': // cannot be empty (and the following things also)
657664
case 'cdtr': // cannot be empty (and the following things also)
658-
case 'dbtr': if(empty($input)) return false; // cannot be empty
665+
case 'dbtr':
666+
if(empty($input))
667+
return false; // cannot be empty
668+
case 'orgid_id':
669+
return ( self::checkLength($input, self::TEXT_LENGTH_VERY_SHORT)
670+
&& self::checkCharset($input) )
671+
? $input : false;
659672
case 'orgnlcdtrschmeid_nm':
660673
case 'ultmtcdtr':
661-
case 'ultmtdbtr': return (self::checkLength($input, 70) && self::checkCharset($input)) ? $input : false;
662-
case 'rmtinf': return (self::checkLength($input, 140) && self::checkCharset($input)) ? $input : false;
674+
case 'ultmtdbtr':
675+
return ( self::checkLength($input, self::TEXT_LENGTH_SHORT)
676+
&& self::checkCharset($input) )
677+
? $input : false;
678+
case 'rmtinf':
679+
return ( self::checkLength($input, self::TEXT_LENGTH_LONG)
680+
&& self::checkCharset($input) )
681+
? $input : false;
663682
case 'orgnldbtracct_iban':
664683
case 'iban': return self::checkIBAN($input,$options);
665684
case 'orgnldbtragt_bic':
685+
case 'orgid_bob':
666686
case 'bic': return self::checkBIC($input,$options);
667687
case 'ccy': return self::checkActiveOrHistoricCurrencyCode($input);
668688
case 'amdmntind':
@@ -787,24 +807,38 @@ public static function checkAndSanitizeAll(array &$inputs, $flags = 0, array $op
787807
return implode(', ', $fieldsWithErrors);
788808
}
789809

790-
public static function sanitizeShortText($input,$allowEmpty = false, $flags = 0)
810+
public static function sanitizeText($length, $input, $allowEmpty = false, $flags = 0)
791811
{
792-
$res = self::sanitizeLength(self::replaceSpecialChars($input, $flags), 70);
812+
$res = self::sanitizeLength(self::replaceSpecialChars($input, $flags), $length);
793813

794814
if($allowEmpty || !empty($res))
795815
return $res;
796816

797817
return false;
798818
}
799819

800-
public static function sanitizeLongText($input,$allowEmpty = false, $flags = 0)
820+
/**
821+
* @deprecated
822+
* @param $input
823+
* @param bool $allowEmpty
824+
* @param int $flags
825+
* @return bool|string
826+
*/
827+
public static function sanitizeShortText($input,$allowEmpty = false, $flags = 0)
801828
{
802-
$res = self::sanitizeLength(self::replaceSpecialChars($input, $flags), 140);
803-
804-
if($allowEmpty || !empty($res))
805-
return $res;
829+
return self::sanitizeText(self::TEXT_LENGTH_SHORT, $input, $allowEmpty, $flags);
830+
}
806831

807-
return false;
832+
/**
833+
* @deprecated1111
834+
* @param $input
835+
* @param bool $allowEmpty
836+
* @param int $flags
837+
* @return bool|string
838+
*/
839+
public static function sanitizeLongText($input,$allowEmpty = false, $flags = 0)
840+
{
841+
return self::sanitizeText(self::TEXT_LENGTH_LONG, $input, $allowEmpty, $flags);
808842
}
809843

810844
/**
@@ -822,15 +856,20 @@ public static function sanitize($field, $input, $flags = 0)
822856
$field = strtolower($field);
823857
switch($field) // fall-through's are on purpose
824858
{
859+
case 'orgid_id':
860+
return self::sanitizeText(self::TEXT_LENGTH_VERY_SHORT, $input, true, $flags);
825861
case 'ultmtcdrt':
826-
case 'ultmtdebtr': return self::sanitizeShortText($input,true,$flags);
862+
case 'ultmtdebtr':
863+
return self::sanitizeText(self::TEXT_LENGTH_SHORT, $input, true, $flags);
827864
case 'orgnlcdtrschmeid_nm':
828865
case 'initgpty':
829866
case 'cdtr':
830867
case 'dbtr':
831-
return self::sanitizeShortText($input,false,$flags);
832-
case 'rmtinf': return self::sanitizeLongText($input,true,$flags);
833-
default: return false;
868+
return self::sanitizeText(self::TEXT_LENGTH_SHORT, $input, false, $flags);
869+
case 'rmtinf':
870+
return self::sanitizeText(self::TEXT_LENGTH_LONG, $input, true, $flags);
871+
default:
872+
return false;
834873
}
835874
}
836875

0 commit comments

Comments
 (0)