Licensed.php
3 KB
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
<?php
/**
* @package AllediaInstaller
* @contact www.alledia.com, hello@alledia.com
* @copyright 2016 Alledia.com, All rights reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use Alledia\Framework\AutoLoader;
/**
* Licensed class, for extensions with Free and Pro versions
*/
class Licensed extends Generic
{
/**
* License type: free or pro
*
* @var string
*/
protected $license;
/**
* The path for the pro library
*
* @var string
*/
protected $proLibraryPath;
/**
* The path for the free library
*
* @var string
*/
protected $libraryPath;
/**
* Class constructor, set the extension type.
*
* @param string $namespace The element of the extension
* @param string $type The type of extension
* @param string $folder The folder for plugins (only)
*/
public function __construct($namespace, $type, $folder = '', $basePath = JPATH_SITE)
{
parent::__construct($namespace, $type, $folder, $basePath);
$this->license = @strtolower($this->manifest->alledia->license);
// Make sure we are using the correct namespace
$this->namespace = @$this->manifest->alledia->namespace;
$this->getLibraryPath();
$this->getProLibraryPath();
}
/**
* Check if the license is pro
*
* @return boolean True for pro license
*/
public function isPro()
{
return $this->license === 'pro';
}
/**
* Check if the license is free
*
* @return boolean True for free license
*/
public function isFree()
{
return ! $this->isPro();
}
/**
* Get the include path for the include on the free library, based on the extension type
*
* @return string The path for pro
*/
public function getLibraryPath()
{
if (empty($this->libraryPath)) {
$basePath = $this->getExtensionPath();
$this->libraryPath = $basePath . '/library';
}
return $this->libraryPath;
}
/**
* Get the include path for the include on the pro library, based on the extension type
*
* @return string The path for pro
*/
public function getProLibraryPath()
{
if (empty($this->proLibraryPath)) {
$basePath = $this->getLibraryPath();
$this->proLibraryPath = $basePath . '/Pro';
}
return $this->proLibraryPath;
}
/**
* Loads the library, if existent (including the Pro Library)
*
* @return bool
*/
public function loadLibrary()
{
$libraryPath = $this->getLibraryPath();
// If we have a library path, lets load it
if (file_exists($libraryPath)) {
// Setup autoloaded libraries
AutoLoader::register('Alledia\\' . $this->namespace, $libraryPath);
return true;
}
return false;
}
}