phpc.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A server for PHP programmers & friends. Join us for discussions on the PHP programming language, frameworks, packages, tools, open source, tech, life, and more.

Administered by:

Server stats:

819
active users

@angelov Hi Dejan, this post is very well written. I would like to know what you think about using Http-related concepts like the StatusCodes within your domain layer. I like your approach but I'm not sure about mixing.
If an Exception is thrown while services are called via CLI then it would not know about StatusCodes but rather ExitCodes.

@dazz Hey, for mixing - do you mean applying the specific attributes on the (domain) exception classes, or making the attributes related to a HTTP status code?

@angelov Hey, the first. The Attributes are about adding Http-StatusCode info to your Domain-Exceptions. That would mean UI-layer and business domain layer would get mixed. Business layer should not know about Http.

@angelov I'm at the SymfonyLive. Nicolas just showed this slide.

@angelov and the circle closes here :D

@dazz The attribute in the framework allows us to easily set the status code, in the same way as we configure the, for example, Doctrine metadata in entities.
For better decoupling we can introduce custom attributes in our app as described in my article, and as part of our domain, declaring that some kind of a business error has happened (eg. something does not exist, something is not allowed, etc.)

@dazz Which brings us to the part where we may introduce HTTP knowledge to the domain attributes. To achieve that we can add a map in our exception handler and associate the status code to each of the attributes.