Services (utility class) SS 4

Silverstripe Version: 4.9

*Question: How can i create class like services in symfony for example

Hello, i want to ask what is the best way to achive something like in symfony we called services (utility classes for something) can i make folder in src then build simply class and make Special nemaspace and after that use this class in pages classes or i should do something else?

Im asking couse i cant find anything about that in SS doc i found only something about common variables but i Need to make class with some functions which i can use in many Pages classes and i dont know, i should use any Special directory structure or no. Or maybe is another way to achive this :slight_smile:

Thank you in advance
Have a nice Day!

Yes, see e.g. vendor/silverstripe/framework/src/ORM/ArrayLib.php.

Ok, everything work perfectly, but i have A question about ss cache or apache, after i made the class server report an error " class cant be found" dev/build?flush=all dont solve the problem but after restart apache everything was fine… silverstripe have any cache for classes or its a problem in apache? Couse this is weird, can somebody explain me why did this happen?

This happens to me all the time when I have OpCache enabled, so I’m pretty sure your problem is on the PHP side. If using mod_php (as it seems in your case), restarting the web server is a way to ensure that cache is clear. Maybe reloading it should suffice, but I’m not sure.

Do yourself a favor and disable any cache on your development machine, most notably OpCache and APCU. This usually means editing the relevant php.ini.