bnf/slim-typo3 问题修复 & 功能扩展

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

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

bnf/slim-typo3

Composer 安装命令:

composer require bnf/slim-typo3

包简介

Slim Framework integration for TYPO3

README 文档

README

Build Status Coverage Status

Introduction

This extension provides a TYPO3 RequestHandler which runs a Slim App. The Slim App will be executed when one of its routes match the request. If no route matches, the lower prioritized default TYPO3 RequestHandler(s) will be executed.

This request handler basically works like a TYPO3 eID (executed with identically environment), but with proper routing and nice looking URLs.

Note: The EIDRequestHandler has higher priority and will not be influenced by this router. That means the slim app can not accept a GET parameter eID.

Usage

$ composer require bnf/slim-typo3:~0.5.0

Quick Example

Register the app definition in ext_localconf.php (or AdditionalConfiguration.php):

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Bnf\SlimTypo3\AppRegistry::class)
    ->push(function ($app) {
        $app->get('/hello/{name}', function ($request, $response) {
            $response->getBody()->write('Hello ' . htmlspecialchars($request->getAttribute('name')));
            return $response;
        });
    });

That's all and now your route controller should be executed when requesting /hello/world.

Full Example

  • TODO: Configuration/Services.yaml – tag based registration

ext_localconf.php:

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Bnf\SlimTypo3\AppRegistry::class)
    ->push(\Your\Namespace\TestApp::class);

TestApp.php

<?php
declare(strict_types=1);
namespace Your\Namespace;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App;
use TYPO3\CMS\Core\SingletonInterface;

class TestApp implements SingletonInterface
{
    public function __invoke(App $app)
    {
        $app->add(function (Request $request, Response $response, callable $next) {
            $response->getBody()->write('I am middleware.. ');
            return $next($request, $response, $next);
        });

        $app->get('/bar[/{foo}]', static::class . ':bar');
    }

    public function bar(Request $request, Response $response): Response
    {
        $response->getBody()->write('baz');

        $foo = $request->getAttribute('foo');
        if ($foo) {
            $response->getBody()->write(' ' . htmlspecialchars($foo));
        }

        return $response;
    }
}

Example Extension

See https://github.com/bnf/slim-typo3-testapp for an example extension.

TODO

Support generating multiple RequestsHandlers with multiple App configs? (and maybe basePaths). (Well, maybe not. Con: that add's another abstraction on top of Slim\App which already knows about route groups – BUT it would support different Middleware configs.)

Example:

App1: /api
App2: /api2
App3: /getFooData.xml

Suggestions

For this TYPO3 integration we suggest to add middleware's as string. That has a slight overhead as Slim's CallableResolver will preg_match the string, but has the advantage, that not all middleware's need to be instantiated although they may never be called (as no route matches and we do not process the request). As TYPO3 is the host it's likely that most of the times the TYPO3 RequestHandlers will be executed therefore the slim bootstrap should be as lightweight as possible.

You can supply middleware's as class (or container identifier) strings and Slim's CallableResolver will retrieve the instance from the container (if the container has a definition for that class) or instantiate a new class: new $class($container);

Therefore use:

// Will implicitly call `new \Your\Namespace\Middleware\Foo($container)`
// when the middleware is executed.
$app->add(\Your\Namespace\Middleware\Foo::class);
// or ('view' needs to be defined in the container)
$app->add('view');

instead of:

// You SHOULD NOT do this
$app->add(new \Your\Namespace\Middleware\Foo::class);
// nor this
$app->add($container->get(\Your\Namespace\Middleware\Foo::class));
// nor this
$app->add($container->get('view'));

bnf/slim-typo3 适用场景与选型建议

bnf/slim-typo3 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.89k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extension」 「typo3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bnf/slim-typo3 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bnf/slim-typo3 我们能提供哪些服务?
定制开发 / 二次开发

基于 bnf/slim-typo3 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2017-08-14