-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.class.php
141 lines (128 loc) · 3.98 KB
/
utilities.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace andmaengine\bank_engine;
/**
* @description-pt-BR Leitor de arquivo de extrato bancário eletrônico
* @description-en-US File reader of eletronic bank statement
* @Category andmaengine
* @Package andmaengine\bank_engine
* @Copyright Copyright (c) 2017-2030
* @Language PHP
* @Updated To 7.2.0
* @license
* @author Anderson Matheus Arruda < andmarruda at gmail dot com >
* @link
**/
use \SplFileObject;
use \Exception;
use \DateTime;
require_once(__DIR__. '/language.class.php');
final class utilities{
// ------------ PUBLIC PARAMETERS ------------ //
/**
* @name date_format
* @description-pt-BR O formato atual da data presente no arquivo
* @description-en-US The current format of the date present in the file
* @var string
**/
public static $date_format;
/**
* @name decimal_length
* @description-pt-BR Quantidade de casas decimais
* @description-en-US Number of decimal places
* @var int
**/
public static $decimal_length;
// ------------ PUBLIC FUNCTIONS ------------ //
/**
* @description-pt-BR Converte o valor para o tipo desejado
* @description-en-US Converts the value to the desired type
* @version 1.0.0
* @access public
* @name convert_to_type
* @author Anderson Matheus Arruda < andmarruda at gmail dot com >
* @modifyBy
* @modifyDescription
* @param string $type
* @param mixed $value
* @return
**/
public static function convert_to_type(string $type, $value)
{
switch(strtolower($type))
{
case 'string':
return (string) $value;
break;
case 'int':
case 'integer':
return (int) $value;
break;
case 'bool':
case 'boolean':
return (bool) $value;
break;
case 'float':
return (float) $value;
break;
default:
return (string) $value;
}
}
/**
* @description-pt-BR Recebe dados de entrada para validar tipos
* @description-en-US Receive incoming data for type validation
* @version 1.0.0
* @access public
* @name ` reader
* @author Anderson Matheus Arruda < andmarruda at gmail dot com >
* @modifyBy
* @modifyDescription
* @param string $file_pattern
* @param string $file_path
* @return void
**/
public static function inline(array $configuration_dimension, string $line_content)
{
$value_inline=substr($line_content, $configuration_dimension['initial_position'] -1, $configuration_dimension['length']);
return self::convert_to_type($configuration_dimension['type'], $value_inline);
}
/**
* @description-pt-BR Converte o valor para formato de data do banco de dados
* @description-en-US Converts's the value to database's date format
* @version 1.0.0
* @access public
* @name convert_date
* @author Anderson Matheus Arruda < andmarruda at gmail dot com >
* @modifyBy
* @modifyDescription
* @param string $dte
* @param string $output_format
* @return string
**/
public static function convert_date($date, $output_format='Y-m-d') : string
{
$date=trim($date);
if($date=='')
return $date;
$dt = DateTime::createFromFormat(self::$date_format, $date);
return $dt->format($output_format);
}
/**
* @description-pt-BR Converte o valor para formato de float adicionando ponto decimal
* @description-en-US Converts the value to float format by adding decimal point
* @version 1.0.0
* @access public
* @name convert_date
* @author Anderson Matheus Arruda < andmarruda at gmail dot com >
* @modifyBy
* @modifyDescription
* @param string $number
* @return string
**/
public static function convert_float_with_decimal($number) : float
{
$return = substr($number, 0, self::$decimal_length * -1). '.'. substr($number, self::$decimal_length * -1);
return (float) $return;
}
}
?>