ta-tikoma/bog-jug 问题修复 & 功能扩展

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

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

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.

Static Badge Static Badge Static Badge GitHub

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 namespace BogJug\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.

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-21