Modular system in PHP, how to protect?

There was a need to write a project in PHP5, so-called core for later writing and connecting modules. The project is calculated to modules has been written to it, not only my hands but also other users. More specifically, the module is likely to be presented in the form of a file containing the module class. Now I'm interested in the following items:
  • How do I restrict module access to the database within one table?
  • How to disable the module include files of the kernel?
  • How to disable the module some functions in any manifestation?

You will not prompt, where to smoke, what libraries or methods to apply?
July 8th 19 at 11:45
2 answers
July 8th 19 at 11:47
Solution
the module is likely to be presented in the form of a file containing the module class

How do I restrict module access to the database within one table

appears to be hellish mix of queries to the database and logic. In General, one class-file, there is not enough
Read about inversion of control and dependency injection, the questions will disappear.
Get that custom module will only use what your "core" will give him and nothing more.
As far as I understood these principles, they provide the ability to quickly change code and be able to test it. Frankly, I do not quite understand how with this case you can restrict access to modules. - Trey_Whi commented on July 8th 19 at 11:50
: see, for example, have your module in a single controller. Well, he should do something useful and as possible know about the rest of the system. He needs to take their data from somewhere, so he any connection with the repository.
Next - your repository/model for module/entity active record/something that communicates with the data warehouse has somewhere to get to know nothing more.
It turns out that the kernel creates a specimen of your essence to work with the data, gives her what table it works, gives her something that can get data from the repository. After all the essence of the transfer controller module that will pull methods of this entity.
If you want as much as possible to limit the module, we can write interfaces for your entities based on them to implement such basic entities for tables that will run the modules, and then using the container for dependencies to declare relations of entities with interfaces and have them transfer in-type controller module. then you can do one file
for example will be
https://gist.github.com/MetaDone/4ad23763b3027e116... - Chyna.Jerde commented on July 8th 19 at 11:53
: These things I understand. Now the question is: how to disable module in one of my functions directly call, for example, PDO? - Trey_Whi commented on July 8th 19 at 11:56
directly you stop to pull anything that is in the system. If you want is sooo hard to check that the module really only use what is in the system and nothing more, then look here - php.net/manual/ru/book.reflection.php. you can check whether you set appropriate properties, it is determined whether the desired interfaces, and much more. In case of discrepancy throw exceptions, but even so it can be circumvented.
or look in the direction of https://zephir-lang.com/ and submit your code as an extension, just hide implementation details, and interfaces will prompt end users that need to be implemented in the framework of the module and that they can use - Chyna.Jerde commented on July 8th 19 at 11:59
: zephir does not suit me, for I may not have access to the same php.ini to add the extension, and even more so to the console to assemble the extension. But if absolutely nothing else will be able to find it, I will have to use them. - Trey_Whi commented on July 8th 19 at 12:02
: And Yes, I still do not see the possibility to close from using a standard PHP function. There is an option to use something like your script language or tie the Lua parser, which is available in PHP7 - Trey_Whi commented on July 8th 19 at 12:05
July 8th 19 at 11:49
Can't quite understand - but you write your bike-framework...
What is wrong with, for example, Zend or Symfony?

Yes - use the principle: - one class - one file - only responsibility.
And then, as I understand it, your class module will be used with other modules and with the database work and some more other functions to perform... This is the road to hell...

Find more questions by tags ProgrammingPHP