-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Symfony bundle and some basic infrastructure. This is where version0 should have been. Few things to point out here. Firstly, the lightweight controllers. They do little more than take the request, set up the command and pass it off to the handler. When I first started this, I had seen a few tech talks and was all about decouple from the framework, controllers as services etc. I agree massively with decouple from the framework with regards the domain and even the ports layer (commands/handlers) but I've come a little bit full circle in the controllers as services and using DI to completely decouple your controllers. I know think, it doesn't really matter. So long as your controllers are really light, it doesn't really matter if they're coupled to shit, because essentially they don't matter. They are merely passing messages from framework to domain. The second point to note is that you can see from the images and twig templates how advaned my UI is :).
- Loading branch information
Showing
22 changed files
with
197 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace Jenko\House\Command; | ||
|
||
final class ExitRoom | ||
final class EnterRoomCommand | ||
{ | ||
public $room; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace Jenko\House\Command; | ||
|
||
final class EnterRoom | ||
final class ExitRoomCommand | ||
{ | ||
public $room; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Jenko\HouseBundle\Controller; | ||
|
||
use Jenko\House\Command\EnterRoomCommand; | ||
use Jenko\House\Handler\EnterRoomHandler; | ||
use Jenko\House\House; | ||
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class EnterRoomController | ||
{ | ||
/** | ||
* @var EngineInterface | ||
*/ | ||
private $templating; | ||
|
||
/** | ||
* @param EngineInterface $templating | ||
*/ | ||
public function __construct(EngineInterface $templating) | ||
{ | ||
$this->templating = $templating; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function enterAction(Request $request) | ||
{ | ||
$command = new EnterRoomCommand(); | ||
$command->room = $request->get('location'); | ||
|
||
$handler = new EnterRoomHandler(); | ||
/** @var House $house */ | ||
$house = $handler->handle($command); | ||
|
||
return $this->templating->renderResponse( | ||
'JenkoHouseBundle::room.html.twig', | ||
['currentRoom' => $house->whereAmI(), 'previousRoom' => $house->whereWasI()] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Jenko\HouseBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; | ||
|
||
class OutsideController | ||
{ | ||
/** | ||
* @var EngineInterface | ||
*/ | ||
private $templating; | ||
|
||
public function __construct(EngineInterface $templating) | ||
{ | ||
$this->templating = $templating; | ||
} | ||
|
||
public function outsideAction() | ||
{ | ||
return $this->templating->renderResponse('JenkoHouseBundle::outside.html.twig'); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Jenko/HouseBundle/DependencyInjection/JenkoHouseExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Jenko\HouseBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
|
||
class JenkoHouseExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.yml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Jenko\HouseBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class JenkoHouseBundle extends Bundle | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
jenko_house_outside: | ||
path: / | ||
defaults: { _controller: jenko.house.controllers.outside:outsideAction } | ||
requirements: | ||
_method: GET | ||
|
||
jenko_house_enter_room: | ||
path: /location/{location} | ||
defaults: { _controller: jenko.house.controllers.enter_room:enterAction } | ||
requirements: | ||
_method: GET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
parameters: | ||
jenko.house.controllers.outside.class: Jenko\HouseBundle\Controller\OutsideController | ||
jenko.house.controllers.enter_room.class: Jenko\HouseBundle\Controller\EnterRoomController | ||
|
||
services: | ||
jenko.house.controllers.outside: | ||
class: %jenko.house.controllers.outside.class% | ||
arguments: | ||
- @templating | ||
|
||
jenko.house.controllers.enter_room: | ||
class: %jenko.house.controllers.enter_room.class% | ||
arguments: | ||
- @templating |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<img src="{{ asset('bundles/jenkohouse/img/front-garden.jpg') }}" /> | ||
|
||
<p><a href="{{ path('jenko_house_enter_room', {location: 'hallway'}) }}">Enter front door</a></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<img src="{{ asset('bundles/jenkohouse/img/' ~ currentRoom.name ~ '.jpg') }}" /> | ||
|
||
<p>Room size: {{ currentRoom.dimensions }}</p> | ||
|
||
{% for room in currentRoom.exits %} | ||
<p><a href="{{ path('jenko_house_enter_room', {location: room.name}) }}">Go to {{ room.name }}</a></p> | ||
{% endfor %} | ||
|
||
{% if previousRoom is not null %} | ||
<p><a href="{{ path('jenko_house_enter_room', {location: previousRoom.name}) }}">Go back to {{ previousRoom.name }}</a></p> | ||
{% else %} | ||
<p><a href="{{ path('jenko_house_outside') }}">Go outside</a></p> | ||
{% endif %} |