mfPutFileContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 31
rs 9.6333
1
<?php
2
3
/**
4
 * This file is responsible for updating the MyFatoorah Library everyday
5
 *
6
 * MyFatoorah offers a seamless business experience by offering a technology put together by our tech team. This enables smooth business operations involving sales activity, product invoicing, shipping, and payment processing. MyFatoorah invoicing and payment gateway solution trigger your business to greater success at all levels in the new age world of commerce. Leverage your sales and payments at all e-commerce platforms (ERPs, CRMs, CMSs) with transparent and slick applications that are well-integrated into social media and telecom services. For every closing sale click, you make a business function gets done for you, along with generating factual reports and statistics to fine-tune your business plan with no-barrier low-cost.
7
 * Our technology experts have designed the best GCC E-commerce solutions for the native financial instruments (Debit Cards, Credit Cards, etc.) supporting online sales and payments, for events, shopping, mall, and associated services.
8
 *
9
 * Created by MyFatoorah http://www.myfatoorah.com/
10
 * Developed By [email protected]
11
 * Date: 31/03/2024
12
 * Time: 12:00
13
 *
14
 * API Documentation on https://myfatoorah.readme.io/docs
15
 * Library Documentation and Download link on https://myfatoorah.readme.io/docs/php-library
16
 *
17
 * @author    MyFatoorah <[email protected]>
18
 * @copyright MyFatoorah, All rights reserved
19
 * @license   GNU General Public License v3.0
20
 */
21
$mfVersion = '2.2';
22
23
if (!in_array('curl', get_loaded_extensions())) {
24
    trigger_error('Kindly install and enable PHP cURL extension in your server.', E_USER_WARNING);
25
    return;
26
}
27
28
$mfLibFolder = __DIR__ . '/src/';
29
$mfLibFile   = $mfLibFolder . 'MyFatoorah.php';
30
if (!is_writable($mfLibFile) || ((time() - filemtime($mfLibFile)) < 86400)) {
31
    return;
32
}
33
34
touch($mfLibFile);
35
try {
36
    $mfCurl = curl_init("https://portal.myfatoorah.com/Files/API/php/library/$mfVersion/MyfatoorahLibrary.txt");
37
    curl_setopt_array(
38
        $mfCurl, array(CURLOPT_RETURNTRANSFER => true)
39
    );
40
41
    $mfResponse = curl_exec($mfCurl);
42
    $mfHttpCode = curl_getinfo($mfCurl, CURLINFO_HTTP_CODE);
43
    $mfCurlErr  = curl_error($mfCurl);
44
45
    curl_close($mfCurl);
46
47
    if ($mfCurlErr) {
48
        trigger_error('cURL Error: ' . $mfCurlErr, E_USER_WARNING);
49
    }
50
51
    if ($mfHttpCode == 200 && is_string($mfResponse)) {
52
        mfPutFileContent($mfLibFolder, $mfResponse);
53
    }
54
} catch (\Exception $ex) {
55
    trigger_error('Exception: ' . $ex->getMessage(), E_USER_WARNING);
56
}
57
58
function mfPutFileContent($mfLibFolder, $mfResponse)
59
{
60
    $mfSplitFile = explode('class', $mfResponse);
61
62
    $mfNamespace = '<?php namespace MyFatoorah\Library; ';
63
    $mfClass     = 'class ';
64
65
    $useExClass = 'use Exception; ';
66
    $useMfClass = 'use MyFatoorah\Library\MyFatoorah; ';
67
68
    //namespace MyFatoorah\Library
69
    file_put_contents($mfLibFolder . 'MyFatoorah.php', $mfNamespace . $useExClass . $mfClass . $mfSplitFile[1]);
70
    file_put_contents($mfLibFolder . 'MyFatoorahHelper.php', $mfNamespace . $useExClass . $mfClass . $mfSplitFile[2]);
71
72
    //namespace MyFatoorah\Library\API
73
    $mfLibFolder .= 'API/';
74
75
    $mfApiNamespace = '<?php namespace MyFatoorah\Library\API; ';
76
    file_put_contents($mfLibFolder . 'MyFatoorahList.php', $mfApiNamespace . $useMfClass . $useExClass . $mfClass . $mfSplitFile[3]);
77
    file_put_contents($mfLibFolder . 'MyFatoorahRefund.php', $mfApiNamespace . $useMfClass . $mfClass . $mfSplitFile[4]);
78
    file_put_contents($mfLibFolder . 'MyFatoorahShipping.php', $mfApiNamespace . $useMfClass . $mfClass . $mfSplitFile[5]);
79
    file_put_contents($mfLibFolder . 'MyFatoorahSupplier.php', $mfApiNamespace . $useMfClass . $mfClass . $mfSplitFile[6]);
80
81
    //namespace MyFatoorah\Library\API\Payment
82
    $mfLibFolder .= 'Payment/';
83
84
    $mfApiPaymentNamespace = '<?php namespace MyFatoorah\Library\API\Payment; ';
85
    $useMfListClass        = 'use MyFatoorah\Library\API\MyFatoorahList; ';
86
    file_put_contents($mfLibFolder . 'MyFatoorahPayment.php', $mfApiPaymentNamespace . $useMfClass . $useExClass . $mfClass . $mfSplitFile[7]);
87
    file_put_contents($mfLibFolder . 'MyFatoorahPaymentEmbedded.php', $mfApiPaymentNamespace . $useMfListClass . $mfClass . $mfSplitFile[8]);
88
    file_put_contents($mfLibFolder . 'MyFatoorahPaymentStatus.php', $mfApiPaymentNamespace . $useExClass . $mfClass . $mfSplitFile[9]);
89
}
90