Open Journal Systems  3.3.0
vendor/omnipay/common/src/Common/Helper.php
1 <?php
6 namespace Omnipay\Common;
7 
8 use InvalidArgumentException;
9 
16 class Helper
17 {
24  public static function camelCase($str)
25  {
26  $str = self::convertToLowercase($str);
27  return preg_replace_callback(
28  '/_([a-z])/',
29  function ($match) {
30  return strtoupper($match[1]);
31  },
32  $str
33  );
34  }
35 
42  protected static function convertToLowercase($str)
43  {
44  $explodedStr = explode('_', $str);
45  $lowercasedStr = [];
46 
47  if (count($explodedStr) > 1) {
48  foreach ($explodedStr as $value) {
49  $lowercasedStr[] = strtolower($value);
50  }
51  $str = implode('_', $lowercasedStr);
52  }
53 
54  return $str;
55  }
56 
63  public static function validateLuhn($number)
64  {
65  $str = '';
66  foreach (array_reverse(str_split($number)) as $i => $c) {
67  $str .= $i % 2 ? $c * 2 : $c;
68  }
69 
70  return array_sum(str_split($str)) % 10 === 0;
71  }
72 
82  public static function initialize($target, array $parameters = null)
83  {
84  if ($parameters) {
85  foreach ($parameters as $key => $value) {
86  $method = 'set'.ucfirst(static::camelCase($key));
87  if (method_exists($target, $method)) {
88  $target->$method($value);
89  }
90  }
91  }
92  }
93 
100  public static function getGatewayShortName($className)
101  {
102  if (0 === strpos($className, '\\')) {
103  $className = substr($className, 1);
104  }
105 
106  if (0 === strpos($className, 'Omnipay\\')) {
107  return trim(str_replace('\\', '_', substr($className, 8, -7)), '_');
108  }
109 
110  return '\\'.$className;
111  }
112 
128  public static function getGatewayClassName($shortName)
129  {
130  if (0 === strpos($shortName, '\\')) {
131  return $shortName;
132  }
133 
134  // replace underscores with namespace marker, PSR-0 style
135  $shortName = str_replace('_', '\\', $shortName);
136  if (false === strpos($shortName, '\\')) {
137  $shortName .= '\\';
138  }
139 
140  return '\\Omnipay\\'.$shortName.'Gateway';
141  }
142 }
Omnipay\Common\Helper\validateLuhn
static validateLuhn($number)
Definition: vendor/omnipay/common/src/Common/Helper.php:63
Omnipay\Common\Helper\getGatewayShortName
static getGatewayShortName($className)
Definition: vendor/omnipay/common/src/Common/Helper.php:100
Omnipay\Common
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:6
Omnipay\Common\Helper\convertToLowercase
static convertToLowercase($str)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Helper.php:42
Omnipay\Common\Helper\initialize
static initialize($target, array $parameters=null)
Definition: vendor/omnipay/common/src/Common/Helper.php:82
Omnipay\Common\Helper\camelCase
static camelCase($str)
Definition: vendor/omnipay/common/src/Common/Helper.php:24
Omnipay\Common\Helper\getGatewayClassName
static getGatewayClassName($shortName)
Definition: vendor/omnipay/common/src/Common/Helper.php:128