title: DDD using Doctrine
body: <p>I am in the process or trying to re-model an existing application using an ORM and trying to adhere to DDD as much as possible.</p>
  
  <p>Work order is the AR and has more than a dozen child entities. I intended on modeling this class like so:</p>
  
  <pre><code>class WorkOrder {
  
    private $number = 0;
    private $manual = '';
  
    ...
  
    // Sub-Entities
  
    private $consumables; // Collection (1:m)
    private $dimensions;  // Collection (1:m)
    private $sequences;   // Collection (1:m)
  
    ...
  
  }
  </code></pre>
  
  <p>Now I would need a repository to load (and persist?) this aggregate root -- correct?</p>
  
  <p>The repo would return one or more aggregates which when I access the sub-entities (through indirect getter/setters -- not dot-notation) will lazy load the information I am after???</p>
  
  <p>I will have another class to act as a factory for creating work orders -- which is a detailed process and includes substantial business logic/validation rules...</p>
  
  <p>But if the factory creates the work order aggregate does the repo just persist the AR?</p>
  
  <p>This factory would have to query a third party service (through REST or otherwise) and basically build a snapshot of an approved document describing work scope.</p>
  
  <p>So the repository encapsulates the ORM or which ever persistence layer I should choose?</p>
  
  <p>Right now my file structure would look something like:</p>
  
  <pre><code>WorkOrder/
    /Factory.php
    /Aggregate.php
    /Repository.php
  
    /Entity/Header.php
    /Entity/Shipping.php
    /Entity/Warranty.php
    /Entity/Certification.php
    ...
  </code></pre>
  
  <p>The repository would have methods like:</p>
  
  <pre><code>FindOneByTrackingNumber()
  FindAllByCriteria()
  
  save($root);
  </code></pre>
  
  <p>My factory would have methods like:</p>
  
  <pre><code>createWorkOrderFromRpi()
  createWorkOrderFromCsv()
  ...
  </code></pre>
  
  <p>I have read through several articles and countless posts on here:</p>
  
  <p><a href="http://williamdurand.fr/2013/08/07/ddd-with-symfony2-folder-structure-and-code-first/" rel="noreferrer">http://williamdurand.fr/2013/08/07/ddd-with-symfony2-folder-structure-and-code-first/</a></p>
  
  <p>While the detail is excellent I need a second opinion on my own interpretation, please. :)</p>
  
  <p>Regards,
  Alex</p>