承接 jontynewman/oku-io 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jontynewman/oku-io

Composer 安装命令:

composer require jontynewman/oku-io

包简介

Functionality for generating output from set input per path.

README 文档

README

Functionality for generating output from set input per path.

For example, a given path could take set reStructuredText as input and produce cached HTML as output.

Installation

composer require 'jontynewman/oku-io ^1.0'

Example Usage

The following example assumes that rst2html5 is available, and that the following packages are installed.

The editor will allow users to either input or upload reStructuredText in order to create static web pages.

<?php

use GuzzleHttp\Psr7\Response;
use JontyNewman\HtmlFilter;
use JontyNewman\Oku\ContextInterface;
use JontyNewman\Oku\IO\Cache;
use JontyNewman\Oku\IO\Repository;
use JontyNewman\Oku\Process;
use JontyNewman\Oku\RequestHandler;
use JontyNewman\Oku\ResponseBuilderInterface;

require 'vendor/autoload.php';

$dir = '/path/to/io/directory';

// Convert reStructuredText input files to HTML output files.
$process = new Process('rst2html5');

// Cache HTML output in the specified directory.
$cache = new Cache($process, "{$dir}/html/", 'html');

// Persist reStructuredText input in the specified directory (for future edits).
$repository = new Repository($cache, "{$dir}/rst/", 'rst');

// Allow users to edit and upload reStructuredText.
$editor = function (
	ResponseBuilderInterface $builder,
	ContextInterface $context
) use ($repository): void {

	$path = $context->request()->getUri()->getPath();
	$in = $repository->directory()->offsetGet($path);
	$render = function () use ($in) {

		if (file_exists($in)) {
			HtmlFilter::passthru($in, 'rb');
		}
	};

	$builder->content(function () use ($render, $context) {
		require 'editor.php';
	});
};

// Use a simple 404 page as the default response.
$default = new Response(404, ['Content-Type' => 'text/plain'], 'Not Found');

// Set up the request handler.
$handler = new RequestHandler($repository, $default, $editor);

// Run the application.
$handler->run();

An example template of the editor (i.e. editor.php) follows.

<?php

use JontyNewman\Oku\IO\Repository;
use JontyNewman\Oku\Helpers\Html;

/* @var $render callable */
/* @var $context \JontyNewman\Oku\ContextInterface */

?>
<!DOCTYPE html>
<html>
  <head>
    <title>JontyNewman\Oku\IO</title>
  </head>
  <body>
    <form action="" method="post" enctype="multipart/form-data">
      <p>
        <label>
          File
          <input type="file" name="<?= Html::escape(Repository::FILE); ?>">
        </label>
      </p>
      <p>
        <label>
          Text
          <textarea name="<?= Html::escape(Repository::TEXT); ?>"><?php ($render)(); ?></textarea>
        </label>
      </p>
      <p>
        <?= $context->token(); ?>
        <?= $context->put(); ?>
        <input type="submit" value="Save">
      </p>
    </form>
    <form action="" method="post">
      <p>
        <?= $context->token(); ?>
        <?= $context->delete(); ?>
        <input type="submit" value="Delete">
      </p>
    </form>
    <?= $context->inset(); ?>
  </body>
</html>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固