slifin/edn 问题修复 & 功能扩展

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

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

slifin/edn

Composer 安装命令:

composer require slifin/edn

包简介

Extensible Data Notation Parser.

关键字:

README 文档

README

Parser for the edn format. In PHP.

The parser internally relies on Phlexy for lexing.

Usage

Parsing

To parse edn, just use the parse function:

$edn = file_get_contents('examples/sample.edn');
$data = igorw\edn\parse($edn);

print_r($data);

You can also define custom tag handlers and pass them as a second argument to parse:

use igorw\edn;

class Person {
    public $firstName;
    public $lastName;

    function __construct($firstName, $lastName) {
        $this->firstName = $firstName;
        $this->lastName = $lastName;
    }
}

$edn = '#myapp/Person {:first "Fred" :last "Mertz"}';

$data = edn\parse($edn, [
    'myapp/Person' => function ($node) {
        return new Person(
            $node[edn\keyword('first')],
            $node[edn\keyword('last')]
        );
    },
]);

// [new Person('Fred', 'Mertz')]

Encoding

If you want to take an in-memory data structure and encode it as edn, you can use the encode function:

use igorw\edn;

$person = new edn\Map();
$person[edn\keyword('name')] = 'igorw';

$list = new edn\LinkedList([
    edn\symbol('foo'),
    edn\symbol('bar'),
    edn\symbol('baz'),
    edn\keyword('qux'),
    1.0,
    $person,
]);

$edn = edn\encode([$list]);
// (foo bar baz :qux 1.0 {:name "igorw"})

Tests

This library runs against the shaunxcode/edn-tests suite.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固