-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from cachethq/namespace
Namespace
- Loading branch information
Showing
11 changed files
with
244 additions
and
233 deletions.
There are no files selected for viewing
102 changes: 52 additions & 50 deletions
102
app/CachetHq/Cachet/Controllers/Api/ComponentController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,53 @@ | ||
<?php namespace CachetHq\Cachet\Controllers\Api; | ||
|
||
use Input; | ||
use Dingo\Api\Routing\Controller as DingoController; | ||
use Dingo\Api\Auth\Shield; | ||
use CachetHq\Cachet\Repositories\Component\ComponentRepository; | ||
|
||
class ComponentController extends DingoController { | ||
|
||
protected $auth; | ||
|
||
protected $component; | ||
|
||
public function __construct(Shield $auth, ComponentRepository $component) { | ||
$this->auth = $auth; | ||
$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); | ||
} | ||
|
||
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()); | ||
<?php | ||
|
||
namespace CachetHQ\Cachet\Controllers\Api; | ||
|
||
use Input; | ||
use Dingo\Api\Routing\Controller as DingoController; | ||
use Dingo\Api\Auth\Shield; | ||
use CachetHQ\Cachet\Repositories\Component\ComponentRepository; | ||
|
||
class ComponentController extends DingoController { | ||
|
||
protected $auth; | ||
|
||
protected $component; | ||
|
||
public function __construct(Shield $auth, ComponentRepository $component) { | ||
$this->auth = $auth; | ||
$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); | ||
} | ||
|
||
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
app/CachetHq/Cachet/Repositories/Component/ComponentRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
<?php namespace CachetHq\Cachet\Repositories\Component; | ||
<?php | ||
|
||
interface ComponentRepository { | ||
namespace CachetHQ\Cachet\Repositories\Component; | ||
|
||
public function all(); | ||
interface ComponentRepository { | ||
|
||
public function create($id, array $array); | ||
public function all(); | ||
|
||
public function findOrFail($id); | ||
public function create($id, array $array); | ||
|
||
public function with($id, array $with); | ||
} | ||
public function findOrFail($id); | ||
|
||
public function with($id, array $with); | ||
} |
38 changes: 20 additions & 18 deletions
38
app/CachetHq/Cachet/Repositories/Component/EloquentComponentRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
<?php namespace CachetHq\Cachet\Repositories\Component; | ||
<?php | ||
|
||
use CachetHq\Cachet\Repositories\EloquentRepository; | ||
use Component; | ||
use Exception; | ||
namespace CachetHQ\Cachet\Repositories\Component; | ||
|
||
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository { | ||
use CachetHQ\Cachet\Repositories\EloquentRepository; | ||
use Component; | ||
use Exception; | ||
|
||
protected $model; | ||
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository { | ||
|
||
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; | ||
protected $model; | ||
|
||
if ($component->isInvalid()) { | ||
throw new Exception('Invalid model validation', $component->getErrors()); | ||
public function __construct(Component $model) { | ||
$this->model = $model; | ||
} | ||
|
||
$component->saveOrFail(); | ||
return $component; | ||
public function create($user_id, array $array) { | ||
$component = new $this->model($array); | ||
$component->user_id = $user_id; | ||
|
||
if ($component->isInvalid()) { | ||
throw new Exception('Invalid model validation', $component->getErrors()); | ||
} | ||
|
||
$component->saveOrFail(); | ||
return $component; | ||
} | ||
} | ||
} |
Oops, something went wrong.