Skip to content

Commit 0b1106d

Browse files
committed
Migrate to Laravel 5
1 parent 7292a22 commit 0b1106d

File tree

348 files changed

+4933
-5732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+4933
-5732
lines changed

.coveralls.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
service_name: travis-ci
22

33
# for php-coveralls
4-
src_dir: app/Lio
4+
src_dir: app/
55
coverage_clover: build/logs/clover.xml
6-
json_path: build/logs/coveralls-upload.json
6+
json_path: build/logs/coveralls-upload.json

.env.example

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
APP_ENV=local
2+
APP_DEBUG=true
3+
4+
DB_HOST=localhost
5+
DB_DATABASE=laravelio
6+
DB_USERNAME=homestead
7+
DB_PASSWORD=secret
8+
9+
CACHE_DRIVER=file
10+
SESSION_DRIVER=file
11+
QUEUE_DRIVER=sync
12+
13+
MAIL_DRIVER=smtp
14+
MAIL_HOST=mailtrap.io
15+
MAIL_PORT=2525
16+
MAIL_USERNAME=null
17+
MAIL_PASSWORD=null
18+
MAIL_ENCRYPTION=null
19+
20+
NOCAPTCHA_SITEKEY=
21+
NOCAPTCHA_SECRET=
22+
GITHUB_ID=
23+
GITHUB_SECRET=
24+
GITHUB_URL=

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.idea
3-
bootstrap/compiled.php
4-
vendor/
3+
/vendor
4+
/node_modules
5+
Homestead.yaml
56
.env

.scrutinizer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
filter:
2-
paths: [app/Lio/*]
2+
paths: [app/*]
33
tools:
44
php_analyzer: true
55
php_code_sniffer:
@@ -60,4 +60,4 @@ checks:
6060
classes_in_camel_caps: true
6161
blank_line_after_namespace_declaration: true
6262
avoid_usage_of_logical_operators: true
63-
avoid_tab_indentation: true
63+
avoid_tab_indentation: true

.travis.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
language: php
22

33
php:
4-
- 5.4
5-
- 5.5
64
- 5.6
5+
- 7.0
76
- hhvm
87

8+
sudo: false
9+
910
before_script:
10-
- travis_retry composer self-update
11-
- travis_retry composer require satooshi/php-coveralls:dev-master --dev --no-progress --prefer-source
12-
- travis_retry composer install --prefer-source --no-interaction --dev
11+
- composer self-update
12+
- composer install --prefer-source --no-interaction --dev
1313

1414
script:
15-
- touch .env
16-
- mkdir -p build/logs
17-
- vendor/bin/phpspec run --verbose --format=dot
18-
- vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml
15+
- vendor/bin/phpspec run --verbose
16+
- vendor/bin/phpunit -v --coverage-clover ./build/logs/clover.xml
1917

2018
after_script:
2119
- php vendor/bin/coveralls -v
2220

2321
matrix:
2422
allow_failures:
23+
- php: 7.0
2524
- php: hhvm
26-
fast_finish: true

app/Accounts/InvalidRoleException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
namespace Lio\Accounts;
3+
4+
class InvalidRoleException extends \Exception {}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

34
use Lio\Core\Entity;
45

56
class Role extends Entity
67
{
8+
/**
9+
* The database table used by the model.
10+
*
11+
* @var string
12+
*/
713
protected $table = 'roles';
814

15+
/**
16+
* The attributes that are mass assignable.
17+
*
18+
* @var array
19+
*/
920
protected $fillable = ['name', 'description'];
1021

1122
protected $validationRules = [
@@ -14,6 +25,6 @@ class Role extends Entity
1425

1526
public function users()
1627
{
17-
$this->belongsToMany('Lio\Accounts\User');
28+
$this->belongsToMany(User::class);
1829
}
1930
}

src/Accounts/RoleRepository.php renamed to app/Accounts/RoleRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

34
use Lio\Core\EloquentRepository;
45

src/Accounts/SendConfirmationEmail.php renamed to app/Accounts/SendConfirmationEmail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(Mailer $mailer)
3131
*
3232
* @param \Lio\Accounts\User $user
3333
*/
34-
public function send($user)
34+
public function send(User $user)
3535
{
3636
$this->mailer->send(
3737
$this->view,

src/Accounts/User.php renamed to app/Accounts/User.php

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

34
use Carbon\Carbon;
4-
use Illuminate\Auth\Reminders\RemindableTrait;
5-
use Illuminate\Auth\UserInterface;
6-
use Illuminate\Auth\Reminders\RemindableInterface;
7-
use Illuminate\Auth\UserTrait;
8-
use Illuminate\Database\Eloquent\SoftDeletingTrait;
9-
use Lio\Core\Entity;
105
use Eloquent;
11-
use McCool\LaravelAutoPresenter\PresenterInterface;
6+
use Illuminate\Auth\Authenticatable;
7+
use Illuminate\Auth\Passwords\CanResetPassword;
8+
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9+
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
10+
use Illuminate\Database\Eloquent\SoftDeletes;
11+
use Lio\Core\Entity;
12+
use McCool\LaravelAutoPresenter\HasPresenter;
1213

13-
class User extends Entity implements UserInterface, RemindableInterface, PresenterInterface
14+
class User extends Entity implements AuthenticatableContract, CanResetPasswordContract, HasPresenter
1415
{
15-
use UserTrait, RemindableTrait, SoftDeletingTrait;
16+
use Authenticatable, CanResetPassword, SoftDeletes;
1617

17-
const STATE_ACTIVE = 1;
18-
const STATE_BLOCKED = 2;
18+
/**
19+
* The database table used by the model.
20+
*
21+
* @var string
22+
*/
23+
protected $table = 'users';
1924

20-
protected $table = 'users';
21-
protected $hidden = ['github_id', 'email', 'remember_token'];
25+
/**
26+
* The attributes that are mass assignable.
27+
*
28+
* @var array
29+
*/
2230
protected $fillable = ['email', 'name', 'github_url', 'github_id', 'image_url', 'is_banned', 'ip'];
23-
protected $dates = ['deleted_at'];
31+
32+
/**
33+
* The attributes excluded from the model's JSON form.
34+
*
35+
* @var array
36+
*/
37+
protected $hidden = ['github_id', 'email', 'remember_token'];
38+
39+
/**
40+
* The attributes that should be mutated to dates.
41+
*
42+
* @var array
43+
*/
44+
protected $dates = ['deleted_at'];
2445

2546
protected $validationRules = [
2647
'github_id' => 'unique:users,github_id,<id>',
@@ -30,21 +51,14 @@ class User extends Entity implements UserInterface, RemindableInterface, Present
3051

3152
private $rolesCache;
3253

33-
// Articles
34-
public function articles()
35-
{
36-
return $this->hasMany('Lio\Articles\Article', 'author_id');
37-
}
38-
39-
// Roles
4054
public function roles()
4155
{
42-
return $this->belongsToMany('Lio\Accounts\Role');
56+
return $this->belongsToMany(Role::class);
4357
}
4458

4559
public function getRoles()
4660
{
47-
if ( ! isset($this->rolesCache)) {
61+
if (! isset($this->rolesCache)) {
4862
$this->rolesCache = $this->roles;
4963
}
5064

@@ -68,16 +82,16 @@ public function hasRole($roleName)
6882

6983
public function hasRoles($roleNames = [])
7084
{
71-
$roleList = \App::make('Lio\Accounts\RoleRepository')->getRoleList();
85+
$roleList = app(RoleRepository::class)->getRoleList();
7286

7387
foreach ((array) $roleNames as $allowedRole) {
7488
// validate that the role exists
75-
if ( ! in_array($allowedRole, $roleList)) {
89+
if (! $roleList->contains($allowedRole)) {
7690
throw new InvalidRoleException("Unidentified role: {$allowedRole}");
7791
}
7892

7993
// validate that the user has the role
80-
if ( ! $this->roleCollectionHasRole($allowedRole)) {
94+
if (! $this->roleCollectionHasRole($allowedRole)) {
8195
return false;
8296
}
8397
}
@@ -89,7 +103,7 @@ private function roleCollectionHasRole($allowedRole)
89103
{
90104
$roles = $this->getRoles();
91105

92-
if ( ! $roles) {
106+
if (! $roles) {
93107
return false;
94108
}
95109

@@ -135,32 +149,36 @@ public function getLatestRepliesPaginated($max = 5)
135149

136150
public function hasCreatedAThreadRecently()
137151
{
138-
$thread = $this->forumThreads()->first();
139-
140-
if ($thread) {
152+
if ($thread = $this->forumThreads()->first()) {
141153
return $thread->created_at->gte(new Carbon('10 minutes ago'));
142154
}
143155

144156
return false;
145157
}
146158

147159
/**
148-
* Determine if the user has confirmed his email address already or not
149-
*
150160
* @return bool
151161
*/
152162
public function isConfirmed()
153163
{
154164
return (bool) $this->confirmed;
155165
}
156166

167+
/**
168+
* @return bool
169+
*/
170+
public function isBanned()
171+
{
172+
return (bool) $this->is_banned;
173+
}
174+
157175
/**
158176
* Get the presenter class.
159177
*
160-
* @return string The class path to the presenter.
178+
* @return string
161179
*/
162-
public function getPresenter()
180+
public function getPresenterClass()
163181
{
164-
return 'Lio\Accounts\UserPresenter';
182+
return UserPresenter::class;
165183
}
166184
}

src/Accounts/UserCreator.php renamed to app/Accounts/UserCreator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

34
use Illuminate\Support\Str;
45

@@ -65,4 +66,4 @@ private function createValidUserRecord($listener, $data)
6566

6667
return $listener->userCreated($user);
6768
}
68-
}
69+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

34
interface UserCreatorListener
45
{
56
public function userValidationError($errors);
67
public function userCreated($user);
7-
}
8+
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

3-
use HTML;
44
use McCool\LaravelAutoPresenter\BasePresenter;
55

66
class UserPresenter extends BasePresenter
77
{
88
public function roleList()
99
{
10-
$roles = $this->getRoles();
10+
$roles = $this->roles;
1111

12-
if ( ! $roles->count()) {
13-
return "none";
12+
if (! $roles->count()) {
13+
return 'none';
1414
}
1515

1616
$roleArray = [];
@@ -24,16 +24,16 @@ public function roleList()
2424

2525
public function profileUrl()
2626
{
27-
return action('UsersController@getProfile', [$this->resource->name]);
27+
return action('UsersController@getProfile', [$this->getWrappedObject()->name]);
2828
}
2929

3030
public function thumbnail()
3131
{
32-
return HTML::image($this->image_url . "&size=50", $this->resource->name);
32+
return '<img src="' . $this->image_url . '&size=50" alt="' . $this->getWrappedObject()->name . '">';
3333
}
3434

3535
public function imageMedium()
3636
{
37-
return HTML::image($this->image_url . "&size=300");
37+
return '<img src="' . $this->image_url . '&size=300">';
3838
}
39-
}
39+
}

src/Accounts/UserRepository.php renamed to app/Accounts/UserRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

34
use Lio\Core\EloquentRepository;
45
use Lio\Core\Exceptions\EntityNotFoundException;

src/Accounts/UserUpdater.php renamed to app/Accounts/UserUpdater.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace Lio\Accounts;
1+
<?php
2+
namespace Lio\Accounts;
23

34
use Illuminate\Support\Str;
45
use Illuminate\Validation\Validator;
@@ -82,4 +83,4 @@ private function updateUser(User $user, UserUpdaterListener $listener, array $da
8283

8384
return $listener->userUpdated($user, $data['email'] !== $oldEmail);
8485
}
85-
}
86+
}

0 commit comments

Comments
 (0)