2
votes

I am new to symfony and I have a question related to clean Domain Driven Design Implementation in Symfony using Doctrine

In Zend framework one I had a structure as follows

Model Folder

User (Folder and Table in database)

Row.php (Class name Model_User_Row in folder User)

Rowset.php (Class name Model_User_Rowset in folder User)

Table.php (Class name Model_User_Table in folder User)

Repository.php (Class name Model_User_Repository in folder User)

Service.php (Class name Model_User_Service in folder User)

I wish to create similar structure in Symfony using Doctrine (I know that Doctrine has its own way)

My problem is the doctrine Tool Creates a Entity folder and Repository folder in AppBundle and puts everything in those folders.

My wish is to create in Symfony

AppBundle

Model (Folder)

User (Folder)

User.php //entity in folder User

UserRepository.php // repository in folder User

I tried changing the following code

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: false
    mappings:
      person:
        type:      annotation
        dir:       "%kernel.root_dir%/../src/AppBundle/Model/Person"
        prefix:    AppBundle\Model\Person
        alias:     AppBundle
        is_bundle: false

and then create new enitities but it did not work

please advise

1
My advice is stop fighting the framework and do it the default way, at least initially anyway. Once you get familiar with the framework you may want to change, or how it does things may make more sense. - Richard
I am fine with accepting Standard way of Symfony. I would like to know where to store my Service class. My service class would talk to the repository. I do not want to use repository directly from the controller as this will create problems in unit testing (creating mock objects). Most of the symfony code examples directly talk to repository in the controller. - shobekhan

1 Answers

2
votes

I have the same concerns than you, usually I go with this structure

Entity
  -- Model (here goes User.php)
  -- Repository (here goes UserRepository.php)
Services 
  -- Domain (my 100% business Logic, 100% covered by tests with mocks)
  -- FormBuilder (where I hydrate my formsType by their DTO etc..)
  -- ..etc..

Because I Use Entity as the top directory, the only configuration you need is to move Entities/Repositories to their directories and adjust The repositoryClass in the annotation