Skip to content
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

Merged
merged 1 commit into from
May 27, 2015
Merged

EZP-21764: Don't instantiate eZINI outside of classes #129

merged 1 commit into from
May 27, 2015

Conversation

jeromegamez
Copy link
Contributor

At the moment, eZINI instances for ezfind.ini, solr.ini and site.ini get created outside of the the classes ezfSolrDocumentFieldBase and ezfeZPSolrQueryBuilder, 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
:octocat: Jérôme

PS: This PR is part of a process to make the eZ Find Unit Tests work again.

@lolautruche
Copy link
Contributor

Hi and thanks again @jeromegamez !

Why don't you create a utility method instead of always repeating the same code ?

@jeromegamez
Copy link
Contributor Author

I thought about this, but then, we could also just call e.g. self::$FindINI = eZINI::instance( 'ezfind.ini' ); which seems to be the appropriate helper method. What do you think?

@lolautruche
Copy link
Contributor

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.

@jeromegamez
Copy link
Contributor Author

Done!

... looks weird, though :)

@lolautruche
Copy link
Contributor

It's not exactly what I suggested.
The problem in your change is that your utility method doesn't return the instance 😉

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 ;-)

@jeromegamez
Copy link
Contributor Author

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 self::$FindINI with $eZFindIni? I tried it the other way to reduce the amount of code changes, but if this is the best approach, I'm happy to do it this way.

@lolautruche
Copy link
Contributor

Yes, this is what I meant.

@jeromegamez
Copy link
Contributor Author

This should look better now, I hope.

@lolautruche
Copy link
Contributor

+1

2 similar comments
@yannickroger
Copy link
Contributor

+1

@guillaumelecerf
Copy link
Contributor

+1

@jeromegamez
Copy link
Contributor Author

Rebased into current master to resolve merge conflicts and ease merging.

@jeromegamez
Copy link
Contributor Author

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 .

@andrerom
Copy link
Contributor

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 eZINI::instance, so now that a method call is added to get property, the micro micro wasted static property cache optimization is no longer even worth it.

@jeromegamez
Copy link
Contributor Author

And another year later, I finally removed the static ini helper methods and replaced them with proper eZINI::instance() calls :).

/// Vars
public $ContentObjectAttribute;
static $FindINI;
static $DocumentFieldName;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@andrerom
Copy link
Contributor

+1, also for 5.4 and 5.3 backport if it applies cleanly (for easier maintenance)

@paulborgermans
Copy link
Contributor

did not find any use of it "outside", for example in other pending pull requests ;)

@andrerom
Copy link
Contributor

🚢 🎉 :)

andrerom added a commit that referenced this pull request May 27, 2015
…i_instances

EZP-21764: Don't instantiate eZINI outside of classes
@andrerom andrerom merged commit b003a48 into ezsystems:master May 27, 2015
@jeromegamez
Copy link
Contributor Author

YEAH! 🎊 🎉 Thanks, André!

@jeromegamez jeromegamez deleted the EZP-21764_unintentional_ezini_instances branch May 27, 2015 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants