Skip to content

Commit

Permalink
Support for OrgId fields ID and BicOrBei.
Browse files Browse the repository at this point in the history
  • Loading branch information
AbcAeffchen committed Feb 21, 2018
1 parent ec669b2 commit 89fd61e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
9 changes: 9 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Sephpa - Change Log
===============

## 1.2.5 - Feb 21, '18
- added support for `OrgId` fields `ID` and `BicOrBei`. They can be used in check and sanitize
functions using the keys `orgid_id` and `orgid_bob`.
- added constants for max text lengths `SepaUtilities::TEXT_LENGTH_VERY_SHORT`,
`SepaUtilities::TEXT_LENGTH_SHORT` and `SepaUtilities::TEXT_LENGTH_LONG`
- The functions `sanitizeShortText()` and `sanitizeLongText()` are now deprecated and will be
removed in the next major version. The replacemant is `sanitizeText()` using the `TEXT_LENGTH_*`
constants.

## 1.2.4 - Oct 22, '17
- Added the function `version2string` to get a string representation
of a SEPA file version.
Expand Down
71 changes: 55 additions & 16 deletions src/SepaUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
Expand Down Expand Up @@ -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}',
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 89fd61e

Please sign in to comment.