1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Model\Admin\Application; |
4
|
|
|
|
5
|
|
|
use Ffcms\Core\Arch\Model; |
6
|
|
|
use Ffcms\Core\Exception\SyntaxException; |
7
|
|
|
use Ffcms\Core\Helper\Type\Arr; |
8
|
|
|
use Ffcms\Core\Helper\Type\Str; |
9
|
|
|
use Apps\ActiveRecord\App as AppRecord; |
10
|
|
|
|
11
|
|
|
class FormInstall extends Model |
12
|
|
|
{ |
13
|
|
|
public $sysname; |
14
|
|
|
|
15
|
|
|
private $_apps; |
16
|
|
|
private $_type; |
17
|
|
|
private $_definedControllers = []; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* FormInstall constructor. Pass applications object from controller |
21
|
|
|
* @param $apps |
22
|
|
|
* @param string $type |
23
|
|
|
* @throws SyntaxException |
24
|
|
|
*/ |
25
|
|
|
public function __construct($apps, $type) |
26
|
|
|
{ |
27
|
|
|
$this->_apps = $apps; |
28
|
|
|
// check if passed type is allowed to use |
29
|
|
|
if (!Arr::in($type, ['app', 'widget'])) { |
30
|
|
|
throw new SyntaxException('The type of extension is not defined!'); |
31
|
|
|
} |
32
|
|
|
$this->_type = $type; |
33
|
|
|
parent::__construct(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Insert applications defined controllers to local var |
38
|
|
|
*/ |
39
|
|
|
public function before() |
40
|
|
|
{ |
41
|
|
|
foreach ($this->_apps as $app) { |
42
|
|
|
$this->_definedControllers[] = (string)$app->sys_name; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
parent::before(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Label form |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function labels() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
'sysname' => __('System name') |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Validation rules |
61
|
|
|
*/ |
62
|
|
|
public function rules() |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
['sysname', 'required'], |
66
|
|
|
['sysname', 'notin', $this->_definedControllers] |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function make() |
71
|
|
|
{ |
72
|
|
|
$cName = ucfirst(Str::lowerCase($this->sysname)); |
73
|
|
|
$cPath = 'Apps\Controller\Admin\\' . $cName; |
74
|
|
|
// if object class is not loaded - prevent install |
75
|
|
|
if (!class_exists($cPath) || !defined($cPath . '::VERSION')) { |
76
|
|
|
return false; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// get ext version |
80
|
|
|
$cVersion = (float)constant($cPath . '::VERSION'); |
81
|
|
|
if ($cVersion < 0.1) { |
82
|
|
|
$cVersion = 0.1; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// save row to db |
86
|
|
|
$record = new AppRecord(); |
87
|
|
|
$record->type = $this->_type; |
|
|
|
|
88
|
|
|
$record->sys_name = $cName; |
|
|
|
|
89
|
|
|
$record->name = ''; |
|
|
|
|
90
|
|
|
$record->disabled = 1; |
|
|
|
|
91
|
|
|
$record->version = $cVersion; |
|
|
|
|
92
|
|
|
$record->save(); |
93
|
|
|
|
94
|
|
|
// callback to install method in extension |
95
|
|
|
if (method_exists($cPath, 'install')) { |
96
|
|
|
call_user_func($cPath . '::install'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return true; |
100
|
|
|
} |
101
|
|
|
} |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.