Permalink
Browse files

Switching out robclancy/presenter for mccool/laravel-auto-presenter t…

…o better support dependency injection
  • Loading branch information...
REBELinBLUE committed Mar 4, 2017
1 parent 1fc4085 commit 75e7fc0140a35b3d2ed9c52d28ad9db7684b0611
Showing with 457 additions and 251 deletions.
  1. +5 −5 app/DeployStep.php
  2. +11 −6 app/Deployment.php
  3. +1 −1 app/Http/Controllers/Admin/ProjectController.php
  4. +1 −1 app/Http/Controllers/Admin/TemplateController.php
  5. +1 −1 app/Http/Controllers/Admin/UserController.php
  6. +4 −3 app/Http/Controllers/DeploymentController.php
  7. +5 −5 app/Project.php
  8. +5 −5 app/ServerLog.php
  9. +5 −5 app/Template.php
  10. +5 −23 app/User.php
  11. +1 −2 app/View/Presenters/CommandPresenter.php
  12. +0 −1 app/View/Presenters/DeployStepPresenter.php
  13. +1 −2 app/View/Presenters/DeploymentPresenter.php
  14. +57 −0 app/View/Presenters/Presenter.php
  15. +5 −3 app/View/Presenters/RuntimePresenter.php
  16. +0 −2 app/View/Presenters/ServerLogPresenter.php
  17. +4 −7 app/View/Presenters/UserPresenter.php
  18. +1 −1 composer.json
  19. +151 −69 composer.lock
  20. +11 −11 config/app.php
  21. +1 −0 phpcs.xml.dist
  22. +6 −7 tests/Unit/DeployStepTest.php
  23. +6 −7 tests/Unit/DeploymentTest.php
  24. +16 −7 tests/Unit/ProjectTest.php
  25. +6 −7 tests/Unit/ServerLogTest.php
  26. +6 −7 tests/Unit/TemplateTest.php
  27. +6 −24 tests/Unit/UserTest.php
  28. +4 −2 tests/Unit/View/Presenters/CommandPresenterTest.php
  29. +4 −2 tests/Unit/View/Presenters/DeployStepPresenterTest.php
  30. +25 −11 tests/Unit/View/Presenters/DeploymentPresenterTest.php
  31. +49 −0 tests/Unit/View/Presenters/PresenterTest.php
  32. +24 −12 tests/Unit/View/Presenters/ProjectPresenterTest.php
  33. +9 −3 tests/Unit/View/Presenters/RuntimePresenterTest.php
  34. +6 −4 tests/Unit/View/Presenters/UserPresenterTest.php
  35. +4 −4 tests/Unit/stubs/Model.php
  36. +11 −1 tests/Unit/stubs/Presenter.php
View
@@ -3,13 +3,13 @@
namespace REBELinBLUE\Deployer;
use Illuminate\Database\Eloquent\Model;
+use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\View\Presenters\DeployStepPresenter;
-use Robbo\Presenter\PresentableInterface;
/**
* The deployment step model.
*/
-class DeployStep extends Model implements PresentableInterface
+class DeployStep extends Model implements HasPresenter
{
/**
* The attributes that are mass assignable.
@@ -55,11 +55,11 @@ public function command()
/**
* Gets the view presenter.
*
- * @return DeployStepPresenter
+ * @return string
*/
- public function getPresenter()
+ public function getPresenterClass()
{
- return new DeployStepPresenter($this);
+ return DeployStepPresenter::class;
}
/**
View
@@ -5,15 +5,15 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
+use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\Events\ModelChanged;
use REBELinBLUE\Deployer\View\Presenters\DeploymentPresenter;
use REBELinBLUE\Deployer\View\Presenters\RuntimeInterface;
-use Robbo\Presenter\PresentableInterface;
/**
* Deployment model.
*/
-class Deployment extends Model implements PresentableInterface, RuntimeInterface
+class Deployment extends Model implements HasPresenter, RuntimeInterface
{
use SoftDeletes;
@@ -278,11 +278,11 @@ public function getBranchUrlAttribute()
/**
* Gets the view presenter.
*
- * @return DeploymentPresenter
+ * @return string
*/
- public function getPresenter()
+ public function getPresenterClass()
{
- return new DeploymentPresenter($this);
+ return DeploymentPresenter::class;
}
/**
@@ -308,7 +308,12 @@ public function getDeployerNameAttribute()
return $this->source;
}
- return $this->getPresenter()->committer_name;
+ // FIXME: This is horrible
+ $presenter = $this->getPresenterClass();
+
+ /** @var DeploymentPresenter $presenter */
+ $presenter = new $presenter();
+ return $presenter->setWrappedObject($this)->committer_name;
}
/**
@@ -56,7 +56,7 @@ public function index(
'title' => $translator->trans('projects.manage'),
'templates' => $templateRepository->getAll(),
'groups' => $groupRepository->getAll(),
- 'projects' => $projects->toJson(), // Because PresentableInterface toJson() is not working in the view
+ 'projects' => $projects->toJson(),
]);
}
@@ -120,7 +120,7 @@ public function index()
return $this->view->make('admin.templates.listing', [
'title' => $this->translator->trans('templates.manage'),
- 'templates' => $templates->toJson(), // Because PresentableInterface toJson() is not working in the view
+ 'templates' => $templates->toJson(),
]);
}
@@ -41,7 +41,7 @@ public function index(ViewFactory $view, Translator $translator)
{
return $view->make('admin.users.listing', [
'title' => $translator->trans('users.manage'),
- 'users' => $this->repository->getAll()->toJson(), // PresentableInterface toJson() is not working in view
+ 'users' => $this->repository->getAll()->toJson(),
]);
}
@@ -7,6 +7,7 @@
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
+use Illuminate\Support\Collection;
use REBELinBLUE\Deployer\Command;
use REBELinBLUE\Deployer\Repositories\Contracts\DeploymentRepositoryInterface;
use REBELinBLUE\Deployer\Repositories\Contracts\ProjectRepositoryInterface;
@@ -119,15 +120,15 @@ public function show($deployment_id, UrlGenerator $url)
{
$deployment = $this->deploymentRepository->getById($deployment_id);
- $output = [];
+ $output = new Collection();
foreach ($deployment->steps as $step) {
foreach ($step->servers as $server) {
$server->server;
$server->runtime = ($server->runtime() === false ? null : $server->getPresenter()->readable_runtime);
$server->output = ((is_null($server->output) || !strlen($server->output)) ? null : '');
- $output[] = $server;
+ $output->push($server);
}
}
@@ -141,7 +142,7 @@ public function show($deployment_id, UrlGenerator $url)
'subtitle' => $project->name,
'project' => $project,
'deployment' => $deployment,
- 'output' => json_encode($output), // PresentableInterface does not correctly json encode the models
+ 'output' => $output->toJson(),
]);
}
View
@@ -5,19 +5,19 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Bus\DispatchesJobs;
+use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\Jobs\GenerateKey;
use REBELinBLUE\Deployer\Jobs\RegeneratePublicKey;
use REBELinBLUE\Deployer\Traits\BroadcastChanges;
use REBELinBLUE\Deployer\Traits\ProjectRelations;
use REBELinBLUE\Deployer\View\Presenters\ProjectPresenter;
-use Robbo\Presenter\PresentableInterface;
use UnexpectedValueException;
use Version\Compare as VersionCompare;
/**
* Project model.
*/
-class Project extends Model implements PresentableInterface
+class Project extends Model implements HasPresenter
{
use SoftDeletes, BroadcastChanges, ProjectRelations, DispatchesJobs;
@@ -216,11 +216,11 @@ public function getRepositoryUrlAttribute()
/**
* Gets the view presenter.
*
- * @return ProjectPresenter
+ * @return string
*/
- public function getPresenter()
+ public function getPresenterClass()
{
- return new ProjectPresenter($this);
+ return ProjectPresenter::class;
}
/**
View
@@ -3,16 +3,16 @@
namespace REBELinBLUE\Deployer;
use Illuminate\Database\Eloquent\Model;
+use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\Events\ServerLogChanged;
use REBELinBLUE\Deployer\Events\ServerOutputChanged;
use REBELinBLUE\Deployer\View\Presenters\RuntimeInterface;
use REBELinBLUE\Deployer\View\Presenters\ServerLogPresenter;
-use Robbo\Presenter\PresentableInterface;
/**
* Server log model.
*/
-class ServerLog extends Model implements PresentableInterface, RuntimeInterface
+class ServerLog extends Model implements HasPresenter, RuntimeInterface
{
const COMPLETED = 0;
const PENDING = 1;
@@ -91,10 +91,10 @@ public function runtime()
/**
* Gets the view presenter.
*
- * @return ServerLogPresenter
+ * @return string
*/
- public function getPresenter()
+ public function getPresenterClass()
{
- return new ServerLogPresenter($this);
+ return ServerLogPresenter::class;
}
}
View
@@ -3,14 +3,14 @@
namespace REBELinBLUE\Deployer;
use Illuminate\Database\Eloquent\Model;
+use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\Traits\ProjectRelations;
use REBELinBLUE\Deployer\View\Presenters\CommandPresenter;
-use Robbo\Presenter\PresentableInterface;
/**
* Model for templates.
*/
-class Template extends Model implements PresentableInterface
+class Template extends Model implements HasPresenter
{
use ProjectRelations;
@@ -91,10 +91,10 @@ public function getVariableCountAttribute()
/**
* Gets the view presenter.
*
- * @return CommandPresenter
+ * @return string
*/
- public function getPresenter()
+ public function getPresenterClass()
{
- return new CommandPresenter($this);
+ return CommandPresenter::class;
}
}
View
@@ -2,19 +2,18 @@
namespace REBELinBLUE\Deployer;
-use Creativeorange\Gravatar\Gravatar;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
+use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\Notifications\System\ResetPassword;
use REBELinBLUE\Deployer\Traits\BroadcastChanges;
use REBELinBLUE\Deployer\View\Presenters\UserPresenter;
-use Robbo\Presenter\PresentableInterface;
/**
* User model.
*/
-class User extends Authenticatable implements PresentableInterface
+class User extends Authenticatable implements HasPresenter
{
use SoftDeletes, BroadcastChanges, Notifiable;
@@ -48,22 +47,6 @@ class User extends Authenticatable implements PresentableInterface
'id' => 'integer',
];
- /**
- * A hack to allow avatar_url to be called on the result of Auth::user().
- *
- * @param string $key
- *
- * @return mixed
- */
- public function __get($key)
- {
- if ($key === 'avatar_url') {
- return $this->getPresenter()->avatar_url;
- }
-
- return parent::__get($key);
- }
-
/**
* Generate a change email token.
*
@@ -80,12 +63,11 @@ public function requestEmailToken()
/**
* Gets the view presenter.
*
- * @return UserPresenter
+ * @return string
*/
- public function getPresenter()
+ public function getPresenterClass()
{
- // FIXME: Horrible!
- return new UserPresenter($this, app(Gravatar::class));
+ return UserPresenter::class;
}
/**
@@ -4,7 +4,6 @@
use Illuminate\Support\Facades\Lang;
use REBELinBLUE\Deployer\Command;
-use Robbo\Presenter\Presenter;
/**
* The view presenter for a command class.
@@ -118,7 +117,7 @@ private function commandNames($stage)
{
$commands = [];
- foreach ($this->getObject()->commands as $command) {
+ foreach ($this->getWrappedObject()->commands as $command) {
if ($command->step === $stage) {
$commands[] = $command->name;
}
@@ -4,7 +4,6 @@
use Illuminate\Support\Facades\Lang;
use REBELinBLUE\Deployer\Command;
-use Robbo\Presenter\Presenter;
/**
* The view presenter for a deploy step class.
@@ -5,7 +5,6 @@
use Illuminate\Support\Facades\Lang;
use REBELinBLUE\Deployer\Command;
use REBELinBLUE\Deployer\Deployment;
-use Robbo\Presenter\Presenter;
/**
* The view presenter for a project class.
@@ -62,7 +61,7 @@ public function presentReadableStatus()
*/
public function presentOptionalCommandsUsed()
{
- return $this->getObject()->commands->filter(function (Command $command) {
+ return $this->getWrappedObject()->commands->filter(function (Command $command) {
return $command->optional;
})->implode('id', ',');
}
Oops, something went wrong.

0 comments on commit 75e7fc0

Please sign in to comment.