私は六角形のアーキテクチャについて多くのことを読んできましたが、ほとんどの概念を理解しています (そうであることを願っています) 。そのアーキテクチャのユースケースの例は見つかりませんでした。
私のアプリケーション ドメイン モデルが人々を酔わせることだとしましょう。ビジネスロジック全体Person
は、ドメイン層にあるクラスに含まれています。
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';
}
}
ドメイン層にはPersonRepository
interface PersonRepository
{
public function findPersonByName($name);
}
実装者:
class DoctrinePersonRepository implements PersonRepository
{
public function findPersonByName($name)
{
// actual retrieving
}
}
アクセスして人を酔わせたいとしましょう: GET /person/johnDoe/drink
。次のようなユース ケースを作成する必要があります。
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();
}
}
コントローラーから呼び出しますか?この言及されたケースは、ドメイン層またはアプリケーション層に存在する必要がありますか? この場合のポートとアダプターは何ですか? この人を酔わせる方法が必要な場合はどうすればよいですか? 1 つは GET 要求から、もう 1 つはphp console person:drink John
CLI コマンドからですか? アプリをどのように構成すればよいですか?