diff --git a/composer.json b/composer.json index f77fb6ad86..098e34eac5 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/resources/views/forms/widget.blade.php b/resources/views/forms/widget.blade.php index e21169c833..2f194df6ef 100644 --- a/resources/views/forms/widget.blade.php +++ b/resources/views/forms/widget.blade.php @@ -1,4 +1,5 @@ @php use function Statamic\trans as __; @endphp +@php use Statamic\Support\Arr; @endphp
@@ -19,7 +20,7 @@ @foreach($submissions as $submission) @foreach($fields as $key => $field) - {{ array_get($submission, $field) }} + {{ Arr::get($submission, $field) }} @endforeach {{ ($submission['date']->diffInDays() <= 14) ? $submission['date']->diffForHumans() : $submission['date']->format($format) }} diff --git a/src/Assets/AssetContainerManager.php b/src/Assets/AssetContainerManager.php index da68eec326..bff190ab01 100644 --- a/src/Assets/AssetContainerManager.php +++ b/src/Assets/AssetContainerManager.php @@ -6,6 +6,7 @@ use Statamic\Facades\Parse; use Statamic\Facades\Path; use Statamic\Facades\URL; +use Statamic\Support\Arr; class AssetContainerManager { @@ -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); } diff --git a/src/Assets/AssetRepository.php b/src/Assets/AssetRepository.php index cd2109a2bf..fab889b8cf 100644 --- a/src/Assets/AssetRepository.php +++ b/src/Assets/AssetRepository.php @@ -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); } @@ -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()); }); } diff --git a/src/Auth/Eloquent/User.php b/src/Auth/Eloquent/User.php index d2b01637ae..830ba65d39 100644 --- a/src/Auth/Eloquent/User.php +++ b/src/Auth/Eloquent/User.php @@ -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) { @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/src/Auth/File/User.php b/src/Auth/File/User.php index e19d2107f2..bd84104d49 100644 --- a/src/Auth/File/User.php +++ b/src/Auth/File/User.php @@ -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; /** @@ -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']); } @@ -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(); @@ -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(); }); @@ -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(); @@ -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(); }); @@ -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); } /** diff --git a/src/Auth/File/UserGroupRepository.php b/src/Auth/File/UserGroupRepository.php index 8545aac14c..22de623e9c 100644 --- a/src/Auth/File/UserGroupRepository.php +++ b/src/Auth/File/UserGroupRepository.php @@ -8,6 +8,7 @@ use Statamic\Facades; use Statamic\Facades\File; use Statamic\Facades\YAML; +use Statamic\Support\Arr; class UserGroupRepository extends BaseRepository { @@ -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) { diff --git a/src/Auth/Protect/Protectors/Authenticated.php b/src/Auth/Protect/Protectors/Authenticated.php index 3852e30cfd..6eaaa58e2a 100644 --- a/src/Auth/Protect/Protectors/Authenticated.php +++ b/src/Auth/Protect/Protectors/Authenticated.php @@ -3,6 +3,7 @@ namespace Statamic\Auth\Protect\Protectors; use Statamic\Exceptions\ForbiddenHttpException; +use Statamic\Support\Arr; class Authenticated extends Protector { @@ -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; } @@ -35,7 +36,7 @@ protected function getLoginUrl() $url = parse_url($url); - if ($query = array_get($url, 'query')) { + if ($query = Arr::get($url, 'query')) { $query .= '&'; } @@ -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); } } diff --git a/src/Auth/Protect/Protectors/IpAddress.php b/src/Auth/Protect/Protectors/IpAddress.php index 0f66fb7467..fb35a52fe1 100644 --- a/src/Auth/Protect/Protectors/IpAddress.php +++ b/src/Auth/Protect/Protectors/IpAddress.php @@ -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(); diff --git a/src/Auth/Protect/Protectors/Password/Guard.php b/src/Auth/Protect/Protectors/Password/Guard.php index ce4493b489..3ec5f0f168 100644 --- a/src/Auth/Protect/Protectors/Password/Guard.php +++ b/src/Auth/Protect/Protectors/Password/Guard.php @@ -2,6 +2,8 @@ namespace Statamic\Auth\Protect\Protectors\Password; +use Statamic\Support\Arr; + class Guard { protected $config; @@ -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); } diff --git a/src/Auth/Protect/Protectors/Password/PasswordProtector.php b/src/Auth/Protect/Protectors/Password/PasswordProtector.php index 42e2b09bbd..d7af6a5722 100644 --- a/src/Auth/Protect/Protectors/Password/PasswordProtector.php +++ b/src/Auth/Protect/Protectors/Password/PasswordProtector.php @@ -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 { @@ -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(); } diff --git a/src/Auth/RoleRepository.php b/src/Auth/RoleRepository.php index 9cbfc750de..d6de053544 100644 --- a/src/Auth/RoleRepository.php +++ b/src/Auth/RoleRepository.php @@ -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', [])); }); } diff --git a/src/Console/Commands/GeneratorCommand.php b/src/Console/Commands/GeneratorCommand.php index 9de87901c9..490033f038 100644 --- a/src/Console/Commands/GeneratorCommand.php +++ b/src/Console/Commands/GeneratorCommand.php @@ -59,7 +59,7 @@ protected function getStub($stub = null) */ protected function getNameInput() { - return studly_case(parent::getNameInput()); + return Str::studly(parent::getNameInput()); } /** @@ -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; } @@ -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') { diff --git a/src/Console/Commands/MakeAddon.php b/src/Console/Commands/MakeAddon.php index bada10e715..0992270294 100644 --- a/src/Console/Commands/MakeAddon.php +++ b/src/Console/Commands/MakeAddon.php @@ -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; @@ -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}"; } @@ -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') { @@ -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); } /** @@ -332,7 +333,7 @@ protected function addonNamespace() */ protected function addonTitle() { - return str_replace('-', ' ', title_case($this->nameSlug)); + return str_replace('-', ' ', Str::title($this->nameSlug)); } /** diff --git a/src/Console/Commands/MakeFieldtype.php b/src/Console/Commands/MakeFieldtype.php index 64dd08c02e..0720c3207c 100644 --- a/src/Console/Commands/MakeFieldtype.php +++ b/src/Console/Commands/MakeFieldtype.php @@ -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 @@ -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; } diff --git a/src/Console/Commands/MakeTag.php b/src/Console/Commands/MakeTag.php index ed734c066c..92bb893816 100644 --- a/src/Console/Commands/MakeTag.php +++ b/src/Console/Commands/MakeTag.php @@ -5,6 +5,7 @@ use Archetype\Facades\PHPFile; use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; +use Statamic\Support\Str; class MakeTag extends GeneratorCommand { @@ -82,7 +83,7 @@ protected function buildClass($name) { $class = parent::buildClass($name); - $class = str_replace('dummy_tag', snake_case($this->getNameInput()), $class); + $class = str_replace('dummy_tag', Str::snake($this->getNameInput()), $class); return $class; } diff --git a/src/Console/Commands/MakeWidget.php b/src/Console/Commands/MakeWidget.php index 61796a0bc0..65ef362760 100644 --- a/src/Console/Commands/MakeWidget.php +++ b/src/Console/Commands/MakeWidget.php @@ -5,6 +5,7 @@ use Archetype\Facades\PHPFile; use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; +use Statamic\Support\Str; class MakeWidget extends GeneratorCommand { @@ -70,7 +71,7 @@ protected function generateWidgetView() 'name' => $this->getNameInput(), ]; - $filename = str_slug(snake_case($this->getNameInput())); + $filename = Str::slug(Str::snake($this->getNameInput())); $this->createFromStub( 'widget.blade.php.stub', @@ -107,7 +108,7 @@ protected function buildClass($name) { $class = parent::buildClass($name); - $name = str_slug(snake_case($this->getNameInput())); + $name = Str::slug(Str::snake($this->getNameInput())); $viewPath = 'widgets.'.$name; if ($this->argument('addon')) { diff --git a/src/Console/Commands/ProEnable.php b/src/Console/Commands/ProEnable.php index 7d0650313f..865cc726d1 100644 --- a/src/Console/Commands/ProEnable.php +++ b/src/Console/Commands/ProEnable.php @@ -6,6 +6,7 @@ use Illuminate\Console\ConfirmableTrait; use Statamic\Console\EnhancesCommands; use Statamic\Console\RunsInPlease; +use Statamic\Support\Str; class ProEnable extends Command { @@ -147,9 +148,9 @@ protected function updateConfig() $contents = file_get_contents($configPath); - if (str_contains($contents, "'pro' => false,")) { + if (Str::contains($contents, "'pro' => false,")) { $contents = str_replace("'pro' => false,", "'pro' => env('STATAMIC_PRO_ENABLED', false),", $contents); - } elseif (str_contains($contents, "'pro' => true,")) { + } elseif (Str::contains($contents, "'pro' => true,")) { $contents = str_replace("'pro' => true,", "'pro' => env('STATAMIC_PRO_ENABLED', false),", $contents); } else { return false; diff --git a/src/Console/Processes/Process.php b/src/Console/Processes/Process.php index 4f76f84f45..5e1c014c69 100644 --- a/src/Console/Processes/Process.php +++ b/src/Console/Processes/Process.php @@ -8,6 +8,7 @@ use Statamic\Console\Processes\Exceptions\ProcessException; use Statamic\Facades\Path; use Statamic\Support\Arr; +use Statamic\Support\Str; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process as SymfonyProcess; @@ -57,7 +58,7 @@ class Process */ public function __construct($basePath = null) { - $this->basePath = str_finish($basePath ?? base_path(), '/'); + $this->basePath = Str::finish($basePath ?? base_path(), '/'); $this->env = $this->constructEnv(); } @@ -449,7 +450,7 @@ public function fromParent() { $that = clone $this; - $that->basePath = str_finish(Path::resolve($this->basePath.'/../'), '/'); + $that->basePath = Str::finish(Path::resolve($this->basePath.'/../'), '/'); return $that; } diff --git a/src/Extend/HasHandle.php b/src/Extend/HasHandle.php index 148da22239..d1106e447d 100644 --- a/src/Extend/HasHandle.php +++ b/src/Extend/HasHandle.php @@ -3,6 +3,7 @@ namespace Statamic\Extend; use ReflectionClass; +use Statamic\Support\Str; trait HasHandle { @@ -16,6 +17,6 @@ public static function handle() $class = (new ReflectionClass(static::class))->getShortName(); - return snake_case($class); + return Str::snake($class); } } diff --git a/src/Extensions/Translation/Translator.php b/src/Extensions/Translation/Translator.php index e131894147..9ab90afaf4 100644 --- a/src/Extensions/Translation/Translator.php +++ b/src/Extensions/Translation/Translator.php @@ -4,8 +4,10 @@ use Illuminate\Contracts\Translation\Loader; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Arr; use Illuminate\Translation\Translator as BaseTranslator; use Statamic\Statamic; +use Statamic\Support\Str; class Translator extends BaseTranslator { @@ -19,7 +21,7 @@ public function __construct(Filesystem $files, Loader $loader, $locale) public function parseKey($key) { - if (Statamic::isCpRoute() && starts_with($key, 'validation.')) { + if (Statamic::isCpRoute() && Str::startsWith($key, 'validation.')) { $key = 'statamic::'.$key; } @@ -45,7 +47,7 @@ public function toJson() $translations->put('*', $this->loader->load($this->locale, '*', '*')); // The Javascript side is expecting one flattened object. - return array_dot($translations); + return Arr::dot($translations); } protected function getTranslations($path, $namespace) diff --git a/src/Facades/Endpoint/Path.php b/src/Facades/Endpoint/Path.php index 4dd425a461..d034e53793 100644 --- a/src/Facades/Endpoint/Path.php +++ b/src/Facades/Endpoint/Path.php @@ -3,6 +3,7 @@ namespace Statamic\Facades\Endpoint; use Statamic\Facades\Pattern; +use Statamic\Support\Arr; use Statamic\Support\Str; /** @@ -209,7 +210,7 @@ public function extension($path) { $path = Str::before($path, '?'); - return array_get(pathinfo($path), 'extension'); + return Arr::get(pathinfo($path), 'extension'); } /** diff --git a/src/Fields/Blueprint.php b/src/Fields/Blueprint.php index e1278480f9..e5b3bdd758 100644 --- a/src/Fields/Blueprint.php +++ b/src/Fields/Blueprint.php @@ -399,7 +399,7 @@ public function isEmpty(): bool public function title() { - return array_get($this->contents, 'title', Str::humanize(Str::of($this->handle)->after('::')->afterLast('.'))); + return Arr::get($this->contents, 'title', Str::humanize(Str::of($this->handle)->after('::')->afterLast('.'))); } public function isNamespaced(): bool diff --git a/src/Fields/ClassRuleParser.php b/src/Fields/ClassRuleParser.php index 5c128f81fd..23b76e8c09 100644 --- a/src/Fields/ClassRuleParser.php +++ b/src/Fields/ClassRuleParser.php @@ -10,7 +10,7 @@ public function parse(string $rule): array { $rule = Str::substr($rule, 4); - if (! str_contains($rule, '(')) { + if (! Str::contains($rule, '(')) { return [$rule, []]; } @@ -29,7 +29,7 @@ public function parse(string $rule): array } if (is_numeric($arg)) { - return [$key => str_contains($arg, '.') ? (float) $arg : (int) $arg]; + return [$key => Str::contains($arg, '.') ? (float) $arg : (int) $arg]; } elseif (Str::startsWith($arg, '"') && Str::endsWith($arg, '"')) { return [$key => (string) Str::of($arg)->trim('"')->replace('\\"', '"')]; } elseif (Str::startsWith($arg, "'") && Str::endsWith($arg, "'")) { diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 5c48e79707..35e6ae06db 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -97,7 +97,7 @@ public function parentIndex() public function type() { - return array_get($this->config, 'type', 'text'); + return Arr::get($this->config, 'type', 'text'); } public function fieldtype() @@ -107,12 +107,12 @@ public function fieldtype() public function display() { - return array_get($this->config, 'display', __(Str::slugToTitle($this->handle))); + return Arr::get($this->config, 'display', __(Str::slugToTitle($this->handle))); } public function instructions() { - return array_get($this->config, 'instructions'); + return Arr::get($this->config, 'instructions'); } public function visibility() @@ -395,7 +395,7 @@ public function conditions(): array public function get(string $key, $fallback = null) { - return array_get($this->config, $key, $fallback); + return Arr::get($this->config, $key, $fallback); } private function preProcessedConfig() diff --git a/src/Fields/FieldTransformer.php b/src/Fields/FieldTransformer.php index c79612aa4c..f03b3d2214 100644 --- a/src/Fields/FieldTransformer.php +++ b/src/Fields/FieldTransformer.php @@ -103,7 +103,7 @@ private static function inlineTabField(array $submitted) private static function referenceTabField(array $submitted) { - $config = Arr::removeNullValues(array_only($submitted['config'], $submitted['config_overrides'])); + $config = Arr::removeNullValues(Arr::only($submitted['config'], $submitted['config_overrides'])); return array_filter([ 'handle' => $submitted['handle'], @@ -125,11 +125,11 @@ public static function toVue($field): array private static function referenceFieldToVue($field): array { - $fieldsetField = array_get(static::fieldsetFields(), $field['field'], []); + $fieldsetField = Arr::get(static::fieldsetFields(), $field['field'], []); $mergedConfig = array_merge( - $fieldsetFieldConfig = array_get($fieldsetField, 'config', []), - $config = array_get($field, 'config', []) + $fieldsetFieldConfig = Arr::get($fieldsetField, 'config', []), + $config = Arr::get($field, 'config', []) ); $mergedConfig['width'] = $mergedConfig['width'] ?? 100; diff --git a/src/Fields/Fields.php b/src/Fields/Fields.php index d80c256a93..32a97d22ea 100644 --- a/src/Fields/Fields.php +++ b/src/Fields/Fields.php @@ -256,7 +256,7 @@ private function getReferencedField(array $config): Field throw new \Exception("Field {$config['field']} not found."); } - if ($overrides = array_get($config, 'config')) { + if ($overrides = Arr::get($config, 'config')) { $field->setConfig(array_merge($field->config(), $overrides)); } @@ -283,7 +283,7 @@ private function getImportedFields(array $config): array }); } - if ($prefix = array_get($config, 'prefix')) { + if ($prefix = Arr::get($config, 'prefix')) { $fields = $fields->mapWithKeys(function ($field) use ($prefix) { $field = clone $field; $handle = $prefix.$field->handle(); diff --git a/src/Fields/Fieldset.php b/src/Fields/Fieldset.php index e14f7ba7a4..c50538373e 100644 --- a/src/Fields/Fieldset.php +++ b/src/Fields/Fieldset.php @@ -15,6 +15,7 @@ use Statamic\Facades\GlobalSet; use Statamic\Facades\Path; use Statamic\Facades\Taxonomy; +use Statamic\Support\Arr; use Statamic\Support\Str; class Fieldset @@ -58,7 +59,7 @@ public function initialPath($path = null) public function setContents(array $contents) { - $fields = array_get($contents, 'fields', []); + $fields = Arr::get($contents, 'fields', []); // Support legacy syntax if (! empty($fields) && array_keys($fields)[0] !== 0) { @@ -86,7 +87,7 @@ public function title() public function fields(): Fields { - $fields = array_get($this->contents, 'fields', []); + $fields = Arr::get($this->contents, 'fields', []); return new Fields($fields); } diff --git a/src/Fields/FieldsetRepository.php b/src/Fields/FieldsetRepository.php index b500cb0457..d85ffa1740 100644 --- a/src/Fields/FieldsetRepository.php +++ b/src/Fields/FieldsetRepository.php @@ -7,6 +7,7 @@ use Statamic\Facades\File; use Statamic\Facades\Path; use Statamic\Facades\YAML; +use Statamic\Support\Arr; use Statamic\Support\Str; class FieldsetRepository @@ -29,7 +30,7 @@ public function directory() public function find(string $handle): ?Fieldset { - if ($cached = array_get($this->fieldsets, $handle)) { + if ($cached = Arr::get($this->fieldsets, $handle)) { return $cached; } @@ -193,8 +194,8 @@ protected function getFieldsetsByDirectory(string $directory, ?string $namespace ->getFilesByTypeRecursively($directory, 'yaml') ->reject(fn ($path) => Str::startsWith($path, $directory.'/vendor/')) ->map(function ($file) use ($directory, $namespace) { - $basename = str_after($file, str_finish($directory, '/')); - $handle = str_before($basename, '.yaml'); + $basename = Str::after($file, Str::finish($directory, '/')); + $handle = Str::before($basename, '.yaml'); $handle = str_replace('/', '.', $handle); if ($namespace) { diff --git a/src/Fields/Tab.php b/src/Fields/Tab.php index 80c2aee11f..ef0d095e89 100644 --- a/src/Fields/Tab.php +++ b/src/Fields/Tab.php @@ -85,11 +85,11 @@ public function toPublishArray() public function display() { - return array_get($this->contents, 'display', __(Str::humanize($this->handle))); + return Arr::get($this->contents, 'display', __(Str::humanize($this->handle))); } public function instructions() { - return array_get($this->contents, 'instructions'); + return Arr::get($this->contents, 'instructions'); } } diff --git a/src/Fields/Validator.php b/src/Fields/Validator.php index 2e1a46b459..8fd8866a62 100644 --- a/src/Fields/Validator.php +++ b/src/Fields/Validator.php @@ -81,7 +81,7 @@ public function merge($original, $overrides) foreach ($overrides as $field => $fieldRules) { $fieldRules = self::explodeRules($fieldRules); - if (array_has($original, $field)) { + if (Arr::has($original, $field)) { $original[$field] = array_merge($original[$field], $fieldRules); } else { $original[$field] = $fieldRules; diff --git a/src/Fieldtypes/AssetFolder.php b/src/Fieldtypes/AssetFolder.php index 1b3f322c6f..6484dc0119 100644 --- a/src/Fieldtypes/AssetFolder.php +++ b/src/Fieldtypes/AssetFolder.php @@ -3,6 +3,7 @@ namespace Statamic\Fieldtypes; use Statamic\Facades\AssetContainer; +use Statamic\Support\Str; class AssetFolder extends Relationship { @@ -26,7 +27,7 @@ public function getIndexItems($request) }) ->prepend(['id' => '/', 'title' => '/']) ->when($request->search, function ($folders, $search) { - return $folders->filter(fn ($folder) => str_contains($folder['title'], $search)); + return $folders->filter(fn ($folder) => Str::contains($folder['title'], $search)); }) ->values(); } diff --git a/src/Fieldtypes/Bard.php b/src/Fieldtypes/Bard.php index 2b6407de4f..832c4a29a0 100644 --- a/src/Fieldtypes/Bard.php +++ b/src/Fieldtypes/Bard.php @@ -336,7 +336,7 @@ protected function processRow($row, $index) { $row['attrs']['values'] = parent::processRow($row['attrs']['values'], $index); - if (array_get($row, 'attrs.enabled', true) === true) { + if (Arr::get($row, 'attrs.enabled', true) === true) { unset($row['attrs']['enabled']); } diff --git a/src/Fieldtypes/Replicator.php b/src/Fieldtypes/Replicator.php index a437022e07..a0e1be8a61 100644 --- a/src/Fieldtypes/Replicator.php +++ b/src/Fieldtypes/Replicator.php @@ -182,7 +182,7 @@ public function shallowAugment($values) protected function performAugmentation($values, $shallow) { return collect($values)->reject(function ($set, $key) { - return array_get($set, 'enabled', true) === false; + return Arr::get($set, 'enabled', true) === false; })->map(function ($set, $index) use ($shallow) { if (! Arr::get($this->flattenedSetsConfig(), "{$set['type']}.fields")) { return $set; diff --git a/src/Fieldtypes/RowId.php b/src/Fieldtypes/RowId.php index 5022c43064..8fa08b488b 100644 --- a/src/Fieldtypes/RowId.php +++ b/src/Fieldtypes/RowId.php @@ -2,11 +2,13 @@ namespace Statamic\Fieldtypes; +use Statamic\Support\Str; + class RowId { public function generate() { - return str_random(8); + return Str::random(8); } public function handle(): string diff --git a/src/Fieldtypes/Sets.php b/src/Fieldtypes/Sets.php index 6b04779fbd..6006439923 100644 --- a/src/Fieldtypes/Sets.php +++ b/src/Fieldtypes/Sets.php @@ -93,7 +93,7 @@ public function preProcessConfig($sets) return array_merge($config, [ 'handle' => $name, 'id' => $name, - 'fields' => (new NestedFields)->preProcessConfig(array_get($config, 'fields', [])), + 'fields' => (new NestedFields)->preProcessConfig(Arr::get($config, 'fields', [])), ]); }) ->values() diff --git a/src/Fieldtypes/TemplateFolder.php b/src/Fieldtypes/TemplateFolder.php index 9268403090..217c426c93 100644 --- a/src/Fieldtypes/TemplateFolder.php +++ b/src/Fieldtypes/TemplateFolder.php @@ -4,6 +4,7 @@ use RecursiveDirectoryIterator; use RecursiveIteratorIterator; +use Statamic\Support\Str; class TemplateFolder extends Relationship { @@ -24,7 +25,7 @@ public function getIndexItems($request) foreach ($iterator as $file) { if ($file->isDir() && ! $iterator->isDot() && ! $iterator->isLink()) { - $directories->push(str_replace_first($path.DIRECTORY_SEPARATOR, '', $file->getPathname())); + $directories->push(Str::replaceFirst($path.DIRECTORY_SEPARATOR, '', $file->getPathname())); } } diff --git a/src/Forms/Email.php b/src/Forms/Email.php index 48dc816daf..e07d4983dd 100644 --- a/src/Forms/Email.php +++ b/src/Forms/Email.php @@ -62,21 +62,21 @@ public function build() protected function addAddresses() { - $this->to($this->addresses(array_get($this->config, 'to'))); + $this->to($this->addresses(Arr::get($this->config, 'to'))); - if ($from = array_get($this->config, 'from')) { + if ($from = Arr::get($this->config, 'from')) { $this->from($this->addresses($from)); } - if ($replyTo = array_get($this->config, 'reply_to')) { + if ($replyTo = Arr::get($this->config, 'reply_to')) { $this->replyTo($this->addresses($replyTo)); } - if ($cc = array_get($this->config, 'cc')) { + if ($cc = Arr::get($this->config, 'cc')) { $this->cc($this->addresses($cc)); } - if ($bcc = array_get($this->config, 'bcc')) { + if ($bcc = Arr::get($this->config, 'bcc')) { $this->bcc($this->addresses($bcc)); } @@ -85,8 +85,8 @@ protected function addAddresses() protected function addViews() { - $html = array_get($this->config, 'html'); - $text = array_get($this->config, 'text'); + $html = Arr::get($this->config, 'html'); + $text = Arr::get($this->config, 'text'); if (! $text && ! $html) { return $this->view('statamic::forms.automagic-email'); @@ -97,7 +97,7 @@ protected function addViews() } if ($html) { - $method = array_get($this->config, 'markdown') ? 'markdown' : 'view'; + $method = Arr::get($this->config, 'markdown') ? 'markdown' : 'view'; $this->$method($html); } @@ -106,7 +106,7 @@ protected function addViews() protected function addAttachments() { - if (! array_get($this->config, 'attachments')) { + if (! Arr::get($this->config, 'attachments')) { return $this; } @@ -124,7 +124,7 @@ private function attachAssets($field) { $value = $field['value']; - $value = array_get($field, 'config.max_files') === 1 + $value = Arr::get($field, 'config.max_files') === 1 ? collect([$value])->filter() : $value->get(); @@ -137,7 +137,7 @@ private function attachFiles($field) { $value = $field['value']; - $value = array_get($field, 'config.max_files') === 1 + $value = Arr::get($field, 'config.max_files') === 1 ? collect([$value])->filter() : $value; @@ -151,7 +151,7 @@ protected function addData() $augmented = $this->submission->toAugmentedArray(); $fields = $this->getRenderableFieldData(Arr::except($augmented, ['id', 'date', 'form'])); - if (array_has($this->config, 'attachments')) { + if (Arr::has($this->config, 'attachments')) { $fields = $fields->reject(fn ($field) => in_array($field['fieldtype'], ['assets', 'files'])); } diff --git a/src/Forms/Metrics/AbstractMetric.php b/src/Forms/Metrics/AbstractMetric.php index 21d8760be0..62f79444a5 100644 --- a/src/Forms/Metrics/AbstractMetric.php +++ b/src/Forms/Metrics/AbstractMetric.php @@ -4,6 +4,7 @@ use Statamic\Contracts\Forms\Form; use Statamic\Contracts\Forms\Metric; +use Statamic\Support\Arr; use Statamic\Support\Str; abstract class AbstractMetric implements Metric @@ -48,7 +49,7 @@ public function config() */ public function get($key, $default = null) { - return array_get($this->config(), $key, $default); + return Arr::get($this->config(), $key, $default); } /** diff --git a/src/Http/Controllers/API/ApiController.php b/src/Http/Controllers/API/ApiController.php index d1df7933dd..c7c959fe77 100644 --- a/src/Http/Controllers/API/ApiController.php +++ b/src/Http/Controllers/API/ApiController.php @@ -102,7 +102,7 @@ protected function filter($query) } elseif ($value === 'false') { $value = false; } elseif (is_numeric($value)) { - $value = str_contains($value, '.') ? (float) $value : (int) $value; + $value = Str::contains($value, '.') ? (float) $value : (int) $value; } if (Str::contains($filter, ':')) { diff --git a/src/Http/Controllers/CP/Collections/CollectionsController.php b/src/Http/Controllers/CP/Collections/CollectionsController.php index ec69f8264a..9f7cdd7ac8 100644 --- a/src/Http/Controllers/CP/Collections/CollectionsController.php +++ b/src/Http/Controllers/CP/Collections/CollectionsController.php @@ -16,6 +16,7 @@ use Statamic\Rules\Handle; use Statamic\Statamic; use Statamic\Structures\CollectionStructure; +use Statamic\Support\Arr; use Statamic\Support\Str; class CollectionsController extends CpController @@ -237,15 +238,15 @@ public function update(Request $request, $collection) ->mount($values['mount'] ?? null) ->revisionsEnabled($values['revisions'] ?? false) ->taxonomies($values['taxonomies'] ?? []) - ->futureDateBehavior(array_get($values, 'future_date_behavior')) - ->pastDateBehavior(array_get($values, 'past_date_behavior')) - ->mount(array_get($values, 'mount')) - ->propagate(array_get($values, 'propagate')) + ->futureDateBehavior(Arr::get($values, 'future_date_behavior')) + ->pastDateBehavior(Arr::get($values, 'past_date_behavior')) + ->mount(Arr::get($values, 'mount')) + ->propagate(Arr::get($values, 'propagate')) ->titleFormats($values['title_formats']) ->requiresSlugs($values['require_slugs']) ->previewTargets($values['preview_targets']); - if ($sites = array_get($values, 'sites')) { + if ($sites = Arr::get($values, 'sites')) { $collection ->sites($sites) ->originBehavior($values['origin_behavior']); diff --git a/src/Http/Controllers/CP/Collections/EntryPreviewController.php b/src/Http/Controllers/CP/Collections/EntryPreviewController.php index 9f10e81878..8d56767a09 100644 --- a/src/Http/Controllers/CP/Collections/EntryPreviewController.php +++ b/src/Http/Controllers/CP/Collections/EntryPreviewController.php @@ -6,6 +6,7 @@ use Statamic\Contracts\Entries\Entry as EntryContract; use Statamic\Facades\Entry; use Statamic\Http\Controllers\CP\PreviewController; +use Statamic\Support\Arr; class EntryPreviewController extends PreviewController { @@ -18,7 +19,7 @@ public function create(Request $request, $collection, $site) ->addValues($preview = $request->preview) ->process(); - $values = array_except($fields->values()->all(), ['slug']); + $values = Arr::except($fields->values()->all(), ['slug']); $entry = Entry::make() ->slug($preview['slug'] ?? 'slug') diff --git a/src/Http/Controllers/CP/CpController.php b/src/Http/Controllers/CP/CpController.php index 31d6c28d06..f13f6b770a 100644 --- a/src/Http/Controllers/CP/CpController.php +++ b/src/Http/Controllers/CP/CpController.php @@ -10,6 +10,7 @@ use Statamic\Facades\YAML; use Statamic\Http\Controllers\Controller; use Statamic\Statamic; +use Statamic\Support\Arr; use Statamic\Support\Str; /** @@ -58,7 +59,7 @@ public function themes() // Get the name if one exists in a meta file if (File::disk('themes')->exists($folder.'/meta.yaml')) { $meta = YAML::parse(File::disk('themes')->get($folder.'/meta.yaml')); - $name = array_get($meta, 'name', $folder); + $name = Arr::get($meta, 'name', $folder); } $themes[] = compact('folder', 'name'); diff --git a/src/Http/Controllers/CP/DashboardController.php b/src/Http/Controllers/CP/DashboardController.php index 278b001fde..714904d532 100644 --- a/src/Http/Controllers/CP/DashboardController.php +++ b/src/Http/Controllers/CP/DashboardController.php @@ -5,6 +5,7 @@ use Statamic\Facades\Preference; use Statamic\Facades\Site; use Statamic\Facades\User; +use Statamic\Support\Arr; use Statamic\Widgets\Loader; class DashboardController extends CpController @@ -51,7 +52,7 @@ private function getDisplayableWidgets($loader) }) ->map(function ($config) use ($loader) { return [ - 'widget' => $widget = $loader->load(array_get($config, 'type'), $config), + 'widget' => $widget = $loader->load(Arr::get($config, 'type'), $config), 'classes' => $widget->config('classes'), 'width' => $widget->config('width', 100), 'html' => (string) $widget->html(), diff --git a/src/Http/Controllers/CP/Fields/ManagesBlueprints.php b/src/Http/Controllers/CP/Fields/ManagesBlueprints.php index 630354139b..aa039412a7 100644 --- a/src/Http/Controllers/CP/Fields/ManagesBlueprints.php +++ b/src/Http/Controllers/CP/Fields/ManagesBlueprints.php @@ -33,7 +33,7 @@ private function indexItems(Collection $blueprints, $item) private function setBlueprintContents(Request $request, Blueprint $blueprint) { $tabs = collect($request->tabs)->mapWithKeys(function ($tab) { - return [array_pull($tab, 'handle') => [ + return [Arr::pull($tab, 'handle') => [ 'display' => $tab['display'], 'sections' => $this->tabSections($tab['sections']), ]]; diff --git a/src/Http/Controllers/CP/PreviewController.php b/src/Http/Controllers/CP/PreviewController.php index 0030aac1ca..f0bbe48c65 100644 --- a/src/Http/Controllers/CP/PreviewController.php +++ b/src/Http/Controllers/CP/PreviewController.php @@ -5,6 +5,8 @@ use Facades\Statamic\CP\LivePreview; use Illuminate\Http\Request; use Statamic\Facades\URL; +use Statamic\Support\Arr; +use Statamic\Support\Str; class PreviewController extends CpController { @@ -22,7 +24,7 @@ public function edit(Request $request, $_, $data) ->addValues($request->input('preview', [])) ->process(); - foreach (array_except($fields->values()->all(), ['slug']) as $key => $value) { + foreach (Arr::except($fields->values()->all(), ['slug']) as $key => $value) { $data->setSupplement($key, $value); } @@ -46,7 +48,7 @@ private function getPreviewUrl($data, $target, $token) return vsprintf('%s%slive-preview=%s&token=%s', [ $url, strpos($url, '?') === false ? '?' : '&', - str_random(), // random string to prevent caching + Str::random(), // random string to prevent caching $token, ]); } diff --git a/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php b/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php index 0f4cc93ee7..af02a60b14 100644 --- a/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php +++ b/src/Http/Controllers/CP/Taxonomies/TaxonomiesController.php @@ -16,6 +16,8 @@ use Statamic\Http\Controllers\CP\CpController; use Statamic\Rules\Handle; use Statamic\Stache\Repositories\TermRepository as StacheTermRepository; +use Statamic\Support\Arr; +use Statamic\Support\Str; class TaxonomiesController extends CpController { @@ -103,7 +105,7 @@ public function store(Request $request) 'handle' => ['nullable', new Handle], ]); - $handle = $request->handle ?? snake_case($request->title); + $handle = $request->handle ?? Str::snake($request->title); if (Taxonomy::findByHandle($handle)) { throw new \Exception('Taxonomy already exists'); @@ -171,7 +173,7 @@ public function update(Request $request, $taxonomy) ->template($values['template'] ?? null) ->layout($values['layout'] ?? null); - if ($sites = array_get($values, 'sites')) { + if ($sites = Arr::get($values, 'sites')) { $taxonomy->sites($sites); } diff --git a/src/Http/Controllers/CP/Taxonomies/TermPreviewController.php b/src/Http/Controllers/CP/Taxonomies/TermPreviewController.php index 9970678bae..a2dde5da34 100644 --- a/src/Http/Controllers/CP/Taxonomies/TermPreviewController.php +++ b/src/Http/Controllers/CP/Taxonomies/TermPreviewController.php @@ -6,6 +6,7 @@ use Statamic\Contracts\Taxonomies\Term as TermContract; use Statamic\Facades\Term; use Statamic\Http\Controllers\CP\PreviewController; +use Statamic\Support\Arr; class TermPreviewController extends PreviewController { @@ -18,7 +19,7 @@ public function create(Request $request, $taxonomy, $site) ->addValues($preview = $request->preview) ->process(); - $values = array_except($fields->values()->all(), ['slug']); + $values = Arr::except($fields->values()->all(), ['slug']); $term = Term::make() ->slug($preview['slug'] ?? 'slug') diff --git a/src/Http/Controllers/CP/Users/RolesController.php b/src/Http/Controllers/CP/Users/RolesController.php index 4e65c60bb0..83e6c1c5be 100644 --- a/src/Http/Controllers/CP/Users/RolesController.php +++ b/src/Http/Controllers/CP/Users/RolesController.php @@ -10,6 +10,7 @@ use Statamic\Http\Controllers\CP\CpController; use Statamic\Http\Middleware\RequireStatamicPro; use Statamic\Rules\Handle; +use Statamic\Support\Str; class RolesController extends CpController { @@ -67,7 +68,7 @@ public function store(Request $request) 'permissions' => 'array', ]); - $handle = $request->handle ?: snake_case($request->title); + $handle = $request->handle ?: Str::snake($request->title); if (Role::find($handle)) { $error = __('A Role with that handle already exists.'); @@ -128,7 +129,7 @@ public function update(Request $request, $role) $role ->title($request->title) - ->handle($request->handle ?: snake_case($request->title)); + ->handle($request->handle ?: Str::snake($request->title)); if ($request->super && User::current()->isSuper()) { $role->permissions(['super']); diff --git a/src/Http/Controllers/CP/Users/UserGroupsController.php b/src/Http/Controllers/CP/Users/UserGroupsController.php index 7ff480fbcf..0c05f0cde7 100644 --- a/src/Http/Controllers/CP/Users/UserGroupsController.php +++ b/src/Http/Controllers/CP/Users/UserGroupsController.php @@ -8,6 +8,7 @@ use Statamic\Facades\UserGroup; use Statamic\Http\Controllers\CP\CpController; use Statamic\Http\Middleware\RequireStatamicPro; +use Statamic\Support\Str; class UserGroupsController extends CpController { @@ -171,7 +172,7 @@ public function store(Request $request) $values = $fields->process()->values()->except(['title', 'handle', 'roles']); - $handle = $request->handle ?: snake_case($request->title); + $handle = $request->handle ?: Str::snake($request->title); if (UserGroup::find($handle)) { $error = __('A User Group with that handle already exists.'); diff --git a/src/Http/Controllers/OAuthController.php b/src/Http/Controllers/OAuthController.php index d1744fb024..31ec7ad284 100644 --- a/src/Http/Controllers/OAuthController.php +++ b/src/Http/Controllers/OAuthController.php @@ -6,6 +6,7 @@ use Laravel\Socialite\Facades\Socialite; use Laravel\Socialite\Two\InvalidStateException; use Statamic\Facades\OAuth; +use Statamic\Support\Arr; class OAuthController { @@ -39,12 +40,12 @@ protected function successRedirectUrl() $previous = session('_previous.url'); - if (! $query = array_get(parse_url($previous), 'query')) { + if (! $query = Arr::get(parse_url($previous), 'query')) { return $default; } parse_str($query, $query); - return array_get($query, 'redirect', $default); + return Arr::get($query, 'redirect', $default); } } diff --git a/src/Http/View/Composers/JavascriptComposer.php b/src/Http/View/Composers/JavascriptComposer.php index 738d6d4540..927292102c 100644 --- a/src/Http/View/Composers/JavascriptComposer.php +++ b/src/Http/View/Composers/JavascriptComposer.php @@ -34,7 +34,7 @@ private function commonVariables() return [ 'csrfToken' => csrf_token(), 'cpUrl' => cp_route('index'), - 'cpRoot' => str_start(config('statamic.cp.route'), '/'), + 'cpRoot' => Str::start(config('statamic.cp.route'), '/'), 'urlPath' => Str::after(request()->getRequestUri(), config('statamic.cp.route').'/'), 'resourceUrl' => Statamic::cpAssetUrl(), 'flash' => Statamic::flash(), diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index 4f0b538afe..00bc863338 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -1395,7 +1395,7 @@ public function limit($value, $params) public function link($value, $params) { $attributes = $this->buildAttributesFromParameters($params); - $title = array_pull($attributes, 'title', null); + $title = Arr::pull($attributes, 'title', null); return Html::link($value, $title, $attributes); } @@ -1787,7 +1787,7 @@ public function random($value) $value = $value->all(); } - return array_random($value); + return Arr::random($value); } /** diff --git a/src/Providers/AddonServiceProvider.php b/src/Providers/AddonServiceProvider.php index 4df4504a5f..307bd9e76c 100644 --- a/src/Providers/AddonServiceProvider.php +++ b/src/Providers/AddonServiceProvider.php @@ -417,15 +417,15 @@ protected function bootPublishables() protected function bootRoutes() { - if ($web = array_get($this->routes, 'web')) { + if ($web = Arr::get($this->routes, 'web')) { $this->registerWebRoutes($web); } - if ($cp = array_get($this->routes, 'cp')) { + if ($cp = Arr::get($this->routes, 'cp')) { $this->registerCpRoutes($cp); } - if ($actions = array_get($this->routes, 'actions')) { + if ($actions = Arr::get($this->routes, 'actions')) { $this->registerActionRoutes($actions); } diff --git a/src/Query/StatusQueryBuilder.php b/src/Query/StatusQueryBuilder.php index 1ee60ee1d2..8da4c2d018 100644 --- a/src/Query/StatusQueryBuilder.php +++ b/src/Query/StatusQueryBuilder.php @@ -4,6 +4,7 @@ use Illuminate\Support\Traits\ForwardsCalls; use Statamic\Contracts\Query\Builder; +use Statamic\Support\Arr; class StatusQueryBuilder implements Builder { @@ -48,7 +49,7 @@ public function first() public function __call($method, $parameters) { - if (in_array($method, self::METHODS) && in_array(array_first($parameters), ['status', 'published'])) { + if (in_array($method, self::METHODS) && in_array(Arr::first($parameters), ['status', 'published'])) { $this->queryFallbackStatus = false; } diff --git a/src/Routing/UrlBuilder.php b/src/Routing/UrlBuilder.php index 9120c8dc0a..1a9b2a3434 100644 --- a/src/Routing/UrlBuilder.php +++ b/src/Routing/UrlBuilder.php @@ -82,8 +82,8 @@ private function routeData() private function slugify($value) { - $slashPlaceholder = strtolower(str_random()); - $dotPlaceholder = strtolower(str_random()); + $slashPlaceholder = strtolower(Str::random()); + $dotPlaceholder = strtolower(Str::random()); $value = str_replace('/', $slashPlaceholder, $value); $value = str_replace('.', $dotPlaceholder, $value); diff --git a/src/Search/Comb/Comb.php b/src/Search/Comb/Comb.php index b2b8ecd43e..09526c7cc9 100644 --- a/src/Search/Comb/Comb.php +++ b/src/Search/Comb/Comb.php @@ -934,10 +934,10 @@ private function getStemmedWords($words) $output = []; if (! is_array($words)) { - $output = str_singular($words); + $output = Str::singular($words); } else { foreach ($words as $word) { - array_push($output, str_singular($word)); + array_push($output, Str::singular($word)); } } diff --git a/src/Search/Comb/Index.php b/src/Search/Comb/Index.php index 62d0353f07..950539573d 100644 --- a/src/Search/Comb/Index.php +++ b/src/Search/Comb/Index.php @@ -10,6 +10,7 @@ use Statamic\Search\Index as BaseIndex; use Statamic\Search\IndexNotFoundException; use Statamic\Search\Result; +use Statamic\Support\Arr; class Index extends BaseIndex { @@ -37,7 +38,7 @@ public function lookup($query) $data['search_score'] = $result['score']; $data['search_snippets'] = $result['snippets']; - return array_except($data, '_category'); + return Arr::except($data, '_category'); }); } diff --git a/src/Search/Index.php b/src/Search/Index.php index 9cf98a2d98..5eebe09f3f 100644 --- a/src/Search/Index.php +++ b/src/Search/Index.php @@ -4,6 +4,7 @@ use Statamic\Contracts\Search\Searchable; use Statamic\Support\Arr; +use Statamic\Support\Str; abstract class Index { @@ -35,7 +36,7 @@ public function name() public function title() { - return $this->config['title'] ?? title_case($this->name); + return $this->config['title'] ?? Str::title($this->name); } public function config() diff --git a/src/Search/IndexManager.php b/src/Search/IndexManager.php index 3a87ea64b6..ffa12e8c74 100644 --- a/src/Search/IndexManager.php +++ b/src/Search/IndexManager.php @@ -9,6 +9,7 @@ use Statamic\Search\Comb\Index as CombIndex; use Statamic\Search\Null\NullIndex; use Statamic\Support\Manager; +use Statamic\Support\Str; class IndexManager extends Manager { @@ -87,7 +88,7 @@ protected function resolveLocalized($name, $locale) if (isset($this->customCreators[$config['driver']])) { return $this->callLocalizedCustomCreator($config, $name, $locale); } else { - $driverMethod = 'create'.camel_case($config['driver']).'Driver'; + $driverMethod = 'create'.Str::camel($config['driver']).'Driver'; if (method_exists($this, $driverMethod)) { return $this->{$driverMethod}($config, $name, $locale); diff --git a/src/Sites/Sites.php b/src/Sites/Sites.php index 76afa07f5e..9392430cd2 100644 --- a/src/Sites/Sites.php +++ b/src/Sites/Sites.php @@ -4,6 +4,7 @@ use Closure; use Statamic\Facades\User; +use Statamic\Support\Arr; use Statamic\Support\Str; class Sites @@ -94,7 +95,7 @@ public function setConfig($key, $value = null) if (is_null($value)) { $this->config = $key; } else { - array_set($this->config, $key, $value); + Arr::set($this->config, $key, $value); } $this->sites = $this->toSites($this->config['sites']); diff --git a/src/Stache/Stores/AssetContainersStore.php b/src/Stache/Stores/AssetContainersStore.php index 81627841e9..536ea7b000 100644 --- a/src/Stache/Stores/AssetContainersStore.php +++ b/src/Stache/Stores/AssetContainersStore.php @@ -4,6 +4,7 @@ use Statamic\Facades\AssetContainer; use Statamic\Facades\YAML; +use Statamic\Support\Arr; class AssetContainersStore extends BasicStore { @@ -18,17 +19,17 @@ public function makeItemFromFile($path, $contents) $data = YAML::file($path)->parse($contents); return AssetContainer::make($handle) - ->disk(array_get($data, 'disk')) - ->title(array_get($data, 'title')) - ->allowDownloading(array_get($data, 'allow_downloading')) - ->allowMoving(array_get($data, 'allow_moving')) - ->allowRenaming(array_get($data, 'allow_renaming')) - ->allowUploads(array_get($data, 'allow_uploads')) - ->createFolders(array_get($data, 'create_folders')) - ->sourcePreset(array_get($data, 'source_preset')) - ->warmPresets(array_get($data, 'warm_presets')) - ->searchIndex(array_get($data, 'search_index')) - ->sortField(array_get($data, 'sort_by')) - ->sortDirection(array_get($data, 'sort_dir')); + ->disk(Arr::get($data, 'disk')) + ->title(Arr::get($data, 'title')) + ->allowDownloading(Arr::get($data, 'allow_downloading')) + ->allowMoving(Arr::get($data, 'allow_moving')) + ->allowRenaming(Arr::get($data, 'allow_renaming')) + ->allowUploads(Arr::get($data, 'allow_uploads')) + ->createFolders(Arr::get($data, 'create_folders')) + ->sourcePreset(Arr::get($data, 'source_preset')) + ->warmPresets(Arr::get($data, 'warm_presets')) + ->searchIndex(Arr::get($data, 'search_index')) + ->sortField(Arr::get($data, 'sort_by')) + ->sortDirection(Arr::get($data, 'sort_dir')); } } diff --git a/src/Stache/Stores/CollectionEntriesStore.php b/src/Stache/Stores/CollectionEntriesStore.php index 1182491c4c..a1da08c3b5 100644 --- a/src/Stache/Stores/CollectionEntriesStore.php +++ b/src/Stache/Stores/CollectionEntriesStore.php @@ -13,6 +13,7 @@ use Statamic\Facades\Site; use Statamic\Facades\YAML; use Statamic\Stache\Indexes; +use Statamic\Support\Arr; use Statamic\Support\Str; use Symfony\Component\Finder\SplFileInfo; @@ -27,7 +28,7 @@ protected function collection() public function getItemFilter(SplFileInfo $file) { - $dir = str_finish($this->directory(), '/'); + $dir = Str::finish($this->directory(), '/'); $relative = Path::tidy($file->getPathname()); if (substr($relative, 0, strlen($dir)) == $dir) { @@ -54,7 +55,7 @@ public function makeItemFromFile($path, $contents) $data = YAML::file($path)->parse($contents); - if (! $id = array_pull($data, 'id')) { + if (! $id = Arr::pull($data, 'id')) { $idGenerated = true; $id = app('stache')->generateId(); } @@ -66,7 +67,7 @@ public function makeItemFromFile($path, $contents) ->id($id) ->collection($collection); - if ($origin = array_pull($data, 'origin')) { + if ($origin = Arr::pull($data, 'origin')) { $entry->origin($origin); } @@ -74,7 +75,7 @@ public function makeItemFromFile($path, $contents) ->blueprint($data['blueprint'] ?? null) ->locale($site) ->initialPath($path) - ->published(array_pull($data, 'published', true)) + ->published(Arr::pull($data, 'published', true)) ->data($data); $slug = (new GetSlugFromPath)($path); @@ -105,7 +106,7 @@ protected function extractAttributesFromPath($path) { $site = Site::default()->handle(); $collection = pathinfo($path, PATHINFO_DIRNAME); - $collection = str_after($collection, $this->parent->directory()); + $collection = Str::after($collection, $this->parent->directory()); if (Site::hasMultiple()) { [$collection, $site] = explode('/', $collection); @@ -113,7 +114,7 @@ protected function extractAttributesFromPath($path) // Support entries within subdirectories at any level. if (Str::contains($collection, '/')) { - $collection = str_before($collection, '/'); + $collection = Str::before($collection, '/'); } return [$collection, $site]; diff --git a/src/Stache/Stores/CollectionsStore.php b/src/Stache/Stores/CollectionsStore.php index 9d7518deed..1fc2f0f715 100644 --- a/src/Stache/Stores/CollectionsStore.php +++ b/src/Stache/Stores/CollectionsStore.php @@ -8,6 +8,8 @@ use Statamic\Facades\Site; use Statamic\Facades\Stache; use Statamic\Facades\YAML; +use Statamic\Support\Arr; +use Statamic\Support\Str; use Symfony\Component\Finder\SplFileInfo; class CollectionsStore extends BasicStore @@ -24,8 +26,8 @@ public function getItemKey($item) public function getItemFilter(SplFileInfo $file) { - $dir = str_finish($this->directory, '/'); - $relative = str_after(Path::tidy($file->getPathname()), $dir); + $dir = Str::finish($this->directory, '/'); + $relative = Str::after(Path::tidy($file->getPathname()), $dir); return $file->getExtension() === 'yaml' && substr_count($relative, '/') === 0; } @@ -35,32 +37,32 @@ public function makeItemFromFile($path, $contents) $handle = pathinfo($path, PATHINFO_FILENAME); $data = YAML::file($path)->parse($contents); - $sites = array_get($data, 'sites', Site::hasMultiple() ? [] : [Site::default()->handle()]); + $sites = Arr::get($data, 'sites', Site::hasMultiple() ? [] : [Site::default()->handle()]); $collection = Collection::make($handle) - ->title(array_get($data, 'title')) - ->routes(array_get($data, 'route')) - ->requiresSlugs(array_get($data, 'slugs', true)) - ->titleFormats(array_get($data, 'title_format')) - ->mount(array_get($data, 'mount')) - ->dated(array_get($data, 'date', false)) + ->title(Arr::get($data, 'title')) + ->routes(Arr::get($data, 'route')) + ->requiresSlugs(Arr::get($data, 'slugs', true)) + ->titleFormats(Arr::get($data, 'title_format')) + ->mount(Arr::get($data, 'mount')) + ->dated(Arr::get($data, 'date', false)) ->sites($sites) - ->template(array_get($data, 'template')) - ->layout(array_get($data, 'layout')) - ->cascade(array_get($data, 'inject', [])) - ->searchIndex(array_get($data, 'search_index')) - ->revisionsEnabled(array_get($data, 'revisions', false)) + ->template(Arr::get($data, 'template')) + ->layout(Arr::get($data, 'layout')) + ->cascade(Arr::get($data, 'inject', [])) + ->searchIndex(Arr::get($data, 'search_index')) + ->revisionsEnabled(Arr::get($data, 'revisions', false)) ->defaultPublishState($this->getDefaultPublishState($data)) - ->originBehavior(array_get($data, 'origin_behavior', 'select')) - ->structureContents(array_get($data, 'structure')) - ->sortField(array_get($data, 'sort_by')) - ->sortDirection(array_get($data, 'sort_dir')) - ->taxonomies(array_get($data, 'taxonomies')) - ->propagate(array_get($data, 'propagate')) - ->previewTargets($this->normalizePreviewTargets(array_get($data, 'preview_targets', []))) - ->autosaveInterval(array_get($data, 'autosave')); - - if ($dateBehavior = array_get($data, 'date_behavior')) { + ->originBehavior(Arr::get($data, 'origin_behavior', 'select')) + ->structureContents(Arr::get($data, 'structure')) + ->sortField(Arr::get($data, 'sort_by')) + ->sortDirection(Arr::get($data, 'sort_dir')) + ->taxonomies(Arr::get($data, 'taxonomies')) + ->propagate(Arr::get($data, 'propagate')) + ->previewTargets($this->normalizePreviewTargets(Arr::get($data, 'preview_targets', []))) + ->autosaveInterval(Arr::get($data, 'autosave')); + + if ($dateBehavior = Arr::get($data, 'date_behavior')) { $collection ->futureDateBehavior($dateBehavior['future'] ?? null) ->pastDateBehavior($dateBehavior['past'] ?? null); @@ -71,7 +73,7 @@ public function makeItemFromFile($path, $contents) protected function getDefaultPublishState($data) { - $value = array_get($data, 'default_status', 'published'); + $value = Arr::get($data, 'default_status', 'published'); if (! in_array($value, ['published', 'draft'])) { throw new \Exception('Invalid collection default_status value. Must be "published" or "draft".'); diff --git a/src/Stache/Stores/GlobalVariablesStore.php b/src/Stache/Stores/GlobalVariablesStore.php index 77096a3431..45e65adaee 100644 --- a/src/Stache/Stores/GlobalVariablesStore.php +++ b/src/Stache/Stores/GlobalVariablesStore.php @@ -7,6 +7,7 @@ use Statamic\Facades\Site; use Statamic\Facades\YAML; use Statamic\Support\Arr; +use Statamic\Support\Str; use Symfony\Component\Finder\SplFileInfo; class GlobalVariablesStore extends BasicStore @@ -22,7 +23,7 @@ public function getItemFilter(SplFileInfo $file) return false; } - $filename = str_after(Path::tidy($file->getPathName()), $this->directory); + $filename = Str::after(Path::tidy($file->getPathName()), $this->directory); if (! Site::hasMultiple()) { return substr_count($filename, '/') === 0; @@ -33,8 +34,8 @@ public function getItemFilter(SplFileInfo $file) public function makeItemFromFile($path, $contents) { - $relative = str_after($path, $this->directory); - $handle = str_before($relative, '.yaml'); + $relative = Str::after($path, $this->directory); + $handle = Str::before($relative, '.yaml'); $data = YAML::file($path)->parse($contents); diff --git a/src/Stache/Stores/GlobalsStore.php b/src/Stache/Stores/GlobalsStore.php index 205082b544..72c0372870 100644 --- a/src/Stache/Stores/GlobalsStore.php +++ b/src/Stache/Stores/GlobalsStore.php @@ -7,6 +7,7 @@ use Statamic\Facades\Stache; use Statamic\Facades\YAML; use Statamic\Support\Arr; +use Statamic\Support\Str; use Symfony\Component\Finder\SplFileInfo; class GlobalsStore extends BasicStore @@ -29,15 +30,15 @@ public function getItemFilter(SplFileInfo $file) { // The global sets themselves should only exist in the root // (ie. no slashes in the filename) - $filename = str_after(Path::tidy($file->getPathName()), $this->directory); + $filename = Str::after(Path::tidy($file->getPathName()), $this->directory); return substr_count($filename, '/') === 0 && $file->getExtension() === 'yaml'; } public function makeItemFromFile($path, $contents) { - $relative = str_after($path, $this->directory); - $handle = str_before($relative, '.yaml'); + $relative = Str::after($path, $this->directory); + $handle = Str::before($relative, '.yaml'); $data = YAML::file($path)->parse(); diff --git a/src/Stache/Stores/NavigationStore.php b/src/Stache/Stores/NavigationStore.php index cb8b5c287c..4eb886de79 100644 --- a/src/Stache/Stores/NavigationStore.php +++ b/src/Stache/Stores/NavigationStore.php @@ -5,6 +5,7 @@ use Statamic\Facades; use Statamic\Facades\Path; use Statamic\Facades\YAML; +use Statamic\Support\Str; use Symfony\Component\Finder\SplFileInfo; class NavigationStore extends BasicStore @@ -18,15 +19,15 @@ public function getItemFilter(SplFileInfo $file) { // The structures themselves should only exist in the root // (ie. no slashes in the filename) - $filename = str_after(Path::tidy($file->getPathName()), $this->directory); + $filename = Str::after(Path::tidy($file->getPathName()), $this->directory); return substr_count($filename, '/') === 0 && $file->getExtension() === 'yaml'; } public function makeItemFromFile($path, $contents) { - $relative = str_after($path, $this->directory); - $handle = str_before($relative, '.yaml'); + $relative = Str::after($path, $this->directory); + $handle = Str::before($relative, '.yaml'); $data = YAML::file($path)->parse($contents); diff --git a/src/Stache/Stores/Store.php b/src/Stache/Stores/Store.php index 65785353fa..6ff33ca044 100644 --- a/src/Stache/Stores/Store.php +++ b/src/Stache/Stores/Store.php @@ -12,6 +12,7 @@ use Statamic\Stache\Indexes\Index; use Statamic\Statamic; use Statamic\Support\Arr; +use Statamic\Support\Str; abstract class Store { @@ -34,7 +35,7 @@ public function directory($directory = null) return $this->directory; } - $this->directory = str_finish(Path::tidy($directory), '/'); + $this->directory = Str::finish(Path::tidy($directory), '/'); return $this; } diff --git a/src/Stache/Stores/TaxonomiesStore.php b/src/Stache/Stores/TaxonomiesStore.php index 7971ac7936..16d3eec932 100644 --- a/src/Stache/Stores/TaxonomiesStore.php +++ b/src/Stache/Stores/TaxonomiesStore.php @@ -6,6 +6,8 @@ use Statamic\Facades\Site; use Statamic\Facades\Taxonomy; use Statamic\Facades\YAML; +use Statamic\Support\Arr; +use Statamic\Support\Str; use Symfony\Component\Finder\SplFileInfo; class TaxonomiesStore extends BasicStore @@ -26,7 +28,7 @@ public function getItemKey($item) public function getItemFilter(SplFileInfo $file) { - $filename = str_after(Path::tidy($file->getPathName()), $this->directory); + $filename = Str::after(Path::tidy($file->getPathName()), $this->directory); return $file->getExtension() === 'yaml' && substr_count($filename, '/') === 0; } @@ -36,24 +38,24 @@ public function makeItemFromFile($path, $contents) $handle = pathinfo($path, PATHINFO_FILENAME); $data = YAML::file($path)->parse($contents); - $sites = array_get($data, 'sites', Site::hasMultiple() ? [] : [Site::default()->handle()]); + $sites = Arr::get($data, 'sites', Site::hasMultiple() ? [] : [Site::default()->handle()]); return Taxonomy::make($handle) - ->title(array_get($data, 'title')) - ->cascade(array_get($data, 'inject', [])) - ->revisionsEnabled(array_get($data, 'revisions', false)) - ->searchIndex(array_get($data, 'search_index')) + ->title(Arr::get($data, 'title')) + ->cascade(Arr::get($data, 'inject', [])) + ->revisionsEnabled(Arr::get($data, 'revisions', false)) + ->searchIndex(Arr::get($data, 'search_index')) ->defaultPublishState($this->getDefaultPublishState($data)) ->sites($sites) - ->previewTargets($this->normalizePreviewTargets(array_get($data, 'preview_targets', []))) - ->termTemplate(array_get($data, 'term_template', null)) - ->template(array_get($data, 'template', null)) - ->layout(array_get($data, 'layout', null)); + ->previewTargets($this->normalizePreviewTargets(Arr::get($data, 'preview_targets', []))) + ->termTemplate(Arr::get($data, 'term_template', null)) + ->template(Arr::get($data, 'template', null)) + ->layout(Arr::get($data, 'layout', null)); } protected function getDefaultPublishState($data) { - $value = array_get($data, 'default_status', 'published'); + $value = Arr::get($data, 'default_status', 'published'); if (! in_array($value, ['published', 'draft'])) { throw new \Exception('Invalid taxonomy default_status value. Must be "published" or "draft".'); diff --git a/src/Stache/Stores/TaxonomyTermsStore.php b/src/Stache/Stores/TaxonomyTermsStore.php index f9873c63c7..0c3fd5018a 100644 --- a/src/Stache/Stores/TaxonomyTermsStore.php +++ b/src/Stache/Stores/TaxonomyTermsStore.php @@ -28,7 +28,7 @@ class TaxonomyTermsStore extends ChildStore public function getItemFilter(SplFileInfo $file) { - $dir = str_finish($this->directory(), '/'); + $dir = Str::finish($this->directory(), '/'); $relative = $file->getPathname(); if (substr($relative, 0, strlen($dir)) == $dir) { @@ -45,7 +45,7 @@ public function getItemFilter(SplFileInfo $file) public function makeItemFromFile($path, $contents) { $taxonomy = pathinfo($path, PATHINFO_DIRNAME); - $taxonomy = str_after($taxonomy, $this->parent->directory()); + $taxonomy = Str::after($taxonomy, $this->parent->directory()); $data = YAML::file($path)->parse($contents); diff --git a/src/Stache/Stores/UsersStore.php b/src/Stache/Stores/UsersStore.php index e0c563f8dd..4bbcc16bb1 100644 --- a/src/Stache/Stores/UsersStore.php +++ b/src/Stache/Stores/UsersStore.php @@ -8,6 +8,7 @@ use Statamic\Facades\YAML; use Statamic\Stache\Indexes\Users\Group; use Statamic\Stache\Indexes\Users\Role; +use Statamic\Support\Arr; class UsersStore extends BasicStore { @@ -39,7 +40,7 @@ public function makeItemFromFile($path, $contents) { $data = YAML::file($path)->parse($contents); - if (! $id = array_pull($data, 'id')) { + if (! $id = Arr::pull($data, 'id')) { $idGenerated = true; $id = app('stache')->generateId(); } @@ -48,10 +49,10 @@ public function makeItemFromFile($path, $contents) ->id($id) ->initialPath($path) ->email(pathinfo($path, PATHINFO_FILENAME)) - ->preferences(array_pull($data, 'preferences', [])) + ->preferences(Arr::pull($data, 'preferences', [])) ->data($data); - if (array_get($data, 'password') || isset($idGenerated)) { + if (Arr::get($data, 'password') || isset($idGenerated)) { $user->writeFile(); } diff --git a/src/Statamic.php b/src/Statamic.php index b99e7d210b..b459092d2a 100644 --- a/src/Statamic.php +++ b/src/Statamic.php @@ -209,7 +209,7 @@ public static function isApiRoute() return false; } - return starts_with(request()->path(), config('statamic.api.route')); + return Str::startsWith(request()->path(), config('statamic.api.route')); } public static function apiRoute($route, $params = []) @@ -441,13 +441,13 @@ private static function createVersionedAssetPath($name, $path, $extension) // In case a file without any version will be passed, // a random version number will be created. if (! Str::contains($path, '?v=')) { - $version = str_random(); + $version = Str::random(); // Add the file extension if not provided. - $path = str_finish($path, ".{$extension}"); + $path = Str::finish($path, ".{$extension}"); // Add the version to the path. - $path = str_finish($path, "?v={$version}"); + $path = Str::finish($path, "?v={$version}"); } return $path; diff --git a/src/StaticCaching/NoCache/StringRegion.php b/src/StaticCaching/NoCache/StringRegion.php index 44fbb4d0ad..a37233cb93 100644 --- a/src/StaticCaching/NoCache/StringRegion.php +++ b/src/StaticCaching/NoCache/StringRegion.php @@ -2,6 +2,8 @@ namespace Statamic\StaticCaching\NoCache; +use Statamic\Support\Str; + class StringRegion extends Region { protected $content; @@ -13,7 +15,7 @@ public function __construct(Session $session, string $content, array $context, s $this->content = $content; $this->context = $this->filterContext($context); $this->extension = $extension; - $this->key = sha1($content.str_random()); + $this->key = sha1($content.Str::random()); } public function key(): string diff --git a/src/StaticCaching/NoCache/ViewRegion.php b/src/StaticCaching/NoCache/ViewRegion.php index 1330234ccd..4d013d5b85 100644 --- a/src/StaticCaching/NoCache/ViewRegion.php +++ b/src/StaticCaching/NoCache/ViewRegion.php @@ -2,6 +2,8 @@ namespace Statamic\StaticCaching\NoCache; +use Statamic\Support\Str; + class ViewRegion extends Region { protected $view; @@ -11,7 +13,7 @@ public function __construct(Session $session, string $view, array $context) $this->session = $session; $this->view = $view; $this->context = $this->filterContext($context); - $this->key = str_random(32); + $this->key = Str::random(32); } public function key(): string diff --git a/src/StaticCaching/Replacers/CsrfTokenReplacer.php b/src/StaticCaching/Replacers/CsrfTokenReplacer.php index ca4c53ef13..e7c0d562ef 100644 --- a/src/StaticCaching/Replacers/CsrfTokenReplacer.php +++ b/src/StaticCaching/Replacers/CsrfTokenReplacer.php @@ -5,6 +5,7 @@ use Illuminate\Http\Response; use Statamic\Facades\StaticCache; use Statamic\StaticCaching\Replacer; +use Statamic\Support\Str; class CsrfTokenReplacer implements Replacer { @@ -20,7 +21,7 @@ public function prepareResponseToCache(Response $response, Response $initial) return; } - if (! str_contains($content, $token)) { + if (! Str::contains($content, $token)) { return; } diff --git a/src/Structures/Tree.php b/src/Structures/Tree.php index 99c120da33..045b8f7007 100644 --- a/src/Structures/Tree.php +++ b/src/Structures/Tree.php @@ -201,7 +201,7 @@ public function fileData() protected function removeEmptyChildren($array) { return collect($array)->map(function ($item) { - $item['children'] = $this->removeEmptyChildren(array_get($item, 'children', [])); + $item['children'] = $this->removeEmptyChildren(Arr::get($item, 'children', [])); if (empty($item['children'])) { unset($item['children']); diff --git a/src/Support/FileCollection.php b/src/Support/FileCollection.php index 48774f29e4..3ed53e8de9 100644 --- a/src/Support/FileCollection.php +++ b/src/Support/FileCollection.php @@ -123,7 +123,7 @@ public function multisort($sort) foreach ($sorts as $sort) { $bits = explode(':', $sort); $sort_by = $bits[0]; - $sort_dir = array_get($bits, 1); + $sort_dir = Arr::get($bits, 1); [$one, $two] = $this->getSortableValues($sort_by, $a, $b); @@ -200,8 +200,8 @@ public function toArray() $data[] = [ 'file' => URL::format($path), // Todo: This will only work when using the local file adapter 'filename' => $pathinfo['filename'], - 'extension' => array_get($pathinfo, 'extension'), - 'basename' => array_get($pathinfo, 'basename'), + 'extension' => Arr::get($pathinfo, 'extension'), + 'basename' => Arr::get($pathinfo, 'basename'), 'size' => File::sizeHuman($path), 'size_bytes' => $size, 'size_kilobytes' => $kb, diff --git a/src/Support/Manager.php b/src/Support/Manager.php index f5dc87d898..62e0a79323 100644 --- a/src/Support/Manager.php +++ b/src/Support/Manager.php @@ -43,7 +43,7 @@ protected function resolve($name) if (isset($this->customCreators[$config['driver']])) { return $this->callCustomCreator($config, $name); } else { - $driverMethod = 'create'.camel_case($config['driver']).'Driver'; + $driverMethod = 'create'.Str::camel($config['driver']).'Driver'; if (method_exists($this, $driverMethod)) { return $this->{$driverMethod}($config, $name); diff --git a/src/Support/Str.php b/src/Support/Str.php index 9296cdc3a6..e5e4a5a0b8 100644 --- a/src/Support/Str.php +++ b/src/Support/Str.php @@ -92,7 +92,7 @@ public static function slug($string, $separator = '-', $language = 'en', $dictio $string = $language ? static::ascii($string, $language) : $string; // Statamic is a-OK with underscores in slugs. - $string = str_replace('_', $placeholder = strtolower(str_random(16)), $string); + $string = str_replace('_', $placeholder = strtolower(Str::random(16)), $string); $slug = IlluminateStr::slug($string, $separator, $language, $dictionary); diff --git a/src/Tags/Concerns/RendersForms.php b/src/Tags/Concerns/RendersForms.php index 82c7b19d75..2f74515451 100644 --- a/src/Tags/Concerns/RendersForms.php +++ b/src/Tags/Concerns/RendersForms.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Support\MessageBag; +use Statamic\Support\Str; trait RendersForms { @@ -126,7 +127,7 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate { $errors = session('errors') ? session('errors')->getBag($errorBag) : new MessageBag; - $missing = str_random(); + $missing = Str::random(); $old = old($field->handle(), $missing); $default = $field->value() ?? $field->defaultValue(); $value = $old === $missing ? $default : $old; diff --git a/src/Tags/Markdown.php b/src/Tags/Markdown.php index 2efc0896de..594e0cf19f 100644 --- a/src/Tags/Markdown.php +++ b/src/Tags/Markdown.php @@ -2,6 +2,7 @@ namespace Statamic\Tags; +use Statamic\Support\Arr; use Statamic\Support\Html; class Markdown extends Tags @@ -30,7 +31,7 @@ public function indent() // Count the number of whitespace characters at the beginning of the // first line to prevent over-trimming. preg_match($regex, $lines[$firstLine], $matches, PREG_OFFSET_CAPTURE); - $maxTrim = array_get($matches, '0.1'); + $maxTrim = Arr::get($matches, '0.1'); $md = $lines->map(function ($line) use ($maxTrim) { // Trim the appropriate amount of whitespace at the start of diff --git a/src/Tags/ParentTags.php b/src/Tags/ParentTags.php index 9a53a1ebd5..b5ff77af09 100644 --- a/src/Tags/ParentTags.php +++ b/src/Tags/ParentTags.php @@ -55,7 +55,7 @@ private function getParentUrl() { $parent = $this->getParent(); - return array_get($parent, 'url'); + return Arr::get($parent, 'url'); } /** diff --git a/src/Tags/Tags.php b/src/Tags/Tags.php index 1d476090c4..5063e0c561 100644 --- a/src/Tags/Tags.php +++ b/src/Tags/Tags.php @@ -91,8 +91,8 @@ public function setProperties($properties) $this->setContent($properties['content']); $this->setContext($properties['context']); $this->setParameters($properties['params']); - $this->tag = array_get($properties, 'tag'); - $this->method = array_get($properties, 'tag_method'); + $this->tag = Arr::get($properties, 'tag'); + $this->method = Arr::get($properties, 'tag_method'); $this->runHooks('init'); } diff --git a/src/View/Antlers/Language/Runtime/Sandbox/LanguageOperatorManager.php b/src/View/Antlers/Language/Runtime/Sandbox/LanguageOperatorManager.php index 4c0867e1d0..ebe0b86e31 100644 --- a/src/View/Antlers/Language/Runtime/Sandbox/LanguageOperatorManager.php +++ b/src/View/Antlers/Language/Runtime/Sandbox/LanguageOperatorManager.php @@ -204,13 +204,13 @@ protected function getQueryValue($node, $data, $originalValue = '') } if (is_array($data)) { - return array_get($data, $node->name); + return Arr::get($data, $node->name); } return data_get($data, $node->name); } elseif ($node instanceof StringValueNode) { if (is_array($data)) { - return array_get($data, $node->value); + return Arr::get($data, $node->value); } return data_get($data, $node->value); @@ -226,7 +226,7 @@ protected function getQueryValue($node, $data, $originalValue = '') if (is_string($node)) { if (is_array($data)) { - return array_get($data, $node); + return Arr::get($data, $node); } return data_get($data, $node); diff --git a/src/View/Blade/TagsDirective.php b/src/View/Blade/TagsDirective.php index 02c7f157f0..1771f81f94 100644 --- a/src/View/Blade/TagsDirective.php +++ b/src/View/Blade/TagsDirective.php @@ -4,6 +4,7 @@ use Illuminate\Support\Collection; use Statamic\Statamic; +use Statamic\Support\Str; class TagsDirective { @@ -18,7 +19,7 @@ public static function handle($tags): array $params = []; } - $var = is_string($key) ? $key : camel_case(str_replace(':', '_', $tag)); + $var = is_string($key) ? $key : Str::camel(str_replace(':', '_', $tag)); return [$var => Statamic::tag($tag)->params($params)->fetch()]; })->all(); diff --git a/src/View/Cascade.php b/src/View/Cascade.php index 4c8d2c32b9..23063fda16 100644 --- a/src/View/Cascade.php +++ b/src/View/Cascade.php @@ -66,12 +66,12 @@ public function content() public function get($key) { - return array_get($this->data, $key); + return Arr::get($this->data, $key); } public function set($key, $value) { - array_set($this->data, $key, $value); + Arr::set($this->data, $key, $value); } public function data($data) diff --git a/src/Yaml/Yaml.php b/src/Yaml/Yaml.php index 406e209e18..560f56646c 100644 --- a/src/Yaml/Yaml.php +++ b/src/Yaml/Yaml.php @@ -6,6 +6,7 @@ use ReflectionProperty; use Statamic\Facades\File; use Statamic\Facades\Pattern; +use Statamic\Support\Arr; use Statamic\Support\Str; use Statamic\Yaml\ParseException as StatamicParseException; use Symfony\Component\Yaml\Yaml as SymfonyYaml; @@ -53,7 +54,7 @@ public function parse($str = null) if (Pattern::startsWith($str, '---')) { $split = preg_split("/\n---/", $str, 2, PREG_SPLIT_NO_EMPTY); $str = $split[0]; - if (empty($content = ltrim(array_get($split, 1, '')))) { + if (empty($content = ltrim(Arr::get($split, 1, '')))) { $content = null; } } diff --git a/tests/Antlers/Fixtures/Addon/Tags/TestTags.php b/tests/Antlers/Fixtures/Addon/Tags/TestTags.php index ade2efef90..6ad088476a 100644 --- a/tests/Antlers/Fixtures/Addon/Tags/TestTags.php +++ b/tests/Antlers/Fixtures/Addon/Tags/TestTags.php @@ -2,6 +2,7 @@ namespace Tests\Antlers\Fixtures\Addon\Tags; +use Statamic\Support\Arr; use Statamic\Tags\Tags; class TestTags extends Tags @@ -26,7 +27,7 @@ public function someParsing() { $var = $this->params->get('var'); - $val = array_get($this->context, $var); + $val = Arr::get($this->context, $var); return $this->parse([$var => $val]); } diff --git a/tests/Auth/Eloquent/EloquentRoleTest.php b/tests/Auth/Eloquent/EloquentRoleTest.php index e528d999a2..f9d65bd9cf 100644 --- a/tests/Auth/Eloquent/EloquentRoleTest.php +++ b/tests/Auth/Eloquent/EloquentRoleTest.php @@ -8,6 +8,7 @@ use Statamic\Auth\Eloquent\Role as EloquentRole; use Statamic\Auth\Eloquent\RoleModel; use Statamic\Auth\Eloquent\User as EloquentUser; +use Statamic\Support\Str; use Tests\TestCase; class EloquentRoleTest extends TestCase @@ -79,7 +80,7 @@ public function makeUser() 'name' => $this->faker->name, 'email' => $this->faker->unique()->safeEmail, // 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret - 'remember_token' => str_random(10), + 'remember_token' => Str::random(10), ]) ); } diff --git a/tests/Auth/Eloquent/EloquentUserGroupTest.php b/tests/Auth/Eloquent/EloquentUserGroupTest.php index b274085d82..21574bee77 100644 --- a/tests/Auth/Eloquent/EloquentUserGroupTest.php +++ b/tests/Auth/Eloquent/EloquentUserGroupTest.php @@ -10,6 +10,7 @@ use Statamic\Auth\Eloquent\UserGroup as EloquentGroup; use Statamic\Auth\Eloquent\UserGroupModel; use Statamic\Facades\UserGroup; +use Statamic\Support\Str; use Tests\TestCase; class EloquentUserGroupTest extends TestCase @@ -78,7 +79,7 @@ public function makeUser() 'name' => $this->faker->name, 'email' => $this->faker->unique()->safeEmail, // 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret - 'remember_token' => str_random(10), + 'remember_token' => Str::random(10), ]) ); } diff --git a/tests/Auth/Eloquent/EloquentUserTest.php b/tests/Auth/Eloquent/EloquentUserTest.php index 653223752a..c9ce8e133f 100644 --- a/tests/Auth/Eloquent/EloquentUserTest.php +++ b/tests/Auth/Eloquent/EloquentUserTest.php @@ -12,6 +12,7 @@ use Statamic\Contracts\Auth\Role as RoleContract; use Statamic\Contracts\Auth\UserGroup as UserGroupContract; use Statamic\Facades; +use Statamic\Support\Str; use Tests\Auth\PermissibleContractTests; use Tests\Auth\UserContractTests; use Tests\Preferences\HasPreferencesTests; @@ -238,7 +239,7 @@ public function makeUser() 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), // 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret - 'remember_token' => str_random(10), + 'remember_token' => Str::random(10), ]) ); } diff --git a/tests/Fakes/FakeFieldsetRepository.php b/tests/Fakes/FakeFieldsetRepository.php index 4febc462f1..4954671322 100644 --- a/tests/Fakes/FakeFieldsetRepository.php +++ b/tests/Fakes/FakeFieldsetRepository.php @@ -3,6 +3,7 @@ namespace Tests\Fakes; use Statamic\Fields\Fieldset; +use Statamic\Support\Arr; class FakeFieldsetRepository { @@ -10,7 +11,7 @@ class FakeFieldsetRepository public function find(string $handle): ?Fieldset { - if ($fieldset = array_get($this->fieldsets, $handle)) { + if ($fieldset = Arr::get($this->fieldsets, $handle)) { // Return a clone so that modifications to the object will only be updated when saving. return clone $fieldset; } diff --git a/tests/Fixtures/Addon/Tags/TestTags.php b/tests/Fixtures/Addon/Tags/TestTags.php index 085d644b83..89c27f987e 100644 --- a/tests/Fixtures/Addon/Tags/TestTags.php +++ b/tests/Fixtures/Addon/Tags/TestTags.php @@ -2,6 +2,7 @@ namespace Tests\Fixtures\Addon\Tags; +use Statamic\Support\Arr; use Statamic\Tags\Tags; class TestTags extends Tags @@ -22,7 +23,7 @@ public function someParsing() { $var = $this->params->get('var'); - $val = array_get($this->context, $var); + $val = Arr::get($this->context, $var); return $this->parse([$var => $val]); } diff --git a/tests/Http/Middleware/AddViewPathsTest.php b/tests/Http/Middleware/AddViewPathsTest.php index 07792346cc..e763ce2c43 100644 --- a/tests/Http/Middleware/AddViewPathsTest.php +++ b/tests/Http/Middleware/AddViewPathsTest.php @@ -5,6 +5,7 @@ use Illuminate\Http\Request; use Statamic\Facades\Site; use Statamic\Http\Middleware\AddViewPaths; +use Statamic\Support\Arr; use Statamic\Support\Str; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpFoundation\Response; @@ -71,14 +72,14 @@ public function adds_namespaced_view_paths($requestUrl, $expectedPaths) $handled = false; (new AddViewPaths())->handle($request, function () use ($expectedPaths, &$handled) { - $this->assertEquals($expectedPaths, array_get(view()->getFinder()->getHints(), 'foo')); + $this->assertEquals($expectedPaths, Arr::get(view()->getFinder()->getHints(), 'foo')); $handled = true; return new Response; }); $this->assertTrue($handled); - $this->assertEquals($originalHints, array_get(view()->getFinder()->getHints(), 'foo')); + $this->assertEquals($originalHints, Arr::get(view()->getFinder()->getHints(), 'foo')); } private function setCurrentSiteBasedOnUrl($requestUrl) diff --git a/tests/Imaging/GlideImageManipulatorTest.php b/tests/Imaging/GlideImageManipulatorTest.php index 474c59fa00..fc8186e5b6 100644 --- a/tests/Imaging/GlideImageManipulatorTest.php +++ b/tests/Imaging/GlideImageManipulatorTest.php @@ -6,6 +6,7 @@ use Statamic\Assets\Asset; use Statamic\Contracts\Imaging\UrlBuilder; use Statamic\Imaging\GlideImageManipulator; +use Statamic\Support\Arr; use Tests\TestCase; class GlideImageManipulatorTest extends TestCase @@ -137,7 +138,7 @@ public function focal_crop_uses_asset_value() $this->man->fit('crop_focal'); $this->assertArrayHasKey('fit', $this->man->getParams()); - $this->assertEquals('crop-60-40', array_get($this->man->getParams(), 'fit')); + $this->assertEquals('crop-60-40', Arr::get($this->man->getParams(), 'fit')); } /** @test */ @@ -149,6 +150,6 @@ public function focal_crop_just_uses_crop_if_no_value_exists() $this->man->fit('crop_focal'); $this->assertArrayHasKey('fit', $this->man->getParams()); - $this->assertEquals('crop', array_get($this->man->getParams(), 'fit')); + $this->assertEquals('crop', Arr::get($this->man->getParams(), 'fit')); } } diff --git a/tests/Modifiers/WhereTest.php b/tests/Modifiers/WhereTest.php index 1982a859b5..a03182baaa 100644 --- a/tests/Modifiers/WhereTest.php +++ b/tests/Modifiers/WhereTest.php @@ -3,6 +3,7 @@ namespace Tests\Modifiers; use Statamic\Modifiers\Modify; +use Statamic\Support\Arr; use Tests\TestCase; /** @@ -20,7 +21,7 @@ public function it_filters_data_by_a_given_key(): void ]; $expected = ['Dominion', 'Netrunner']; $modified = $this->modify($games, ['feeling', 'love']); - $this->assertEquals($expected, array_pluck($modified, 'title')); + $this->assertEquals($expected, Arr::pluck($modified, 'title')); } /** @test */ @@ -36,7 +37,7 @@ public function it_has_a_workaround_for_colon_syntax() ]; $expected = ['Dominion', 'Netrunner']; $modified = $this->modify($games, ['feeling:love']); - $this->assertEquals($expected, array_pluck($modified, 'title')); + $this->assertEquals($expected, Arr::pluck($modified, 'title')); } private function modify($value, array $params) diff --git a/tests/Policies/PolicyTestCase.php b/tests/Policies/PolicyTestCase.php index fe6ca6b6c0..6c24f3dcf1 100644 --- a/tests/Policies/PolicyTestCase.php +++ b/tests/Policies/PolicyTestCase.php @@ -4,6 +4,7 @@ use Statamic\Facades\Site; use Statamic\Facades\User; +use Statamic\Support\Str; use Tests\FakesRoles; use Tests\PreventSavingStacheItemsToDisk; use Tests\TestCase; @@ -21,7 +22,7 @@ protected function withSites(array $sites) protected function userWithPermissions(array $permissions) { - $role = str_random(); + $role = Str::random(); $this->setTestRole($role, $permissions); diff --git a/tests/PreventSavingStacheItemsToDisk.php b/tests/PreventSavingStacheItemsToDisk.php index d95aedf8c6..375a903eed 100644 --- a/tests/PreventSavingStacheItemsToDisk.php +++ b/tests/PreventSavingStacheItemsToDisk.php @@ -4,6 +4,7 @@ use Statamic\Facades\Path; use Statamic\Facades\Stache; +use Statamic\Support\Str; trait PreventSavingStacheItemsToDisk { @@ -15,7 +16,7 @@ protected function preventSavingStacheItemsToDisk() Stache::stores()->each(function ($store) { $dir = Path::tidy(__DIR__.'/__fixtures__'); - $relative = str_after(str_after($store->directory(), $dir), '/'); + $relative = Str::after(Str::after($store->directory(), $dir), '/'); $store->directory($this->fakeStacheDirectory.'/'.$relative); }); }