juzim/todo-txt-parser 问题修复 & 功能扩展

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

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

juzim/todo-txt-parser

Composer 安装命令:

composer require juzim/todo-txt-parser

包简介

A todo.txt parsing and validation library for PHP

README 文档

README

A todo.txt parsing and validation library for PHP

Installation

$ composer require "juzim/todo-txt-parser:~1.0"

Usage

$parser = new TodoTxtParser();
$task = $parser->buildTaskFromString('x 2016-11-22 2016-11-20 (A) due:2016-09-05 Tell @me to write the @README for +todoTxtParser');

This will return a TodoTxtTask object that includes all values (see todo.txt rules):

Get raw string:
$task->getOriginalText()   // 'x 2016-11-22 (A) 2016-01-02 Tell @me to write the @README for +todoTxtParser due:2016-09-05'

Get clean string (only readable text): 
$task->getCleanText()   // 'Tell @me to write the @README for +todoTxtParser'

Get metadata:
$task->isCompleted()    // starts with 'x '     ->  true
$task->getCompletedAt() // YYYY-MM-DD after 'x' ->  DateTime/2016-11-22
$task->getPriority()    // (A-Z)                ->  'A'
$task->getCreatedAt()   // YYYY-MM-DD           ->  DateTime/2016-01-02
$task->getProjects()    // +                    ->  ['todoTxtParser']
$task->getContexts()    // @                    ->  ['me', 'README']
$task->getAddOns()      // {key}:{text}         ->  ['due' => '2016-09-05']

The following errors get collected:

ERROR_NO_TEXT_GIVEN                     -> No text given
ERROR_NO_TASK_DESCRIPTION               -> Task is missing a description/only has metadata
ERROR_INVALID_DATE_CREATED_AT           -> Invalid created at date
ERROR_INVALID_DATE_COMPLETED_AT         -> Invalid completed at date
ERROR_COMPLETED_AT_MISSING              -> Task is completed but has no completed at date
ERROR_CREATED_AT_IN_THE_FUTURE          -> Created at date is in the future
ERROR_COMPLETED_AT_IN_THE_FUTURE        -> Completed at date is in the future
ERROR_DUPLICATE_ADD_ON_KEY              -> Duplicate add-on key
ERROR_COMPLETED_AT_BEFORE_CREATED_AT    -> Task was completed before it was created

If at least one of those errors occurred, a TodoTxtValidationException is thrown at the end which includes all collected errors in readable format. Specific errors can be ignored with $parser->ignoreError(TodoTxtParser::ERROR_NAME).

Notes

  • Metadata that doesn't match one of the rules becomes part of the description
  • Leading/trailing whitespace and duplicate spaces get removed
  • Add-Ons are not part of the clean text (not sure if that's correct thou)
  • Anything goes for the description text, so remember to filter/escape accordingly
  • For now there are no rules for projects, contexts and add-ons other then the regex, but some restrictions like valid characters or length might be added later on

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固