? ? Pending

User tests: Successful: Unsuccessful:

avatar okonomiyaki3000
okonomiyaki3000
27 Jan 2017

Pull Request for Issue # .

Summary of Changes

A) Stop type-hinting AbstractUri::toString so that array isn't required
B) Check if a string has been passed, if so get the $parts array from func_get_args

Testing Instructions

Try this:

$uri->toString(array('path', 'query', 'fragment'));

Then try this:

$uri->toString('path', 'query', 'fragment');

Should be the same.

OK, how about this:

$parts = array(...); // Put whatever parts you want in here
$uri->toString($parts) === call_user_func_array(array($uri, 'toString'), $parts);

Should always be true.

Documentation Changes Required

Probably not.

Why?

OK, I like type-hinting too but, look, there's no reason to pass an array into this thing. Just pass the strings in any order and don't worry about it. Prefer an array? OK, still works. But, honestly, what's more readable?

$uri->toString(array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'));

or

$uri->toString('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment');

Not that you would ever write either of those since it's the default anyway... but you get the idea.

avatar okonomiyaki3000 okonomiyaki3000 - open - 27 Jan 2017
avatar okonomiyaki3000 okonomiyaki3000 - change - 27 Jan 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 27 Jan 2017
Category External Library Libraries
avatar laoneo
laoneo - comment - 27 Jan 2017

You need to make the change against the Framework package here https://github.com/joomla-framework/uri/blob/master/src/AbstractUri.php. Then we can load it trough composer and add it to the CMS. The vendor directory shouldn't being changed in a PR.

avatar mbabker
mbabker - comment - 27 Jan 2017

Honestly, I'm ? here. In the end all it's doing is introducing a hack that lets you pass an array of parts without wrapping it in an array declaration.

avatar okonomiyaki3000
okonomiyaki3000 - comment - 28 Jan 2017

@laoneo Thanks, I'll do that.

@mbabker I'm not sure in what way this is a hack. And, yes, in the end all this is doing is exactly what it's intended to do. Look at it this way, if this were a new function with no questions of BC or anything else what would you say are the merits of each of these approaches?

a) Take any number of strings directly
b) Take an array of strings
c) Take an associative array where each url part is a key and will be used if the value is truthy
d) Like c but with an object instead
e) c + d (array/object agnostic)
f) All of the above

Honestly, if this were really a new function, I'd say use class constants instead of strings anyway but that's a bit of a tangent.

avatar mbabker
mbabker - comment - 28 Jan 2017

It turns something with a defined signature (granted it's not the most well defined thing, but it still has a purpose) and turns it into a variadic function with what results in a signature that cannot be documented accurately. Even if this were a new method I'd look at it the same way. Honestly I'm not the biggest fan of variadic functions or unkeyed arrays being used for function signatures, I prefer specificity in my code and documentation as to me it results in clearer expectations for the developer maintaining the code and the consumer using it.

avatar okonomiyaki3000
okonomiyaki3000 - comment - 28 Jan 2017

In fact, I agree with you in principle but I also prefer to look at things on a case by case basis rather than stick to some absolute ideals. I don't believe this change introduces any significant ambiguity to the way this function can be used but it does make it simpler to use. I suppose how those things balance out is mainly a matter of opinion.

It might not be terribly relevant but Joomla already has many functions that work in a similarly flexible way. For example JDatabaseQuery::select, which I would say is more ambiguous than this proposal.

avatar Bakual
Bakual - comment - 28 Jan 2017

Yes, Joomla has many such functions. Mostly old functioms where it couldn't be changed for B/C reasons.
Let's not introduce more from them if not absolutel needed.

avatar Bakual
Bakual - comment - 28 Jan 2017

Closing this as it is the wrong repo anyway (it should be in the framework as @laoneo poiinted out) and chances are high it doesn't get accepted anyway.

avatar Bakual Bakual - change - 28 Jan 2017
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2017-01-28 14:01:05
Closed_By Bakual
Labels Added: ? ?
avatar Bakual Bakual - close - 28 Jan 2017
avatar mbabker
mbabker - comment - 28 Jan 2017

The difference with this proposal and JDatabaseQuery::select() is the latter method either accepts a single string or a single array whereas this proposal changes the method to accept an unlimited number of strings, and that's what I'm not a fan of here. If there's really going to be a change, I'd rather it be similar to the database query and it allow a single string (just wrap it in an array if need be).

Add a Comment

Login with GitHub to post a comment