Reputation: 390
I'm working with a number of 'helper' classes, which affectively have a bunch of static functions which allow the controllers and actions have access to chunks of shared functionality.
Problem is that these files have been used as a dumping ground for any functionality which is required across the modules/application and as a result they are > 3k lines in size and at the top they've got about 50 require_once
declarations!
Obviously if a view in the application wan't to use a small part of the functionality available from these helpers it inherits all the required files, and you end up bloating your app.
If I were to include the files on a per need basis, I could end up making numerous require_once
calls to the required files, which has it's own overhead (compounded with frequency), when I need use a large amount of the functionality available from these helper files.
So essentially my question is where is the balance struck and is there a best practice that one can employ?
Thanks,
Flunga
Upvotes: 2
Views: 421
Reputation: 546085
Take a look at the autoloading feature. this will reduce all your includes down to only what is required, when it is required.
Upvotes: 9
Reputation: 117529
Your best bet when constructing such dependencies to stay "acyclic". You can have higher-level functionality "require" the low level functionality it needs to operate, but design it in a way so that things do not point to each other.
This way, by breaking it into small enough units you will be able to ensure that when you don't need all the modules, only the minimal number of dependencies get pulled in.
I'm certainly unaware of any reason to "require" code you're not going to use in a page.
Upvotes: 1