Skip to content

Commit

Permalink
update manual
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Dec 28, 2015
1 parent 72ae1cb commit 56c3540
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 143 deletions.
4 changes: 2 additions & 2 deletions doc/concept/api_versioning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ In the following a short example howto add versioning to an schema API
{
}
protected function doCreate(RecordInterface $record, Version $version)
protected function doPost(RecordInterface $record, Version $version)
{
}
protected function doUpdate(RecordInterface $record, Version $version)
protected function doPut(RecordInterface $record, Version $version)
{
}
Expand Down
31 changes: 30 additions & 1 deletion doc/concept/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ you have to check
* is the token not expired

PSX calculates and compares the signature if you return an consumer. For more
informations see :rfc:`5849#anchor`
informations see :rfc:`5849`.

.. code-block:: php
Expand All @@ -75,3 +75,32 @@ informations see :rfc:`5849#anchor`
return array($auth);
}
Oauth2 authentication
--------------------

Sample oauth2 authentication. In the callback you have to check whether the
provided `Bearer` access token is valid. For more informations see :rfc:`6749`.

.. code-block:: php
<?php
use PSX\Dispatch\RequestFilter\Oauth2Authentication;
...
public function getPreFilter()
{
$auth = new Oauth2Authentication(function($accessToken) {
if ($accessToken == '[accessToken]') {
return true;
}
return false;
});
return array($auth);
}
6 changes: 3 additions & 3 deletions doc/concept/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Reading requests

If we want import data from a request we have to known the format of the
request body. PSX uses the content type header to determine which reader should
be used. I.e. if we have an application/xml content type we use the xml reader
and if we have an application/json content type we use the json reader. The
be used. I.e. if we have an `application/xml` content type we use the xml reader
and if we have an `application/json` content type we use the json reader. The
reader returns the request data in a form which can be easily used in php. I.e.
the xml reader returns a DOMDocument and the json reader returns a stdClass.

Expand All @@ -25,7 +25,7 @@ the xml reader returns a DOMDocument and the json reader returns a stdClass.

Since we need a uniform structure of the data we must apply a transformation in
some cases. The transformation depends also on the content type. If we receive
an application/xml content type the XmlArray transformer gets applied.
an `application/xml` content type the XmlArray transformer gets applied.

.. literalinclude:: ../../library/PSX/Data/TransformerInterface.php
:language: php
Expand Down
43 changes: 0 additions & 43 deletions doc/concept/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,46 +211,3 @@ Therefor we need to define the following schema classes.
With the schema you can define a much finer representation of your data model.
More informations about the schema concept at :doc:`schema`.

Entity
------

PSX has also an entity importer which get the meta informations from the
annotations of an entity. At the moment the entity importer will not lookup
any references means that only the available fields of the entity will be
imported. In the following an example howto use an entity.

.. code-block:: php
<?php
namespace Foo\Application;
use PSX\ControllerAbstract;
class Index extends ControllerAbstract
{
public function doIndex()
{
$entry = $this->import(new FooEntity());
// do something with the entry
}
}
Writing a custom importer
-------------------------

The meta informations how the request data looks can be obtained from different
sources. If you have already meta data in your project about your models you
could write your own importer. The importer has an accept method which checks
whether the source is valid to get passed to the import method. The import
method takes the response from the reader and creates an record based on the
meta data from the source.

.. literalinclude:: ../../library/PSX/Data/Record/ImporterInterface.php
:language: php
:lines: 31-52
:prepend: <?php

The importer must be added to the importer manager in the DI container. After
that you can use your own class in the import method inside the controller
46 changes: 45 additions & 1 deletion doc/concept/object_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object, array or scalar value. If the value is a PSX\\Data\\RecordInterface,
stdClass or associative array the value gets treated as object. If it is an
array the value gets treated as array. All other values have no structural
meaning and are treated as scalar values. If a scalar value is an object PSX
tries to case it to a string.
tries to cast it to a string.

Examples
--------
Expand Down Expand Up @@ -122,3 +122,47 @@ In the following some examples to show how PSX handles the object graph
"title": "foo"
}
}
.. code-block:: php
<?php
$this->setBody(array(
'foo' => new \ArrayIterator(['foo', 'bar'])
));
.. code-block:: json
{
"foo": [
"foo",
"bar"
]
}
.. code-block:: php
<?php
$generator = function(){
foreach (['foo', 'bar'] as $value) {
yield $value;
}
};
$this->setBody(array(
'foo' => $generator()
));
.. code-block:: json
{
"foo": [
"foo",
"bar"
]
}
2 changes: 1 addition & 1 deletion doc/concept/table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Abstract
--------

The PSX table class provides a simple repository pattern which can be used as
alternative to a ORM. It works with plain SQL queries. Each table class
alternative to an ORM. It works with plain SQL queries. Each table class
represents a SQL table which contains the table name and all available columns.
A table class returns record objects which are filled with the values from the
query. It is also the place where you can put all complex business queries. To
Expand Down
6 changes: 3 additions & 3 deletions doc/design/command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Usage
-----

This chapter gives a short overview of the most important methods which you need
inside an command. To simplify things take a look at the following source code.
inside a command. To simplify things take a look at the following source code.

.. code-block:: php
Expand All @@ -43,10 +43,10 @@ inside an command. To simplify things take a look at the following source code.
public function onExecute(Parameters $parameters, OutputInterface $output)
{
// returns whether an parameter is available
// returns whether a parameter is available
$parameters->has('bar')
// returns the value of an parameter or null
// returns the value of a parameter or null
$bar = $parameters->get('bar')
// inside the command you can use every injected service
Expand Down
8 changes: 4 additions & 4 deletions doc/design/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ Usage
// returns the request url as PSX\Uri
$this->getUrl();
// returns an request header
// returns a request header
$this->getHeader('Content-Type');
// returns an GET parameter
// returns a GET parameter
$this->getParameter('id');
// returns the request body. For x-www-form-urlencoded or json data
// this will be an stdClass for xml an DOMDocument
// this will be a stdClass for xml a DOMDocument
$body = $this->getBody();
// returns the value for the key "title". This works with
// x-www-form-urlencoded, json or xml data
$title = $this->getAccessor()->get('title');
// if you want assign an value to the template which is not exposed
// if you want assign a value to the template which is not exposed
// to the public you can assign it directly to the template
$this->template->assign('foo', 'bar');
Expand Down
59 changes: 38 additions & 21 deletions doc/getting_started/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ CLI
PSX provides several commands which help to develop and debug PSX applications.
In the following we will describe the available commands:

### debug
debug
-----

#### `debug:jsonschema`
`debug:jsonschema`
^^^^^^^^^^^^^^^^^^

Parses the json schema and prints informations about the parsed schema. Can be
used to debug json schemas.
Expand All @@ -16,7 +18,8 @@ used to debug json schemas.
$ vendor/bin/psx debug:jsonschema schema.json
#### `debug:raml`
`debug:raml`
^^^^^^^^^^^^

Parses the raml schema and prints informations about the parsed schema. Can be
used to debug raml schemas.
Expand All @@ -25,9 +28,11 @@ used to debug raml schemas.
$ vendor/bin/psx debug:raml schema.json
### generate
generate
--------

#### `generate:api`
`generate:api`
^^^^^^^^^^^^^^

Generates a new api controller in the source folder under the provided
namespace. I.e. the following command would create the file `src/Acme/Foo.php`
Expand All @@ -36,26 +41,29 @@ namespace. I.e. the following command would create the file `src/Acme/Foo.php`
$ vendor/bin/psx generate:api Acme\Foo connection,http
#### `generate:bootstrap_cache`
`generate:bootstrap_cache`
^^^^^^^^^^^^^^^^^^^^^^^^^^

Generates a bootstrap cache file in the cache folder. This file includes common
used classes which can be used to imrpove the performance of your application.
Note this is only needed if you are using PHP < 5.5
used classes which can be used to improve the performance of your application.
Note this is only needed if you are not using a byte code cache (PHP < 5.5)

.. code::
$ vendor/bin/psx generate:bootstrap_cache
#### `generate:command`
`generate:command`
^^^^^^^^^^^^^^^^^^

Generates a new command in the source folder under the provided
namespace. I.e. the following command would create the file `src/Acme/Foo.php`
Generates a new command in the source folder under the provided namespace. I.e.
the following command would create the file `src/Acme/Foo.php`

.. code::
$ vendor/bin/psx generate:command Acme\Foo connection,http
#### `generate:controller`
`generate:controller`
^^^^^^^^^^^^^^^^^^^^^

Generates a new controller in the source folder under the provided namespace.
I.e. the following command would create the file `src/Acme/Foo.php`
Expand All @@ -64,7 +72,8 @@ I.e. the following command would create the file `src/Acme/Foo.php`
$ vendor/bin/psx generate:controller Acme\Foo connection,http
#### `generate:schema`
`generate:schema`
^^^^^^^^^^^^^^^^^

Generates a new schema controller in the source folder under the provided
namespace. I.e. the following command would create the file `src/Acme/Foo.php`
Expand All @@ -73,7 +82,8 @@ namespace. I.e. the following command would create the file `src/Acme/Foo.php`
$ vendor/bin/psx generate:schema Acme\Foo connection,http
#### `generate:table`
`generate:table`
^^^^^^^^^^^^^^^^

Generates a table class based on an actual table. The sql_ credentials must be
provided in the `configuration.php` to use this command
Expand All @@ -83,7 +93,8 @@ provided in the `configuration.php` to use this command
$ vendor/bin/psx generate:table Acme\Foo table_name
#### `generate:view`
`generate:view`
^^^^^^^^^^^^^^^

Generates a new view controller in the source folder under the provided
namespace. I.e. the following command would create the file `src/Acme/Foo.php`
Expand All @@ -92,41 +103,47 @@ namespace. I.e. the following command would create the file `src/Acme/Foo.php`
$ vendor/bin/psx generate:view Acme\Foo connection,template
### schema
schema
------

#### `schema:jsonschema`
`schema:jsonschema`
^^^^^^^^^^^^^^^^^^^

Prints the json schema of a provided route

.. code::
$ vendor/bin/psx schema:jsonschema /foo
#### `schema:raml`
`schema:raml`
^^^^^^^^^^^^^

Prints the raml schema of a provided route

.. code::
$ vendor/bin/psx schema:raml /foo
#### `schema:swagger`
`schema:swagger`
^^^^^^^^^^^^^^^^

Prints the swagger schema of a provided route

.. code::
$ vendor/bin/psx schema:swagger /foo
#### `schema:wsdl`
`schema:wsdl`
^^^^^^^^^^^^^

Prints the wsdl schema of a provided route

.. code::
$ vendor/bin/psx schema:wsdl /foo
#### `schema:xsd`
`schema:xsd`
^^^^^^^^^^^^

Prints the xsd schema of a provided route

Expand Down
Loading

0 comments on commit 56c3540

Please sign in to comment.