Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Apr 28, 2016
1 parent 626c895 commit eff2ba1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 55 deletions.
1 change: 0 additions & 1 deletion doc/concept.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Concept
concept/import_data
concept/object_graph
concept/schema
concept/table
concept/authentication
concept/value_object
concept/date_time
2 changes: 1 addition & 1 deletion doc/design/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Usage
use PSX\Framework\Controller\ControllerAbstract;
class Controller extends ControllerAbstract;
class Controller extends ControllerAbstract
{
/**
* @Inject
Expand Down
4 changes: 2 additions & 2 deletions doc/design/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ The routing file was inspired by the java play framework.
Routing file
------------

PSX parses the routing file and the route which matches first is taken. Lets see
the following example routing file
PSX parses the routing file and the route which matches first is taken. Lets
take a look at the following example routing file

.. code-block:: none
Expand Down
2 changes: 1 addition & 1 deletion doc/getting_started/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace. I.e. the following command would create the file `src/Acme/Foo.php`
`generate:table`
^^^^^^^^^^^^^^^^

Generates a table class based on an actual table. The sql_ credentials must be
Generates a table class based on an actual table. The `sql_` credentials must be
provided in the `configuration.php` to use this command

.. code::
Expand Down
115 changes: 68 additions & 47 deletions doc/getting_started/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,90 +21,111 @@ annotations.
namespace PSX\Project;
use PSX\Framework\Controller\AnnotationApiAbstract;
use PSX\Framework\Controller\SchemaApiAbstract;
use PSX\Record\RecordInterface;
/**
* @Title("Endpoint")
* @PathParam(name="foo_id", type="integer")
*/
class Endpoint extends AnnotationApiAbstract
class Endpoint extends SchemaApiAbstract
{
/**
* @QueryParam(name="count", description="Count of comments")
* @Outgoing(code=200, schema="schema/song.json")
* @Outgoing(code=200, schema="PSX\Project\Model\Song")
*/
protected function doGet()
{
$count = $this->queryParameters->getProperty('count');
// @TODO return the result i.e. from a database
return [
'title' => 'Wut ueber den verlorenen groschen',
'artist' => 'Beethoven',
];
return new Song('Wut ueber den verlorenen groschen', 'Beethoven');
}
/**
* @Incoming(schema="schema/song.json")
* @Outgoing(code=201, schema="schema/message.json")
* @Incoming(schema="PSX\Project\Model\Song")
* @Outgoing(code=201, schema="PSX\Project\Model\Message")
*/
protected function doPost(RecordInterface $record)
{
// @TODO work with the record
return [
'success' => true,
'message' => 'Successful created',
];
return new Message(true, 'Successful created');
}
}
The file `schema/song.json` contains the json schema of the data and could look
like:
The schema must be either a simple POPO class which contains annotations to
describe the schema or a json schema file. The model class
`PSX\Project\Model\Song` could look like:

.. code-block:: json
.. code-block:: php
class Song
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "song",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"artist": {
"type": "string"
/**
* @Type("string")
*/
protected $title;
/**
* @Type("string")
*/
protected $artist;
public function __construct($title = null, $artist = null)
{
$this->title = $title;
$this->artist = $artist;
}
public function getTitle()
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
}
public function getArtist()
{
return $this->artist;
}
public function setArtist($artist)
{
$this->artist = $artist;
}
}
}
The following annotations are available:

+--------------+--------------+------------------------------------------------+
| Annotation | Target | Example |
+==============+==============+================================================+
| @Description | Class/Method | @Description("Bar") |
+--------------+--------------+------------------------------------------------+
| @Exclude | Method | @Exclude |
+--------------+--------------+------------------------------------------------+
| @Incoming | Method | @Incoming(schema="schema/song.json") |
+--------------+--------------+------------------------------------------------+
| @Outgoing | Method | @Outgoing(code=200, schema="schema/song.json") |
+--------------+--------------+------------------------------------------------+
| @PathParam | Class | @PathParam(name="foo", type="integer") |
+--------------+--------------+------------------------------------------------+
| @QueryParam | Method | @QueryParam(name="bar", type="integer") |
+--------------+--------------+------------------------------------------------+
| @Title | Class/Method | @Title("Foo") |
+--------------+--------------+------------------------------------------------+
More informations at the :ref:`schema concept <concept/schema>`. The following
annotations are available for the controller:

+--------------+--------------+------------------------------------------------------+
| Annotation | Target | Example |
+==============+==============+======================================================+
| @Description | Class/Method | @Description("Bar") |
+--------------+--------------+------------------------------------------------------+
| @Exclude | Method | @Exclude |
+--------------+--------------+------------------------------------------------------+
| @Incoming | Method | @Incoming(schema="PSX\Project\Model\Song") |
+--------------+--------------+------------------------------------------------------+
| @Outgoing | Method | @Outgoing(code=200, schema="PSX\Project\Model\Song") |
+--------------+--------------+------------------------------------------------------+
| @PathParam | Class | @PathParam(name="foo", type="integer") |
+--------------+--------------+------------------------------------------------------+
| @QueryParam | Method | @QueryParam(name="bar", type="integer") |
+--------------+--------------+------------------------------------------------------+
| @Title | Class/Method | @Title("Foo") |
+--------------+--------------+------------------------------------------------------+

RAML
----

It is possible to use an existing RAML (http://raml.org/) specification to build
the API endpoint. In the following a sample API with the fitting RAML
Instead of annotations it is also possible to provide a schema file which
describes the endpoint. At the moment we support the RAML (http://raml.org/)
specification.

.. code-block:: php
Expand Down
6 changes: 3 additions & 3 deletions doc/getting_started/service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Service
=======

In the previous chapter we have defined a controller which received the request
and produces the response. This chapter describes where we can define the logic
of our API endpoint.
In the previous chapter we have defined a controller which receives the request
and produces the response. This chapter describes where we can define the
business logic of our API endpoint.

Definition
----------
Expand Down

0 comments on commit eff2ba1

Please sign in to comment.