360i/sonno
Composer 安装命令:
composer require 360i/sonno
包简介
Sonno is a lightweight PHP framework based loosely on Jersey, a Java ReST framework reference implementation of the JAX-RS specification.
README 文档
README
Sonno - A RESTful PHP Framework!
Sonno is a lightweight PHP framework based loosely on Jersey, a Java ReST framework reference implementation of the JAX-RS specification.
Plain-Old-PHP objects are configured with a set of annotations describing a set of Resources.
<?php namespace Sonno\Example\Resource; use Sonno\Http\Response\Response, Sonno\Annotation\Path, Sonno\Annotation\GET, Sonno\Annotation\POST, Sonno\Annotation\Context, Sonno\Annotation\Produces, Sonno\Annotation\Consumes, Sonno\Annotation\PathParam, Sonno\Example\Representation\User\Collection as UserCollection; /** * @Path("/") */ class HelloResource { /** * @Context("Request") */ protected $_request; /** * @GET * @Produces({"text/plain"}) */ public function getHelloWorld() { return 'Hello ReSTful World!'; } /** * @GET * @Path("/users") * @Produces({"application/xml"}) */ public function getUserCollection() { return new UserCollection('application/xml'); } /** * @POST * @Path("/users") * @Consumes({"application/xml"}) */ public function saveUserXml() { // Retrieve the request body. $data = $this->_request->getRequestBody(); // ... Do some processing of $data, then save it... $response = new Response(); return $response->setCreated('http://example.sonno.dev/users/10'); } }
License
Sonno is licensed under the New BSD license. A copy can be found here: http://sonno.360i.com/LICENSE.txt
Dependencies
The current version of Sonno supports configuring a ReSTful web application via annotations. Rather than reinvent the wheel and develop our own annotation reader, we've provided interfaces and adapters. The adapter that ships with this version uses Doctrine-Common version >= 2.1.1. That's not to say that any developer couldn't implement their own annotation reader, then build an adapter that implements Sonno\Annotation\Reader\ReaderInterface.
Here's an example of how a Sonno application can be configured using Doctrine's annotation reader:
<?php use Sonno\Configuration\Driver\AnnotationDriver, Sonno\Annotation\Reader\DoctrineReader, Doctrine\Common\Annotations\AnnotationReader, Doctrine\Common\Annotations\AnnotationRegistry; $doctrineReader = new AnnotationReader(); AnnotationRegistry::registerAutoloadNamespace( 'Sonno\Annotation', realpath('path/to/Sonno/src') ); $annotationReader = new DoctrineReader($doctrineReader); $resources = array( 'FQNS\To\SomeResource', 'FQNS\To\SomeOtherResource', ); $driver = new AnnotationDriver($resources, $annotationReader); $config = $driver->parseConfig();
Summary of Annotations
| Annotation | Target | Description |
| @Path | Class, Method | Specifies a relative path for a resource. When used on a class this annotation identifies that class as a root resource. When used on a method this annotation identifies a sub-resource method or locator. |
| @Consumes | Class, Method | Specifies a list of media types that can be consumed. |
| @Produces | Class, Method | Specifies a list of media types that can be produced. |
| @Context | Property | Identifies an injection target for a Request object. |
| @DELETE | Method | Specifies that the annotated method handles HTTP DELETE requests. |
| @GET | Method | Specifies that the annotated method handles HTTP GET requests. |
| @HEAD | Method | Specifies that the annotated method handles HTTP HEAD requests. |
| @OPTIONS | Method | Specifies that the annotated method handles HTTP OPTIONS requests. |
| @POST | Method | Specifies that the annotated method handles HTTP POST requests. |
| @PUT | Method | Specifies that the annotated method handles HTTP PUT requests. |
| @PathParam | Method | Specifies that the value of a method parameter is to be extracted from the request URI path. The value of the annotation identifies the name of a URI template parameter. |
| @QueryParam | Method | Specifies that the value of a method parameter is to be extracted from a URI query parameter. The value of the annotation identifies the name of a query parameter. |
| @CookieParam | Method | Specifies that the value of a method parameter is to be extracted from a HTTP cookie. The value of the annotation identifies the name of a the cookie. |
| @FormParam | Method | Specifies that the value of a method parameter is to be extracted from a form parameter in a request entity body. The value of the annotation identifies the name of a form parameter. Note that whilst the annotation target allows use on fields and methods, the specification only requires support for use on resource method parameters. |
| @HeaderParam | Method | Specifies that the value of a method parameter is to be extracted from a HTTP header. The value of the annotation identifies the name of a HTTP header. |
Contribution Guidelines
Coding Standard
We strictly adhere to the Zend Framework coding standard. Before pushing to the
origin, you should run
PHP_CodeSniffer:
$ phpcs --standard=zend src. All errors and warnings
should be cleaned up before making a pull request.
Add Test Cases
We try to keep our Code Coverage high and our CRAP index low. Before submitting a pull request, run the PHPUnit test suite and ensure that all tests pass. If you add functionality or fix a bug, please include test cases to cover the code you've sumitted.
Additional Resources
360i/sonno 适用场景与选型建议
360i/sonno 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44 次下载、GitHub Stars 达 15, 最近一次更新时间为 2013 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「api」 「restful」 「JAX-RS」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 360i/sonno 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 360i/sonno 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 360i/sonno 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
This is a restful api to onesignal.
A RESTful API package for the Laravel and Lumen frameworks.
Simple and lightweight HTTP client based cURL
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: New
- 更新时间: 2013-02-06