Skip to content

Commit

Permalink
Merge pull request #9 from gdubost/feature/21960
Browse files Browse the repository at this point in the history
[FEATURE#21960] Gestion multi messages
  • Loading branch information
gdubost committed Nov 4, 2015
2 parents 316b5ce + 7f418e2 commit ba865db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
60 changes: 25 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# composer-conversation-proxy-provider
Permets aux differentes applications d'avoir un proxy vers conversation-api

Installation
------------
## Installation

Modifier `composer.json` :

```
{
// ...
"require": {
"etna/conversation-proxy-provider": "~0.1"
"etna/conversation-proxy-provider": "~1.0.x"
},
"repositories": [
{
Expand All @@ -21,52 +20,41 @@ Modifier `composer.json` :
}
```

Utilisation
-----------
## Utilisation

Il faut tout d'abord creer une classe pour la configuration de ce provider :
```
class ConversationConfig implements ServiceProviderInterface
{
private $application_env;
### Déclarer le composant

public function __construct($application_env = null)
{
if (null === $application_env) {
throw new \Exception("Application env is not set");
}
$this->application_env = $application_env;
}
Le composant `etna/config-provider` met à disposition une classe permettant de faire utiliser ce proxy a notre application.

public function boot(Application $app)
{
return $app;
}
Lors de la configuration de l'application il faut donc utiliser la classe `ETNA\Silex\Provider\Config\ConversationProxy` :

```
use ETNA\Silex\Provider\Config as ETNAConf;
class EtnaConfig implements ServiceProviderInterface
{
public function register(Application $app)
{
switch ($this->application_env) {
case "production":
putenv("CONVERSATION_API_URL=https://conversation-api.etna-alternance.net");
break;
case "development":
putenv("CONVERSATION_API_URL=http://conversation-api.etna.dev");
break;
}
//Dans le cas ou l'on souhaite fournir son propre controlleur
$controller = new ConversationController();
$app->register(new ConversationProxyProvider($controller));
//Sinon
$app->register(new ConversationProxyProvider());
...
//L'utilisation du controlleur custom est expliquée plus bas
$my_controller = new ConversationController();
$app->register(new ETNAConf\ConversationProxy($my_controller));
...
}
}
```

### Le contenu de ce composant

##### Le controlleur custom

Ce provider met a disposition un `DumbMethodsProxy` qui fournit toutes les routes basiques de conversations :
- Likes
- Message
- Views
- Recherche

Il est possible de creer un controlleur qui hérite de ce `DumbMethodsProxy` pour rajouter des routes custom :
```
Expand Down Expand Up @@ -103,6 +91,8 @@ class ConversationController extends DumbMethodsProxy
}
```

##### Les plus de ce proxy

Ce provider met a disposition :
- L'objet Conversation, qui est une "entité" qui se comporte comme une entité doctrine le ferait
- On peut la remplir avec un array grace a `$conversation->fromArray($array)`
Expand Down
10 changes: 3 additions & 7 deletions src/ConversationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ public function save(Conversation $conversation)
return $this->app->abort(400, "Need content to create conversation");
}

$body["content"] = $body["messages"][0]["content"];
$body["type"] = $body["messages"][0]["type"];
$body["metas"] = json_encode($body["metas"]);
unset($body["messages"]);

$request = $this->app["conversation_proxy"]->post("/conversations", [], $body);
$response = $this->fireRequest($request, $this->app["cookies.authenticator"]);
$body["metas"] = json_encode($body["metas"]);
$request = $this->app["conversation_proxy"]->post("/conversations", [], $body);
$response = $this->fireRequest($request, $this->app["cookies.authenticator"]);
} else {
foreach ($actions as $action) {
$route = $action["route"];
Expand Down

0 comments on commit ba865db

Please sign in to comment.