11<?php
2- /**
3- * Pterodactyl - Panel
4- * Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5- *
6- * This software is licensed under the terms of the MIT license.
7- * https://opensource.org/licenses/MIT
8- */
92
103namespace Pterodactyl \Services \Helpers ;
114
12- use stdClass ;
135use Exception ;
146use GuzzleHttp \Client ;
157use Cake \Chronos \Chronos ;
8+ use Illuminate \Support \Arr ;
169use Illuminate \Contracts \Cache \Repository as CacheRepository ;
17- use Illuminate \Contracts \Config \Repository as ConfigRepository ;
1810use Pterodactyl \Exceptions \Service \Helper \CdnVersionFetchingException ;
1911
2012class SoftwareVersionService
2113{
22- const VERSION_CACHE_KEY = 'pterodactyl:versions ' ;
14+ const VERSION_CACHE_KEY = 'pterodactyl:versioning_data ' ;
15+
16+ /**
17+ * @var array
18+ */
19+ private static $ result ;
2320
2421 /**
2522 * @var \Illuminate\Contracts\Cache\Repository
@@ -31,28 +28,20 @@ class SoftwareVersionService
3128 */
3229 protected $ client ;
3330
34- /**
35- * @var \Illuminate\Contracts\Config\Repository
36- */
37- protected $ config ;
38-
3931 /**
4032 * SoftwareVersionService constructor.
4133 *
4234 * @param \Illuminate\Contracts\Cache\Repository $cache
4335 * @param \GuzzleHttp\Client $client
44- * @param \Illuminate\Contracts\Config\Repository $config
4536 */
4637 public function __construct (
4738 CacheRepository $ cache ,
48- Client $ client ,
49- ConfigRepository $ config
39+ Client $ client
5040 ) {
5141 $ this ->cache = $ cache ;
5242 $ this ->client = $ client ;
53- $ this ->config = $ config ;
5443
55- $ this ->cacheVersionData ();
44+ self :: $ result = $ this ->cacheVersionData ();
5645 }
5746
5847 /**
@@ -62,7 +51,7 @@ public function __construct(
6251 */
6352 public function getPanel ()
6453 {
65- return object_get ( $ this -> cache -> get (self ::VERSION_CACHE_KEY ) , 'panel ' , 'error ' ) ;
54+ return Arr:: get (self ::$ result , 'panel ' ) ?? 'error ' ;
6655 }
6756
6857 /**
@@ -72,7 +61,7 @@ public function getPanel()
7261 */
7362 public function getDaemon ()
7463 {
75- return object_get ( $ this -> cache -> get (self ::VERSION_CACHE_KEY ) , 'daemon ' , 'error ' ) ;
64+ return Arr:: get (self ::$ result , 'daemon ' ) ?? 'error ' ;
7665 }
7766
7867 /**
@@ -82,7 +71,17 @@ public function getDaemon()
8271 */
8372 public function getDiscord ()
8473 {
85- return object_get ($ this ->cache ->get (self ::VERSION_CACHE_KEY ), 'discord ' , 'https://pterodactyl.io/discord ' );
74+ return Arr::get (self ::$ result , 'discord ' ) ?? 'https://pterodactyl.io/discord ' ;
75+ }
76+
77+ /**
78+ * Get the URL for donations.
79+ *
80+ * @return string
81+ */
82+ public function getDonations ()
83+ {
84+ return Arr::get (self ::$ result , 'donations ' ) ?? 'https://paypal.me/PterodactylSoftware ' ;
8685 }
8786
8887 /**
@@ -92,11 +91,11 @@ public function getDiscord()
9291 */
9392 public function isLatestPanel ()
9493 {
95- if ($ this -> config ->get ('app.version ' ) === 'canary ' ) {
94+ if (config () ->get ('app.version ' ) === 'canary ' ) {
9695 return true ;
9796 }
9897
99- return version_compare ($ this -> config ->get ('app.version ' ), $ this ->getPanel ()) >= 0 ;
98+ return version_compare (config () ->get ('app.version ' ), $ this ->getPanel ()) >= 0 ;
10099 }
101100
102101 /**
@@ -116,20 +115,22 @@ public function isLatestDaemon($version)
116115
117116 /**
118117 * Keeps the versioning cache up-to-date with the latest results from the CDN.
118+ *
119+ * @return array
119120 */
120121 protected function cacheVersionData ()
121122 {
122- $ this ->cache ->remember (self ::VERSION_CACHE_KEY , Chronos::now ()->addMinutes (config ('pterodactyl.cdn.cache_time ' )), function () {
123+ return $ this ->cache ->remember (self ::VERSION_CACHE_KEY , Chronos::now ()->addMinutes (config ()-> get ( 'pterodactyl.cdn.cache_time ' , 60 )), function () {
123124 try {
124- $ response = $ this ->client ->request ('GET ' , $ this -> config ->get ('pterodactyl.cdn.url ' ));
125+ $ response = $ this ->client ->request ('GET ' , config () ->get ('pterodactyl.cdn.url ' ));
125126
126127 if ($ response ->getStatusCode () === 200 ) {
127- return json_decode ($ response ->getBody ());
128+ return json_decode ($ response ->getBody (), true );
128129 }
129130
130131 throw new CdnVersionFetchingException ;
131132 } catch (Exception $ exception ) {
132- return new stdClass () ;
133+ return [] ;
133134 }
134135 });
135136 }
0 commit comments