title: Refactoring a Controller in symfony to adapt to hexagonal architecture
body: <p>I have create a controller that creates a Owner record into database. Everything was done on the CreateOwnerController like this and working properly:</p>
  
  <pre><code>class CreateOwnerController extends Controller
  {
       public function executeAction(Request $request)
       { 
         $em = $this-&gt;getDoctrine()-&gt;getManager();
         $owner = new Owner($request-&gt;request-&gt;get("name"));
         $em-&gt;persist($owner);
         $em-&gt;flush();
  
      return new Response('Added',200);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now,In order to refactor that I have created an interface that defines the OwnerRepository:</p>
  
  <pre><code>interface OwnerRepositoryInterface {
      public function save(Owner $owner);
  }
  </code></pre>
  
  <p>And a OwnerRepository that implements this interface:</p>
  
  <pre><code>class OwnerRepository extends EntityRepository implements OwnerRepositoryInterface {
      public function save(Owner $owner) {
          $this-&gt;_em-&gt;persist($owner);
          $this-&gt;_em-&gt;flush();
      }
  }
  </code></pre>
  
  <p>Then I have Created for the application layer a CreateOwnerUseCase Class that receives a OwnerRepository and executes a method to save in into OwnerRepository:</p>
  
  <pre><code>class CreateOwnerUseCase {
      private $ownerRepository;
      public function __construct(OwnerRepositoryInterface $ownerRepository) {
          $this-&gt;ownerRepository = $ownerRepository;
      }
  
      public function execute(string $ownerName) {
          $owner = new Owner($ownerName);
          $this-&gt;ownerRepository-&gt;save($owner);
      }
  }
  </code></pre>
  
  <p>Ok, i'm spliting the initial Controller intro layer Domain / Aplication / Framework layers.</p>
  
  <p>On the <code>CreateOwnerController</code> now i have instantiated that Use Case and passed as parameter the <code>OwnerRepository</code> like this:</p>
  
  <pre><code>class CreateOwnerController extends Controller {
      public function executeAction(Request $request) { 
          $createOwnerUseCase = new CreateOwnerUseCase(new OwnerRepository());
          $createOwnerUseCase-&gt;execute($request-&gt;request-&gt;get("name"));
          return new Response('Added',200);
      }
  
  }
  </code></pre>
  
  <p>But it fails when Make the request to create new Owner:</p>
  
  <blockquote>
    <p>Warning: Missing argument 1 for Doctrine\ORM\EntityRepository::__construct(), called in /ansible/phpexercises/Frameworks/mpweb-frameworks-symfony/src/MyApp/Bundle/AppBundle/Controller/CreateOwnerController.php </p>
  </blockquote>
  
  <p>It happens on <code>OwnerRepository</code> passed as parameter. It wants an <code>$em</code> and Mapped Class... What is the meaning of this mapped Class? How solve this error?</p>