Tidy up integrations, use contracts

This commit is contained in:
James Brooks
2016-07-13 14:33:20 +01:00
parent ec0f0768f0
commit 503252c3a2
9 changed files with 145 additions and 57 deletions
@@ -14,9 +14,6 @@ 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\Integrations\Credits;
use CachetHQ\Cachet\Integrations\Feed;
use CachetHQ\Cachet\Integrations\Releases;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@@ -55,9 +52,6 @@ class AppServiceProvider extends ServiceProvider
public function register() public function register()
{ {
$this->registerDateFactory(); $this->registerDateFactory();
$this->registerCredits();
$this->registerFeed();
$this->registerReleases();
} }
/** /**
@@ -74,47 +68,4 @@ class AppServiceProvider extends ServiceProvider
return new DateFactory($appTimezone, $cacheTimezone); return new DateFactory($appTimezone, $cacheTimezone);
}); });
} }
/**
* Register the credits class.
*
* @return void
*/
protected function registerCredits()
{
$this->app->singleton(Credits::class, function ($app) {
$cache = $app['cache.store'];
return new Credits($cache);
});
}
/**
* Register the feed class.
*
* @return void
*/
protected function registerFeed()
{
$this->app->singleton(Feed::class, function ($app) {
$cache = $app['cache.store'];
return new Feed($cache);
});
}
/**
* Register the releases class.
*
* @return void
*/
protected function registerReleases()
{
$this->app->singleton(Releases::class, function ($app) {
$cache = $app['cache.store'];
$token = $app['config']->get('services.github.token');
return new Releases($cache, $token);
});
}
} }
@@ -11,8 +11,14 @@
namespace CachetHQ\Cachet\Foundation\Providers; namespace CachetHQ\Cachet\Foundation\Providers;
use CachetHQ\Cachet\Integrations\Contracts\Credits as CreditsContract;
use CachetHQ\Cachet\Integrations\Contracts\Feed as FeedContract;
use CachetHQ\Cachet\Integrations\Contracts\Releases as ReleasesContract;
use CachetHQ\Cachet\Integrations\Contracts\System as SystemContract; use CachetHQ\Cachet\Integrations\Contracts\System as SystemContract;
use CachetHQ\Cachet\Integrations\Core\Credits;
use CachetHQ\Cachet\Integrations\Core\Feed;
use CachetHQ\Cachet\Integrations\Core\System; use CachetHQ\Cachet\Integrations\Core\System;
use CachetHQ\Cachet\Integrations\GitHub\Releases;
use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Container\Container;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -30,7 +36,39 @@ class IntegrationServiceProvider extends ServiceProvider
*/ */
public function register() public function register()
{ {
$this->registerCredits();
$this->registerFeed();
$this->registerSystem(); $this->registerSystem();
$this->registerReleases();
}
/**
* Register the credits class.
*
* @return void
*/
protected function registerCredits()
{
$this->app->singleton(CreditsContract::class, function ($app) {
$cache = $app['cache.store'];
return new Credits($cache);
});
}
/**
* Register the feed class.
*
* @return void
*/
protected function registerFeed()
{
$this->app->singleton(FeedContract::class, function ($app) {
$cache = $app['cache.store'];
return new Feed($cache);
});
} }
/** /**
@@ -44,4 +82,19 @@ class IntegrationServiceProvider extends ServiceProvider
return new System(); return new System();
}); });
} }
/**
* Register the releases class.
*
* @return void
*/
protected function registerReleases()
{
$this->app->singleton(ReleasesContract::class, function ($app) {
$cache = $app['cache.store'];
$token = $app['config']->get('services.github.token');
return new Releases($cache, $token);
});
}
} }
@@ -11,8 +11,8 @@
namespace CachetHQ\Cachet\Http\Controllers\Api; namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Integrations\Contracts\Releases;
use CachetHQ\Cachet\Integrations\Contracts\System; use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Integrations\Releases;
/** /**
* This is the general api controller. * This is the general api controller.
@@ -38,7 +38,7 @@ class GeneralController extends AbstractApiController
*/ */
public function version() public function version()
{ {
$latest = app(Releases::class)->latest(); $latest = app()->make(Releases::class)->latest();
return $this->setMetaData([ return $this->setMetaData([
'on_latest' => version_compare(CACHET_VERSION, $latest['tag_name']) === 1, 'on_latest' => version_compare(CACHET_VERSION, $latest['tag_name']) === 1,
+27
View File
@@ -0,0 +1,27 @@
<?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\Integrations\Contracts;
/**
* This is the credits interface.
*
* @author James Brooks <james@alt-three.com>
*/
interface Credits
{
/**
* Returns the latest credits.
*
* @return array|null
*/
public function latest();
}
+27
View File
@@ -0,0 +1,27 @@
<?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\Integrations\Contracts;
/**
* This is the feed interface.
*
* @author James Brooks <james@alt-three.com>
*/
interface Feed
{
/**
* Returns the latest entries.
*
* @return array|null
*/
public function latest();
}
+27
View File
@@ -0,0 +1,27 @@
<?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\Integrations\Contracts;
/**
* This is the releases interface.
*
* @author James Brooks <james@alt-three.com>
*/
interface Releases
{
/**
* Returns the latest release.
*
* @return string
*/
public function latest();
}
@@ -9,13 +9,14 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace CachetHQ\Cachet\Integrations; namespace CachetHQ\Cachet\Integrations\Core;
use CachetHQ\Cachet\Integrations\Contracts\Credits as CreditsContract;
use Exception; use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository; use Illuminate\Contracts\Cache\Repository;
class Credits class Credits implements CreditsContract
{ {
/** /**
* The default url. * The default url.
@@ -9,8 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace CachetHQ\Cachet\Integrations; namespace CachetHQ\Cachet\Integrations\Core;
use CachetHQ\Cachet\Integrations\Contracts\Feed as FeedContract;
use Exception; use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository; use Illuminate\Contracts\Cache\Repository;
@@ -20,7 +21,7 @@ use Illuminate\Contracts\Cache\Repository;
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
*/ */
class Feed class Feed implements FeedContract
{ {
/** /**
* The default url. * The default url.
@@ -9,12 +9,13 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace CachetHQ\Cachet\Integrations; namespace CachetHQ\Cachet\Integrations\GitHub;
use CachetHQ\Cachet\Integrations\Contracts\Releases as ReleasesContract;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository; use Illuminate\Contracts\Cache\Repository;
class Releases class Releases implements ReleasesContract
{ {
/** /**
* The default url. * The default url.