3
3
* SepaUtilities
4
4
*
5
5
* @license GNU LGPL v3.0 - For details have a look at the LICENSE file
6
- * @copyright ©2017 Alexander Schickedanz
6
+ * @copyright ©2018 Alexander Schickedanz
7
7
* @link https://github.com/AbcAeffchen/SepaUtilities
8
8
*
9
9
* @author Alexander Schickedanz <[email protected] >
@@ -114,6 +114,13 @@ class SepaUtilities
114
114
*/
115
115
const BIC_REQUIRED_THRESHOLD = 20160131 ;
116
116
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
+
117
124
private static $ ibanPatterns = ['EG ' => 'EG[0-9]{2}[0-9A-Z]{23} ' ,
118
125
'AL ' => 'AL[0-9]{10}[0-9A-Z]{16} ' ,
119
126
'DZ ' => 'DZ[0-9]{2}[0-9A-Z]{20} ' ,
@@ -655,14 +662,27 @@ public static function check($field, $input, array $options = null, $version = n
655
662
: self ::checkRestrictedIdentificationSEPA2 ($ input );
656
663
case 'initgpty ' : // cannot be empty (and the following things also)
657
664
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 ;
659
672
case 'orgnlcdtrschmeid_nm ' :
660
673
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 ;
663
682
case 'orgnldbtracct_iban ' :
664
683
case 'iban ' : return self ::checkIBAN ($ input ,$ options );
665
684
case 'orgnldbtragt_bic ' :
685
+ case 'orgid_bob ' :
666
686
case 'bic ' : return self ::checkBIC ($ input ,$ options );
667
687
case 'ccy ' : return self ::checkActiveOrHistoricCurrencyCode ($ input );
668
688
case 'amdmntind ' :
@@ -787,24 +807,38 @@ public static function checkAndSanitizeAll(array &$inputs, $flags = 0, array $op
787
807
return implode (', ' , $ fieldsWithErrors );
788
808
}
789
809
790
- public static function sanitizeShortText ( $ input ,$ allowEmpty = false , $ flags = 0 )
810
+ public static function sanitizeText ( $ length , $ input , $ allowEmpty = false , $ flags = 0 )
791
811
{
792
- $ res = self ::sanitizeLength (self ::replaceSpecialChars ($ input , $ flags ), 70 );
812
+ $ res = self ::sanitizeLength (self ::replaceSpecialChars ($ input , $ flags ), $ length );
793
813
794
814
if ($ allowEmpty || !empty ($ res ))
795
815
return $ res ;
796
816
797
817
return false ;
798
818
}
799
819
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 )
801
828
{
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
+ }
806
831
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 );
808
842
}
809
843
810
844
/**
@@ -822,15 +856,20 @@ public static function sanitize($field, $input, $flags = 0)
822
856
$ field = strtolower ($ field );
823
857
switch ($ field ) // fall-through's are on purpose
824
858
{
859
+ case 'orgid_id ' :
860
+ return self ::sanitizeText (self ::TEXT_LENGTH_VERY_SHORT , $ input , true , $ flags );
825
861
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 );
827
864
case 'orgnlcdtrschmeid_nm ' :
828
865
case 'initgpty ' :
829
866
case 'cdtr ' :
830
867
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 ;
834
873
}
835
874
}
836
875
0 commit comments