Skip to content

Commit

Permalink
Add an embeded view
Browse files Browse the repository at this point in the history
Add another service
  • Loading branch information
sroze committed Feb 7, 2016
1 parent dba2928 commit e1edd76
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app/Resources/views/default/embedded.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'layout.html.twig' %}

{% block contents %}
<div id="welcome">
<h1><span>Embeded version</span> {{ service }} @ {{ page }}</h1>
</div>

<pre style="border: 1px solid #333;">{{ contents }}</pre>

<div id="next">
<h2>What's next?</h2>
<p>
<a href="{{ path('home') }}">Back to home</a>
</p>
</div>
{% endblock %}
4 changes: 4 additions & 0 deletions app/Resources/views/default/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<strong>Call an API</strong>
<a href="{{ path('last_release') }}">Get the last Tolerance release</a>
</li>
<li>
<strong>Embedded page</strong>
<a href="{{ path('embedded', {'service': 'service2', 'page': 'last-release'}) }}">Displayed page <code>/last-release</code> of service <code>service2</code></a>
</li>
</ul>
</div>
{% endblock %}
3 changes: 2 additions & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ swiftmailer:

# CSA Guzzle Configuration
csa_guzzle:
profiler: %kernel.debug%
clients:
github_api:
config:
base_uri: https://api.github.com
timeout: 2.0
headers:
Accept: application/vnd.github.v3+json
internal: ~

# Tolerance configuration
tolerance:
message_profile:
current_peer:
service: ExampleSymfony
environment: %kernel.environment%

storage:
Expand Down
5 changes: 5 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ services:
app.neo4j.client:
class: Neoxygen\NeoClient\Client
factory: ["@app.neo4j.client_builder", build]

app.tolerance.current_peer_enhancer:
class: App\Tolerance\CurrentPeerEnhancer
decorates: tolerance.message_profile.peer.resolver.current
arguments: ["@app.tolerance.current_peer_enhancer.inner"]
18 changes: 16 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
app:
service1:
build: .
volumes:
- .:/app
links:
- neo4j
- service2
expose:
- 80
environment:
TOLERANCE_SERVICE_NAME: "First Service"

service2:
build: .
volumes:
- .:/app
links:
- neo4j
expose:
- 80
environment:
TOLERANCE_SERVICE_NAME: "Second Service"

neo4j:
image: neo4j

35 changes: 35 additions & 0 deletions src/App/Tolerance/CurrentPeerEnhancer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Tolerance;

use Tolerance\MessageProfile\Peer\ArbitraryPeer;
use Tolerance\MessageProfile\Peer\Resolver\PeerResolver;

final class CurrentPeerEnhancer implements PeerResolver
{
/**
* @var PeerResolver
*/
private $decoratedPeerResolver;

/**
* @param PeerResolver $decoratedPeerResolver
*/
public function __construct(PeerResolver $decoratedPeerResolver)
{
$this->decoratedPeerResolver = $decoratedPeerResolver;
}

/**
* {@inheritdoc}
*/
public function resolve()
{
$peer = $this->decoratedPeerResolver->resolve();

return ArbitraryPeer::fromArray(array_merge($peer->getArray(), [
'service' => getenv('TOLERANCE_SERVICE_NAME'),
'container' => getenv('HOSTNAME'),
]));
}
}
26 changes: 26 additions & 0 deletions src/AppBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AppBundle\Controller;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
Expand Down Expand Up @@ -32,4 +33,29 @@ public function releaseAction()
'release' => $release,
]);
}

/**
* @Route("/embedded/{service}/{page}", name="embedded")
*/
public function embeddedAction($service, $page)
{
$url = sprintf('http://%s/app_dev.php/%s', $service, $page);
$response = $this->getClient('internal')->get($url);

return $this->render('default/embedded.html.twig', [
'service' => $service,
'page' => $page,
'contents' => $response->getBody()->getContents(),
]);
}

/**
* @param string $name
*
* @return Client
*/
private function getClient($name)
{
return $this->get('csa_guzzle.client.'.$name);
}
}

0 comments on commit e1edd76

Please sign in to comment.