waynestate / string-middleware
基于插件的字符串处理器
1.1.2
2015-06-16 15:53 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.5
This package is auto-updated.
Last update: 2024-09-08 07:51:44 UTC
README
基于插件的字符串处理器
安装
要安装此库,请运行以下命令,您将获得最新版本
composer require waynestate/string-middleware
使用方法
// Start with some string
$input = 'Some string to parse';
// Create the instance of the Parser
$parser = new \Waynestate\ParserMiddleware\ParserMiddleware();
// Define the list of parsers to run, in chronological order
// Each must implement the Waynestate\StringParser\StringParserInterface
$parsers = array(
'Waynestate\StringParser\SelfParser',
'Waynestate\StringParsers\ReverseParser',
);
// Set the stack of parsers
$parser->setStack($parsers);
// Parse the string and return the output
$output = $parser->parse($input);
// Output is now modified by each parser
var_dump($output);
示例解析器
反转字符串
/**
* Class Header Parser
*/
class HeaderParser implements Waynestate\StringParser\StringParserInterface
{
/**
* Replace every occurrence of "<p>[header ...]</p>" with "<h1>...</h1>"
*
* @param string $string
* @return string
*/
public function parse($string) {
return preg_replace("/<p>\[header (.*)\]<\/p>/", '<h1>${1}</h1>', $string);
}
}
测试
phpunit
代码覆盖率
phpunit --coverage-html ./coverage