定制 sinso/app-routes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sinso/app-routes

Composer 安装命令:

composer require sinso/app-routes

包简介

Easy way to route rest-like URLs to your code

README 文档

README

Route any URL to your application.

You use this package if you want to route certain URLs directly to your controllers, completely ignoring the TYPO3 page routing.
This is especially useful to create REST APIs.

Installation

composer req sinso/app-routes

Configuration

This package will look for Configuration/AppRoutes.yaml files in any loaded extension. Creating this file is all you need to get started:

myApp:
  prefix: /myApi/v2
  routes:
    - name: orders
      path: /orders
      defaults:
        handler: MyVendor\MyExtension\Api\OrdersEndpoint
    - name: order
      path: /order/{orderUid}
      defaults:
        handler: MyVendor\MyExtension\Api\OrderEndpoint

The class you provide as defaults.handler has to implement \Psr\Http\Server\RequestHandlerInterface. The routing parameters will be available in $request->getQueryParams().

Options

Under the hood symfony/routing is used.

Everything that is available as YAML configuration option in symfony/routing should work with this package out of the box.

This package offers these additional options:

  • defaults.cache: true - If true, then responses are cached (see more details below). (default: false)
  • defaults.requiresTypoScript: true - If true, then the frontend.typoscript request attribute will be initialized before your handler is called (default: false).

Generate Route URLs

To generate URLs you can use the Sinso\AppRoutes\Service\Router:

$router = GeneralUtility::makeInstance(\Sinso\AppRoutes\Service\Router::class);
$url = $router->getUrlGenerator()->generate('myApp.order', ['orderUid' => 42]);
// https://www.example.com/myApi/v2/order/42

If you need to generate a URL in a Fluid template, there's also a ViewHelper for that:

<html
	xmlns:ar="http://typo3.org/ns/Sinso/AppRoutes/ViewHelpers"
	data-namespace-typo3-fluid="true"
>

{ar:route(routeName: 'myApp.order', parameters: {orderUid: '42'})}

</html>

Configuration Module

In the configuration module there's an entry "App Routes", that shows all configured routes.

Server Side Caching

  • Caching can be enabled per route via configuration defaults.cache: true.
  • The TYPO3 pages cache is used to cache API responses.
  • Your request handler will not be called at all if the request can be served from cache.
  • Only responses for GET and HEAD requests can be cached.
  • The cache key is built from all query parameters that were matched by your route.
  • Any cache tags added to TYPO3's CacheDataCollector ($request->getAttribute('frontend.cache.collector')) are applied to the cache entry.
  • If you have $GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] enabled, the HTTP response contains headers describing its cache status.
  • Responses with Cache-Control: no-cache or Cache-Control: no-store are not cached.
  • Responses with Cache-Control: max-age=300 overwrite the default TTL of the pages cache.

ETag

Setting an ETag header in your response will enable conditional requests, i.e. the client doesn't need to download the response body if it already has the latest version.

  • If your response contains an ETag header and it matches the If-None-Match header of the request, the response HTTP status will be 304 Not Modified and the response body will be empty.

sinso/app-routes 适用场景与选型建议

sinso/app-routes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 116.91k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2020 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 sinso/app-routes 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 23
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2020-12-15