olajoscs / nestable-generator
Nestable结构编辑器的json生成器和解析器
1.0.1
2017-09-07 07:54 UTC
Requires
- php: ~7.1
Requires (Dev)
- phpunit/phpunit: ^5.3.0
This package is not auto-updated.
Last update: 2024-09-28 03:02:05 UTC
README
这是一个小型PHP包,用于提供Nestable2 JavaScript插件的生成器和解析器。
要求
- php ~7.1
用法
实例化NestableGenerator
类
- 首先需要一个元素数组,这将是生成json的基础。这些元素必须实现
Element
接口。基本功能已在AbstractElement
类中实现,但如果需要自定义实现,则可以跳过。 - 需要一个实现
NestedElement
接口的对象 - 这个对象是json生成的来源。将Element
对象转换为NestedElement
对象。这些NestedElements
对象具有一个children属性,以便构建结构。 NestableGenerator
对象只需要一个构造函数参数:一个ElementCollection
对象,该对象由Element
对象的数组构建。这个ElementCollection
需要一个Element
对象的数组和一个空的NestableElement
对象,后者将被用作参考。
生成json
一旦使用ElementCollection
创建了NestableGenerator
,只需调用generate()
。它返回Nestable需要生成块的JSON。
解析JSON
Nestable可以以JSON形式发送创建的结构。为了解析它,需要实例化NestableGenerator
类并调用parse($json)
,其中$json
是由Nestable生成的JSON字符串。它返回Element
对象的数组。