Skip to content
This repository has been archived by the owner on Aug 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #4 from Bigpoint/fix_ressource
Browse files Browse the repository at this point in the history
fix more occurances of 'ressource'
  • Loading branch information
Karsten Bruckmann committed Jan 27, 2015
2 parents 243b167 + a65fa49 commit 1ef36bd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In order to create a rest api based on this framework you need a structure simil
│ └── V1
│ ├── Collection
│ │ └── EndpointA.php
│ └── Ressource
│ └── Resource
│ └── EndpointA.php
└── www
└── index.php
Expand Down Expand Up @@ -109,15 +109,17 @@ $bootstrap = new \SlimBootstrap\Bootstrap(
$applicationConfig
);
$bootstrap->init();
$bootstrap->addRessourceGetEndpoint(
$bootstrap->addResourceEndpoint(
\SlimBootstrap\Bootstrap::HTTP_METHOD_GET,
'/dummy/:name',
'dummy',
array(
'name' => '\w+',
),
new \DummyApi\Endpoint\Ressource\Dummy()
new \DummyApi\Endpoint\Resource\Dummy()
);
$bootstrap->addCollectionGetEndpoint(
$bootstrap->addCollectionEndpoint(
\SlimBootstrap\Bootstrap::HTTP_METHOD_GET,
'/dummy',
'dummy',
new \DummyApi\Endpoint\Collection\Dummy()
Expand All @@ -127,15 +129,15 @@ $bootstrap->run();

## Create Endpoints
### Collection Endpoint
The framework supports two types of endpoints. Collection endpoints, to return multiple results and ressource endpoints to return / handle a special result.
The framework supports two types of endpoints. Collection endpoints, to return multiple results and resource endpoints to return / handle a special result.

**Collection endpoints**

These endpoints should implement one of the _CollectionEndpoint_ interfaces located under [\SlimBootstrap\Endpoint](src/SlimBootstrap/Endpoint). It will then get an array of filter parameters which can be passed as GET parameters and if it is not a GET endpoint an array of data which will be the payload send with the request. The endpoint should return an array of [\SlimBootstrap\DataObject](src/SlimBootstrap/DataObject.php) where each DataObject holds one result.

**Ressource endpoints**
**Resource endpoints**

These endpoints should implement one of the _RessourceEndpoint_ interfaces located under [\SlimBootstrap\Endpoint](src/SlimBootstrap/Endpoint). It will then get an array of the parameters in the URL the ressource is identified with and if it is not a GET endpoint an array of data which will be the payload send with the request. The endpoint should return a [\SlimBootstrap\DataObject](src/SlimBootstrap/DataObject.php) and it should throw a [\SlimBootstrap\Exception](src/SlimBootstrap/Exception.php) if the endpoint encounters an error. The message of that exception will be printed out as result and the code will be used as HTTP status code.
These endpoints should implement one of the _RessurceEndpoint_ interfaces located under [\SlimBootstrap\Endpoint](src/SlimBootstrap/Endpoint). It will then get an array of the parameters in the URL the resource is identified with and if it is not a GET endpoint an array of data which will be the payload send with the request. The endpoint should return a [\SlimBootstrap\DataObject](src/SlimBootstrap/DataObject.php) and it should throw a [\SlimBootstrap\Exception](src/SlimBootstrap/Exception.php) if the endpoint encounters an error. The message of that exception will be printed out as result and the code will be used as HTTP status code.

### Supported HTTP methods
At the moment the framework supports the following HTTP methods:
Expand All @@ -144,18 +146,18 @@ At the moment the framework supports the following HTTP methods:
- POST
- PUT

For each of these methods the framework supplies two interfaces for the Collection and Ressource endpoint under [\SlimBootstrap\Endpoint](src/SlimBootstrap/Endpoint).
For each of these methods the framework supplies two interfaces for the Collection and Resource endpoint under [\SlimBootstrap\Endpoint](src/SlimBootstrap/Endpoint).

### Registering endpoints to the framework
The written endpoints have to be registered to the framework and the underling Slim instance in order to be accessible. This can be done by calling the appropriate add methods on the [\SlimBootstrap\Bootstrap](src/SlimBootstrap/Bootstrap.php) instance after the `init()` call and before the `run()` call. The framework is using the basic form of slim to [register a route](http://docs.slimframework.com/#Routing-Overview) and bind an endpoint to the route. In order to do this the methods need some specific parameters which are explained here for the GET endpoints but are very similar for the other endpoints:

**addCollectionGetEndpoint**
**addCollectionEndpoint**

This methods needs a `route` which is the relativ url it can be called as so for example "/myendpoint". As second argument it needs a `name` which will be used to identify the route and which can then be used in the ACL config to configure access to this route / endpoint. The third parameter is an instance of [SlimBootstrap\Endpoint\CollectionGet](src/SlimBootstrap/Endpoint/CollectionGet.php).
This methods needs a HTTP protocol for which this endpoint should be registered. This should be one of the `\SlimBootstrap\Bootstrap::HTTP_METHOD_*` constatnts. As second argument it needs a `route` which is the relativ url it can be called as so for example "/myendpoint". As third argument it needs a `name` which will be used to identify the route and which can then be used in the ACL config to configure access to this route / endpoint. The fourth parameter is an instance of [SlimBootstrap\Endpoint\Collection*](src/SlimBootstrap/Endpoint/).

**addRessourceGetEndpoint**
**addResourceEndpoint**

This methods needs a `route` which is the relativ url it can be called as so for example "/myendpoint/:someId". As second argument it needs a `name` which will be used to identify the route and which can then be used in the ACL config to configure access to this route / endpoint. The third parameter is an array of conditions that can define constrains for the passed id (`someId`). These constrains are normal PHP regular expressions. Finally the fourth parameter is an instance of [SlimBootstrap\Endpoint\RessourceGet](src/SlimBootstrap/Endpoint/RessourceGet.php).
This methods needs a HTTP protocol for which this endpoint should be registered. This should be one of the `\SlimBootstrap\Bootstrap::HTTP_METHOD_*` constatnts. As second argument it needs a `route` which is the relativ url it can be called as so for example "/myendpoint/:someId". As third argument it needs a `name` which will be used to identify the route and which can then be used in the ACL config to configure access to this route / endpoint. The fourth parameter is an array of conditions that can define constrains for the passed id (`someId`). These constrains are normal PHP regular expressions. Finally the fifth parameter is an instance of [SlimBootstrap\Endpoint\Resource*](src/SlimBootstrap/Endpoint/).

## Response Output

Expand Down Expand Up @@ -230,15 +232,17 @@ $bootstrap = new \SlimBootstrap\Bootstrap(
+ $aclConfig
);
$bootstrap->init();
$bootstrap->addRessourceGetEndpoint(
$bootstrap->addResourceEndpoint(
\SlimBootstrap\Bootstrap::HTTP_METHOD_GET,
'/dummy/:name',
'dummy',
array(
'name' => '\w+',
),
new \DummyApi\Endpoint\Ressource\Dummy()
new \DummyApi\Endpoint\Resource\Dummy()
);
$bootstrap->addCollectionGetEndpoint(
$bootstrap->addCollectionEndpoint(
\SlimBootstrap\Bootstrap::HTTP_METHOD_GET,
'/dummy',
'dummy',
new \DummyApi\Endpoint\Collection\Dummy()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
namespace ###NAMESPACE###\Endpoint\V1\Ressource;
namespace ###NAMESPACE###\Endpoint\V1\Resource;

use \###NAMESPACE###;
use \SlimBootstrap;

/**
* Class Dummy
*
* @package ###NAMESPACE###\Endpoint\V1\Ressource
* @package ###NAMESPACE###\Endpoint\V1\Resource
*/
class Dummy implements SlimBootstrap\Endpoint\RessourceGet
class Dummy implements SlimBootstrap\Endpoint\ResourceGet
{
/**
* This function is called on a GET request to get all data for this
Expand Down
4 changes: 2 additions & 2 deletions generator/skeleton/www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
$bootstrap->init();

// --- V1 Endpoints - begin ---
$bootstrap->addRessourceEndpoint(
$bootstrap->addResourceEndpoint(
\SlimBootstrap\Bootstrap::HTTP_METHOD_GET,
'/v1/dummy/:dummyId',
'dummy',
array(
'dummyId' => '\\d+',
),
new \###NAMESPACE###\Endpoint\V1\Ressource\Dummy()
new \###NAMESPACE###\Endpoint\V1\Resource\Dummy()
);
$bootstrap->addCollectionEndpoint(
\SlimBootstrap\Bootstrap::HTTP_METHOD_GET,
Expand Down
16 changes: 8 additions & 8 deletions src/SlimBootstrap/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

/**
* This class represents a result set for the endpoints.
* One instance represents a HAL+JSON ressource for one specific embedded
* ressource.
* One instance represents a HAL+JSON resource for one specific embedded
* resource.
*
* @package SlimBootstrap
*/
class DataObject
{
/**
* The identifiers to show in the HAL+JSON output how this ressource is
* The identifiers to show in the HAL+JSON output how this resource is
* identified.
*
* @var array
Expand All @@ -26,7 +26,7 @@ class DataObject
private $_data = array();

/**
* The links to show in the HAL+JSON output for this ressource.
* The links to show in the HAL+JSON output for this resource.
*
* @var array
*/
Expand All @@ -36,7 +36,7 @@ class DataObject
* @param array $identifiers The identifiers to show in the HAL+JSON output.
* @param array $data The actual data to pass to the output.
* @param array $links The links to show in the HAL+JSON output for
* this ressource.
* this resource.
*/
public function __construct(
array $identifiers,
Expand All @@ -49,7 +49,7 @@ public function __construct(
}

/**
* Returns the HAL+JSON identifiers for this ressource.
* Returns the HAL+JSON identifiers for this resource.
*
* @return array
*/
Expand All @@ -59,7 +59,7 @@ public function getIdentifiers()
}

/**
* Returns the actual payload of this ressource.
* Returns the actual payload of this resource.
*
* @return array
*/
Expand All @@ -69,7 +69,7 @@ public function getData()
}

/**
* Returns the links for this HAL+JSON ressource.
* Returns the links for this HAL+JSON resource.
*
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion src/SlimBootstrap/Endpoint/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(array $endpoints)
}

/**
* This function creates a ressource that has links to all existing
* This function creates a resource that has links to all existing
* endpoints.
*
* @return SlimBootstrap\DataObject
Expand Down

0 comments on commit 1ef36bd

Please sign in to comment.