Found, the solution is simple: to make a single class from singletona that does not violate the principles of OOP (in my case with the system settings), but to create its object using an IoC container, for example: "Pimple":
Объявление сервисов «Синглтонов»:
By default, every time Pimple is called, it returns a new service object. If one instance is required for the entire application , all you need to do is wrap the declaration in the share () method:
$IoC['object_name'] = $IoC->share(function ($c) { return new Config($c['class_name']); });
BUT, as it was before, in versions 1.x , now the Pimple developers have removed the share () method. Although no one will forbid you to use the old version 1.x, it is on the githab (link is below).
Although in the new versions (3.x) of this container there is no share () method, but still it is better to use an IoC container to manage dependencies than Singleton:
// Регистрируем зависимости через IoC контейнер "Pimple": $IoC = new Container(); // Объявление сервисов: $IoC['obj_conf'] = function ($c) { return new Config($c['Config']); };
References:
- https://habrahabr.ru/post/199296/
- http://pimple.sensiolabs.org/
- https://github.com/silexphp/Pimple/blob/1.1/lib/Pimple.php - version 1.x
And further:
There are quite a lot of IoC containers, use what is convenient for you: