M
M
Mors Clamor2021-04-13 20:44:01
1C-Bitrix
Mors Clamor, 2021-04-13 20:44:01

Where to add your classes to Bitrix?

Hello! There was a need to implement additional functionality for Bitrix, namely Assets as in Yii2, that is, I want to implement a decorator over the standard Assets for Bitrix. The question immediately arose, where to place the file with the class, in what namespaces and folders, without being tied to a specific project or component? Thanks in advance

PS: If there is already something like this in Bitrix, then share the info, please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2021-04-13
@66demon666

There are several ways, the main thing to remember is that classes are not for the sake of classes, but for maintainable code and its reuse.
1. Autoload classes using Composer (many use).
2. Write your autoload. (if you have something very non-standard)
3. In the form of a bitrix module, autoload will be (IMHO the most correct option for bitrix)
When using composer, class files can be located anywhere, but it is considered good practice to store them (like the vendor folder ) one level above the public folder.
In Namespace, you are not limited, the main thing is to make an explicit and clear structure and names that carry a semantic load.
PS: Don't forget about DRY, KISS, SOLID, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question