Completed
Push — master ( 92cef5...5801fe )
by Iurii
01:16
created

Main::checkJqueryVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/**
4
 * @package Jquery Mobile
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\jquery_mobile;
11
12
use gplcart\core\Library,
13
    gplcart\core\Container;
14
15
/**
16
 * Main class for Jquery Mobile module
17
 */
18
class Main
19
{
20
21
    /**
22
     * Library class instance
23
     * @var \gplcart\core\Library $library
24
     */
25
    protected $library;
26
27
    /**
28
     * @param Library $library
29
     */
30
    public function __construct(Library $library)
31
    {
32
        $this->library = $library;
33
    }
34
35
    /**
36
     * Implements hook "library.list"
37
     * @param array $libraries
38
     */
39
    public function hookLibraryList(array &$libraries)
40
    {
41
        $libraries['jquery_mobile'] = array(
42
            'name' => /* @text */'Jquery Mobile',
43
            'description' => /* @text */'A HTML5-based user interface system designed to make responsive web sites and apps that are accessible on all smartphone, tablet and desktop devices',
44
            'type' => 'asset',
45
            'module' => 'jquery_mobile',
46
            'url' => 'http://jquerymobile.com',
47
            'download' => 'http://jquerymobile.com/resources/download/jquery.mobile-1.4.5.zip',
48
            'version_source' => array(
49
                'file' => 'vendor/jquery/jquery-mobile/jquery.mobile-1.4.5.min.js',
50
                'pattern' => '/jQuery Mobile (\\d+\\.+\\d+\\.+\\d+)/',
51
                'lines' => 2
52
            ),
53
            'files' => array(
54
                'vendor/jquery/jquery-mobile/jquery.mobile-1.4.5.min.js',
55
                'vendor/jquery/jquery-mobile/jquery.mobile-1.4.5.min.css'
56
            ),
57
        );
58
    }
59
60
    /**
61
     * Implements hook "module.install.before"
62
     * @param null|string
63
     */
64
    public function hookModuleInstallBefore(&$result)
65
    {
66
        $this->checkJqueryVersion($result);
67
    }
68
69
    /**
70
     * Implements hook "module.enable.after"
71
     */
72
    public function hookModuleEnableAfter()
73
    {
74
        $this->library->clearCache();
75
    }
76
77
    /**
78
     * Implements hook "module.disable.after"
79
     */
80
    public function hookModuleDisableAfter()
81
    {
82
        $this->library->clearCache();
83
    }
84
85
    /**
86
     * Implements hook "module.install.after"
87
     */
88
    public function hookModuleInstallAfter()
89
    {
90
        $this->library->clearCache();
91
    }
92
93
    /**
94
     * Implements hook "module.uninstall.after"
95
     */
96
    public function hookModuleUninstallAfter()
97
    {
98
        $this->library->clearCache();
99
    }
100
101
    /**
102
     * Check Jquery version
103
     * @param mixed $result
104
     */
105
    protected function checkJqueryVersion(&$result)
106
    {
107
        $library = $this->library->get('jquery');
108
        if (version_compare($library['version'], '1.8.0', '<')) {
109
            $result = $this->getTranslationModel()->text('Jquery Mobile requires Jquery >= 1.8.0');
110
        }
111
    }
112
113
    /**
114
     * Translation UI model class instance
115
     * @return \gplcart\core\models\Translation
116
     */
117
    protected function getTranslationModel()
118
    {
119
        return Container::get('gplcart\\core\\models\\Translation');
120
    }
121
122
}
123