Page MenuHomeDevCentral

D180.id431.diff
No OneTemporary

D180.id431.diff

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,12 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
use Nasqueron\Notifications\Features;
-use Nasqueron\Notifications\Services;
use Nasqueron\Notifications\Http\Controllers\Controller;
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,38 @@
<?php
-namespace Nasqueron\Notifications;
+namespace Nasqueron\Notifications\Services;
use Storage;
class Services {
///
+ /// Properties
+ ///
+
+ /**
+ * @var Service[]
+ */
+ public $services = [];
+
+ ///
+ /// Constructors
+ ///
+
+ /**
+ * Initializes a new instance of the Services class deserializing a JSON file.
+ *
+ * @param $file the JSON file to deserialize
+ * @return Services the deserialized instance
+ */
+ public static function loadFromJson ($file) {
+ $data = json_decode(Storage::get($file));
+ $mapper = new \JsonMapper();
+
+ return $mapper->map($data, new self());
+ }
+
+ ///
/// Methods to get a list of services
///
@@ -15,10 +41,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 +51,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 +74,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 +92,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

Mime Type
text/plain
Expires
Mon, Nov 18, 07:35 (22 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2250332
Default Alt Text
D180.id431.diff (7 KB)

Event Timeline