syntaxseed, (edited )
@syntaxseed@phpc.social avatar

Where does everyone store the files for enums & value objects?

  • src/
  • controllers/
  • entities/
  • repositories/
  • services/
  • views/

Another 2 sub directories under src/ ?

Some kind of types/ subdir then enums/ and objects/ under that? 🤔

#PHP #programming

thgs,
@thgs@phpc.social avatar

@syntaxseed in my mind value objects are enums. But again.. in my mind all numbers are a list of enums.

I just put them in the Value object directory of the correct layer, I guess

Crell,
@Crell@phpc.social avatar

@syntaxseed You're highlighting why that directory structure is problematic and limiting. 🙂

You could have a Model directory for data model stuff, which somewhat overlaps with entities. If it's an enum used by a repository, you can stick it in the repositories directory.

I am not aware of any real standard at the moment.

gmazzap,
@gmazzap@phpc.social avatar

@Crell @syntaxseed Agreed. Organizing things by what they do isn't optimal. Imagine to organize a house like that: a room for things that throws water, like kitchen sink and the shower, and another for things that emit warm, like fireplace and stove. If you organize thing semantically, you can have a folder with some views, some controllers, enums, value objects, etc, all related to the same conceptual part of the thing. Another folder with other views, other controllers, etc.

Flyingmana,
@Flyingmana@phpc.social avatar

@syntaxseed depends on the amount of usages, the amount of classes in general and so on.

Also depends on if Entities are strictly belonging to an ORM, or are open for all kind of data holding objects. But generally I would see enums there.

We got more flexible caused by the amount of classes we have, so if the usage is limited, we would put it besides the Service introducing it.
like, MyBenderService and MyBenderServiceStatusEnum, MyBenderServiceBenderValueObject.

Flyingmana,
@Flyingmana@phpc.social avatar

@syntaxseed of course we have a lot of sub directories in services for all the different domain parts 😅

only think I would strongly advice against is using a directory or namespace called objects.
Its to ambiguous, and close to the reserved keyword "object"
Then better use ValueObjects, or some also like to use DTOs

syntaxseed,
@syntaxseed@phpc.social avatar

@Flyingmana The entities are all Doctrine objects.

But yes... very good point about 'objects' being to generic.

kniziol,

@syntaxseed From a technical point of view directories like you mentioned look good (enums/ and objects/).

Let me suggest another, non-technical idea. Try to put Enums or Value Objects close to their cooperators, their "colleagues".

Simple example: if a particular Enum is responsible for a category of product, let's keep it together with the Product class.

syntaxseed,
@syntaxseed@phpc.social avatar

@kniziol I like that idea but unfortunately none of my projects are organized by domain like that. But after your project gets to a certain size... you really do need to start organizing that way or it just becomes chaos. 😅

thgs,
@thgs@phpc.social avatar

@kniziol @syntaxseed my enums or value objects are sociable and polyamorous. It is sometimes vague who they primarily collaborate with.

fredbrooker,
@fredbrooker@witter.cz avatar

@syntaxseed me?

data/

thomastospace,
@thomastospace@phpc.social avatar

@syntaxseed If its part of an entity (eg PostType, used by entity Post) then its in src/Entity/Enum. Otherwise it's often in a subdirectory close to where it 'belongs' like a valueobject.

tobiaskoengeter,
@tobiaskoengeter@sueden.social avatar

@syntaxseed we always store the Enums under /src/Enums 😊

chrastecky,
@chrastecky@phpc.social avatar

@syntaxseed In src/Enum for me. If the app is larger, I don't use this simplistic structure, because it actively works against you.

nanawel,

@syntaxseed That would seem fine to me.

My philosophy now is "Wherever it seems the most logical and coherent" if there's no preexisting standard.

syntaxseed,
@syntaxseed@phpc.social avatar

@nanawel Yeah I tend to agree. I don't like too many "top level" directories so I'm leaning toward types/ with enums/ and objects/ under that.

alessandrolai,
@alessandrolai@phpc.social avatar

@syntaxseed @nanawel I just refactored a new project that was starting out with that same Symfony-style base namespace and it came out exactly with not so many first-level folders: I split by concern (it's a service to sent templates emails, so delivery, templates, admin...) , then subfolders are allowed to be "per kind" (controller, entity..), but not always.

I was very happy of how it came out, and this approach can solve your kibd of issue "naturally". I definitely suggest it.

wyri,
@wyri@haxim.us avatar

@syntaxseed Honestly, not clue where to put them in that structure. Using a package like/DDD/hexagon structure for my projects so they naturally end up were they fit. In that structure, either each in their own dir under src/ or otherwise maybe with entities and services?

driusan,

@syntaxseed Wherever the namespace dictates that the autoloader wants it to be on the file system?

syntaxseed,
@syntaxseed@phpc.social avatar

@driusan It's a Symfony app so there isn't really a dictated spot other than under src/.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • php
  • DreamBathrooms
  • magazineikmin
  • ethstaker
  • InstantRegret
  • tacticalgear
  • rosin
  • love
  • Youngstown
  • slotface
  • ngwrru68w68
  • kavyap
  • cubers
  • thenastyranch
  • mdbf
  • provamag3
  • modclub
  • GTA5RPClips
  • normalnudes
  • khanakhh
  • everett
  • cisconetworking
  • osvaldo12
  • anitta
  • Leos
  • Durango
  • tester
  • megavids
  • JUstTest
  • All magazines