I've been reading a lot a bout hexagonal architecture and I do get most of the concepts (well, I hope I do), I didn't find any example of that architecture use-case wise.
Let's say that my application domain model is to make people drunk. The whole business logic is contained in Person
class which resides in the domain layer.
class Person
{
private $name;
private $age;
function __construct($name, $age)
{
$this->age = $age;
$this->name = $name;
}
public function drink()
{
if ($this->age < 18) {
echo $this->name . ' cant drink';
}
echo $this->name . ' drinks tequila';
}
}
Domain layer also contains a PersonRepository
interface PersonRepository
{
public function findPersonByName($name);
}
implemented by:
class DoctrinePersonRepository implements PersonRepository
{
public function findPersonByName($name)
{
// actual retrieving
}
}
Let's assume I want to make a person drunk by accessing: GET /person/johnDoe/drink
.
Should I create a use case like:
class MakePersonDrinkCase
{
/**
* @var PersonRepository
*/
private $personRepository;
function __construct(PersonRepository $personRepository)
{
$this->personRepository = $personRepository;
}
function makePersonDrunk($name)
{
$person = $this->personRepository->findPersonByName($name);
if ($name) {
throw new \Exception('Person not found');
}
$person->drink();
}
}
and call it from the controller? Should this mentioned case reside in domain layer or application layer? What is a port and adapter in this case? What if I want to have to ways of getting this person drunk - one from GET request, and other from some php console person:drink John
CLI command? How should I structure my app?