mirror of
https://github.com/flarum/core.git
synced 2025-10-28 22:07:33 +01:00
Use Laravel's class-based Str and Arr helpers
Starting with version 5.9, the global funtions will be deprecated. * https://laravel-news.com/laravel-5-8-deprecates-string-and-array-helpers * https://github.com/laravel/framework/pull/26898
This commit is contained in:
@@ -19,6 +19,7 @@ use Flarum\User\User;
|
||||
use Flarum\User\UserRepository;
|
||||
use Flarum\User\UserValidator;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class EditUserHandler
|
||||
@@ -64,8 +65,8 @@ class EditUserHandler
|
||||
$canEdit = $actor->can('edit', $user);
|
||||
$isSelf = $actor->id === $user->id;
|
||||
|
||||
$attributes = array_get($data, 'attributes', []);
|
||||
$relationships = array_get($data, 'relationships', []);
|
||||
$attributes = Arr::get($data, 'attributes', []);
|
||||
$relationships = Arr::get($data, 'relationships', []);
|
||||
$validate = [];
|
||||
|
||||
if (isset($attributes['username'])) {
|
||||
@@ -115,7 +116,7 @@ class EditUserHandler
|
||||
|
||||
$newGroupIds = [];
|
||||
foreach ($relationships['groups']['data'] as $group) {
|
||||
if ($id = array_get($group, 'id')) {
|
||||
if ($id = Arr::get($group, 'id')) {
|
||||
$newGroupIds[] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ use Flarum\User\RegistrationToken;
|
||||
use Flarum\User\User;
|
||||
use Flarum\User\UserValidator;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Intervention\Image\ImageManager;
|
||||
|
||||
@@ -75,19 +77,19 @@ class RegisterUserHandler
|
||||
$this->assertAdmin($actor);
|
||||
}
|
||||
|
||||
$password = array_get($data, 'attributes.password');
|
||||
$password = Arr::get($data, 'attributes.password');
|
||||
|
||||
// If a valid authentication token was provided as an attribute,
|
||||
// then we won't require the user to choose a password.
|
||||
if (isset($data['attributes']['token'])) {
|
||||
$token = RegistrationToken::validOrFail($data['attributes']['token']);
|
||||
|
||||
$password = $password ?: str_random(20);
|
||||
$password = $password ?: Str::random(20);
|
||||
}
|
||||
|
||||
$user = User::register(
|
||||
array_get($data, 'attributes.username'),
|
||||
array_get($data, 'attributes.email'),
|
||||
Arr::get($data, 'attributes.username'),
|
||||
Arr::get($data, 'attributes.email'),
|
||||
$password
|
||||
);
|
||||
|
||||
@@ -95,7 +97,7 @@ class RegisterUserHandler
|
||||
$this->applyToken($user, $token);
|
||||
}
|
||||
|
||||
if ($actor->isAdmin() && array_get($data, 'attributes.isEmailConfirmed')) {
|
||||
if ($actor->isAdmin() && Arr::get($data, 'attributes.isEmailConfirmed')) {
|
||||
$user->activate();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Flarum\User;
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\User\Exception\InvalidConfirmationTokenException;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $token
|
||||
@@ -54,7 +55,7 @@ class EmailToken extends AbstractModel
|
||||
{
|
||||
$token = new static;
|
||||
|
||||
$token->token = str_random(40);
|
||||
$token->token = Str::random(40);
|
||||
$token->user_id = $userId;
|
||||
$token->email = $email;
|
||||
$token->created_at = Carbon::now();
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Flarum\User;
|
||||
|
||||
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Support\Str;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
@@ -98,7 +99,7 @@ class Gate implements GateContract
|
||||
{
|
||||
if (is_callable($callback)) {
|
||||
$this->abilities[$ability] = $callback;
|
||||
} elseif (is_string($callback) && str_contains($callback, '@')) {
|
||||
} elseif (is_string($callback) && Str::contains($callback, '@')) {
|
||||
$this->abilities[$ability] = $this->buildAbilityCallback($callback);
|
||||
} else {
|
||||
throw new InvalidArgumentException("Callback must be a callable or a 'Class@method' string.");
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Flarum\User;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $token
|
||||
@@ -50,7 +51,7 @@ class PasswordToken extends AbstractModel
|
||||
{
|
||||
$token = new static;
|
||||
|
||||
$token->token = str_random(40);
|
||||
$token->token = Str::random(40);
|
||||
$token->user_id = $userId;
|
||||
$token->created_at = Carbon::now();
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Flarum\User;
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\User\Exception\InvalidConfirmationTokenException;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $token
|
||||
@@ -62,7 +63,7 @@ class RegistrationToken extends AbstractModel
|
||||
{
|
||||
$token = new static;
|
||||
|
||||
$token->token = str_random(40);
|
||||
$token->token = Str::random(40);
|
||||
$token->provider = $provider;
|
||||
$token->identifier = $identifier;
|
||||
$token->user_attributes = $attributes;
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Flarum\User;
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\User\Event\Saving;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SelfDemotionGuard
|
||||
{
|
||||
@@ -35,7 +36,7 @@ class SelfDemotionGuard
|
||||
return;
|
||||
}
|
||||
|
||||
$groups = array_get($event->data, 'relationships.groups.data');
|
||||
$groups = Arr::get($event->data, 'relationships.groups.data');
|
||||
|
||||
// If there is no group data (not even an empty array), this means
|
||||
// groups were not changed (and thus not removed) - we're fine!
|
||||
|
||||
@@ -37,6 +37,7 @@ use Flarum\User\Event\Registered;
|
||||
use Flarum\User\Event\Renamed;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -460,7 +461,7 @@ class User extends AbstractModel
|
||||
return $value['default'];
|
||||
}, static::$preferences);
|
||||
|
||||
$user = array_only((array) json_decode($value, true), array_keys(static::$preferences));
|
||||
$user = Arr::only((array) json_decode($value, true), array_keys(static::$preferences));
|
||||
|
||||
return array_merge($defaults, $user);
|
||||
}
|
||||
@@ -508,7 +509,7 @@ class User extends AbstractModel
|
||||
*/
|
||||
public function getPreference($key, $default = null)
|
||||
{
|
||||
return array_get($this->preferences, $key, $default);
|
||||
return Arr::get($this->preferences, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user