Skip to content

Commit

Permalink
Massive Cleanup
Browse files Browse the repository at this point in the history
The keyword here is "Massive". Also: goodbye repositories.
  • Loading branch information
driesvints committed Mar 28, 2017
1 parent 4564599 commit 6b3f35e
Show file tree
Hide file tree
Showing 69 changed files with 547 additions and 985 deletions.
27 changes: 9 additions & 18 deletions app/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
namespace App;

use App\Forum\Thread;
use Auth;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\ServiceProvider;
use Hash;
use Validator;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -18,22 +16,8 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->bootHelpers();
$this->bootPasscheckValidationRule();
$this->bootEloquentMorphs();
}

private function bootHelpers()
{
require __DIR__ . '/helpers.php';
}

private function bootPasscheckValidationRule()
{
Validator::extend('passcheck', function ($attribute, $value, $parameters)
{
return Hash::check($value, Auth::user()->getAuthPassword());
});
$this->bootMacros();
}

private function bootEloquentMorphs()
Expand All @@ -42,4 +26,11 @@ private function bootEloquentMorphs()
Thread::TABLE => Thread::class,
]);
}

public function bootMacros()
{
foreach ($this->app[Filesystem::class]->files(resource_path('macros')) as $path) {
require $path;
}
}
}
11 changes: 0 additions & 11 deletions app/DateTime/Timestamps.php

This file was deleted.

71 changes: 63 additions & 8 deletions app/Forum/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace App\Forum;

use App\DateTime\Timestamps;
use App\Tags\TagAble;
use App\Users\Authored;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\DateTime\HasTimestamps;
use App\Forum\Exceptions\CouldNotMarkReplyAsSolution;
use App\Helpers\HasSlug;
use App\Helpers\HasTimestamps;
use App\Helpers\ModelHelpers;
use App\Replies\Reply;
use App\Replies\UsesReplies;
use App\Replies\ReplyAble;
use App\Tags\UsesTags;
use App\Users\HasAuthor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Thread extends Model implements Authored, ReplyAble, TagAble, Timestamps
class Thread extends Model implements ReplyAble
{
use HasAuthor, HasTimestamps, UsesReplies, UsesTags;
use HasAuthor, HasSlug, HasTimestamps, ModelHelpers, UsesReplies, UsesTags;

const TABLE = 'threads';

Expand Down Expand Up @@ -87,6 +87,24 @@ public function isSolutionReply(Reply $reply): bool
return false;
}

public function markSolution(Reply $reply)
{
$thread = $reply->replyAble();

if (! $thread instanceof Thread) {
throw CouldNotMarkReplyAsSolution::replyAbleIsNotAThread($reply);
}

$this->solutionReplyRelation()->associate($reply);
$this->save();
}

public function unmarkSolution()
{
$this->solutionReplyRelation()->dissociate();
$this->save();
}

public function replySubject(): string
{
return $this->subject();
Expand All @@ -96,4 +114,41 @@ public function replyExcerpt(): string
{
return $this->excerpt();
}

public static function createFromData(ThreadData $data): Thread
{
$thread = new static();
$thread->subject = $data->subject();
$thread->body = $data->body();
$thread->authorRelation()->associate($data->author());
$thread->topicRelation()->associate($data->topic());
$thread->slug = static::generateUniqueSlug($data->subject());
$thread->ip = $data->ip();
$thread->save();

if ($tags = $data->tags()) {
$thread->tagsRelation()->sync($tags);
}

$thread->save();

return $thread;
}

public function updateFromRequest(Thread $thread, array $attributes = [])
{
$this->update(array_only($attributes, ['subject', 'body']));

$this->slug = static::generateUniqueSlug($thread->subject(), $thread->id());

if ($topic = array_get($attributes, 'topic')) {
$this->topicRelation()->associate($topic);
}

if ($tags = (array) array_get($attributes, 'tags', [])) {
$this->tagsRelation()->sync($tags);
}

$this->save();
}
}
110 changes: 0 additions & 110 deletions app/Forum/ThreadRepository.php

This file was deleted.

8 changes: 4 additions & 4 deletions app/Forum/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace App\Forum;

use App\DateTime\Timestamps;
use App\Helpers\HasTimestamps;
use App\Helpers\HasSlug;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use App\DateTime\HasTimestamps;

class Topic extends Model implements Timestamps
class Topic extends Model
{
use HasTimestamps;
use HasSlug, HasTimestamps;

/**
* @var string
Expand Down
34 changes: 0 additions & 34 deletions app/Forum/TopicRepository.php

This file was deleted.

17 changes: 0 additions & 17 deletions app/Helpers/BuildsModels.php

This file was deleted.

32 changes: 0 additions & 32 deletions app/Helpers/GeneratesSlugs.php

This file was deleted.

Loading

0 comments on commit 6b3f35e

Please sign in to comment.