Skip to content

Commit

Permalink
[5.x] Drop laravel/helpers dependency (#9811)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Apr 3, 2024
1 parent 8bd663a commit a9f4e41
Show file tree
Hide file tree
Showing 98 changed files with 306 additions and 233 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"james-heinrich/getid3": "^1.9.21",
"laravel/framework": "^10.40 || ^11.0",
"laravel/helpers": "^1.1",
"league/commonmark": "^2.2",
"league/csv": "^9.0",
"league/glide": "^2.0",
Expand Down
3 changes: 2 additions & 1 deletion resources/views/forms/widget.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@php use function Statamic\trans as __; @endphp
@php use Statamic\Support\Arr; @endphp

<div class="card p-0 overflow-hidden">
<div class="flex justify-between items-center p-4">
Expand All @@ -19,7 +20,7 @@
@foreach($submissions as $submission)
<tr>
@foreach($fields as $key => $field)
<td><a href="{{ cp_route('forms.submissions.show', [$form->handle(), $submission['id']]) }}">{{ array_get($submission, $field) }}</a></td>
<td><a href="{{ cp_route('forms.submissions.show', [$form->handle(), $submission['id']]) }}">{{ Arr::get($submission, $field) }}</a></td>
@endforeach
<td class="rtl:text-left ltr:text-right">
{{ ($submission['date']->diffInDays() <= 14) ? $submission['date']->diffForHumans() : $submission['date']->format($format) }}
Expand Down
3 changes: 2 additions & 1 deletion src/Assets/AssetContainerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Statamic\Facades\Parse;
use Statamic\Facades\Path;
use Statamic\Facades\URL;
use Statamic\Support\Arr;

class AssetContainerManager
{
Expand Down Expand Up @@ -69,7 +70,7 @@ public function createS3Filesystem($config)
{
$config = $this->parseEnv($config);

$config['root'] = array_get($config, 'path');
$config['root'] = Arr::get($config, 'path');

return $this->filesystem->createS3Driver($config);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Assets/AssetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public function findByUrl(string $url)
$siteUrl = rtrim(Site::current()->absoluteUrl(), '/');
$containerUrl = $container->url();

if (starts_with($containerUrl, '/')) {
if (Str::startsWith($containerUrl, '/')) {
$containerUrl = $siteUrl.$containerUrl;
}

if (starts_with($containerUrl, $siteUrl)) {
if (Str::startsWith($containerUrl, $siteUrl)) {
$url = $siteUrl.$url;
}

$path = str_after($url, $containerUrl);
$path = Str::after($url, $containerUrl);

return $container->asset($path);
}
Expand All @@ -77,8 +77,8 @@ protected function resolveContainerFromUrl($url)
return AssetContainer::all()->sortByDesc(function ($container) {
return strlen($container->url());
})->first(function ($container, $id) use ($url) {
return starts_with($url, $container->url())
|| starts_with(URL::makeAbsolute($url), $container->url());
return Str::startsWith($url, $container->url())
|| Str::startsWith(URL::makeAbsolute($url), $container->url());
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/Auth/Eloquent/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function data($data = null)
'groups' => $this->groups()->map->handle()->values()->all(),
]);

return collect(array_except($data, ['id', 'email']));
return collect(Arr::except($data, ['id', 'email']));
}

foreach ($data as $key => $value) {
Expand Down Expand Up @@ -117,7 +117,7 @@ protected function saveRoles()

public function assignRole($role)
{
$roles = collect(array_wrap($role))->map(function ($role) {
$roles = collect(Arr::wrap($role))->map(function ($role) {
return is_string($role) ? Role::find($role) : $role;
})->filter();

Expand All @@ -132,7 +132,7 @@ public function assignRole($role)

public function removeRole($role)
{
$roles = collect(array_wrap($role))->map(function ($role) {
$roles = collect(Arr::wrap($role))->map(function ($role) {
return is_string($role) ? Role::find($role) : $role;
})->filter();

Expand Down Expand Up @@ -183,7 +183,7 @@ protected function saveGroups()

public function addToGroup($group)
{
$groups = collect(array_wrap($group))->map(function ($group) {
$groups = collect(Arr::wrap($group))->map(function ($group) {
return is_string($group) ? UserGroup::find($group) : $group;
})->filter();

Expand All @@ -198,7 +198,7 @@ public function addToGroup($group)

public function removeFromGroup($group)
{
$groups = collect(array_wrap($group))->map(function ($group) {
$groups = collect(Arr::wrap($group))->map(function ($group) {
return is_string($group) ? UserGroup::find($group) : $group;
})->filter();

Expand Down
15 changes: 8 additions & 7 deletions src/Auth/File/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Statamic\Facades\Stache;
use Statamic\Facades\YAML;
use Statamic\Preferences\HasPreferencesInProperty;
use Statamic\Support\Arr;
use Statamic\Support\Traits\FluentlyGetsAndSets;

/**
Expand Down Expand Up @@ -46,11 +47,11 @@ public function data($data = null)

$this->traitData($data);

if (array_has($data, 'password')) {
if (Arr::has($data, 'password')) {
$this->remove('password')->password($data['password']);
}

if (array_has($data, 'password_hash')) {
if (Arr::has($data, 'password_hash')) {
$this->remove('password_hash')->passwordHash($data['password_hash']);
}

Expand Down Expand Up @@ -167,7 +168,7 @@ protected function getRoles()

public function assignRole($role)
{
$roles = collect(array_wrap($role))->map(function ($role) {
$roles = collect(Arr::wrap($role))->map(function ($role) {
return is_string($role) ? $role : $role->handle();
})->all();

Expand All @@ -178,7 +179,7 @@ public function assignRole($role)

public function removeRole($role)
{
$toBeRemoved = collect(array_wrap($role))->map(function ($role) {
$toBeRemoved = collect(Arr::wrap($role))->map(function ($role) {
return is_string($role) ? $role : $role->handle();
});

Expand All @@ -201,7 +202,7 @@ public function hasRole($role)

public function addToGroup($group)
{
$groups = collect(array_wrap($group))->map(function ($group) {
$groups = collect(Arr::wrap($group))->map(function ($group) {
return is_string($group) ? $group : $group->handle();
})->all();

Expand All @@ -212,7 +213,7 @@ public function addToGroup($group)

public function removeFromGroup($group)
{
$toBeRemoved = collect(array_wrap($group))->map(function ($group) {
$toBeRemoved = collect(Arr::wrap($group))->map(function ($group) {
return is_string($group) ? $group : $group->handle();
});

Expand Down Expand Up @@ -314,7 +315,7 @@ public function getMeta($key, $default = null)
{
$yaml = YAML::file($this->metaPath())->parse();

return array_get($yaml, $key, $default);
return Arr::get($yaml, $key, $default);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Auth/File/UserGroupRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Statamic\Facades;
use Statamic\Facades\File;
use Statamic\Facades\YAML;
use Statamic\Support\Arr;

class UserGroupRepository extends BaseRepository
{
Expand All @@ -30,7 +31,7 @@ public function all(): Collection
return $this->groups = $this->raw()->map(function ($data, $handle) {
$group = Facades\UserGroup::make()
->handle($handle)
->title(array_get($data, 'title'))
->title(Arr::get($data, 'title'))
->data($data);

foreach ($data['roles'] ?? [] as $role) {
Expand Down
7 changes: 4 additions & 3 deletions src/Auth/Protect/Protectors/Authenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Auth\Protect\Protectors;

use Statamic\Exceptions\ForbiddenHttpException;
use Statamic\Support\Arr;

class Authenticated extends Protector
{
Expand All @@ -25,7 +26,7 @@ public function protect()

protected function getLoginUrl()
{
if (! $url = array_get($this->config, 'login_url')) {
if (! $url = Arr::get($this->config, 'login_url')) {
return null;
}

Expand All @@ -35,7 +36,7 @@ protected function getLoginUrl()

$url = parse_url($url);

if ($query = array_get($url, 'query')) {
if ($query = Arr::get($url, 'query')) {
$query .= '&';
}

Expand All @@ -49,6 +50,6 @@ protected function isLoginUrl()

protected function shouldAppendRedirect()
{
return array_get($this->config, 'append_redirect', false);
return Arr::get($this->config, 'append_redirect', false);
}
}
3 changes: 2 additions & 1 deletion src/Auth/Protect/Protectors/IpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace Statamic\Auth\Protect\Protectors;

use Statamic\Exceptions\ForbiddenHttpException;
use Statamic\Support\Arr;

class IpAddress extends Protector
{
public function protect()
{
$ips = array_get($this->config, 'allowed', []);
$ips = Arr::get($this->config, 'allowed', []);

if (! in_array(request()->ip(), $ips)) {
throw new ForbiddenHttpException();
Expand Down
4 changes: 3 additions & 1 deletion src/Auth/Protect/Protectors/Password/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Statamic\Auth\Protect\Protectors\Password;

use Statamic\Support\Arr;

class Guard
{
protected $config;
Expand All @@ -13,7 +15,7 @@ public function __construct($scheme)

public function check($password)
{
$allowed = array_get($this->config, 'allowed', []);
$allowed = Arr::get($this->config, 'allowed', []);

return in_array($password, $allowed);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Auth/Protect/Protectors/Password/PasswordProtector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Facades\Statamic\Auth\Protect\Protectors\Password\Token;
use Statamic\Auth\Protect\Protectors\Protector;
use Statamic\Exceptions\ForbiddenHttpException;
use Statamic\Support\Arr;

class PasswordProtector extends Protector
{
Expand All @@ -15,7 +16,7 @@ class PasswordProtector extends Protector
*/
public function protect()
{
if (empty(array_get($this->config, 'allowed', []))) {
if (empty(Arr::get($this->config, 'allowed', []))) {
throw new ForbiddenHttpException();
}

Expand Down
6 changes: 3 additions & 3 deletions src/Auth/RoleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function all(): Collection
return $this->roles = $this->raw()->map(function ($role, $handle) {
return Facades\Role::make()
->handle($handle)
->title(array_get($role, 'title'))
->addPermission(array_get($role, 'permissions', []))
->preferences(array_get($role, 'preferences', []));
->title(Arr::get($role, 'title'))
->addPermission(Arr::get($role, 'permissions', []))
->preferences(Arr::get($role, 'preferences', []));
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/Console/Commands/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function getStub($stub = null)
*/
protected function getNameInput()
{
return studly_case(parent::getNameInput());
return Str::studly(parent::getNameInput());
}

/**
Expand Down Expand Up @@ -126,7 +126,7 @@ protected function getAddonPath($addon)
{
// If explicitly setting addon path from an external command like `make:addon`,
// use explicit path and allow external command to handle path output.
if (starts_with($addon, '/') && $this->files->exists($addon)) {
if (Str::startsWith($addon, '/') && $this->files->exists($addon)) {
return $addon;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ protected function getOptions()
*/
public function __get($attribute)
{
$words = explode('_', snake_case($attribute));
$words = explode('_', Str::snake($attribute));

// If trying to access `type` attribute, allow dynamic string manipulation like `typeLowerPlural`.
if ($words[0] === 'type') {
Expand Down
11 changes: 6 additions & 5 deletions src/Console/Commands/MakeAddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Statamic\Console\RunsInPlease;
use Statamic\Console\ValidatesInput;
use Statamic\Rules\ComposerPackage;
use Statamic\Support\Str;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

Expand Down Expand Up @@ -102,8 +103,8 @@ protected function normalizePackage()
{
$parts = explode('/', $this->package);

$this->vendorSlug = str_slug(snake_case($parts[0]));
$this->nameSlug = str_slug(snake_case($parts[1]));
$this->vendorSlug = Str::slug(Str::snake($parts[0]));
$this->nameSlug = Str::slug(Str::snake($parts[1]));
$this->package = "{$this->vendorSlug}/{$this->nameSlug}";
}

Expand Down Expand Up @@ -268,7 +269,7 @@ protected function runOptionalAddonGenerator($type)
{
$prefix = $this->runningInPlease ? '' : 'statamic:';

$name = studly_case($this->nameSlug);
$name = Str::studly($this->nameSlug);

// Prevent conflicts when also creating a scope, since they're in the same directory.
if ($type === 'filter') {
Expand Down Expand Up @@ -322,7 +323,7 @@ protected function addonPath($file = null, $makeDirectory = true)
*/
protected function addonNamespace()
{
return studly_case($this->vendorSlug).'\\'.studly_case($this->nameSlug);
return Str::studly($this->vendorSlug).'\\'.Str::studly($this->nameSlug);
}

/**
Expand All @@ -332,7 +333,7 @@ protected function addonNamespace()
*/
protected function addonTitle()
{
return str_replace('-', ' ', title_case($this->nameSlug));
return str_replace('-', ' ', Str::title($this->nameSlug));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Commands/MakeFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;
use Statamic\Support\Str;
use Symfony\Component\Console\Input\InputOption;

class MakeFieldtype extends GeneratorCommand
Expand Down Expand Up @@ -97,7 +98,7 @@ protected function buildVueComponent($name)
$component = $this->files->get($this->getStub('fieldtype.vue.stub'));

$component = str_replace('DummyName', $name, $component);
$component = str_replace('dummy_name', snake_case($name), $component);
$component = str_replace('dummy_name', Str::snake($name), $component);

return $component;
}
Expand Down
Loading

0 comments on commit a9f4e41

Please sign in to comment.