Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 8 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
12 README.md
@@ -334,7 +334,7 @@ RESTful CRUD works:
class BlogResourceHandler extends ResourceHandler
{
public function create() {
- print_r( $_POST );
+ $this->codeCreated();
return array( 'id' => 1 );
}
@@ -364,6 +364,16 @@ RESTful CRUD works:
}
```
+For the status code, see the list below:
+
+- codeOk (200)
+- codeCreated (201)
+- codeAccepted (202)
+- codeNoContent (204)
+- codeBadRequest (400)
+- codeForbidden (403)
+- codeNotFound (404)
+
Before you dispatch URLs, router object calls the `expand` method of `ResourceHandler` class, which
generates RESTful routes into the routeset of router object. And below is the generated URLs:
View
2 package.ini
@@ -1,6 +1,6 @@
[package]
name = Roller
-version = 1.5.1
+version = 1.6.0
desc = A flexible, high-performance PHP router for PHP5.3+
channel = pear.corneltek.com
author = Yo-An Lin <cornelius.howl@gmail.com>
View
16 package.xml
@@ -11,10 +11,10 @@
<active>yes</active>
</lead>
<date>2012-04-09</date>
- <time>03:56:47</time>
+ <time>17:12:28</time>
<version>
- <release>1.5.0</release>
- <api>1.5.0</api>
+ <release>1.6.0</release>
+ <api>1.6.0</api>
</version>
<stability>
<release>stable</release>
@@ -26,7 +26,7 @@
<dir name="/">
<file name="tests/bootstrap.php" role="test" md5sum="b805c1c4ad52d54cb97ceef8f42e13bb"/>
<file name="tests/ExtensionTest.php" role="test" md5sum="77cb51f42fe7d97a6304b9c0d677f351"/>
- <file name="tests/RESTfulTest.php" role="test" md5sum="48a301816befeab51b964db3baa7d273"/>
+ <file name="tests/RESTfulTest.php" role="test" md5sum="e1490e7abc06a64d0bfcbb5a33a15cab"/>
<file name="tests/Roller/Annotation/ClassReaderTest.php" role="test" md5sum="8d67c46483bc048bd8a5530b9f1b2d57"/>
<file name="tests/Roller/Dumper/ConsoleDumperTest.php" role="test" md5sum="2beda835f820ac3e82414eac7f86c369"/>
<file name="tests/Roller/RouteCompilerTest.php" role="test" md5sum="dd428eddb11f4f48f01702162b6f090d"/>
@@ -41,16 +41,16 @@
<file name="src/Roller/Exception/RouteException.php" role="php" md5sum="c2821b1a76753aea22e11c5e7b310873"/>
<file name="src/Roller/Exception/RouterException.php" role="php" md5sum="47f7624f9454e42c11b5e1f9afe54365"/>
<file name="src/Roller/MatchedRoute.php" role="php" md5sum="d3c3840c31046b911f4320377be3a936"/>
- <file name="src/Roller/Plugin/RESTful/BaseHandler.php" role="php" md5sum="057e6e6f972276796ad4aa2b980eab78"/>
- <file name="src/Roller/Plugin/RESTful/GenericHandler.php" role="php" md5sum="32710a4e839b278f0456b18c8d16e476"/>
- <file name="src/Roller/Plugin/RESTful/ResourceHandler.php" role="php" md5sum="e2c70bbfc3c26c20e31db6dbb5c63233"/>
+ <file name="src/Roller/Plugin/RESTful/BaseHandler.php" role="php" md5sum="61db9bc57a7580a5132fb2e8ad7fc3e8"/>
+ <file name="src/Roller/Plugin/RESTful/GenericHandler.php" role="php" md5sum="22269db2f6b93540d81f9d914903a6fa"/>
+ <file name="src/Roller/Plugin/RESTful/ResourceHandler.php" role="php" md5sum="3dd34d46c4c2fabdee0ac57e33366a9c"/>
<file name="src/Roller/Plugin/RESTful.php" role="php" md5sum="b14e7a518138d50597d841841c9a09e5"/>
<file name="src/Roller/PluginInterface.php" role="php" md5sum="e18eacc88ca940293cb510bcd6806eb6"/>
<file name="src/Roller/RouteCompiler.php" role="php" md5sum="e26fbc57f35653649136631b4531a77f"/>
<file name="src/Roller/Router.php" role="php" md5sum="626c59364eeeb8f949ad6940ffcce82c"/>
<file name="src/Roller/RouteSet.php" role="php" md5sum="35e38c66a9c1422df3fab66295d9d006"/>
<file name="CHANGES.md" role="doc" md5sum="fccbafddd6c60e2e1726129e514e3c84"/>
- <file name="README.md" role="doc" md5sum="05626f242692f8973ec7d01748280476"/>
+ <file name="README.md" role="doc" md5sum="a3ffa40153b94aa95bf7c5db9b5a66c5"/>
<file name="notes.md" role="doc" md5sum="d41d8cd98f00b204e9800998ecf8427e"/>
</dir>
</contents>
View
42 src/Roller/Plugin/RESTful/BaseHandler.php
@@ -11,27 +11,51 @@
/**
* HTTP Status Code:
*
- * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
- * http://restpatterns.org/HTTP_Status_Codes
+ * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
+ * @link http://restpatterns.org/HTTP_Status_Codes
+ *
+ * REST Pattern
+ * @link http://restpatterns.org/
*/
- public function codeCreated($message = 'Created')
+
+ public function codeOk()
+ {
+ header("HTTP/1.1 200 OK");
+ }
+
+ public function codeCreated()
+ {
+ header('HTTP/1.1 201 Created');
+ }
+
+ public function codeAccepted()
+ {
+ header('HTTP/1.1 202 Accepted');
+ }
+
+ public function codeNoContent()
+ {
+ header('HTTP/1.1 204 No Content');
+ }
+
+ public function codeBadRequest()
{
- header("HTTP/1.1 201 $message");
+ header('HTTP/1.1 400 Bad Request');
}
- public function codeOk($message = 'OK')
+ public function codeForbidden()
{
- header("HTTP/1.1 200 $message");
+ header('HTTP/1.1 403 Forbidden');
}
- public function codeBadRequest($message = 'Bad Request')
+ public function codeNotFound()
{
- header("HTTP/1.1 400 $message");
+ header('HTTP/1.1 404 Not Found');
}
public function returnError($format,$message = null)
{
- $this->codeBadRequest($message);
+ $this->codeBadRequest();
return $this->renderFormat(array(
'success' => false,
'errors' => $message,
View
12 src/Roller/Plugin/RESTful/GenericHandler.php
@@ -15,31 +15,31 @@
public function handleFind($resource,$format)
{
$this->data = $this->find($resource);
- return $this->returnSuccess($format, "Record find success.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleCreate($resource,$format)
{
$this->data = $this->create($resource);
- return $this->returnSuccess($format, "Record $id created.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleUpdate($resource,$id,$format)
{
$this->data = $this->update($resource,$id);
- return $this->returnSuccess($format, "Record $id updated.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleLoad($resource,$id,$format)
{
$this->data = $this->load($resource,$id);
- return $this->returnSuccess($format, "Record $id loaded.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleDelete($resource,$id,$format)
{
- $this->data = $this->load($resource,$id);
- return $this->returnSuccess($format, "Record $id deleted.");
+ $this->data = $this->delete($resource,$id);
+ return $this->renderFormat($this->data ,$format );
}
public function expand($routes, $h)
View
12 src/Roller/Plugin/RESTful/ResourceHandler.php
@@ -81,31 +81,31 @@ public function expand($routes, $h, $r)
public function handleFind($format)
{
$this->data = $this->find();
- return $this->returnSuccess($format, "Record find success.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleCreate($format)
{
$this->data = $this->create();
- return $this->returnSuccess($format, "Record $id created.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleUpdate($id,$format)
{
$this->data = $this->update($id);
- return $this->returnSuccess($format, "Record $id updated.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleLoad($id,$format)
{
$this->data = $this->load($id);
- return $this->returnSuccess($format, "Record $id loaded.");
+ return $this->renderFormat($this->data ,$format );
}
public function handleDelete($id,$format)
{
- $this->data = $this->load($id);
- return $this->returnSuccess($format, "Record $id deleted.");
+ $this->data = $this->delete($id);
+ return $this->renderFormat($this->data ,$format );
}
View
8 tests/RESTfulTest.php
@@ -70,11 +70,11 @@ function testGenericHandler()
$_SERVER['REQUEST_METHOD'] = 'GET';
$r = $router->dispatch( '/restful/blog' );
- is( '{"success":true,"data":[1,2,3,4,5,6,7,8,9,10],"message":"Record find success."}' , $r() );
+ is( '[1,2,3,4,5,6,7,8,9,10]' , $r() );
$_SERVER['REQUEST_METHOD'] = 'GET';
$r = $router->dispatch( '/restful/blog/3' );
- is( '{"success":true,"data":{"id":"3"},"message":"Record 3 loaded."}' , $r() );
+ is( '{"id":"3"}' , $r() );
}
@@ -93,11 +93,11 @@ function test()
$_SERVER['REQUEST_METHOD'] = 'GET';
$r = $router->dispatch('/restful/blog/1');
- is( '{"success":true,"data":{"id":"1","title":"title"},"message":"Record 1 loaded."}' , $r() );
+ is( '{"id":"1","title":"title"}' , $r() );
$_SRVER['REQUEST_METHOD'] = 'GET';
$r = $router->dispatch('/restful/blog');
- is( '{"success":true,"data":[{"id":0},{"id":1},{"id":2}],"message":"Record find success."}' , $r() );
+ is( '[{"id":0},{"id":1},{"id":2}]' , $r() );
$_SRVER['REQUEST_METHOD'] = 'PUT';
$r = $router->dispatch('/restful/blog/1');

No commit comments for this range

Something went wrong with that request. Please try again.