360i / sonno
Sonno 是一个基于 Jersey 的轻量级 PHP 框架,Jersey 是一个 Java ReST 框架,是 JAX-RS 规范的参考实现。
0.2.1
2013-02-06 23:25 UTC
Requires
- php: >= 5.3.0
- doctrine/common: 2.2.1
- monolog/monolog: 1.2.*
This package is not auto-updated.
Last update: 2024-09-28 14:39:01 UTC
README
Sonno - 一个 RESTful PHP 框架!
Sonno 是一个轻量级 PHP 框架,基于 Jersey,它是 JAX-RS 规范的 Java ReST 框架参考实现。
使用一组描述资源的注解配置普通的 PHP 对象。
<?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'); } }
许可证
Sonno 采用新 BSD 许可证授权。许可证副本可在此找到: http://sonno.360i.com/LICENSE.txt
依赖
当前版本的 Sonno 支持通过注解配置 ReSTful 网络应用程序。我们并未重新发明轮子,开发自己的注解读取器,而是提供了接口和适配器。本版本附带的适配器使用 Doctrine-Common 版本 >= 2.1.1。这并不意味着任何开发者不能实现自己的注解读取器,然后构建一个实现 Sonno\Annotation\Reader\ReaderInterface 的适配器。
以下是如何使用 Doctrine 的注解读取器配置 Sonno 应用程序的示例
<?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();
注解摘要
贡献指南
编码标准
我们严格遵守 Zend Framework 编码标准。在推送到源代码之前,您应该运行 PHP_CodeSniffer: $ phpcs --standard=zend src
。所有错误和警告应在提交 pull request 之前清理。
添加测试用例
我们努力保持代码覆盖率高,CRAP 指数低。在提交 pull request 之前,运行 PHPUnit 测试套件并确保所有测试通过。如果您添加功能或修复错误,请包括测试用例以涵盖您提交的代码。