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:

800
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?

@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.