This commit is contained in:
Graham Campbell
2014-12-20 21:20:17 +00:00
parent 26e4361d8a
commit 9d8d89248f
103 changed files with 2478 additions and 2353 deletions
+10 -6
View File
@@ -2,14 +2,15 @@
use Watson\Validating\ValidatingTrait;
class Component extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
class Component extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface
{
use ValidatingTrait;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
protected $rules = [
'user_id' => 'integer|required',
'name' => 'required',
'status' => 'integer'
'status' => 'integer',
];
protected $fillable = ['name', 'description', 'status', 'user_id'];
@@ -18,7 +19,8 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
* Lookup all of the incidents reported on the component.
* @return Illuminate\Database\Eloquent\Relations
*/
public function incidents() {
public function incidents()
{
return $this->hasMany('Incident', 'component_id', 'id');
}
@@ -26,15 +28,17 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
* Looks up the human readable version of the status.
* @return string
*/
public function getHumanStatusAttribute() {
return Lang::get('cachet.component.status.' . $this->status);
public function getHumanStatusAttribute()
{
return Lang::get('cachet.component.status.'.$this->status);
}
/**
* Get the transformer instance.
* @return ComponentTransformer
*/
public function getTransformer() {
public function getTransformer()
{
return new CachetHQ\Cachet\Transformers\ComponentTransformer();
}
}
+11 -5
View File
@@ -2,7 +2,8 @@
use Watson\Validating\ValidatingTrait;
class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface
{
use ValidatingTrait;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
@@ -22,7 +23,8 @@ class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableI
* An incident belongs to a component.
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function component() {
public function component()
{
return $this->belongsTo('Component', 'component_id', 'id');
}
@@ -30,8 +32,10 @@ class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableI
* Returns a human readable version of the status.
* @return string
*/
public function getHumanStatusAttribute() {
public function getHumanStatusAttribute()
{
$statuses = Lang::get('cachet.incident.status');
return $statuses[$this->status];
}
@@ -39,7 +43,8 @@ class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableI
* Finds the icon to use for each status.
* @return string
*/
public function getIconAttribute() {
public function getIconAttribute()
{
switch ($this->status) {
case 1: return 'fa fa-flag';
case 2: return 'fa fa-warning';
@@ -52,7 +57,8 @@ class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableI
* Get the transformer instance.
* @return CachetHQ\Cachet\Transformers\IncidentTransformer
*/
public function getTransformer() {
public function getTransformer()
{
return new CachetHQ\Cachet\Transformers\IncidentTransformer();
}
}
+5 -3
View File
@@ -2,7 +2,8 @@
use Watson\Validating\ValidatingTrait;
class IncidentTemplate extends Eloquent {
class IncidentTemplate extends Eloquent
{
use ValidatingTrait;
protected $rules = [
@@ -19,10 +20,11 @@ class IncidentTemplate extends Eloquent {
* Overrides the models boot method.
* @return void
*/
public static function boot() {
public static function boot()
{
parent::boot();
self::saving(function($template) {
self::saving(function ($template) {
$template->slug = Str::slug($template->name);
});
}
+8 -4
View File
@@ -2,7 +2,8 @@
use Watson\Validating\ValidatingTrait;
class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface
{
use ValidatingTrait;
protected $rules = [
@@ -17,7 +18,8 @@ class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInt
* Metrics contain many metric points.
* @return Illuminate\Database\Eloquent\Builder
*/
public function points() {
public function points()
{
return $this->hasMany('MetricPoint', 'metric_id', 'id');
}
@@ -25,7 +27,8 @@ class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInt
* Determines whether a chart should be shown.
* @return bool
*/
public function getShouldDisplayAttribute() {
public function getShouldDisplayAttribute()
{
return $this->display_chart === 1;
}
@@ -33,7 +36,8 @@ class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInt
* Get the transformer instance.
* @return CachetHQ\Cachet\Transformers\MetricTransformer
*/
public function getTransformer() {
public function getTransformer()
{
return new CachetHQ\Cachet\Transformers\MetricTransformer();
}
}
+4 -2
View File
@@ -1,11 +1,13 @@
<?php
class MetricPoint extends Eloquent {
class MetricPoint extends Eloquent
{
/**
* A metric point belongs to a metric unit.
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function metric() {
public function metric()
{
return $this->belongsTo('Metric', 'id', 'metric_id');
}
}
+7 -4
View File
@@ -2,13 +2,14 @@
use Watson\Validating\ValidatingTrait;
class Service extends Eloquent {
class Service extends Eloquent
{
use ValidatingTrait;
protected $rules = [
'type' => 'alpha_dash|required',
'active' => 'required|in:0,1',
'properties' => ''
'properties' => '',
];
/**
@@ -16,7 +17,8 @@ class Service extends Eloquent {
* @param string $properties
* @return object
*/
public function getPropertiesAttribute($properties) {
public function getPropertiesAttribute($properties)
{
return json_decode($properties);
}
@@ -24,7 +26,8 @@ class Service extends Eloquent {
* Sets the properties attribute which auto encodes to a JSON string.
* @param mixed $properties
*/
public function setPropertiesAttribute($properties) {
public function setPropertiesAttribute($properties)
{
$this->attributes['properties'] = json_encode($properties);
}
}
+8 -5
View File
@@ -1,15 +1,17 @@
<?php
class Setting extends Eloquent {
class Setting extends Eloquent
{
protected $fillable = ['name', 'value'];
/**
* Returns a setting from the database.
* @param string $settingName
* @param bool $checkEnv
* @param bool $checkEnv
* @return string
*/
public static function get($settingName, $checkEnv = true) {
public static function get($settingName, $checkEnv = true)
{
// Default setting value.
$setting = null;
@@ -32,11 +34,12 @@ class Setting extends Eloquent {
/**
* Throws an Exception
* @param string $setting
* @param string $setting
* @throws Exception
* @return void
*/
public static function unknownSettingException($setting) {
public static function unknownSettingException($setting)
{
throw new \Exception(
sprintf('Unknown setting %s', $setting)
);
+4 -3
View File
@@ -1,14 +1,15 @@
<?php
use Watson\Validating\ValidatingTrait;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
use Watson\Validating\ValidatingTrait;
class Subscriber extends Eloquent {
class Subscriber extends Eloquent
{
use ValidatingTrait;
use SoftDeletingTrait;
protected $rules = [
'email' => 'required|email'
'email' => 'required|email',
];
protected $fillable = ['email'];
+9 -7
View File
@@ -1,11 +1,12 @@
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\UserTrait;
class User extends Eloquent implements UserInterface, RemindableInterface {
class User extends Eloquent implements UserInterface, RemindableInterface
{
use UserTrait, RemindableTrait;
/**
@@ -32,7 +33,8 @@ class User extends Eloquent implements UserInterface, RemindableInterface {
* @param string @password
* @return void
*/
public function setPasswordAttribute($password) {
public function setPasswordAttribute($password)
{
$this->attributes['password'] = Hash::make($password);
}
@@ -41,12 +43,12 @@ class User extends Eloquent implements UserInterface, RemindableInterface {
* @param integer $size
* @return string
*/
public function getGravatarAttribute($size = 200) {
public function getGravatarAttribute($size = 200)
{
return sprintf(
'https://www.gravatar.com/avatar/%s?size=%d',
md5($this->email),
$size
);
}
}
+20 -14
View File
@@ -1,6 +1,7 @@
<?php
class WebHook extends Eloquent {
class WebHook extends Eloquent
{
// Request Methods.
const HEAD = 0;
const GET = 1;
@@ -11,9 +12,10 @@ class WebHook extends Eloquent {
/**
* Returns all responses for a WebHook.
* @return Illuminate\Database\Eloquent\Builder
* @return Illuminate\Database\Eloquent\Builder
*/
public function response() {
public function response()
{
return $this->hasMany('WebHookContent', 'hook_id', 'id');
}
@@ -22,7 +24,8 @@ class WebHook extends Eloquent {
* @param Illuminate\Database\Eloquent\Builder $query
* @return Illuminate\Database\Eloquent\Builder
*/
public function scopeActive($query) {
public function scopeActive($query)
{
return $query->where('active', 1);
}
@@ -30,17 +33,19 @@ class WebHook extends Eloquent {
* Setups a Ping event that is fired upon a web hook.
* @return array result of the ping
*/
public function ping() {
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
* @param string $eventType the event to send X-Cachet-Event
* @param mixed $data Data to send to the Web Hook
* @return object
*/
public function fire($eventType, $data = null) {
public function fire($eventType, $data = null)
{
$startTime = microtime(true);
$client = new \GuzzleHttp\Client();
@@ -58,10 +63,10 @@ class WebHook extends Eloquent {
$response = $e->getResponse();
}
$timeTaken = microtime(TRUE) - $startTime;
$timeTaken = microtime(true) - $startTime;
// Store the request
$hookResponse = new WebHookResponse;
$hookResponse = new WebHookResponse();
$hookResponse->web_hook_id = $this->id;
$hookResponse->response_code = $response->getStatusCode();
$hookResponse->sent_headers = json_encode($request->getHeaders());
@@ -77,10 +82,11 @@ class WebHook extends Eloquent {
/**
* Returns a human readable request type name.
* @throws Exception
* @return string HEAD, GET, POST, DELETE, PATCH, PUT etc
* @return string HEAD, GET, POST, DELETE, PATCH, PUT etc
*/
public function getRequestMethodAttribute() {
$requestMethod = NULL;
public function getRequestMethodAttribute()
{
$requestMethod = null;
switch ($this->request_type) {
case self::HEAD:
@@ -103,7 +109,7 @@ class WebHook extends Eloquent {
break;
default:
throw new Exception('Unknown request type value: ' . $this->request_type);
throw new Exception('Unknown request type value: '.$this->request_type);
break;
}
+8 -6
View File
@@ -1,11 +1,13 @@
<?php
class WebHookResponse extends Eloquent {
/**
* Returns the hook that a response belongs to.
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function hook() {
class WebHookResponse extends Eloquent
{
/**
* Returns the hook that a response belongs to.
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function hook()
{
return $this->belongsTo('WebHook', 'id', 'hook_id');
}
}