1 | <?php |
||
23 | class InitController extends TemplateController |
||
24 | { |
||
25 | protected $_file = '.hidev/config.yml'; |
||
26 | |||
27 | public $name; |
||
28 | public $vendor; |
||
29 | public $package; |
||
30 | |||
31 | 3 | public function prepareData($name) |
|
32 | { |
||
33 | 3 | $this->name = $name; |
|
34 | list($vendor, $package) = explode('/', $name, 2); |
||
35 | 3 | if ($vendor) { |
|
36 | 3 | $this->vendor = $vendor; |
|
37 | 3 | $vendorPlugin = "$vendor/hidev-$vendor"; |
|
38 | try { |
||
39 | $exists = @file_get_contents("https://packagist.org/packages/$vendorPlugin.json"); |
||
40 | } catch (Exception $e) { |
||
41 | $exists = false; |
||
42 | 3 | } |
|
43 | 3 | if ($exists) { |
|
44 | $this->setItem('vendorRequire', $vendorPlugin); |
||
45 | $this->setItem('novendor', true); |
||
|
|||
46 | } |
||
47 | } |
||
48 | 3 | if ($package) { |
|
49 | 3 | $this->package = $package; |
|
50 | } |
||
51 | 3 | if (!$this->package || !$this->vendor) { |
|
52 | throw new InvalidParamException('Wrong vendor/package given: ' . $name); |
||
53 | } |
||
54 | 3 | } |
|
55 | |||
56 | 3 | public function actionPerform($name = null, $template = '.hidev/config') |
|
57 | { |
||
58 | 3 | $this->_template = $template; |
|
59 | $this->prepareData($name); |
||
60 | if (!file_exists($this->dirname)) { |
||
61 | mkdir($this->dirname); |
||
62 | } |
||
63 | if (!$this->nocomposer) { |
||
64 | $this->actionComposer(); |
||
65 | } |
||
66 | |||
67 | return parent::actionPerform(); |
||
68 | } |
||
69 | |||
70 | 2 | public function actionComposer() |
|
71 | { |
||
72 | $file = new File(['path' => 'composer.json']); |
||
73 | $data = array_filter([ |
||
74 | 2 | 'name' => $this->name, |
|
75 | 2 | 'type' => $this->getType(), |
|
76 | 2 | 'description' => $this->getTitle(), |
|
77 | 'keywords' => preg_split('/\s*,\s*/', $this->getKeywords()), |
||
78 | 2 | 'require-dev' => $this->getPlugins(), |
|
79 | 2 | 'license' => $this->getItem('license'), |
|
80 | ]); |
||
81 | $file->save($data); |
||
82 | $this->setItem('norequire', true); |
||
83 | 2 | } |
|
84 | |||
85 | public function options($actionId) |
||
86 | { |
||
87 | return array_merge(parent::options($actionId), explode(',', 'namespace,headline,title,type,license,keywords,description,year,nick,author,email,novendor,norequire,nocomposer')); |
||
88 | } |
||
89 | |||
90 | public function getType() |
||
94 | |||
95 | public function getTitle() |
||
99 | |||
100 | public function getKeywords() |
||
104 | |||
105 | /// TODO think of better getting nick |
||
106 | public function getNick() |
||
110 | |||
111 | public function getAuthor() |
||
115 | |||
116 | public function getEmail() |
||
120 | |||
121 | /** |
||
122 | * Returns list of plugins in composer requirements format: name => version. |
||
123 | * @return array |
||
124 | */ |
||
125 | 2 | public function getPlugins() |
|
139 | } |
||
140 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: