ta-tikoma/bog-jug
Composer 安装命令:
composer require ta-tikoma/bog-jug
包简介
Convert regex group to objects
README 文档
README
A tool that makes it easier to work with regex groups. Mapped regex group to php-classes, because array is sucks.
Install
composer require ta-tikoma/bog-jug
Use
- Create a class for regex descriptions.
- Use property attributes for defined regex group:
#[Group('...')]for group body;#[After]and#[Before]for defined outside symbols. - If you need to indicate the count of a group, use attributes like
#[ZeroOrOne],#[ZeroOrMore]and others from the namespaceBogJug\Attributes\Count. - Finally, you can add regex flags via the class attributes; for example:
#[SingleLine]. - Now create instance of class BogJug and use one of two base methods:
- Method
->one($regex, $text)to find the first value equal to regex; analogue:preg_match. - Method
->many($regex, $text)to get all values equal regex; analog:preg_match_all.
- Method
Sample example
1. Define class of descriptions.
<?php declare(strict_types=1); namespace tests\Data; use BogJug\Attributes\Flags\SingleLine; use BogJug\Attributes\Regex\After; use BogJug\Attributes\Regex\Group; #[SingleLine] final class TinWoodman { public function __construct( #[Group('head'), After('.*')] public readonly string $noggin, #[Group('arms'), After('.*')] public readonly string $upperLimbs, #[Group('legs'), After('.*')] public readonly string $lowerLimbs, #[Group('body'), After('.*')] public readonly string $torso, #[Group('heart'), After('.*')] public readonly string|null $coeur, ) { } }
2. Call method of BogJug.
$bj = new BogJug(); $tw = $bj->one(TinWoodman::class, <<<OZ One of the big trees had been partly chopped through, and standing beside it, with an uplifted axe in his hands, was a man made entirely of tin. His head and arms and legs were jointed upon his body, but he stood perfectly motionless, as if he could not stir at all. OZ); dump($tw);
3. Take result.
^ tests\Data\TinWoodman^ {#427 +noggin: "head" +upperLimbs: "arms" +lowerLimbs: "legs" +torso: "body" +coeur: null }
统计信息
- 总下载量: 2.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-21