1
1
<?php
2
-
3
- namespace AliAbdalla \Tafqeet \Core ;
4
-
5
- use AliAbdalla \Tafqeet \Helper \Calculators ;
6
- use AliAbdalla \Tafqeet \Helper \Handler ;
7
- use AliAbdalla \Tafqeet \Helper \Validation ;
8
- use AliAbdalla \Tafqeet \Helper \App ;
9
-
10
- class Tafqeet
11
- {
12
- use Calculators,Handler,Validation,App;
13
-
14
- public $ config = [
15
- 'connection_tool ' => ' و ' ,
16
- 'default_currency ' => 'sar ' ,
17
- 'starter ' => 'فقط ' ,
18
- 'end ' => 'لاغير ' ,
19
- 'currencies ' => [
20
- 'sar ' => [
21
- 'main1 ' => 'ريال ' ,
22
- 'main2 ' => 'ريالاً ' ,
23
- 'single ' => 'هللة ' ,
24
- 'multi ' => 'هللات '
25
- ],
26
-
27
- 'sdg ' => [
28
- 'main1 ' => 'قرش ' ,
29
- 'main2 ' => 'قرشاً ' ,
30
- 'single ' => 'قرش ' ,
31
- 'multi ' => 'قروش '
32
- ],
33
-
34
- 'usd ' => [
35
- 'main1 ' => 'دولار ' ,
36
- 'main2 ' => 'دولاراً ' ,
37
- 'single ' => 'سنت ' ,
38
- 'multi ' => 'سنت '
39
- ],
40
-
41
-
42
- ],
43
-
44
- ];
45
- /*
46
- * parsed number
47
- * */
48
- public $ after_comma_sum ;
49
-
50
- /*
51
- * array of numbers after split process
52
- * */
53
- private $ parsed_number ;
54
-
55
- /*
56
- * all number array
57
- * all array count
58
- * */
59
- private $ parsed_number_array = [];
60
- private $ all_numbers_len ;
61
-
62
- /*
63
- * before comma number array
64
- * before comma array count
65
- * */
66
- private $ all_numbers_array ;
67
- private $ before_comma_len ;
68
-
69
- /*
70
- * after comma number array
71
- * after comma array count
72
- * */
73
- private $ before_comma_array ;
74
- private $ after_comma_len ;
75
- private $ after_comma_array ;
76
-
77
- /*
78
- * result before and after comma
79
- *
80
- * */
81
- private $ result_before_comma ;
82
- private $ result_after_comma ;
83
-
84
- private $ is_main1_currency = true ;
85
-
86
- /**
87
- * @param int $amount
88
- * @param string $currency
89
- *
90
- * @return mixed
91
- */
92
- public static function arablic ($ amount = 0 ,$ currency = 'sar ' )
93
- {
94
-
95
- $ amount = money_format ("%i " ,$ amount ); // update the amount to be always 2 digit after comma
96
-
97
- //
98
- return (new self )->setAmount ($ amount )->initValidation ()->prepare ()->run ()->result ($ currency );
99
- }
100
-
101
- /**
102
- * @param string $currency
103
- *
104
- * @return mixed
105
- */
106
- public function result ($ currency = 'sar ' )
107
- {
108
- $ result = $ this ->config ['starter ' ].' ' ;
109
-
110
- if ($ this ->is_main1_currency ){
111
- $ result .= $ this ->result_before_comma .' ' .$ this ->config ['currencies ' ][$ currency ]['main1 ' ];
112
-
113
- }else {
114
- $ result .= $ this ->result_before_comma .' ' .$ this ->config ['currencies ' ][$ currency ]['main2 ' ];
115
-
116
- }
117
- if ($ this ->after_comma_len >= 1 ){
118
- if (in_array ($ this ->after_comma_sum ,[
119
- 3 ,4 ,5 ,6 ,7 ,8 ,9 ,10
120
- ])){
121
- $ result .= $ this ->config ['connection_tool ' ].$ this ->result_after_comma .' ' .
122
- $ this ->config ['currencies ' ][$ currency ]['multi ' ];
123
- }else {
124
- $ result .= $ this ->config ['connection_tool ' ].$ this ->result_after_comma .' ' .
125
- $ this ->config ['currencies ' ][$ currency ]['single ' ];
126
- }
127
-
128
- }
129
-
130
- $ result .= ' ' .$ this ->config ['end ' ];
131
-
132
- return str_replace (' ' ,' ' ,$ result );
133
- }
134
-
135
- /**
136
- * @return $this
137
- */
138
- public function run ()
139
- {
140
- $ this ->result_before_comma = $ this ->runBeforeComma ();
141
- $ this ->result_after_comma = $ this ->runAfterComma ();
142
- return $ this ;
143
- }
144
-
145
- /**
146
- * @return $this
147
- */
148
- public function prepare ()
149
- {
150
- $ this ->split_parsed_number_to_two_number_depend_on_comma ()->split_numbers_before_comma_to_array ()->split_numbers_after_comma_to_array ();
151
- return $ this ;
152
- }
153
-
154
- }
2
+
3
+ namespace AliAbdalla \Tafqeet \Core ;
4
+
5
+ use AliAbdalla \Tafqeet \Helper \App ;
6
+ use AliAbdalla \Tafqeet \Helper \Calculators ;
7
+ use AliAbdalla \Tafqeet \Helper \Handler ;
8
+ use AliAbdalla \Tafqeet \Helper \Validation ;
9
+
10
+ class Tafqeet
11
+ {
12
+ use Calculators;
13
+ use Handler;
14
+ use Validation;
15
+ use App;
16
+
17
+ public $ config = [
18
+ 'connection_tool ' => ' و ' ,
19
+ 'default_currency ' => 'sar ' ,
20
+ 'starter ' => 'فقط ' ,
21
+ 'end ' => 'لاغير ' ,
22
+ 'currencies ' => [
23
+ 'sar ' => [
24
+ 'main1 ' => 'ريال ' ,
25
+ 'main2 ' => 'ريالاً ' ,
26
+ 'single ' => 'هللة ' ,
27
+ 'multi ' => 'هللات ' ,
28
+ ],
29
+
30
+ 'sdg ' => [
31
+ 'main1 ' => 'قرش ' ,
32
+ 'main2 ' => 'قرشاً ' ,
33
+ 'single ' => 'قرش ' ,
34
+ 'multi ' => 'قروش ' ,
35
+ ],
36
+
37
+ 'usd ' => [
38
+ 'main1 ' => 'دولار ' ,
39
+ 'main2 ' => 'دولاراً ' ,
40
+ 'single ' => 'سنت ' ,
41
+ 'multi ' => 'سنت ' ,
42
+ ],
43
+ ],
44
+ ];
45
+ // parsed number
46
+ public $ after_comma_sum ;
47
+
48
+ // array of numbers after split process
49
+ private $ parsed_number ;
50
+
51
+ /*
52
+ * all number array
53
+ * all array count
54
+ * */
55
+ private $ parsed_number_array = [];
56
+ private $ all_numbers_len ;
57
+
58
+ /*
59
+ * before comma number array
60
+ * before comma array count
61
+ * */
62
+ private $ all_numbers_array ;
63
+ private $ before_comma_len ;
64
+
65
+ /*
66
+ * after comma number array
67
+ * after comma array count
68
+ * */
69
+ private $ before_comma_array ;
70
+ private $ after_comma_len ;
71
+ private $ after_comma_array ;
72
+
73
+ // result before and after comma
74
+ private $ result_before_comma ;
75
+ private $ result_after_comma ;
76
+
77
+ private $ is_main1_currency = true ;
78
+
79
+ /**
80
+ * @param int $amount
81
+ * @param string $currency
82
+ *
83
+ * @return mixed
84
+ */
85
+ public static function arablic ($ amount = 0 , $ currency = 'sar ' )
86
+ {
87
+ $ amount = (float ) number_format ((float ) $ amount , 2 );
88
+
89
+ return (new self ())->setAmount ($ amount )->initValidation ()->prepare ()->run ()->result ($ currency );
90
+ }
91
+
92
+ /**
93
+ * @param string $currency
94
+ *
95
+ * @return mixed
96
+ */
97
+ public function result ($ currency = 'sar ' )
98
+ {
99
+ $ result = $ this ->config ['starter ' ].' ' ;
100
+
101
+ if ($ this ->is_main1_currency ) {
102
+ $ result .= $ this ->result_before_comma .' ' .$ this ->config ['currencies ' ][$ currency ]['main1 ' ];
103
+ } else {
104
+ $ result .= $ this ->result_before_comma .' ' .$ this ->config ['currencies ' ][$ currency ]['main2 ' ];
105
+ }
106
+ if ($ this ->after_comma_len >= 1 ) {
107
+ if (in_array ($ this ->after_comma_sum , [
108
+ 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ,
109
+ ])) {
110
+ $ result .= $ this ->config ['connection_tool ' ].$ this ->result_after_comma .' ' .
111
+ $ this ->config ['currencies ' ][$ currency ]['multi ' ];
112
+ } else {
113
+ $ result .= $ this ->config ['connection_tool ' ].$ this ->result_after_comma .' ' .
114
+ $ this ->config ['currencies ' ][$ currency ]['single ' ];
115
+ }
116
+ }
117
+
118
+ $ result .= ' ' .$ this ->config ['end ' ];
119
+
120
+ return str_replace (' ' , ' ' , $ result );
121
+ }
122
+
123
+ /**
124
+ * @return $this
125
+ */
126
+ public function run ()
127
+ {
128
+ $ this ->result_before_comma = $ this ->runBeforeComma ();
129
+ $ this ->result_after_comma = $ this ->runAfterComma ();
130
+
131
+ return $ this ;
132
+ }
133
+
134
+ /**
135
+ * @return $this
136
+ */
137
+ public function prepare ()
138
+ {
139
+ $ this ->split_parsed_number_to_two_number_depend_on_comma ()->split_numbers_before_comma_to_array ()->split_numbers_after_comma_to_array ();
140
+
141
+ return $ this ;
142
+ }
143
+ }
0 commit comments