new pisilinux web sites

This commit is contained in:
Erkan IŞIK
2026-07-01 16:44:17 +03:00
commit b58488b586
21740 changed files with 2066209 additions and 0 deletions
@@ -0,0 +1,331 @@
<?php namespace ZN\Validation\CreditCard;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Formats implements FormatsInterface
{
/**
* Maestro Format
*
* @var array
*/
public static $maestro =
[
'type' => 'maestro',
'pattern' => '/^(51|52|53|54|55|22|23|24|25|26|27)/',
'length' => [12, 13, 14, 15, 16, 18, 19],
'cvcLength' => [3],
'luhn' => true
];
/**
* Forbrugs Foreningen Format
*
* @var array
*/
public static $forbrugsforeningen =
[
'type' => 'forbrugsforeningen',
'pattern' => '/^600/',
'length' => [16],
'cvcLength' => [3],
'luhn' => true
];
/**
* Dankort
*
* @var array
*/
public static $dankort =
[
'type' => 'dankort',
'pattern' => '/^(5019|4175|4571|4)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => true
];
/**
* Visa Format
*
* @var array
*/
public static $visa =
[
'type' => 'visa',
'pattern' => '/^4/',
'length' => [13, 16, 19],
'cvcLength' => [3],
'luhn' => true
];
/**
* Mastercard Format
*
* @var array
*/
public static $mastercard =
[
'type' => 'mastercard',
'pattern' => '/^(51|52|53|54|55|22|23|24|25|26|27)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => true
];
/**
* Amex Format
*
* @var array
*/
public static $amex =
[
'type' => 'amex',
'pattern' => '/^(34|37)/',
'length' => [15],
'cvcLength' => [3, 4],
'luhn' => true
];
/**
* Diners Club Format
*
* @var array
*/
public static $dinersclub =
[
'type' => 'dinersClub',
'pattern' => '/^(300|301|302|303|304|305|309|36|38|39|54|55)/',
'length' => [14, 16],
'cvcLength' => [3, 4],
'luhn' => true
];
/**
* Discover Format
*
* @var array
*/
public static $discover =
[
'type' => 'discover',
'pattern' => '/^(6011|622|644|645|656|647|648|649|65)/',
'length' => [16, 19],
'cvcLength' => [3, 4],
'luhn' => true
];
/**
* Unionpay Format
*
* @var array
*/
public static $unionpay =
[
'type' => 'unionpay',
'pattern' => '/^(62)/',
'length' => [16, 17, 18, 19],
'cvcLength' => [3],
'luhn' => true
];
/**
* JCB Format
*
* @var array
*/
public static $jcb =
[
'type' => 'jcb',
'pattern' => '/^(352|353|354|355|356|357|358)/',
'length' => [16,17,18,19],
'cvcLength' => [3, 4],
'luhn' => true
];
/**
* DinersClub CarteBlanche
*
* @var array
*/
public static $carteblanche =
[
'type' => 'carteblanche',
'pattern' => '/^(300|301|302|303|304|305)/',
'length' => [14],
'cvcLength' => [3],
'luhn' => true
];
/**
* InterPayment
*
* @var array
*/
public static $interpayment =
[
'type' => 'interpayment',
'pattern' => '/^4/',
'length' => [16,17,18,19],
'cvcLength' => [3],
'luhn' => true
];
/**
* NSPK MIR
*
* @var array
*/
public static $mir =
[
'type' => 'mir',
'pattern' => '/^(2200|2201|2202|2203|2204)/',
'length' => [16],
'cvcLength' => [3, 4],
'luhn' => true
];
/**
* Troy
*
* @var array
*/
public static $troy =
[
'type' => 'troy',
'pattern' => '/^(979200|979289)/',
'length' => [16],
'cvcLength' => [3, 4],
'luhn' => true
];
/**
* UATP
*
* @var array
*/
public static $uatp =
[
'type' => 'uatp',
'pattern' => '/^1/',
'length' => [15],
'cvcLength' => [3],
'luhn' => true
];
/**
* Verve
*
* @var array
*/
public static $verve =
[
'type' => 'verve',
'pattern' => '/^(506|650)/',
'length' => [16, 19],
'cvcLength' => [3],
'luhn' => true
];
/**
* BMO ABM Card
*
* @var array
*/
public static $bmoabm =
[
'type' => 'bmoabm',
'pattern' => '/^(500)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => false
];
/**
* CIBC Convenience Card
*
* @var array
*/
public static $cibc =
[
'type' => 'cibc',
'pattern' => '/^(4506)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => false
];
/**
* HSBC Canada Card
*
* @var array
*/
public static $hsbc =
[
'type' => 'hsbc',
'pattern' => '/^(56)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => false
];
/**
* Royal Bank of Canada Client Card
*
* @var array
*/
public static $rbc =
[
'type' => 'rbc',
'pattern' => '/^(45)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => false
];
/**
* Scotiabank Scotia Card
*
* @var array
*/
public static $scotia =
[
'type' => 'scotia',
'pattern' => '/^(4536)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => false
];
/**
* TD Canada Trust Access Card
*
* @var array
*/
public static $tdtrust =
[
'type' => 'tdtrust',
'pattern' => '/^(589297)/',
'length' => [16],
'cvcLength' => [3],
'luhn' => false
];
/**
* Return all card formats
*
* @return array
*/
public static function getList() : array
{
return get_class_vars(self::class);
}
}
@@ -0,0 +1,20 @@
<?php namespace ZN\Validation\CreditCard;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface FormatsInterface
{
/**
* Return all card formats
*
* @return array
*/
public static function getList() : array;
}
@@ -0,0 +1,38 @@
<?php namespace ZN\Validation\CreditCard;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class LuhnAlgorithm implements LuhnAlgorithmInterface
{
/**
* Protected luhn algorithm check
*
* @param string $number
*
* @return string
*/
public static function check(?string $number = NULL)
{
$table =
[
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
];
$total = 0; $transform = 0;
for( $i = strlen($number ?? '') - 1; $i >= 0; $i-- )
{
$total += $table[$transform++ & 0x1][$number[$i]];
}
return $total % 10 === 0;
}
}
@@ -0,0 +1,22 @@
<?php namespace ZN\Validation\CreditCard;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface LuhnAlgorithmInterface
{
/**
* Protected luhn algorithm check
*
* @param string $number
*
* @return string
*/
public static function check(?string $number = NULL);
}
@@ -0,0 +1,169 @@
<?php namespace ZN\Validation\CreditCard;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Validator implements ValidatorInterface
{
/**
* Is valid card
*
* @param string $number
* @param string $type = NULL
*
* @return bool
*/
public static function card(string $number, ?string $type = NULL) : bool
{
$number = preg_replace('/[^0-9]/', '', $number);
if( empty($type) )
{
$type = self::creditCardType($number);
}
if( (self::getCardFormats()[$type] ?? NULL) && self::validCard($number, $type) )
{
return true;
}
return false;
}
/**
* Is valid cvc
*
* @param string $cvc
* @param string $type
*/
public static function cvc(string $cvc, ?string $type = NULL) : bool
{
return ctype_digit($cvc) && (self::getCardFormats()[$type] ?? NULL) && self::validCvcLength($cvc, $type);
}
/**
* Is valid date
*
* @param string $year
* @param string $month
*
* @return bool
*/
public static function date(string $year, string $month) : bool
{
$month = str_pad($month, 2, '0', STR_PAD_LEFT);
if
(
! preg_match('/^20\d\d$/', $year) ||
! preg_match('/^(0[1-9]|1[0-2])$/', $month) ||
( $year < date('Y') || ($year <= date('Y') && $month < date('m')) )
)
{
return false; // @codeCoverageIgnore
}
return true;
}
/**
* Protected credit card type
*
* @param string $number
*
* @return string
*/
protected static function creditCardType(string $number) : string
{
foreach( self::getCardFormats() as $type => $card )
{
if( preg_match($card['pattern'], $number) )
{
return $type;
}
}
return ''; // @codeCoverageIgnore
}
/**
* Protected valid card
*
* @param string $number
* @param string $type
*
* @return string
*/
protected static function validCard(string $number, ?string $type = NULL) : bool
{
return self::validCardFormat($number, $type) && self::validCardNumberLength($number, $type) && self::validLuhnAlgorithm($number, $type);
}
/**
* Protected valid card pattern
*
* @param string $number
* @param string $type
*
* @return bool
*/
protected static function validCardFormat($number, $type) : bool
{
return preg_match(self::getCardFormats()[$type]['pattern'], $number ?? '');
}
/**
* Protected valid card number length
*
* @param string $number
* @param string $type
*
* @return bool
*/
protected static function validCardNumberLength($number, ?string $type = NULL, $function = 'length') : bool
{
return in_array(strlen($number ?? ''), self::getCardFormats()[$type][$function]);
}
/**
* Protected valid cvc length
*
* @param int $cvc
* @param string $type
*
* @return bool
*/
protected static function validCvcLength($cvc, ?string $type = NULL) : bool
{
return self::validCardNumberLength($cvc, $type, 'cvcLength');
}
/**
* Protected valid luhn algorithm
*
* @param string $number
* @param string $type
*
* @return bool
*/
protected static function validLuhnAlgorithm(string $number, ?string $type = NULL) : bool
{
return self::getCardFormats()[$type]['luhn'] ? LuhnAlgorithm::check($number) : true;
}
/**
* Protected get card formats
*
* @return array
*/
protected static function getCardFormats() : array
{
return Formats::getList();
}
}
@@ -0,0 +1,41 @@
<?php namespace ZN\Validation\CreditCard;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface ValidatorInterface
{
/**
* Is valid card
*
* @param string $data
* @param string $type = NULL
*
* @return bool
*/
public static function card(string $data, ?string $type = NULL) : bool;
/**
* Is valid cvc
*
* @param string $cvc
* @param string $type
*/
public static function cvc(string $cvc, ?string $type = NULL) : bool;
/**
* Is valid date
*
* @param string $year
* @param string $month
*
* @return bool
*/
public static function date(string $year, string $month) : bool;
}
+467
View File
@@ -0,0 +1,467 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Lang;
use ZN\Singleton;
use ZN\Request\Method;
use ZN\DataTypes\Arrays;
use ZN\Validation\Exception\InvalidArgumentException;
class Data implements DataInterface
{
use RulesPropertiesTrait;
/**
* Keeps options.
*
* @var array
*/
protected $options = ['post', 'get', 'request', 'data'];
/**
* Keeps match method
*
* @var array
*/
protected $matchMethods = ['match', 'matchpassword'];
/**
* Keeps errors
*
* @var array
*/
protected $errors = [];
/**
* Keeps error
*
* @var array
*/
protected $error = [];
/**
* Keeps messages
*
* @var array
*/
protected $messages = [];
/**
* Keeps user messages
*
* @var array
*/
protected $userMessages = [];
/**
* Keeps index
*
* @var int
*/
protected $index = 0;
/**
* @var string
*/
protected $method;
/**
* Defines rules for control of the grant.
*
* @param string $name
* @param array $config = []
* @param string $viewName = ''
* @param string $met = 'post' - options[post|get]
*
* @return void
*/
public function rules(string $name, array $config = [], $viewName = '', string $met = 'post')
{
if( ! in_array($met, $this->options) )
{
throw new InvalidArgumentException(NULL, '4. ');
}
if( is_array($this->setMethodType($name, $met)) )
{
return $this->setMultipleRules($name, $config, $viewName, $met);
}
$met = $this->settings['method'] ?? 'post';
$viewName = $this->settings['value'] ?? $viewName;
$config = array_merge
(
$config,
$this->settings['config'] ?? [],
$this->settings['validate'] ?? [],
$this->settings['secure'] ?? []
);
$this->settings = [];
$viewName = $viewName ?: $name;
$edit = $this->setMethodType($name, $met);
if( ! isset($edit) ) return false;
$this->method = $met;
foreach( $config as $key => $val )
{
$function = is_numeric($key) ? $val : $key;
if( $this->isValidatorObject($function) )
{
if( is_numeric($key) )
{
$this->validInArray($function, $edit, $name, [':name' => $viewName]);
}
else
{
$this->validIssetArray($function, $edit, (array) $val, $name, $viewName);
}
}
}
$this->setMethodNewValue($name, $edit, $met);
array_push($this->errors, $this->messages);
$this->defaultVariables();
}
/**
* Sets user messages
*
* @param array $settings
*/
public function messages(array $settings)
{
$this->userMessages = $settings;
}
/**
* Add errors
*
* @param string $error
* @param string $name = NULL
*
* @return self
*/
public function addError(string $error, ?string $name = NULL)
{
if( $name )
{
$this->error[$name] = $error;
}
$this->errors[][$this->index] = $error . '<br>'; $this->index++;
}
/**
* It checks the data.
*
* @param string $submit = NULL
* @param string &$error = NULL
*
* @return bool
*/
public function check(string $submit = 'all', &$error = NULL) : bool
{
$session = Singleton::class('ZN\Storage\Session');
$getValidationFormName = Method::request('ValidationFormName');
$rules = $session->select('FormValidationRules' . $getValidationFormName);
$method = $session->select('FormValidationMethod' . $getValidationFormName) ?: 'post';
if( $submit !== NULL && ! $method::$submit() )
{
return false;
}
if( empty($rules) )
{
$this->errors[] = ['Rule check error!']; return false;
}
if( is_array($rules) )
{
foreach( $rules as $name => $rule )
{
if( isset($method::all()[$name]) )
{
$value = $rule['value'] ?? $name;
unset($rule['value']);
$rule = Arrays\Unidimensional::do($rule);
$this->rules($name, $rule, $value, $method);
}
}
}
return ! (Bool) ($error = $this->error('string'));
}
/**
* Get error
*
* @param string $name = 'array' - options[array|string]
* @param string $separator = '<br>'
*/
public function error(string $name = 'array', string $separator = '<br>')
{
$defaultSeparator = '<br>';
if( $name === 'string' || $name === 'array' || $name === 'echo' )
{
if( count($this->errors) > 0 )
{
$result = '';
$resultArray = [];
foreach( $this->errors as $key => $value )
{
if( is_array($value) ) foreach($value as $k => $val)
{
$result .= $val;
$resultArray[] = str_replace($defaultSeparator, '', $val ?? '');
}
}
if( $name === 'string' || $name === 'echo' )
{
return str_replace($defaultSeparator, $separator, $result);
}
if( $name === 'array')
{
return $resultArray;
}
}
}
else if( isset($this->error[$name]) )
{
return $this->error[$name];
}
return false;
}
/**
* Get input post back.
*
* @param string $name
* @param string $met = 'post' - options[post|get]
*/
public function postBack(string $name, string $met = 'post')
{
$method = $this->setMethodType($name, $met);
return $method;
}
/**
* Get error inputs.
*
* @return array
*/
public function errorInputs()
{
return array_keys($this->error);
}
/**
* Protected is validator object
*/
protected function isValidatorObject($object)
{
return method_exists('ZN\Validation\Validator', $object);
}
/**
* protected single in array
*
* @param mixed $key
*
* @return void
*/
protected function validInArray($key, &$data, $name, $viewName)
{
if( is_string($stringCleanData = Validator::$key($data)) )
{
$data = $stringCleanData;
}
elseif( $stringCleanData === false )
{
$this->setMessages($key, $name, $viewName);
}
}
/**
* protected single isset array
*
* @param mixed $key
*
* @return void
*/
protected function validIssetArray($key, $data, $check, $name, $viewName)
{
$data = $this->setMethodType($name, $this->method);
$this->isMatchMethods($key, $check);
if( ! Validator::$key($data, ...$check) )
{
$this->setMessages($key, $name, $this->replaceParameters($check, $viewName));
}
}
/**
* Protected is match methods
*/
protected function isMatchMethods($key, &$check)
{
if( in_array(strtolower($key ?? ''), $this->matchMethods) && isset($check[0]) )
{
$check[0] = Method::{$this->method}($check[0]);
}
}
/**
* protected messages
*/
protected function setMessages($type, $name, $check)
{
if( $userMessage = ($this->userMessages[$type] ?? NULL) )
{
$message = $this->replaceUserMessage($check, $userMessage);
}
else
{
$message = Lang::default('ZN\Validation\ValidationDefaultLanguage')
::select('ViewObjects', 'validation:'.$type, $check);
}
$this->messages[$this->index] = $message.'<br>'; $this->index++;
$this->error[$name] = $message;
}
/**
* Protected replace user message
*/
protected function replaceUserMessage($check, $userMessage)
{
return str_replace(array_keys($check), array_values($check), $userMessage ?? '');
}
/**
* Protected replace parameters
*/
protected function replaceParameters($check, $viewName)
{
$newCheck = [];
foreach( $check as $key => $p )
{
$newCheck[] = ':p' . ($key + 1);
}
array_unshift($newCheck, ':name');
array_unshift($check, $viewName);
return array_combine($newCheck, $check);
}
/**
* Default variables
*
* @param void
*
* @return void
*/
protected function defaultVariables()
{
$this->messages = [];
$this->index = 0;
$this->method = NULL;
}
/**
* protected method type
*
* @param string $name
* @param string $met
*
* @return mixed
*/
protected function setMethodType($name, $met)
{
if( $met === 'data' )
{
return $name;
}
return Method::$met($name);
}
/**
* protected method new value
*
* @param string $name
* @param string $val
* @param string $met
*
* @return mixed
*/
protected function setMethodNewValue($name, $val, $met)
{
if( $met === 'data' )
{
return;
}
return Method::$met($name, $val);
}
/**
* protected multiple rules
*
* @param string $name
* @param array $config = []
* @param string $viewName = ''
* @param string $set = 'post' - options[post|get]
*
* @return void
*/
protected function setMultipleRules(string $name, array $config = [], $viewName = '', string $met = 'post')
{
$postNames = [];
$postKey = '';
$postDatas = (array) Method::$met($name);
foreach( $postDatas as $key => $postData )
{
$postName = $name . $key;
Method::$met($postName, $postData);
$postKey = is_array($viewName)
? $viewName[$key] ?? $postName
: $postName;
$this->rules($postName, $config, $postKey, $met);
}
}
}
@@ -0,0 +1,74 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface DataInterface
{
/**
* It checks the data.
*
* @param string $submit = NULL
*
* @return bool
*/
public function check(string $submit = 'all') : bool;
/**
* Defines rules for control of the grant.
*
* @param string $name
* @param array $config = []
* @param string $viewName = ''
* @param string $met = 'post' - options[post|get]
*
* @return void
*/
public function rules(string $name, array $config = [], $viewName = '', string $met = 'post');
/**
* Sets user messages
*
* @param array $settings
*/
public function messages(array $settings);
/**
* Add errors
*
* @param string $error
* @param string $name = NULL
*
* @return self
*/
public function addError(string $error, ?string $name = NULL);
/**
* Get error
*
* @param string $name = 'array' - options[array|string]
* @param string $separator = '<br>'
*/
public function error(String $name = 'array', string $separator = '<br>');
/**
* Get input post back.
*
* @param string $name
* @param string $met = 'post' - options[post|get]
*/
public function postBack(string $name, string $met = 'post');
/**
* Get error inputs.
*
* @return array
*/
public function errorInputs();
}
@@ -0,0 +1,21 @@
<?php namespace ZN\Validation\Exception;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Exception;
class InvalidArgumentException extends Exception
{
const lang =
[
'en' => '% parameter may contain one of the options [post, get, request or data]!',
'tr' => '% parametre [post, get, request veya data] seçeneklerinden birini içerebilir!'
];
}
@@ -0,0 +1,300 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Base;
trait RulesPropertiesTrait
{
/**
* Keeps settings
*
* @var array
*/
protected $settings = [];
/**
* Valid Card Number
*
* @param string $type
*
* @return Data
*/
public function card(string $type) : Data
{
$this->settings['config']['card'] = $type;
return $this;
}
/**
* Valid Card CVC
*
* @param string $type
*
* @return Data
*/
public function cvc(string $type) : Data
{
$this->settings['config']['cvc'] = $type;
return $this;
}
/**
* Valid Card Date
*
* @return Data
*/
public function cardDate() : Data
{
$this->settings['config'][] = 'cardDate';
return $this;
}
/**
* Method
*
* @param string $method
*
* @return Data
*/
public function method(string $method) : Data
{
$this->settings['method'] = $method;
return $this;
}
/**
* Value
*
* @param string $value
*
* @return Data
*/
public function value(string $value) : Data
{
$this->settings['value'] = $value;
return $this;
}
/**
* Required
*
* @return Data
*/
public function required() : Data
{
$this->settings['config'][] = 'required';
return $this;
}
/**
* Numeric
*
* @return Data
*/
public function numeric() : Data
{
$this->settings['config'][] = 'numeric';
return $this;
}
/**
* Match
*
* @param string $match
*
* @return Data
*/
public function match(string $match) : Data
{
$this->settings['config']['match'] = $match;
return $this;
}
/**
* Match Password
*
* @param string $match
*
* @return Data
*/
public function matchPassword(string $match) : Data
{
$this->settings['config']['matchPassword'] = $match;
return $this;
}
/**
* Compare
*
* @param int $min = NULL
* @param int $max = NULL
*
* @return Data
*/
public function compare(?int $min = NULL, ?int $max = NULL) : Data
{
$this->settings['config']['minchar'] = $min;
$this->settings['config']['maxchar'] = $max;
return $this;
}
/**
* Between
*
* @param float $min = NULL
* @param float $max = NULL
*
* @return Data
*/
public function between(?float $min = NULL, ?float $max = NULL) : Data
{
$this->settings['config']['between'] = [$min, $max];
return $this;
}
/**
* Between Both
*
* @param float $min = NULL
* @param float $max = NULL
*
* @return Data
*/
public function betweenBoth(?float $min = NULL, ?float $max = NULL) : Data
{
$this->settings['config']['betweenBoth'] = [$min, $max];
return $this;
}
/**
* Validate
*
* @param mixed ...$args
*
* @return Data
*/
public function validate(...$args) : Data
{
$this->settings['validate'] = $args;
return $this;
}
/**
* Scure
*
* @param string ...$args
*
* @return Data
*/
public function secure(...$args) : Data
{
$this->settings['secure'] = $args;
return $this;
}
/**
* Pattern
*
* @param string $pattern
* @param string $char = NULL
*
* @return Data
*/
public function pattern(string $pattern, ?string $char = NULL) : Data
{
$this->settings['config']['pattern'] = Base::presuffix($pattern).$char;
return $this;
}
/**
* Phone
*
* @param string $design = NULL
*
* @return Data
*/
public function phone(?string $design = NULL) : Data
{
if( empty($design) )
{
$this->settings['config'][] = 'phone';
}
else
{
$this->settings['config']['phone'] = $design;
}
return $this;
}
/**
* Alpha
*
* @return Data
*/
public function alpha() : Data
{
$this->settings['config'][] = 'alpha';
return $this;
}
/**
* Alpha Numeric
*
* @return Data
*/
public function alnum() : Data
{
$this->settings['config'][] = 'alnum';
return $this;
}
/**
* Captcha
*
* @return Data
*/
public function captcha() : Data
{
$this->settings['config'][] = 'captcha';
return $this;
}
/**
* Answer
*
* @return Data
*/
public function answer() : Data
{
$this->settings['config'][] = 'answer';
return $this;
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Validate implements ValidateInterface
{
/**
* Keeps data.
*
* @var string
*/
protected $data = NULL;
/**
* Keeps status.
*
* @var array
*/
protected $status = [];
/**
* Magic call
*
* @param string $method
* @param array $parameters
*
* @return $this
*/
public function __call($method, $parameters)
{
$this->status[$method] = Validator::$method($this->data, ...$parameters);
return $this;
}
/**
* Get data.
*
* @param string $data
*
* @return Validate
*/
public function data(string $data) : Validate
{
$this->data = $data;
return $this;
}
/**
* Get result
*
* @param void
*
* @return bool
*/
public function get() : bool
{
$this->data = NULL;
foreach( $this->status as $method => $state )
{
if( $state === false )
{
return false;
}
}
return true;
}
/**
* Get status.
*
* @param void
*
* @return array
*/
public function status() : array
{
return $this->status;
}
}
@@ -0,0 +1,40 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface ValidateInterface
{
/**
* Get data.
*
* @param string $data
*
* @return Validate
*/
public function data(string $data) : Validate;
/**
* Get result
*
* @param void
*
* @return bool
*/
public function get() : bool;
/**
* Get status.
*
* @param void
*
* @return array
*/
public function status() : array;
}
@@ -0,0 +1,77 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
/**
* Default Configuration
*
* Enabled when the language file can not be accessed.
*/
class ValidationDefaultLanguage
{
/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
|
| The language of the Validation library.
|
*/
public $en =
[
'validation:required' => ':name field blank, impenetrable!',
'validation:matchPassword' => 'Passwords do not match!',
'validation:match' => ':name datas do not match!',
'validation:email' => ':name field is not valid email address!',
'validation:url' => ':name field is invalid url information!',
'validation:identity' => ':name domain credentials are not valid!',
'validation:noSpecialChar' => ':name field can not contain special characters!',
'validation:numeric' => ':name area should consist only of numbers!',
'validation:alpha' => ':name area should consist only of alpha!',
'validation:alnum' => ':name area should consist only of alphanumeric!',
'validation:phone' => ':name field should contain only information phone!',
'validation:maxchar' => 'most of the space :name more :p1 characters long!',
'validation:minchar' => ':name area of ​​at least :p1 characters long!',
'validation:captcha' => 'Security code is wrong!',
'validation:answer' => 'Security answer is wrong!',
'validation:pattern' => 'Data patterns with incompatible :name!',
'validation:between' => 'The :name field must be between [:p1] - [:p2]!',
'validation:betweenBoth' => 'The :name field must be between or equal [:p1] - [:p2]!',
'validation:card' => ':name field contains invalid card number!',
'validation:cvc' => ':name field contains invalid security number!',
'validation:cardDate' => ':name field contains invalid date information!'
];
public $tr =
[
'validation:required' => ':name alanı boş geçilemez!',
'validation:matchPassword' => 'Şifreler uyumsuz!',
'validation:match' => ':name bilgileri uyumsuz!',
'validation:email' => ':name alanı geçersiz posta adresidir!',
'validation:url' => ':name alanı geçersiz url bilgisidir!',
'validation:identity' => ':name alanı geçersiz kimlik bilgisidir!',
'validation:noSpecialChar' => ':name alanı özel karakter içeremez!',
'validation:numeric' => ':name alanı sadece sayılardan oluşmalıdır!',
'validation:alpha' => ':name alanı sadece harflerden oluşmalıdır!',
'validation:alnum' => ':name alanı sadece sayı ve harflerden oluşmalıdır!',
'validation:phone' => ':name alanı sadece telefon bilgisi içermelidir!',
'validation:maxchar' => ':name alanı en fazla :p1 karakterden oluşmalıdır!',
'validation:minchar' => ':name alanı en az :p1 karakterden oluşmalıdır!',
'validation:captcha' => 'Güvenlik kodu hatalı!',
'validation:answer' => 'Güvenlik cevabı hatalı!',
'validation:pattern' => ':name verisi ile desen uyumsuz!',
'validation:between' => ':name alanı [:p1] - [:p2] değerleri arasında olmalıdır!',
'validation:betweenBoth' => ':name alanı [:p1] - [:p2] değerleri veya arasında olmalıdır!',
'validation:card' => ':name alanı geçersiz kart numarası içermektedir!',
'validation:cvc' => ':name alanı geçersiz güvenlik numarası içermektedir!',
'validation:cardDate' => ':name alanı geçersiz tarih bilgisi içermektedir!'
];
}
+468
View File
@@ -0,0 +1,468 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\IS;
use ZN\Security;
use ZN\Singleton;
use ZN\DateTime\Date;
class Validator implements ValidatorInterface
{
/**
* Is valid card
*
* @param string $data
* @param string $type = NULL
*
* @return bool
*/
public static function card(string $data, ?string $type = NULL) : bool
{
return CreditCard\Validator::card($data, $type);
}
/**
* Is valid cvc
*
* @param string $cvc
* @param string $type
*/
public static function cvc(string $cvc, ?string $type = NULL) : bool
{
return CreditCard\Validator::cvc($cvc, $type);
}
/**
* Is valid date
*
* @param string $year
* @param string $month
*
* @return bool
*/
public static function cardDate(string $date) : bool
{
$dateEx = explode('/', $date);
if( ! isset($dateEx[1]) )
{
return false;
}
$date = (new Date)->convert($dateEx[1] . '-' . $dateEx[0] . '-01', '{y}/{mn0}');
$dateEx = explode('/', $date);
return CreditCard\Validator::date($dateEx[0], $dateEx[1]);
}
/**
* Trim data.
*
* @param string $data
*
* @return string
*/
public static function trim(string $data) : string
{
return trim($data);
}
/**
* Nasty code clean.
*
* @param string $data
*
* @return string
*/
public static function nc(string $data) : string
{
$secnc = Security\Properties::$ncEncode;
return Security\NastyCode::encode($data, $secnc['badChars'], $secnc['changeBadChars']);
}
/**
* Encode html tags.
*
* @param string $data
*
* @return string
*/
public static function html(string $data) : string
{
return Security\Html::encode(Security\Html::decode($data));
}
/**
* Encode cross site scripting.
*
* @param string $data
*
* @return string
*/
public static function xss(string $data) : string
{
return Security\CrossSiteScripting::encode($data);
}
/**
* Encode injection data.
*
* @param string $data
*
* @return string
*/
public static function injection(string $data) : string
{
return Security\Injection::encode($data);
}
/**
* Encode script tags.
*
* @param string $data
*
* @return string
*/
public static function script(string $data) : string
{
return Security\Script::encode($data);
}
/**
* Encode PHP tags.
*
* @param string $data
*
* @return string
*/
public static function php(string $data) : string
{
return Security\PHP::encode($data);
}
/**
* Empty control.
*
* @param string $data
*
* @return bool
*/
public static function required(string $data) : bool
{
return $data !== '';
}
/**
* Answer control
*
* @param string $data
*
* @return bool
*/
public static function answer(string $data) : bool
{
if( empty($data) )
{
return false;
}
return $data == strtolower($_SESSION[md5('answerToQuestion')] ?? '');
}
/**
* Question
*
* @param array $question
*
* @return string
*/
public static function question(array $questions = [])
{
if( empty($questions) )
{
$question = rand(1, 9) . ' ' . ['*', '+'][rand(0, 1)] . ' ' . rand(1, 9);
$_SESSION[md5('answerToQuestion')] = eval('return ' . $question . ';');
return $question;
}
$index = rand(0, count($questions) - 1);
$_SESSION[md5('answerToQuestion')] = strtolower(array_values($questions)[$index] ?? '');
return array_keys($questions)[$index];
}
/**
* Control captcha code.
*
* @param string $data
*
* @return bool
*/
public static function captcha(string $data) : bool
{
if( empty($data) )
{
return false;
}
return $data === Singleton::class('ZN\Captcha\Render')->getCode();
}
/**
* Match password.
*
* @param string $data
* @param string $check
*
* @return bool
*/
public static function matchPassword(string $data, string $check) : bool
{
return self::match($data, $check);
}
/**
* Match.
*
* @param string $data
* @param string $check
*
* @return bool
*/
public static function match(string $data, string $check) : bool
{
return $data === $check;
}
/**
* Pattern.
*
* @param string $data
* @param string $check
*
* @return bool
*/
public static function pattern(string $data, string $check) : bool
{
return preg_match($check, $data);
}
/**
* Checks whether the grant is between the specified values.
*
* @param float $value
* @param float $min
* @param float $max
*
* @return bool
*/
public static function between(Float $value, Float $min, Float $max) : bool
{
return self::betweenBoth($value, $min, $max, 'noboth');
}
/**
* Checks whether the grant is between the specified values.
*
* @param float $value
* @param float $min
* @param float $max
*
* @return bool
*/
public static function betweenBoth(Float $value, Float $min, Float $max, $type = 'both') : bool
{
if( $min > $max )
{
$mmin = $min;
$min = $max;
$max = $mmin;
}
if( $type === 'both' )
{
return $value >= $min && $value <= $max;
}
return $value > $min && $value < $max;
}
/**
* Checks whether the donation has phone information.
*
* @param string $data
* @param string $desing = NULL
*
* @return bool
*/
public static function phone(string $data, ?string $pattern = NULL) : bool
{
if( $pattern !== NULL)
{
$phoneData = preg_replace('/([^\*])/', 'key:$1', $pattern);
$phoneData = '/^'.str_replace(['*', 'key:'], ['[0-9]', '\\'], $phoneData).'$/';
}
else
{
$phoneData = '/\+*[0-9]{10,14}$/';
}
return (bool) preg_match($phoneData, $data);
}
/**
* The data should be numeric.
*
* @param mixed $data
*
* @return bool
*/
public static function numeric($data) : bool
{
return is_numeric($data);
}
/**
* Checks whether the verb is alphabetic.
*
* @param string $data
*
* @return bool
*/
public static function alnum(string $data) : bool
{
return (bool) preg_match('/^\w+$/', $data);
}
/**
* Controls whether the verb is alphanumeric.
*
* @param string $data
*
* @return bool
*/
public static function alpha(string $data) : bool
{
return ctype_alpha($data);
}
/**
* The citizenship identification number checks.
*
* @param string $no
*
* @return bool
*/
public static function identity($no) : bool
{
if( ! is_numeric($no) || strlen($no) !== 11 )
{
return false;
}
$no = (string) $no;
$firstNumbers = $no[0] + $no[2] + $no[4] + $no[6] + $no[8];
$secondNumbers = $no[1] + $no[3] + $no[5] + $no[7];
$numone = $firstNumbers * 7;
$numtwo = $secondNumbers * 9;
$numthree = $firstNumbers * 8;
$totalOneAndTwo = $numone + $numtwo;
$firstLastChar = substr($totalOneAndTwo, -1, 1);
$secondLastChar = substr($numthree, -1, 1);
if( $no[0] == 0 )
{
return false;
}
elseif( $no[9] != $firstLastChar )
{
return false; // @codeCoverageIgnore
}
elseif( $no[10] != $secondLastChar )
{
return false; // @codeCoverageIgnore
}
else
{
return true;
}
}
/**
* Checks whether the email is an e-mail.
*
* @param string $data
*
* @return bool
*/
public static function email(string $data) : bool
{
return IS::email($data);
}
/**
* Checks whether the data is url.
*
* @param string $data
*
* @return bool
*/
public static function url(string $data) : bool
{
return IS::url($data);
}
/**
* Checks whether the data is special char.
*
* @param string $data
*
* @return bool
*/
public static function specialChar(string $data) : bool
{
return (bool) preg_match('/[\W]+/', $data);
}
/**
* Makes the maximum character limit.
*
* @param string $data
* @param int $char
*
* @return bool
*/
public static function maxchar(string $data, int $char) : bool
{
return ( strlen($data) <= $char );
}
/**
* Makes the minimum character limit.
*
* @param string $data
* @param int $char
*
* @return bool
*/
public static function minchar(string $data, int $char) : bool
{
return ( strlen($data) >= $char );
}
}
@@ -0,0 +1,285 @@
<?php namespace ZN\Validation;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface ValidatorInterface
{
/**
* Is valid card
*
* @param string $data
* @param string $type = NULL
*
* @return bool
*/
public static function card(string $data, ?string $type = NULL) : bool;
/**
* Is valid cvc
*
* @param string $cvc
* @param string $type
*/
public static function cvc(string $cvc, ?string $type = NULL) : bool;
/**
* Is valid date
*
* @param string $year
* @param string $month
*
* @return bool
*/
public static function cardDate(string $date) : bool;
/**
* Trim data.
*
* @param string $data
*
* @return string
*/
public static function trim(string $data) : string;
/**
* Nasty code clean.
*
* @param string $data
*
* @return string
*/
public static function nc(string $data) : string;
/**
* Encode html tags.
*
* @param string $data
*
* @return string
*/
public static function html(string $data) : string;
/**
* Encode cross site scripting.
*
* @param string $data
*
* @return string
*/
public static function xss(string $data) : string;
/**
* Encode injection data.
*
* @param string $data
*
* @return string
*/
public static function injection(string $data) : string;
/**
* Encode script tags.
*
* @param string $data
*
* @return string
*/
public static function script(string $data) : string;
/**
* Encode PHP tags.
*
* @param string $data
*
* @return string
*/
public static function php(string $data) : string;
/**
* Empty control.
*
* @param string $data
*
* @return bool
*/
public static function required(string $data) : bool;
/**
* Control captcha code.
*
* @param string $data
*
* @return bool
*/
public static function captcha(string $data) : bool;
/**
* Question
*
* @array $question
*
* @return string
*/
public static function question(array $questions = []);
/**
* Answer control
*
* @param string $data
*
* @return bool
*/
public static function answer(string $data) : bool;
/**
* Match password.
*
* @param string $data
* @param string $check
*
* @return bool
*/
public static function matchPassword(string $data, string $check) : bool;
/**
* Match.
*
* @param string $data
* @param string $check
*
* @return bool
*/
public static function match(string $data, string $check) : bool;
/**
* Pattern.
*
* @param string $data
* @param string $check
*
* @return bool
*/
public static function pattern(string $data, string $check) : bool;
/**
* Checks whether the grant is between the specified values.
*
* @param float $value
* @param float $min
* @param float $max
*
* @return bool
*/
public static function between(Float $value, Float $min, Float $max) : bool;
/**
* Checks whether the grant is between the specified values.
*
* @param float $value
* @param float $min
* @param float $max
*
* @return bool
*/
public static function betweenBoth(Float $value, Float $min, Float $max) : bool;
/**
* Checks whether the donation has phone information.
*
* @param string $data
* @param string $desing = NULL
*
* @return bool
*/
public static function phone(string $data, ?string $pattern = NULL) : bool;
/**
* The data should be numeric.
*
* @param mixed $data
*
* @return bool
*/
public static function numeric($data) : bool;
/**
* Checks whether the verb is alphabetic.
*
* @param string $data
*
* @return bool
*/
public static function alnum(string $data) : bool;
/**
* Controls whether the verb is alphanumeric.
*
* @param string $data
*
* @return bool
*/
public static function alpha(string $data) : bool;
/**
* The citizenship identification number checks.
*
* @param string $no
*
* @return bool
*/
public static function identity($no) : bool;
/**
* Checks whether the email is an e-mail.
*
* @param string $data
*
* @return bool
*/
public static function email(string $data) : bool;
/**
* Checks whether the data is url.
*
* @param string $data
*
* @return bool
*/
public static function url(string $data) : bool;
/**
* Checks whether the data is special char.
*
* @param string $data
*
* @return bool
*/
public static function specialChar(string $data) : bool;
/**
* Makes the maximum character limit.
*
* @param string $data
* @param int $char
*
* @return bool
*/
public static function maxchar(string $data, int $char) : bool;
/**
* Makes the minimum character limit.
*
* @param string $data
* @param int $char
*
* @return bool
*/
public static function minchar(string $data, int $char) : bool;
}