R
R
ragnar_ok2021-07-23 18:35:38
1C-Bitrix
ragnar_ok, 2021-07-23 18:35:38

How to avoid spaghetti code in result_modifier?

Working with result_modifier.php forces you to write spaghetti code. It becomes impossible to maintain this footcloth. How to refactor?

It seems like a normal solution might be to use a component factory (factory method pattern). Create a factory for each component (bitrix:news.list, bitrix:news.detail ...). In the result_modifier.php of the component template, get the required class from the factory with static methods for this particular result_modifier.php.

Is there any generally accepted approach?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-07-24
@ragnar_ok

There is no need to do something in the form of a module for a separate project.
I do this (and often see a similar approach):
In /local/php_interface/lib I place classes that implement some functionality of a particular project, and connect it using composer autoload:
60fb43892d58e809635873.png
Here you can place classes that implement the module and just ordinary helpers - I don’t see anything what's wrong with a procedural approach is if all the ideas are implemented as simple, short and minimally functional pure static methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question