내 질문은 @tereško's의 업데이트 섹션과 관련이 있습니다. "Who should handle the conditions in complex queries, the data mapper or the service layer?"아래는 참조 및 편의를위한 코드입니다. 이 코드 ArticleCollection
에서 데이터 매퍼가 컬렉션 패턴의 항목을 처리하는 중
$category = new Category;
$category->setTitle('privacy');
$list = new ArticleCollection;
$list->setCondition($category);
$list->setDateRange(mktime(0, 0, 0, 12, 9, 2001));
// it would make sense, if unset second value for range of dates
// would default to NOW() in mapper
$mapper = new ArticleCollectionMapper;
$mapper->fetch($list);
foreach ($list as $article)
{
$article->setFlag(Article::STATUS_REMOVED);
}
$mapper->store($list);
가 도메인 개체의 모음입니다,의는
Article
의 그들에게 전화 할 수 있습니다.
ArticleCollectionMapper
이 데이터베이스의 데이터를 가져 와서
$list
에 할당하는 순간에 각 행에 대해
Article
의 인스턴스를 만들어야합니다. 공장 인스턴스 객체
ArticleFactory
과 같이
Article
의 인스턴스를
$list->addArticle($newArticle)
과 같은 메소드를 통해 컬렉션 인스턴스 (
$list
)에 추가 할 예정입니까, 아니면 내가 고려하지 않은 다른 옵션이 있습니까?
안녕하세요, 제레미, 답변 해 주셔서 감사합니다. 사실 나는 비슷한 솔루션을 사용했다. 오히려 당신이 보여준 addArticle을 사용하여 ArticleCollection에 newArticle과 addArticle 메서드가 있습니다. 첫 번째 것은 datama가 자신의 메서드로 채운 article 객체를 반환합니다. addArticle 메서드는 주어진 기사 개체를 목록에 추가하기 만합니다. 그래서 당신은 맞습니다. 공장을 필요로하지 않습니다. –