woutersioen/sir-trevor-php 问题修复 & 功能扩展

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

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

woutersioen/sir-trevor-php

Composer 安装命令:

composer require woutersioen/sir-trevor-php

包简介

A Sir Trevor to HTML conversion helper for PHP

README 文档

README

Build Status Scrutinizer Code Quality SensioLabsInsight

Introduction

This is a Conversion library that handles the input from Sir Trevor and converts it to HTML. In the future, the conversion from HTML to the Json input Sir Trevor needs will be implemented too.

Supported Sir Trevor blocks

  • Heading
  • Paragraph
  • List
  • Video
  • Quote
  • Image

It's easy to add a custom block. Just add a new ConversionType in the Sioen\Types namespace and register it in the ToJsonContect and the ToHtmlContect.

Requirement

This library package requires PHP 5.3 or later.

Installation

Require the library in your composer.json:

run composer require woutersioen/sir-trevor-php.

Make sure you have require 'vendor/autoload.php'; in the top of your script. If you're using a Framework, this should be ok by default.

Usage

Overal

// add the composer autoloader to your file
require_once 'vendor/autoload.php';

// Add the needed use statements to be able to use this library
use Sioen\HtmlToJson;
use Sioen\JsonToHtml;

Conversion to HTML

// fetch the data from the post
$sirTrevorInput = $_POST['textarea'];

// create a JsonToHtml object
$jsonToHtml = new JsonToHtml();

// add the wanted converters (you'll probably want to use your DIC container or a factory)
$jsonToHtml->addConverter(new Sioen\JsonToHtml\BlockquoteConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\HeadingConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\IframeConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\ImageConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\BaseConverter());

// generate your html
$html = $jsonToHtml->toHtml($sirTrevorInput);

Conversion to Json

// fetch html from database or wherever you want to fetch it from
$html = '<h2>This is my html</h2>';

// create a HtmlToJson object
$htmlToJson = new HtmlToJson();

// add the wanted converters (you'll probably want to use your DIC container or a factory)
$jsonToHtml->addConverter(new Sioen\HtmlToJson\BlockquoteConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\HeadingConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\ImageConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\IframeConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\ListConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\BaseConverter());

// generate your json
$json = $htmlToJson->toJson($html);

Adding your own converters.

Create a class that implements/extends the right abstraction

HtmlToJson converters should extend Sioen\HtmlToJson\Converter JsonToHtml converters should implement Sioen\JsonToHtml\Converter

You can add your own converts using the addConverter method.

统计信息

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

GitHub 信息

  • Stars: 28
  • Watchers: 5
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-11-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固