-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-21764: Don't instantiate eZINI outside of classes #129
EZP-21764: Don't instantiate eZINI outside of classes #129
Conversation
Hi and thanks again @jeromegamez ! Why don't you create a utility method instead of always repeating the same code ? |
I thought about this, but then, we could also just call e.g. |
Mmm, you can sometimes have surprises when dealing with eZINI and its multiton pattern. I really prefer that you create one utility method per INI file. |
Done! ... looks weird, though :) |
It's not exactly what I suggested. Should be something like this: public static function getEzFindIniInstance()
{
return self::$FindINI = ( self::$FindINI instanceof eZINI ) ? self::$FindINI : eZINI::instance( 'ezfind.ini' );
} And everywhere else you use this getter when you need it ;-) |
I'm not sure I understand fully. How would I use this method? Should I do a $eZFindINI = self::getEzFindIniInstance(); and replace every usage of |
Yes, this is what I meant. |
This should look better now, I hope. |
+1 |
2 similar comments
+1 |
+1 |
Rebased into current master to resolve merge conflicts and ease merging. |
The change "causing" the merge conflict since last was 6d6292c, which is preserved in this PR, as you can see in https://github.com/jeromegamez/ezfind/blob/EZP-21764_unintentional_ezini_instances/classes/ezfsolrdocumentfieldbase.php#L470 . |
Sorry to jump in one year later, but unless I'm missing something you can skip the whole static property actually. Instance cache is kept inside |
And another year later, I finally removed the static ini helper methods and replaced them with proper |
/// Vars | ||
public $ContentObjectAttribute; | ||
static $FindINI; | ||
static $DocumentFieldName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check if anything is using this given it has been public for so long?
basically small bc break here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I checked - at least inside the eZ Find extension, the static variables are not used in other places.
+1, also for 5.4 and 5.3 backport if it applies cleanly (for easier maintenance) |
did not find any use of it "outside", for example in other pending pull requests ;) |
🚢 🎉 :) |
…i_instances EZP-21764: Don't instantiate eZINI outside of classes
YEAH! 🎊 🎉 Thanks, André! |
At the moment,
eZINI
instances forezfind.ini
,solr.ini
andsite.ini
get created outside of the the classesezfSolrDocumentFieldBase
andezfeZPSolrQueryBuilder
, even when their containing PHP files just get included through the autoloader. This can cause problems, e.g. in the context of Unit Tests when this happens before the INI files get overriden by other processes.This PR preserves the static class variables, but ensures that they get instantiated inside the classes only.
If have thought about converting them to local variables, but wanted to make sure that derived classes, that access them, don't get problems.
Cheers
Jérôme
PS: This PR is part of a process to make the eZ Find Unit Tests work again.