jdwx/quote 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jdwx/quote

Composer 安装命令:

composer require jdwx/quote

包简介

A PHP module for handling complex quoted strings.

README 文档

README

A simple PHP module for handling quoted strings.

Installation

You can require it directly with Composer:

composer require jdwx/quote

Or download the source from GitHub: https://github.com/jdwx/quote-php.git

Requirements

This module requires PHP 8.2 or later.

Usage

This module provides functionality for processing arbitrary strings into lists of arguments, including support for quoting, $variable substitution, and implementing `backtick` replacement through callbacks.

A simple example using this module to get a list of arguments from a string:

$parser = new Parser(
    hardQuote: QuoteOperator::simple(),
    delimiter: DelimiterOperator::whitespace(),
);

var_dump( iterator_to_array( $parser( 'The "quick brown fox" jumps \'over the\' lazy dog.' ) ) );

Produces:

array(6) {
  [0] =>
  string(3) "The"
  [1] =>
  string(15) "quick brown fox"
  [2] =>
  string(5) "jumps"
  [3] =>
  string(8) "over the"
  [4] =>
  string(4) "lazy"
  [5] =>
  string(4) "dog."
}

A more complex example showing most of the features of this module:

$fnVars = new Variables( [
    'foo' => 'quick',
    'fox' => 'nope',
] );
$parser = new Parser(
    comment: QuoteOperator::cComment(),
    hardQuote: QuoteOperator::single(),
    softQuote: QuoteOperator::double(),
    strongCallback: QuoteOperator::backtick(),
    weakCallback: QuoteOperator::varCurly(),
    openCallback: OpenEndedOperator::var(),
    escape: new MultiOperator( [ new HexEscape(), new ControlCharEscape() ] ),
    delimiter: ConsolidatedDelimiterOperator::whitespace(),

    # These are the functions used by callback operators.
    fnStrong: fn( string $st ) : string => strtolower( $st ),
    fnWeak: $fnVars,
    fnOpen: $fnVars
);

$st = 'The/* slow! */ $foo    \'brown $fox\' "jumps over" \\x74he `LAZY` dog.\n';
echo Segment::mergeValues( $parser->parse( $st ) );

Produces:

The quick brown $fox jumps over the lazy dog.

Stability

This module was refactored from existing code that has been widely used in production. But then it experienced a near complete rewrite. It is considered stable and has complete test coverage.

History

This module was refactored out of jdwx/args in June 2025.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-19