Move code to src folder
This commit is contained in:
64
src/Controllers/Api/ComponentController.php
Normal file
64
src/Controllers/Api/ComponentController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class ComponentController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
protected $component;
|
||||
|
||||
public function __construct(ComponentRepository $component)
|
||||
{
|
||||
$this->component = $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all components.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getComponents()
|
||||
{
|
||||
return $this->component->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Component
|
||||
*/
|
||||
public function getComponent($id)
|
||||
{
|
||||
return $this->component->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a component with incidents.
|
||||
*
|
||||
* @param int $id Component ID
|
||||
*
|
||||
* @return \Component
|
||||
*/
|
||||
public function getComponentIncidents($id)
|
||||
{
|
||||
return $this->component->with($id, ['incidents']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new component.
|
||||
*
|
||||
* @return \Component
|
||||
*/
|
||||
public function postComponents()
|
||||
{
|
||||
return $this->component->create($this->auth->user()->id, Input::all());
|
||||
}
|
||||
}
|
||||
64
src/Controllers/Api/IncidentController.php
Normal file
64
src/Controllers/Api/IncidentController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class IncidentController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
protected $incident;
|
||||
|
||||
public function __construct(IncidentRepository $incident)
|
||||
{
|
||||
$this->incident = $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all incidents.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getIncidents()
|
||||
{
|
||||
return $this->incident->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function getIncident($id)
|
||||
{
|
||||
return $this->incident->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new incident.
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function postIncidents()
|
||||
{
|
||||
return $this->incident->create($this->auth->user()->id, Input::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function putIncident($id)
|
||||
{
|
||||
return $this->incident->update($id, Input::all());
|
||||
}
|
||||
}
|
||||
63
src/Controllers/Api/MetricController.php
Normal file
63
src/Controllers/Api/MetricController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class MetricController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
protected $metric;
|
||||
|
||||
public function __construct(MetricRepository $metric)
|
||||
{
|
||||
$this->metric = $metric;
|
||||
}
|
||||
/**
|
||||
* Get all metrics.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetrics()
|
||||
{
|
||||
return $this->metric->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function getMetric($id)
|
||||
{
|
||||
return $this->metric->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric.
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function postMetrics()
|
||||
{
|
||||
return $this->metric->create(Input::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function putMetric($id)
|
||||
{
|
||||
return $this->metric->update($id, Input::all());
|
||||
}
|
||||
}
|
||||
51
src/Controllers/Api/MetricPointController.php
Normal file
51
src/Controllers/Api/MetricPointController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class MetricPointController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
protected $metricpoint;
|
||||
|
||||
public function __construct(MetricPointRepository $metricpoint)
|
||||
{
|
||||
$this->metricpoint = $metricpoint;
|
||||
}
|
||||
/**
|
||||
* Get all metric points.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetricPoints()
|
||||
{
|
||||
return $this->metricpoint->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric point.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return MetricPoint
|
||||
*/
|
||||
public function getMetricPoint($id)
|
||||
{
|
||||
return $this->metricpoint->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric point.
|
||||
*
|
||||
* @return MetricPoint
|
||||
*/
|
||||
public function postMetricPoints()
|
||||
{
|
||||
return $this->metricpoint->create(Input::all());
|
||||
}
|
||||
}
|
||||
14
src/Repositories/Component/ComponentRepository.php
Normal file
14
src/Repositories/Component/ComponentRepository.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Component;
|
||||
|
||||
interface ComponentRepository
|
||||
{
|
||||
public function all();
|
||||
|
||||
public function create($id, array $array);
|
||||
|
||||
public function findOrFail($id);
|
||||
|
||||
public function with($id, array $with);
|
||||
}
|
||||
28
src/Repositories/Component/EloquentComponentRepository.php
Normal file
28
src/Repositories/Component/EloquentComponentRepository.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Component;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use Component;
|
||||
|
||||
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function __construct(Component $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function create($user_id, array $array)
|
||||
{
|
||||
$component = new $this->model($array);
|
||||
$component->user_id = $user_id;
|
||||
|
||||
$this->validate($component);
|
||||
|
||||
$component->saveOrFail();
|
||||
|
||||
return $component;
|
||||
}
|
||||
}
|
||||
149
src/Repositories/EloquentRepository.php
Normal file
149
src/Repositories/EloquentRepository.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
abstract class EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->model->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with related relationships.
|
||||
*
|
||||
* @param id $id
|
||||
* @param array $with Array of model relationships
|
||||
*
|
||||
* @return object|ModelNotFoundException
|
||||
*/
|
||||
public function with($id, array $with = [])
|
||||
{
|
||||
return $this->model->with($with)->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the model to query against a user id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $column
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withAuth($id, $column = 'user_id')
|
||||
{
|
||||
$this->model = $this->model->where($column, $id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by ID.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
return $this->model->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by ID.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return object|ModelNotFoundException
|
||||
*/
|
||||
public function findOrFail($id)
|
||||
{
|
||||
return $this->model->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by type.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @param array $columns
|
||||
*
|
||||
* @return object|ModelNotFoundException
|
||||
*/
|
||||
public function findByOrFail($key, $value, $columns = ['*'])
|
||||
{
|
||||
if (! is_null($item = $this->model->where($key, $value)->first($columns))) {
|
||||
return $item;
|
||||
}
|
||||
|
||||
throw new ModelNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of rows returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count($key = null, $value = null)
|
||||
{
|
||||
if (is_null($key) || is_null($value)) {
|
||||
return $this->model->where($key, $value)->count();
|
||||
}
|
||||
|
||||
return $this->model->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a model by ID.
|
||||
*
|
||||
* @param inetegr $id
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->model->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a given model with Watson validation.
|
||||
*
|
||||
* @param object $model
|
||||
*
|
||||
* @return Exception
|
||||
*/
|
||||
public function validate($model)
|
||||
{
|
||||
if ($model->isInvalid()) {
|
||||
throw new Exception('Invalid model validation');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate whether a model has a correct relationship.
|
||||
*
|
||||
* @param object $model
|
||||
* @param string $relationship Name of the relationship to validate against
|
||||
*
|
||||
* @return Exception
|
||||
*/
|
||||
public function hasRelationship($model, $relationship)
|
||||
{
|
||||
if (! $model->$relationship) {
|
||||
throw new Exception('Invalid relationship exception');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
46
src/Repositories/Incident/EloquentIncidentRepository.php
Normal file
46
src/Repositories/Incident/EloquentIncidentRepository.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use Incident;
|
||||
|
||||
class EloquentIncidentRepository extends EloquentRepository implements IncidentRepository
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function __construct(Incident $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function create($user_id, array $array)
|
||||
{
|
||||
$incident = new $this->model($array);
|
||||
$incident->user_id = $user_id;
|
||||
$this->validate($incident);
|
||||
|
||||
if (isset($array['component_id'])) {
|
||||
$this->hasRelationship($incident, 'component');
|
||||
}
|
||||
|
||||
$incident->saveOrFail();
|
||||
|
||||
return $incident;
|
||||
}
|
||||
|
||||
public function update($id, array $array)
|
||||
{
|
||||
$incident = $this->model->findOrFail($id);
|
||||
$incident->fill($array);
|
||||
$this->validate($incident);
|
||||
|
||||
if (isset($array['component_id'])) {
|
||||
$this->hasRelationship($incident, 'component');
|
||||
}
|
||||
|
||||
$incident->update($array);
|
||||
|
||||
return $incident;
|
||||
}
|
||||
}
|
||||
14
src/Repositories/Incident/IncidentRepository.php
Normal file
14
src/Repositories/Incident/IncidentRepository.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Incident;
|
||||
|
||||
interface IncidentRepository
|
||||
{
|
||||
public function all();
|
||||
|
||||
public function create($id, array $array);
|
||||
|
||||
public function findOrFail($id);
|
||||
|
||||
public function update($id, array $with);
|
||||
}
|
||||
39
src/Repositories/Metric/EloquentMetricRepository.php
Normal file
39
src/Repositories/Metric/EloquentMetricRepository.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Metric;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use Metric;
|
||||
|
||||
class EloquentMetricRepository extends EloquentRepository implements MetricRepository
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function __construct(Metric $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function create(array $array)
|
||||
{
|
||||
$metric = new $this->model($array);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->saveOrFail();
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
public function update($id, array $array)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
$metric->fill($array);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->update($array);
|
||||
|
||||
return $metric;
|
||||
}
|
||||
}
|
||||
14
src/Repositories/Metric/MetricRepository.php
Normal file
14
src/Repositories/Metric/MetricRepository.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Metric;
|
||||
|
||||
interface MetricRepository
|
||||
{
|
||||
public function all();
|
||||
|
||||
public function create(array $array);
|
||||
|
||||
public function findOrFail($id);
|
||||
|
||||
public function update($id, array $with);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\MetricPoint;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
use MetricPoint;
|
||||
|
||||
class EloquentMetricPointRepository extends EloquentRepository implements MetricRepository
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function __construct(MetricPoint $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function create(array $array)
|
||||
{
|
||||
$metric = new $this->model($array);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->saveOrFail();
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
public function update($id, array $array)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
$metric->fill($array);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->update($array);
|
||||
|
||||
return $metric;
|
||||
}
|
||||
}
|
||||
14
src/Repositories/MetricPoint/MetricPointRepository.php
Normal file
14
src/Repositories/MetricPoint/MetricPointRepository.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\MetricPoint;
|
||||
|
||||
interface MetricPointRepository
|
||||
{
|
||||
public function all();
|
||||
|
||||
public function create(array $array);
|
||||
|
||||
public function findOrFail($id);
|
||||
|
||||
public function update($id, array $with);
|
||||
}
|
||||
23
src/Service/EmailService.php
Normal file
23
src/Service/EmailService.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Service\Email;
|
||||
|
||||
class EmailService implements ServiceInterface
|
||||
{
|
||||
protected $properties;
|
||||
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function unregister()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function fire($data)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
10
src/Service/ServiceInterface.php
Normal file
10
src/Service/ServiceInterface.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Service;
|
||||
|
||||
interface ServiceInterface
|
||||
{
|
||||
public function register();
|
||||
public function unregister();
|
||||
public function fire($data);
|
||||
}
|
||||
24
src/Support/ServiceProviders/RepositoryServiceProvider.php
Normal file
24
src/Support/ServiceProviders/RepositoryServiceProvider.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Support\ServiceProviders;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class RepositoryServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\Component\ComponentRepository',
|
||||
'CachetHQ\Cachet\Repositories\Component\EloquentComponentRepository'
|
||||
);
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\Incident\IncidentRepository',
|
||||
'CachetHQ\Cachet\Repositories\Incident\EloquentIncidentRepository'
|
||||
);
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\Metric\MetricRepository',
|
||||
'CachetHQ\Cachet\Repositories\Metric\EloquentMetricRepository'
|
||||
);
|
||||
}
|
||||
}
|
||||
40
src/Support/ServiceProviders/RoutingServiceProvider.php
Normal file
40
src/Support/ServiceProviders/RoutingServiceProvider.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Support\ServiceProviders;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use RecursiveDirectoryIterator;
|
||||
|
||||
class RoutingServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$this->routesInDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Organise Routes.
|
||||
*
|
||||
* @param string $app
|
||||
*/
|
||||
private function routesInDirectory($app = '')
|
||||
{
|
||||
$routeDir = app_path('routes/'.$app.($app !== '' ? '/' : null));
|
||||
|
||||
$iterator = new RecursiveDirectoryIterator($routeDir);
|
||||
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
|
||||
foreach ($iterator as $route) {
|
||||
$isDotFile = strpos($route->getFilename(), '.') === 0;
|
||||
|
||||
if (!$isDotFile && !$route->isDir()) {
|
||||
require $routeDir.$route->getFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/Transformers/ComponentTransformer.php
Normal file
23
src/Transformers/ComponentTransformer.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use Component;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class ComponentTransformer extends TransformerAbstract
|
||||
{
|
||||
public function transform(Component $component)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $component->id,
|
||||
'name' => $component->name,
|
||||
'description' => $component->description,
|
||||
'status_id' => (int) $component->status,
|
||||
'status' => $component->humanStatus,
|
||||
'incident_count' => $component->incidents()->count(),
|
||||
'created_at' => $component->created_at->timestamp,
|
||||
'updated_at' => $component->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
29
src/Transformers/IncidentTransformer.php
Normal file
29
src/Transformers/IncidentTransformer.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use Incident;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class IncidentTransformer extends TransformerAbstract
|
||||
{
|
||||
public function transform(Incident $incident)
|
||||
{
|
||||
$component = $incident->component;
|
||||
|
||||
if ($component) {
|
||||
$transformer = $component->getTransformer();
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (int) $incident->id,
|
||||
'name' => $incident->name,
|
||||
'message' => $incident->message,
|
||||
'status' => (int) $incident->status,
|
||||
'human_status' => $incident->humanStatus,
|
||||
'component' => isset($transformer) ? $transformer->transform($component) : null,
|
||||
'created_at' => $incident->created_at->timestamp,
|
||||
'updated_at' => $incident->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
20
src/Transformers/MetricPointTransformer.php
Normal file
20
src/Transformers/MetricPointTransformer.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use MetricPoint;
|
||||
|
||||
class MetricPointTransformer extends TransformerAbstract
|
||||
{
|
||||
public function transform(MetricPoint $metricPoint)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $metricPoint->id,
|
||||
'metric_id' => $metricPoint->metric_id,
|
||||
'value' => $metricPoint->value,
|
||||
'created_at' => $metricPoint->created_at->timestamp,
|
||||
'updated_at' => $metricPoint->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
22
src/Transformers/MetricTransformer.php
Normal file
22
src/Transformers/MetricTransformer.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Metric;
|
||||
|
||||
class MetricTransformer extends TransformerAbstract
|
||||
{
|
||||
public function transform(Metric $metric)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $metric->id,
|
||||
'name' => $metric->name,
|
||||
'description' => $metric->description,
|
||||
'suffix' => $metric->suffix,
|
||||
'display' => $metric->shouldDisplay,
|
||||
'created_at' => $metric->created_at->timestamp,
|
||||
'updated_at' => $metric->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user