承接 snicco/str-arr 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

snicco/str-arr

最新稳定版本:v2.0.0-beta.9

Composer 安装命令:

composer require snicco/str-arr

包简介

A standalone implementation of Laravel's Str and Arr classes.

README 文档

README

codecov Psalm Type-Coverage Psalm level PhpMetrics - Static Analysis PHP-Versions

This package contains a subset of the illuminate/support Str and Arr classes.

Laravel's string and array helpers are very handy utility classes but pulling in the entire illuminate/support is not an option when you are writing a framework-agnostic package.

The following modifications have been made:

Str:

  • full multibyte support for all methods
  • strict-typehints
  • Str is a final class
  • all hidden illuminate/* dependencies are removed
  • full support for @psalm.

Arr:

  • strict-typehints
  • Arr is a final class
  • all hidden illuminate/* dependencies are removed
  • Collection references are replaces with ArrayAccess or ArrayObject where applicable
  • full support for @psalm and @template annotations.

Installation

composer require snicco/str-arr

Usage

This package is pretty much self-documenting.

Check the source (Str, Arr) and tests (Str , Arr)

Public API of Str:

use Snicco\Component\StrArr\Str;

$subject = 'snicco.io';

Str::contains($subject, '.io') // true
Str::containsAll($subject, ['.io', '.com']) // false
Str::containsAny($subject, ['.io', '.com']) // true

Str::studly('snicco str-arr'); // Snicco StrArr

Str::ucfirst($subject); // Snicco.io

Str::startsWith($subject, 'snicco') // true

Str::endsWith($subject, '.io') // true
Str::doesNotEndWith($subject, '.io') // false

Str::afterFirst($subject, 'c') // co.io
Str::afterLast($subject, 'c') // o.io

Str::betweenFirst($subject, 'c', 'o') // o
Str::betweenLast($subject, 'c', 'o') // co.io

Str::beforeFirst($subject, 'o') // snicc
Str::beforeLast($subject, 'o') // snicco.i

Str::substr($subject, -3) // .io

// This accepts any regex pattern. * will be replaced with ".*"
Str::is($subject, 'snicco.*') // true

Str::replaceFirst($subject, 'c', 'k') // snikco.io
Str::replaceAll($subject, 'c', 'k') // snikko.io

Str::pregReplace($subject, 'c', '/\.\w{2}/', '.de') // snicco.de

Public API of Arr:

use Snicco\Component\StrArr\Arr;use Snicco\Component\StrArr\Str;

$array = [
    'foo' => 'bar'
    'baz' => 'biz'
    'boom' => [
        'bang' => 'pow'
    ]   
]

Arr::only($array, ['foo']) // ['foo'=>'bar']

// Returns the first array element
Arr::first($array) // bar

// Returns the first element matching the condition
Arr::first(
    $array, 
    fn(string $value, string $key) => Str::startsWith($key, 'f')
); // bar

// With a default value
Arr::first($array, fn($value) => is_int($value), 'default') // default

Arr::random($array, 1) // returns one random value.

Arr::toArray('foo') // ['foo']
Arr::toArray([]) // []
Arr::toArray(['foo']) // ['foo']

// Checks if all keys are strings
Arr::isAssoc($array) // true

Arr::isList($array) // false
Arr::isList(['foo', 'bar']) // true

Arr::get($array, 'foo') // bar
Arr::get($array, 'bogus') // null
Arr::get($array, 'bogus', 'default') // default
Arr::get($array, 'boom.bang') // pow

// passed by reference here
Arr::set($array, 'boom.bang', 'POW');

Arr::has($array, 'foo') // true
Arr::has($array, 'bogus') // false
Arr::has($array, 'boom.bang') // true

Arr::hasAll(['foo', 'bogus']) // false

Arr::hasAny(['foo', 'bogus']) // true

// Checks if the passed value is either array or ArrayAccess
Arr::accessible($array) // true

Arr::mergeRecursive($array, ['boom' => ['bang' => 'POW', 'new' => 'NEW']]) 
// [ 'foo' => 'bar'
//    'baz' => 'biz'
//    'boom' => [
//        'bang' => 'POW',
//        'new => 'NEW'
//    ]
// ]

Arr::keyExists($array, 'foo') // true

Arr::flatten($array) // ['bar', 'biz', 'pow']

Arr::except($array, ['foo', 'baz'])
// [
//    'boom' => [
//        'bang' => 'POW',
//        'new => 'NEW'
//    ]
// ]

// Passed by reference here
Arr::remove($array, 'boom.bang');
// [ 'foo' => 'bar'
//    'baz' => 'biz'
//    'boom' => []
// ]

Contributing

This repository is a read-only split of the development repo of the Snicco project.

This is how you can contribute.

Reporting issues and sending pull requests

Please report issues in the Snicco monorepo.

Security

If you discover a security vulnerability, please follow our disclosure procedure.

统计信息

  • 总下载量: 22.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 3
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2022-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固