OK, 이제 Doctrine2 ORM을 새로운 Zend2 프로젝트에서 사용하기로 결정 했으므로 모델 및 엔티티 클래스를 별도로 유지 관리하는 데 가장 좋은 설계 방법에 관한 질문이 있습니다. 나는 이 아니고, 엔티티와 모델의 차이점을 물어 보았습니다. 또한 Repository 클래스와 연결된 서비스 레이어를 정상적으로 작동하도록했습니다. 내가 묻는 것은, 비즈니스 클래스가있는 Model 클래스가 있고, Document 클래스를 말하고, 그런 다음 영속성을 나타내는 DocumentEntity를 분리 한 상태로 유지하려는 경우입니다. 예를 들어, 여기 엔 Entity가 있습니다.내 모델을 Doctrine2의 엔티티와 분리하는 것이 가장 좋은 방법은 무엇입니까?
class Document implements SomeImportantInterface, AnotherImportantInterface {
public function doSomeImportantStuff() {
}
public function doEvenMoreImportantStuff() {
}
}
그리고 마지막으로, 서비스 클래스 :
class DocumentService {
const DOCUMENT_ENTITY = 'DocumentEntity';
/**
* @var EntityManager
*/
protected $em;
/**
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager) {
$this->em = $entityManager;
}
public function getDocument($guid) {
$documentEntity = $this->em->getRepository(self::DOCUMENT_ENTITY)->findByGuid($guid);
return; //what? I want here Document to be returned, not the DocumentEntity..
}
public function createDocument() {
return new Document();
}
public function saveDocument(Document $document) {
// Document -> DocumentEntity
// $documentEntity = ...?
//$this->em->persist($entityDocument);
//$this->em->flush();
}
}
S 자
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="DocumentRepo")
* @ORM\Table(name="document")
*/
class DocumentEntity {
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="UUID")
* @ORM\Column(type="guid")
*/
protected $guid;
/**
* @ORM\Column(length=64)
*/
protected $name;
// more stuff below...
}
, 나는 별도의 유지하려는 비즈니스 로직의 많은 내 모델 클래스있다 o 볼 수 있듯이,이 계획은 DocumentEntities가 아닌 응용 프로그램에서만 사용할 수있는 Document 객체 (서비스를 통해 액세스 할 수 있음)를 갖는 것입니다. 내 마음에 온 두 가지 가능한 방법은 :
- 은, 어쩌면 내가 여기에 뭔가를 누락, DocumentEntity
을 확장하는 문서