1 | <?php |
||
9 | class JsonOutput |
||
10 | { |
||
11 | private $excludedServices = array(); |
||
12 | private $config; |
||
13 | |||
14 | 2 | public function __construct(\SSpkS\Config $config) |
|
18 | |||
19 | /** |
||
20 | * Sets services to exclude from dependencies on output. |
||
21 | * |
||
22 | * @param array $excludedServices Services to exclude. |
||
23 | */ |
||
24 | 1 | public function setExcludedServices($excludedServices) |
|
28 | |||
29 | /** |
||
30 | * Checks if $obj contains $property and if not, returns $alternative. |
||
31 | * |
||
32 | * @param object $obj Object to check |
||
33 | * @param string $property Property to check for |
||
34 | * @param mixed $alternative Alternative to return if key not found |
||
35 | * @return mixed Value from $obj->$property or $alternative |
||
36 | */ |
||
37 | 2 | private function ifEmpty($obj, $property, $alternative = null) |
|
44 | |||
45 | /** |
||
46 | * Returns JSON-ready array of Package $pkg. |
||
47 | * |
||
48 | * @param \SSpkS\Package\Package $pkg Package |
||
49 | * @return array JSON-ready array of $pkg. |
||
50 | */ |
||
51 | 2 | private function packageToJson($pkg) |
|
52 | { |
||
53 | /* |
||
54 | package |
||
55 | version |
||
56 | dname - displayed name |
||
57 | desc |
||
58 | price - 0 |
||
59 | download_count - overall DL count |
||
60 | recent_download_count - DL count of last month? |
||
61 | link - URL |
||
62 | size |
||
63 | md5 |
||
64 | thumbnail - array[URL] |
||
65 | thumbnail_retina - array[URL] (optional) |
||
66 | snapshot - array[URL] (optional) |
||
67 | qinst - true/false (optional) |
||
68 | qstart - true/false (optional) |
||
69 | qupgrade - true/false (optional) |
||
70 | depsers - "pgsql" (optional) |
||
71 | deppkgs - Pkg1>Version:Pkg2:Pkg3 (optional) |
||
72 | conflictpkgs - Pkg1<Version:Pkg2:Pkg3<Version (optional) |
||
73 | start - true/false (optional) |
||
74 | maintainer - name |
||
75 | maintainer_url - URL (optional) |
||
76 | distributor - name (optional) |
||
77 | distributor_url - URL (optional) |
||
78 | changelog - HTML |
||
79 | support_url - URL (optional) |
||
80 | thirdparty - true/false (optional) |
||
81 | category - 0-128 (bits, for multiple categories?) |
||
82 | subcategory - 0 |
||
83 | type - 0 = normal, 1 = driver?, 2 = service? |
||
84 | silent_install - true/false (optional) |
||
85 | silent_uninstall - true/false (optional) |
||
86 | silent_upgrade - true/false (optional) |
||
87 | conf_deppkgs - array[Package[dsm_max_ver, pkg_min_ver]] (optional) |
||
88 | support_conf_folder - true/false (optional) |
||
89 | auto_upgrade_from - version number (optional) |
||
90 | */ |
||
91 | |||
92 | 2 | if (!empty($pkg->install_dep_services)) { |
|
93 | 1 | $deppkgs = trim(str_replace($this->excludedServices, '', $pkg->install_dep_services)); |
|
94 | 1 | } else { |
|
95 | 1 | $deppkgs = null; |
|
96 | } |
||
97 | |||
98 | $packageJSON = array( |
||
99 | 2 | 'package' => $pkg->package, |
|
100 | 2 | 'version' => $pkg->version, |
|
101 | 2 | 'dname' => $pkg->displayname, |
|
102 | 2 | 'desc' => $pkg->description, |
|
103 | 2 | 'price' => 0, |
|
104 | 2 | 'download_count' => 0, // Will only display values over 1000, do not display it by default |
|
105 | 2 | 'recent_download_count' => 0, |
|
106 | 2 | 'link' => $pkg->spk_url, |
|
107 | 2 | 'size' => filesize($pkg->spk), |
|
108 | 2 | 'md5' => md5_file($pkg->spk), |
|
109 | 2 | 'thumbnail' => $pkg->thumbnail_url, |
|
110 | 2 | 'snapshot' => $pkg->snapshot_url, |
|
111 | // quick install/start/upgrade |
||
112 | 2 | 'qinst' => $this->ifEmpty($pkg, 'qinst', false), |
|
113 | 2 | 'qstart' => $this->ifEmpty($pkg, 'start', false), |
|
114 | 2 | 'qupgrade' => $this->ifEmpty($pkg, 'qupgrade', false), |
|
115 | 2 | 'depsers' => $this->ifEmpty($pkg, 'start_dep_services'), // required started packages |
|
116 | 2 | 'deppkgs' => $deppkgs, |
|
117 | 2 | 'conflictpkgs' => null, |
|
118 | 2 | 'start' => true, |
|
119 | 2 | 'maintainer' => $this->ifEmpty($pkg, 'maintainer', $this->config->packages['maintainer']), |
|
|
|||
120 | 2 | 'maintainer_url' => $this->ifEmpty($pkg, 'maintainer_url', $this->config->packages['maintainer_url']), |
|
121 | 2 | 'distributor' => $this->ifEmpty($pkg, 'distributor', $this->config->packages['distributor']), |
|
122 | 2 | 'distributor_url' => $this->ifEmpty($pkg, 'distributor_url', $this->config->packages['distributor_url']), |
|
123 | 2 | 'changelog' => $this->ifEmpty($pkg, 'changelog', ''), |
|
124 | 2 | 'thirdparty' => true, |
|
125 | 2 | 'category' => 0, |
|
126 | 2 | 'subcategory' => 0, |
|
127 | 2 | 'type' => 0, |
|
128 | 2 | 'silent_install' => $this->ifEmpty($pkg, 'silent_install', false), |
|
129 | 2 | 'silent_uninstall' => $this->ifEmpty($pkg, 'silent_uninstall', false), |
|
130 | 2 | 'silent_upgrade' => $this->ifEmpty($pkg, 'silent_upgrade', false), |
|
131 | 2 | 'beta' => $pkg->beta, // beta channel |
|
132 | 2 | ); |
|
133 | 2 | return $packageJSON; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * Outputs given packages as JSON. |
||
138 | * |
||
139 | * @param \SSpkS\Package\Package[] $pkgList List of packages to output. |
||
140 | */ |
||
141 | 2 | public function outputPackages($pkgList) |
|
161 | } |
||
162 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read 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.