Cleaned up the release class and provider (#1820)

This commit is contained in:
Graham Campbell
2016-05-25 09:52:44 +01:00
parent 5534cdbdde
commit 0566133c12
4 changed files with 28 additions and 58 deletions
@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Foundation\Providers;
use AltThree\Bus\Dispatcher; use AltThree\Bus\Dispatcher;
use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions; use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions;
use CachetHQ\Cachet\Dates\DateFactory; use CachetHQ\Cachet\Dates\DateFactory;
use CachetHQ\Cachet\GitHub\Release;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@@ -52,6 +53,7 @@ class AppServiceProvider extends ServiceProvider
public function register() public function register()
{ {
$this->registerDateFactory(); $this->registerDateFactory();
$this->registerRelease();
} }
/** /**
@@ -62,10 +64,25 @@ class AppServiceProvider extends ServiceProvider
protected function registerDateFactory() protected function registerDateFactory()
{ {
$this->app->singleton(DateFactory::class, function ($app) { $this->app->singleton(DateFactory::class, function ($app) {
$appTimezone = $app->config->get('app.timezone'); $appTimezone = $app['config']->get('app.timezone');
$cacheTimezone = $app->config->get('cachet.timezone'); $cacheTimezone = $app['config']->get('cachet.timezone');
return new DateFactory($appTimezone, $cacheTimezone); return new DateFactory($appTimezone, $cacheTimezone);
}); });
} }
/**
* Register the releases class.
*
* @return void
*/
protected function registerRelease()
{
$this->app->singleton(Release::class, function ($app) {
$cache = $app['cache.store'];
$token = $app['config']->get('services.github.token')
return new Release($cache, $token);
});
}
} }
@@ -1,45 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Foundation\Providers;
use CachetHQ\Cachet\GitHub\Release;
use Illuminate\Support\ServiceProvider;
class GitHubServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerRelease();
}
/**
* Register the releases class.
*
* @return void
*/
protected function registerRelease()
{
$this->app->singleton('cachet.release', function ($app) {
$cache = $app['cache.store'];
$config = $app['config'];
return new Release($cache, $config);
});
$this->app->alias('cachet.release', Release::class);
}
}
+9 -10
View File
@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\GitHub;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository as CacheRepository; use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class Release class Release
{ {
@@ -25,24 +24,24 @@ class Release
protected $cache; protected $cache;
/** /**
* The config repository instance. * The github authentication token.
* *
* @var \Illuminate\Contracts\Config\Repository * @var string
*/ */
protected $config; protected $token;
/** /**
* Creates a new release instance. * Creates a new release instance.
* *
* @param \Illuminate\Contracts\Cache\Repository $cache * @param \Illuminate\Contracts\Cache\Repository $cache
* @param \Illuminate\Contracts\Config\Repository $config * @param string $token
* *
* @return void * @return void
*/ */
public function __construct(CacheRepository $cache, ConfigRepository $config) public function __construct(CacheRepository $cache, $token)
{ {
$this->cache = $cache; $this->cache = $cache;
$this->config = $config; $this->token = $token;
} }
/** /**
@@ -56,8 +55,8 @@ class Release
$headers = ['Accept' => 'application/vnd.github.v3+json']; $headers = ['Accept' => 'application/vnd.github.v3+json'];
// We can re-use the Emoji token here, if we have it. // We can re-use the Emoji token here, if we have it.
if ($token = $this->config->get('services.github.token')) { if ($this->token) {
$headers['OAUTH-TOKEN'] = $token; $headers['OAUTH-TOKEN'] = $this->token;
} }
return json_decode((new Client())->get('https://api.github.com/repos/cachethq/cachet/releases/latest', [ return json_decode((new Client())->get('https://api.github.com/repos/cachethq/cachet/releases/latest', [
-1
View File
@@ -184,7 +184,6 @@ return [
'CachetHQ\Cachet\Foundation\Providers\ConsoleServiceProvider', 'CachetHQ\Cachet\Foundation\Providers\ConsoleServiceProvider',
'CachetHQ\Cachet\Foundation\Providers\ConfigServiceProvider', 'CachetHQ\Cachet\Foundation\Providers\ConfigServiceProvider',
'CachetHQ\Cachet\Foundation\Providers\EventServiceProvider', 'CachetHQ\Cachet\Foundation\Providers\EventServiceProvider',
'CachetHQ\Cachet\Foundation\Providers\GitHubServiceProvider',
'CachetHQ\Cachet\Foundation\Providers\RepositoryServiceProvider', 'CachetHQ\Cachet\Foundation\Providers\RepositoryServiceProvider',
'CachetHQ\Cachet\Foundation\Providers\RouteServiceProvider', 'CachetHQ\Cachet\Foundation\Providers\RouteServiceProvider',