Namespaced models and refactored filters
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Commands;
|
||||
namespace CachetHQ\Cachet\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
28
src/Http/After/AllowedDomainsFilter.php
Normal file
28
src/Http/After/AllowedDomainsFilter.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\After;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AllowedDomainsFilter
|
||||
{
|
||||
public function filter(Route $route, Request $request, Response $response)
|
||||
{
|
||||
// Always allow our own domain.
|
||||
$ourDomain = Setting::get('app_domain');
|
||||
$response->headers->set('Access-Control-Allow-Origin', $ourDomain);
|
||||
|
||||
// Should we allow anyone else?
|
||||
if ($setting = Setting::get('allowed_domains')) {
|
||||
$domains = explode(',', $setting);
|
||||
foreach ($domains as $domain) {
|
||||
$response->headers->set('Access-Control-Allow-Origin', $domain);
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
17
src/Http/After/CorsFilter.php
Normal file
17
src/Http/After/CorsFilter.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\After;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CorsFilter
|
||||
{
|
||||
public function filter(Route $route, Request $request, Response $response)
|
||||
{
|
||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
13
src/Http/Before/AuthBasicFilter.php
Normal file
13
src/Http/Before/AuthBasicFilter.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Before;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthBasicFilter
|
||||
{
|
||||
public function filter()
|
||||
{
|
||||
return Auth::basic();
|
||||
}
|
||||
}
|
||||
23
src/Http/Before/AuthFilter.php
Normal file
23
src/Http/Before/AuthFilter.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Before;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class AuthFilter
|
||||
{
|
||||
public function filter(Route $route, Request $request)
|
||||
{
|
||||
if (Auth::guest()) {
|
||||
if ($request->ajax()) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
} else {
|
||||
return Redirect::guest('auth/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Http/Before/CsrfFilter.php
Normal file
17
src/Http/Before/CsrfFilter.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Before;
|
||||
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class CsrfFilter
|
||||
{
|
||||
public function filter()
|
||||
{
|
||||
if (Session::token() !== Input::get('_token')) {
|
||||
throw new TokenMismatchException();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/Http/Before/GuestFilter.php
Normal file
16
src/Http/Before/GuestFilter.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Before;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class GuestFilter
|
||||
{
|
||||
public function filter()
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/Http/Before/HasSettingFilter.php
Normal file
24
src/Http/Before/HasSettingFilter.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Before;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class HasSettingFilter
|
||||
{
|
||||
public function filter(Route $route, Request $request, $settingName)
|
||||
{
|
||||
try {
|
||||
$setting = Setting::where('name', $settingName)->first();
|
||||
if (!$setting->value) {
|
||||
return Redirect::to('setup');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Redirect::to('setup');
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/Http/Before/IsSetupFilter.php
Normal file
24
src/Http/Before/IsSetupFilter.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Before;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class IsSetupFilter
|
||||
{
|
||||
public function filter(Route $route, Request $request)
|
||||
{
|
||||
try {
|
||||
$setting = Setting::where('name', 'app_name')->first();
|
||||
if ($setting->value) {
|
||||
return Redirect::to('/dashboard');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/Http/Before/LoginThrottlingFilter.php
Normal file
21
src/Http/Before/LoginThrottlingFilter.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Before;
|
||||
|
||||
use GrahamCampbell\Throttle\Facades\Throttle;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class LoginThrottlingFilter
|
||||
{
|
||||
public function filter(Route $route, Request $request)
|
||||
{
|
||||
// check if we've reached the rate limit, but don't hit the throttle yet
|
||||
// we can hit the throttle later on in the if validation passes
|
||||
if (!Throttle::check($request, 10, 10)) {
|
||||
return Redirect::back()
|
||||
->with('error', 'You have made too many login requests.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
@@ -45,7 +45,7 @@ class ComponentController extends Controller
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Component
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function getComponent($id)
|
||||
{
|
||||
@@ -55,9 +55,9 @@ class ComponentController extends Controller
|
||||
/**
|
||||
* Return a component with incidents.
|
||||
*
|
||||
* @param int $id Component ID
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Component
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function getComponentIncidents($id)
|
||||
{
|
||||
@@ -67,7 +67,7 @@ class ComponentController extends Controller
|
||||
/**
|
||||
* Create a new component.
|
||||
*
|
||||
* @return \Component
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postComponents()
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
@@ -45,7 +45,7 @@ class IncidentController extends Controller
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Incident
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function getIncident($id)
|
||||
{
|
||||
@@ -55,7 +55,7 @@ class IncidentController extends Controller
|
||||
/**
|
||||
* Create a new incident.
|
||||
*
|
||||
* @return \Incident
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function postIncidents()
|
||||
{
|
||||
@@ -67,7 +67,7 @@ class IncidentController extends Controller
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Incident
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function putIncident($id)
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
@@ -44,7 +44,7 @@ class MetricController extends Controller
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Metric
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function getMetric($id)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ class MetricController extends Controller
|
||||
/**
|
||||
* Create a new metric.
|
||||
*
|
||||
* @return \Metric
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function postMetrics()
|
||||
{
|
||||
@@ -66,7 +66,7 @@ class MetricController extends Controller
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Metric
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function putMetric($id)
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
@@ -44,7 +44,7 @@ class MetricPointController extends Controller
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \MetricPoint
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function getMetricPoint($id)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ class MetricPointController extends Controller
|
||||
/**
|
||||
* Create a new metric point.
|
||||
*
|
||||
* @return \MetricPoint
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function postMetricPoints()
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use GrahamCampbell\Throttle\Facades\Throttle;
|
||||
use Illuminate\Routing\Controller;
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use Component;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Exception;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
@@ -12,11 +12,11 @@ class DashAPIController extends Controller
|
||||
/**
|
||||
* Updates a component with the entered info.
|
||||
*
|
||||
* @param \Component $component
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return \Component
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postUpdateComponent(Component $component)
|
||||
{
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use Component;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
@@ -28,7 +28,7 @@ class DashComponentController extends Controller
|
||||
/**
|
||||
* Shows the edit component view.
|
||||
*
|
||||
* @param \Component $component
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ class DashComponentController extends Controller
|
||||
/**
|
||||
* Updates a component.
|
||||
*
|
||||
* @param \Component $component
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
@@ -83,7 +83,7 @@ class DashComponentController extends Controller
|
||||
/**
|
||||
* Deletes a given component.
|
||||
*
|
||||
* @param \Component $component
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Incident;
|
||||
use IncidentTemplate;
|
||||
|
||||
class DashIncidentController extends Controller
|
||||
{
|
||||
@@ -79,7 +79,7 @@ class DashIncidentController extends Controller
|
||||
/**
|
||||
* Deletes a given incident.
|
||||
*
|
||||
* @param \Incident $incident
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Exception;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Setting;
|
||||
|
||||
class DashSettingsController extends Controller
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use Component;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Carbon\Carbon;
|
||||
use Component;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Incident;
|
||||
use Setting;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Incident;
|
||||
use Setting;
|
||||
use Thujohn\Rss\RssFacade;
|
||||
|
||||
class RssController extends Controller
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Setting;
|
||||
use User;
|
||||
|
||||
class SetupController extends Controller
|
||||
{
|
||||
90
src/Models/Component.php
Normal file
90
src/Models/Component.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use CachetHQ\Cachet\Transformers\ComponentTransformer;
|
||||
use Dingo\Api\Transformer\TransformableInterface;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Component extends Model implements TransformableInterface
|
||||
{
|
||||
use SoftDeletingTrait, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'user_id' => 'integer|required',
|
||||
'name' => 'required',
|
||||
'status' => 'integer',
|
||||
'link' => 'url',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'description', 'status', 'user_id', 'tags', 'link', 'order'];
|
||||
|
||||
/**
|
||||
* Lookup all of the incidents reported on the component.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function incidents()
|
||||
{
|
||||
return $this->hasMany('CachetHQ\Cachet\Models\Incident', 'component_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all components by status.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $status
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeStatus(Builder $query, $status)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all components which don't have the given status.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $status
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeNotStatus(Builder $query, $status)
|
||||
{
|
||||
return $query->where('status', '<>', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the human readable version of the status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute()
|
||||
{
|
||||
return trans('cachet.component.status.'.$this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Transformers\ComponentTransformer
|
||||
*/
|
||||
public function getTransformer()
|
||||
{
|
||||
return new ComponentTransformer();
|
||||
}
|
||||
}
|
||||
113
src/Models/Incident.php
Normal file
113
src/Models/Incident.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use CachetHQ\Cachet\Transformers\IncidentTransformer;
|
||||
use Dingo\Api\Transformer\TransformableInterface;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Incident extends Model implements TransformableInterface
|
||||
{
|
||||
use SoftDeletingTrait, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'user_id' => 'required|integer',
|
||||
'component_id' => 'integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer',
|
||||
'message' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['user_id', 'component_id', 'name', 'status', 'message'];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's serialized form.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $appends = ['humanStatus'];
|
||||
|
||||
/**
|
||||
* An incident belongs to a component.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function component()
|
||||
{
|
||||
return $this->belongsTo('CachetHQ\Cachet\Models\Component', 'component_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human readable version of the status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute()
|
||||
{
|
||||
$statuses = trans('cachet.incident.status');
|
||||
|
||||
return $statuses[$this->status];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the icon to use for each status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIconAttribute()
|
||||
{
|
||||
switch ($this->status) {
|
||||
case 1:
|
||||
return 'ion ion-flag';
|
||||
case 2:
|
||||
return 'ion ion-alert';
|
||||
case 3:
|
||||
return 'ion ion-eye';
|
||||
case 4:
|
||||
return 'ion ion-checkmark';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Markdown formatted version of the status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedMessageAttribute()
|
||||
{
|
||||
return Markdown::render($this->message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Transformers\IncidentTransformer
|
||||
*/
|
||||
public function getTransformer()
|
||||
{
|
||||
return new IncidentTransformer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Incident has message.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMessage()
|
||||
{
|
||||
return (trim($this->message) !== '');
|
||||
}
|
||||
}
|
||||
43
src/Models/IncidentTemplate.php
Normal file
43
src/Models/IncidentTemplate.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Str;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class IncidentTemplate extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'name' => 'alpha|required',
|
||||
'template' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'template'];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::saving(function ($template) {
|
||||
$template->slug = Str::slug($template->name);
|
||||
});
|
||||
}
|
||||
}
|
||||
61
src/Models/Metric.php
Normal file
61
src/Models/Metric.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use CachetHQ\Cachet\Transformers\MetricTransformer;
|
||||
use Dingo\Api\Transformer\TransformableInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Metric extends Model implements TransformableInterface
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'name' => 'required',
|
||||
'suffix' => 'required',
|
||||
'display_chart' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'suffix', 'description', 'display_chart'];
|
||||
|
||||
/**
|
||||
* Metrics contain many metric points.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function points()
|
||||
{
|
||||
return $this->hasMany('CachetHQ\Cachet\Models\MetricPoint', 'metric_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a chart should be shown.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getShouldDisplayAttribute()
|
||||
{
|
||||
return $this->display_chart === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Transformers\MetricTransformer
|
||||
*/
|
||||
public function getTransformer()
|
||||
{
|
||||
return new MetricTransformer();
|
||||
}
|
||||
}
|
||||
18
src/Models/MetricPoint.php
Normal file
18
src/Models/MetricPoint.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MetricPoint extends Model
|
||||
{
|
||||
/**
|
||||
* A metric point belongs to a metric unit.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function metric()
|
||||
{
|
||||
return $this->belongsTo('CachetHQ\Cachet\Models\Metric', 'id', 'metric_id');
|
||||
}
|
||||
}
|
||||
44
src/Models/Service.php
Normal file
44
src/Models/Service.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Service extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'type' => 'alpha_dash|required',
|
||||
'active' => 'required|in:0,1',
|
||||
'properties' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns a decoded properties object for the service.
|
||||
*
|
||||
* @param string $properties
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getPropertiesAttribute($properties)
|
||||
{
|
||||
return json_decode($properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the properties attribute which auto encodes to a JSON string.
|
||||
*
|
||||
* @param mixed $properties
|
||||
*/
|
||||
public function setPropertiesAttribute($properties)
|
||||
{
|
||||
$this->attributes['properties'] = json_encode($properties);
|
||||
}
|
||||
}
|
||||
43
src/Models/Setting.php
Normal file
43
src/Models/Setting.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'value'];
|
||||
|
||||
/**
|
||||
* Returns a setting from the database.
|
||||
*
|
||||
* @param string $settingName
|
||||
* @param bool $checkEnv
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function get($settingName, $checkEnv = true)
|
||||
{
|
||||
$setting = null;
|
||||
|
||||
try {
|
||||
$setting = self::whereName($settingName)->first()->value;
|
||||
} catch (ErrorException $e) {
|
||||
if ($checkEnv) {
|
||||
$env = getenv(strtoupper($settingName));
|
||||
if (!$env) {
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
return $setting;
|
||||
}
|
||||
|
||||
return $setting;
|
||||
}
|
||||
}
|
||||
28
src/Models/Subscriber.php
Normal file
28
src/Models/Subscriber.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Subscriber extends Model
|
||||
{
|
||||
use SoftDeletingTrait, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'email' => 'required|email',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['email'];
|
||||
}
|
||||
64
src/Models/User.php
Normal file
64
src/Models/User.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Auth\Reminders\RemindableInterface;
|
||||
use Illuminate\Auth\Reminders\RemindableTrait;
|
||||
use Illuminate\Auth\UserInterface;
|
||||
use Illuminate\Auth\UserTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class User extends Model implements UserInterface, RemindableInterface
|
||||
{
|
||||
use UserTrait, RemindableTrait;
|
||||
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users';
|
||||
|
||||
/**
|
||||
* The hidden properties.
|
||||
*
|
||||
* These are excluded when we are serializing the model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
/**
|
||||
* The properties that cannot be mass assigned.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Hash any password being inserted by default.
|
||||
*
|
||||
* @param string $password
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPasswordAttribute($password)
|
||||
{
|
||||
$this->attributes['password'] = Hash::make($password);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Gravatar URL for the users email address.
|
||||
*
|
||||
* @param int $size
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGravatarAttribute($size = 200)
|
||||
{
|
||||
return sprintf('https://www.gravatar.com/avatar/%s?size=%d', md5($this->email), $size);
|
||||
}
|
||||
}
|
||||
122
src/Models/WebHook.php
Normal file
122
src/Models/WebHook.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebHook extends Model
|
||||
{
|
||||
const HEAD = 0;
|
||||
const GET = 1;
|
||||
const POST = 2;
|
||||
const PATCH = 3;
|
||||
const PUT = 4;
|
||||
const DELETE = 5;
|
||||
|
||||
/**
|
||||
* Returns all responses for a WebHook.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function response()
|
||||
{
|
||||
return $this->hasMany('WebHookContent', 'hook_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all active hooks.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeActive(Builder $query)
|
||||
{
|
||||
return $query->where('active', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups a ping event that is fired upon a web hook.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\WebHookResponse
|
||||
*/
|
||||
public function ping()
|
||||
{
|
||||
return $this->fire('ping', 'Coming live to you from Cachet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires the actual web hook event.
|
||||
*
|
||||
* @param string $eventType The event to send X-Cachet-Event
|
||||
* @param mixed $data Data to send to the Web Hook
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\WebHookResponse
|
||||
*/
|
||||
public function fire($eventType, $data = null)
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
|
||||
$client = new Client();
|
||||
$request = $client->createRequest($this->requestMethod, $this->endpoint, [
|
||||
'headers' => [
|
||||
'X-Cachet-Event' => $eventType,
|
||||
],
|
||||
'body' => $data
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = $client->send($request);
|
||||
} catch (ClientException $e) {
|
||||
// Do nothing with the exception, we want it.
|
||||
$response = $e->getResponse();
|
||||
}
|
||||
|
||||
$timeTaken = microtime(true) - $startTime;
|
||||
|
||||
// Store the request
|
||||
$hookResponse = new WebHookResponse();
|
||||
$hookResponse->web_hook_id = $this->id;
|
||||
$hookResponse->response_code = $response->getStatusCode();
|
||||
$hookResponse->sent_headers = json_encode($request->getHeaders());
|
||||
$hookResponse->sent_body = json_encode($data);
|
||||
$hookResponse->recv_headers = json_encode($response->getHeaders());
|
||||
$hookResponse->recv_body = json_encode($response->getBody());
|
||||
$hookResponse->time_taken = $timeTaken;
|
||||
$hookResponse->save();
|
||||
|
||||
return $hookResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human readable request type name.
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestMethodAttribute()
|
||||
{
|
||||
$requestMethod = null;
|
||||
|
||||
switch ($this->request_type) {
|
||||
case self::HEAD:
|
||||
return 'HEAD';
|
||||
case self::GET:
|
||||
return 'GET';
|
||||
case self::POST:
|
||||
return 'POST';
|
||||
case self::PATCH:
|
||||
return 'PATCH';
|
||||
case self::PUT:
|
||||
return 'PUT';
|
||||
case self::DELETE:
|
||||
return 'DELETE';
|
||||
default:
|
||||
throw new Exception('Unknown request type value: '.$this->request_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Models/WebHookResponse.php
Normal file
18
src/Models/WebHookResponse.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebHookResponse extends Model
|
||||
{
|
||||
/**
|
||||
* Returns the hook that a response belongs to.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function hook()
|
||||
{
|
||||
return $this->belongsTo('WebHook', 'id', 'hook_id');
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Commands\OneClickDeployCommand;
|
||||
use CachetHQ\Cachet\Console\Commands\OneClickDeployCommand;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ConsoleServiceProvider extends ServiceProvider
|
||||
@@ -14,7 +14,7 @@ class ConsoleServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->commands('CachetHQ\Cachet\Commands\OneClickDeployCommand');
|
||||
$this->commands('CachetHQ\Cachet\Console\Commands\OneClickDeployCommand');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ class ConsoleServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('CachetHQ\Cachet\Commands\OneClickDeployCommand', function ($app) {
|
||||
$this->app->singleton('CachetHQ\Cachet\Console\Commands\OneClickDeployCommand', function ($app) {
|
||||
return new OneClickDeployCommand($app->environment('heroku'));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,40 @@ class RoutingServiceProvider extends ServiceProvider
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerFilters();
|
||||
$this->registerBindings();
|
||||
$this->registerRoutes();
|
||||
}
|
||||
|
||||
protected function registerFilters()
|
||||
{
|
||||
// Laravel's before filters
|
||||
$this->app->router->filter('auth', 'CachetHQ\Cachet\Http\Before\AuthFilter');
|
||||
$this->app->router->filter('auth.basic', 'CachetHQ\Cachet\Http\Before\AuthBasicFilter');
|
||||
$this->app->router->filter('guest', 'CachetHQ\Cachet\Http\Before\GuestFilter');
|
||||
$this->app->router->filter('csrf', 'CachetHQ\Cachet\Http\Before\CsrfFilter');
|
||||
|
||||
// Cachet's before filters
|
||||
$this->app->router->filter('is_setup', 'CachetHQ\Cachet\Http\Before\IsSetupFilter');
|
||||
$this->app->router->filter('has_setting', 'CachetHQ\Cachet\Http\Before\HasSettingFilter');
|
||||
$this->app->router->filter('login_throttling', 'CachetHQ\Cachet\Http\Before\LoginThrottlingFilter');
|
||||
|
||||
// Cachet's after filters
|
||||
$this->app->router->filter('allowed_domains', 'CachetHQ\Cachet\Http\After\AllowedDomainsFilter');
|
||||
$this->app->router->filter('cors', 'CachetHQ\Cachet\Http\After\CorsFilter');
|
||||
}
|
||||
|
||||
protected function registerBindings()
|
||||
{
|
||||
$this->app->router->model('component', 'CachetHQ\Cachet\Models\Component');
|
||||
$this->app->router->model('incident', 'CachetHQ\Cachet\Models\Incident');
|
||||
$this->app->router->model('incident_template', 'CachetHQ\Cachet\Models\IncidentTemplate');
|
||||
$this->app->router->model('setting', 'CachetHQ\Cachet\Models\Setting');
|
||||
$this->app->router->model('user', 'CachetHQ\Cachet\Models\User');
|
||||
}
|
||||
|
||||
protected function registerRoutes()
|
||||
{
|
||||
$files = glob(app_path('routes').'/*.php');
|
||||
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Component;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use Component;
|
||||
|
||||
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \Component
|
||||
* @var \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent component repository instance.
|
||||
*
|
||||
* @param \Component $model
|
||||
* @param \CachetHQ\Cachet\Models\Component $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use Incident;
|
||||
|
||||
class EloquentIncidentRepository extends EloquentRepository implements IncidentRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \Incident
|
||||
* @var \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent incident repository instance.
|
||||
*
|
||||
* @param \Incident $model
|
||||
* @param \CachetHQ\Cachet\Models\Incident $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Metric;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use Metric;
|
||||
|
||||
class EloquentMetricRepository extends EloquentRepository implements MetricRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \Metric
|
||||
* @var \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent metric repository instance.
|
||||
*
|
||||
* @param \Metric $model
|
||||
* @param \CachetHQ\Cachet\Models\Metric $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\MetricPoint;
|
||||
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use MetricPoint;
|
||||
|
||||
class EloquentMetricPointRepository extends EloquentRepository implements MetricPointRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \MetricPoint
|
||||
* @var \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent metric point repository instance.
|
||||
*
|
||||
* @param \MetricPoint $model
|
||||
* @param \CachetHQ\Cachet\Models\MetricPoint $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use Component;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class ComponentTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* Transform a component model into an array.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Component $component)
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use Incident;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class IncidentTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* Transform an incident model into an array.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Incident $incident)
|
||||
{
|
||||
$component = $incident->component;
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use MetricPoint;
|
||||
|
||||
class MetricPointTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* Transform a metric point model into an array.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\MetricPoint $metricPoint
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(MetricPoint $metricPoint)
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Metric;
|
||||
|
||||
class MetricTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* Transform a metric model into an array.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Metric $metric)
|
||||
{
|
||||
return [
|
||||
|
||||
50
src/helpers.php
Normal file
50
src/helpers.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
if (!function_exists('elixir')) {
|
||||
/**
|
||||
* Get the path to a versioned Elixir file.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function elixir($file)
|
||||
{
|
||||
static $manifest = null;
|
||||
|
||||
if (is_null($manifest)) {
|
||||
$manifest = json_decode(file_get_contents(public_path().'/build/rev-manifest.json'), true);
|
||||
}
|
||||
|
||||
if (isset($manifest[$file])) {
|
||||
return '/build/'.$manifest[$file];
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('set_active')) {
|
||||
|
||||
/**
|
||||
* Set active class if request is in path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $classes
|
||||
* @param string $active
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function set_active($path, array $classes = [], $active = 'active')
|
||||
{
|
||||
if (Request::is($path)) {
|
||||
$classes[] = $active;
|
||||
}
|
||||
|
||||
$class = implode(' ', $classes);
|
||||
|
||||
return empty($classes) ? '' : "class=\"{$class}\"";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user