承接 mpstenson/laravel-advanced-string 相关项目开发

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

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

mpstenson/laravel-advanced-string

Composer 安装命令:

composer require mpstenson/laravel-advanced-string

包简介

This application provides advanced string functions beyond what Laravel itself provides.

README 文档

README

Tested, community maintained, supercharged Laravel string functions.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel Advanced String is a Laravel package that adds advanced string manipulation methods to the built in Str class that Laravel provides. You get extended functionality on strings such as advanced password generation, data redaction, and more.

The Laravel Advanced String package by default adds macros to the Str class so your can access the extended functionality in the same class that your other string methods are found in. You can also disable this functionality the in the package config and use the AdvStr class directly.

Example

ssnRedaction-compressed.mp4
Str::redactSsn('My social security number is 222-22-2222'); // My social security number is xxxxxx

OR...

AdvStr::redactSsn('My social security number is 222-22-2222'); // My social security number is xxxxxx

Table of Contents

Installation

You can install the package via composer:

composer require mpstenson/laravel-advanced-string

You can publish the config file with:

php artisan vendor:publish --tag="laravel-advanced-string-config"

This is the contents of the published config file:

return [

    /*
    // Macro the AdvStr class to the Illuminate\Support\Str class. You can disable
    // this here if you don't want the AdvStr methods available on the Str class
    */

    'use_str' => true,

];

Usage

The Laravel Advanced String package by default adds macros to the Str class so your can access the extended functionality immediately

Str::redactSsn('123-45-6789')

Available Methods

advPassword

Generates a random, secure password.

public static function advPassword(
    $length = 32,
    $letters = true,
    $numbers = true,
    $symbols = true,
    $spaces = false,
    $upperLetters = false,
    $lowerLetters = false,
    $exclude = []
)

Parameters:

  • $length (int): Length of the password (default: 32)
  • $letters (bool): Include mixed case letters (default: true)
  • $numbers (bool): Include numbers (default: true)
  • $symbols (bool): Include symbols (default: true)
  • $spaces (bool): Include spaces (default: false)
  • $upperLetters (bool): Include uppercase letters (default: false)
  • $lowerLetters (bool): Include lowercase letters (default: false)
  • $exclude (array): Characters to exclude from the password

Returns:

  • string: Generated password

charWrap

Wraps a string at a given number of characters regardless of words.

public static function charWrap(
    $string, 
    $length = 80
)

Parameters:

  • $string (string): The string to wrap
  • $length (int): The number of characters to wrap at (default: 80)

Returns:

  • string: The wrapped string

emailDomain

Extracts the domain part of an email address, including subdomains.

public static function emailDomain(
    $string
)

Parameters:

  • $string (string): The string to extract the email domain from.

Returns:

  • string: The email domain from the string

randomPhrase

Returns a random phrase with a configurable delimiter.

public static function randomPhrase(
    $wordCount,
    $separator = '-'
)

Parameters:

  • $wordCount (int): The number of words in the phrase.
  • $separator (string): The separator between words (default: '-').

Returns:

  • string: The generated random phrase.

randomWord

Returns a random word.

public static function randomWord(
)

Parameters:

  • none

Returns:

  • string: A random word

readTime

Calculates the read time of a string.

public static function readTime(
    $string, 
    $wpm = 200
)

Parameters:

  • $string (string): The text to calculate read time for
  • $wpm (int): Words per minute (default: 200)

Returns:

  • float: Estimated read time in seconds

redactCreditCard

Redacts credit card numbers in a string.

public static function redactCreditCard(
    $string, 
    $redacted = '********', 
    $exclude = []
)

Parameters:

  • $string (string): The string containing credit card numbers to redact
  • $redacted (string): The string to replace credit card numbers with (default: '********')
  • $exclude (array): An array of credit card types to exclude from redaction. Possible types: 'mastercard','visa','amex','discover','diners','jcb'

Returns:

  • string: The string with credit card numbers redacted

redactSsn

Redacts Social Security Numbers (SSN) in a string.

public static function redactSsn(
    $string, 
    $redacted = '********', 
    $dashes = true, 
    $noDashes = true
)

Parameters:

  • $string (string): The string containing SSNs to redact
  • $redacted (string): The string to replace SSNs with (default: '********')
  • $dashes (bool): Redact SSNs with dashes (default: true)
  • $noDashes (bool): Redact SSNs without dashes (default: true)

Returns:

  • string: The string with SSNs redacted

splitName

Splits a full name into first name, middle name (if present), and last name, removing any prefixes and suffixes. This method can handle both "Firstname Lastname" and "Lastname, Firstname" formats.

public static function splitName(
    $name
)

Parameters:

  • $name (string): The full name to split

Returns:

  • array: An associative array containing 'first', 'middle' (if present), and 'last' name

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

mpstenson/laravel-advanced-string 适用场景与选型建议

mpstenson/laravel-advanced-string 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.82k 次下载、GitHub Stars 达 71, 最近一次更新时间为 2024 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「Matt Stenson」 「laravel-advanced-string」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mpstenson/laravel-advanced-string 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mpstenson/laravel-advanced-string 我们能提供哪些服务?
定制开发 / 二次开发

基于 mpstenson/laravel-advanced-string 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.82k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 71
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 71
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-11