Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3750548
D180.id428.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D180.id428.diff
View Options
diff --git a/app/Console/Commands/ConfigShow.php b/app/Console/Commands/ConfigShow.php
--- a/app/Console/Commands/ConfigShow.php
+++ b/app/Console/Commands/ConfigShow.php
@@ -6,9 +6,10 @@
use Nasqueron\Notifications\Phabricator\ProjectsMap;
use Nasqueron\Notifications\Features;
-use Nasqueron\Notifications\Services;
use Config;
+use Services;
+
class ConfigShow extends Command
{
diff --git a/app/Console/Commands/PhabricatorGetProjectsMap.php b/app/Console/Commands/PhabricatorGetProjectsMap.php
--- a/app/Console/Commands/PhabricatorGetProjectsMap.php
+++ b/app/Console/Commands/PhabricatorGetProjectsMap.php
@@ -3,10 +3,11 @@
namespace Nasqueron\Notifications\Console\Commands;
use Illuminate\Console\Command;
-use Storage;
use Nasqueron\Notifications\Phabricator\ProjectsMap;
-use Nasqueron\Notifications\Services;
+
+use Services;
+use Storage;
class PhabricatorGetProjectsMap extends Command {
/**
diff --git a/app/Facades/Services.php b/app/Facades/Services.php
new file mode 100644
--- /dev/null
+++ b/app/Facades/Services.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Nasqueron\Notifications\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+/**
+ * @see \Nasqueron\Notifications\Services\Services
+ */
+class Services extends Facade {
+
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor() {
+ return 'services';
+ }
+
+}
diff --git a/app/Http/Controllers/Gate/GateController.php b/app/Http/Controllers/Gate/GateController.php
--- a/app/Http/Controllers/Gate/GateController.php
+++ b/app/Http/Controllers/Gate/GateController.php
@@ -3,12 +3,14 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
use Nasqueron\Notifications\Features;
-use Nasqueron\Notifications\Services;
use Nasqueron\Notifications\Http\Controllers\Controller;
+use Nasqueron\Notifications\Services\Services as ServicesContract;
+
use App;
use Report;
use Response;
+use Services;
use Storage;
/**
diff --git a/app/Phabricator/PhabricatorAPI.php b/app/Phabricator/PhabricatorAPI.php
--- a/app/Phabricator/PhabricatorAPI.php
+++ b/app/Phabricator/PhabricatorAPI.php
@@ -2,7 +2,7 @@
namespace Nasqueron\Notifications\Phabricator;
-use Nasqueron\Notifications\Services;
+use Services;
class PhabricatorAPI {
diff --git a/app/Providers/ServicesServiceProvider.php b/app/Providers/ServicesServiceProvider.php
new file mode 100644
--- /dev/null
+++ b/app/Providers/ServicesServiceProvider.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Nasqueron\Notifications\Providers;
+
+use Illuminate\Events\Dispatcher;
+use Illuminate\Support\ServiceProvider;
+
+use Nasqueron\Notifications\Actions\ActionsReport;
+use Nasqueron\Notifications\Events\ReportEvent;
+use Nasqueron\Notifications\Services\Services;
+
+class ServicesServiceProvider extends ServiceProvider {
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ *
+ * @SuppressWarnings(PHPMD.UnusedLocalVariable)
+ */
+ public function register() {
+ $this->app->singleton('services', function ($app) {
+ $path = config('services.gate.credentials');
+ return Services::loadFromJson($path);
+ });
+ }
+}
diff --git a/app/Services/Service.php b/app/Services/Service.php
new file mode 100644
--- /dev/null
+++ b/app/Services/Service.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace Nasqueron\Notifications\Services;
+
+class Service {
+ /**
+ * @var string
+ */
+ public $gate;
+
+ /**
+ * @var string
+ */
+ public $door;
+
+ /**
+ * @var string
+ */
+ public $instance;
+
+ /**
+ * @var string
+ */
+ public $secret;
+}
diff --git a/app/Services.php b/app/Services/Services.php
rename from app/Services.php
rename to app/Services/Services.php
--- a/app/Services.php
+++ b/app/Services/Services.php
@@ -1,12 +1,41 @@
<?php
-namespace Nasqueron\Notifications;
+namespace Nasqueron\Notifications\Services;
use Storage;
class Services {
///
+ /// Properties
+ ///
+
+ /**
+ * @var Service[]
+ */
+ public $services;
+
+ ///
+ /// Constructors
+ ///
+
+ public function __construct () {
+
+ }
+
+ public static function loadFromJson ($file) {
+ $data = json_decode(Storage::get($file));
+
+ $mapper = new \JsonMapper();
+ $instance = $mapper->map(
+ $data,
+ new self()
+ );
+
+ return $instance;
+ }
+
+ ///
/// Methods to get a list of services
///
@@ -15,10 +44,8 @@
*
* @return array
*/
- public static function get () {
- $path = config('services.gate.credentials');
- $data = json_decode(Storage::get($path));
- return $data->services;
+ public function get () {
+ return $this->services;
}
/**
@@ -27,10 +54,10 @@
* @param string $gate The gate (e.g. GitHub)
* @return array
*/
- public static function getForGate ($gate) {
+ public function getForGate ($gate) {
$services = [];
- foreach (self::get() as $service) {
+ foreach ($this->services as $service) {
if ($service->gate === $gate) {
$services[] = $service;
}
@@ -50,8 +77,8 @@
* @param string $door The door (e.g. Nasqueron)
* @return stdClass|null The service information is found; otherwise, null.
*/
- public static function findServiceByDoor ($gate, $door) {
- foreach (self::get() as $service) {
+ public function findServiceByDoor ($gate, $door) {
+ foreach ($this->services as $service) {
if ($service->gate === $gate && $service->door === $door) {
return $service;
}
@@ -68,8 +95,8 @@
* @param mixed $value The property value to find (e.g. 'http://devcentral.nasqueron.org')
* @return stdClass|null The service information is found; otherwise, null.
*/
- public static function findServiceByProperty ($gate, $property, $value) {
- foreach (Services::get() as $service) {
+ public function findServiceByProperty ($gate, $property, $value) {
+ foreach ($this->services as $service) {
if ($service->gate === $gate && $service->$property === $value) {
return $service;
}
diff --git a/config/app.php b/config/app.php
--- a/config/app.php
+++ b/config/app.php
@@ -166,6 +166,7 @@
Nasqueron\Notifications\Providers\EventServiceProvider::class,
Nasqueron\Notifications\Providers\ReportServiceProvider::class,
Nasqueron\Notifications\Providers\RouteServiceProvider::class,
+ Nasqueron\Notifications\Providers\ServicesServiceProvider::class
],
@@ -213,6 +214,7 @@
'Route' => Illuminate\Support\Facades\Route::class,
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
+ 'Services' => Nasqueron\Notifications\Facades\Services::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 18, 01:28 (19 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2250051
Default Alt Text
D180.id428.diff (7 KB)
Attached To
Mode
D180: Refactor Services as a Facade to a more generic Services class
Attached
Detach File
Event Timeline
Log In to Comment