Code in native PHP:
$href = phpUri::parse($target_url)->join($href);
Code I tried in CI which is not working:
$CI->load->library('Phpuri', array($target_url));
$href = $CI->phpuri->parse($target_url);
$href = $CI->phpuri->join($href);
You can see the phpUri native library here. I’ve just changed the case of class name rest is same to make it work in CI. I am using this in another library so using the CI instance.
CodeIgniter’s pattern is a singleton. The phpUri uses static calls. There is a great difference between them that I suggest you to familiarize with.
The point here is that
phpUriuses the static callparsewhich is requested from the class, not the object itself and as CodeIgniter is a singleton, it’s an object with sub-objects (said that for simplicity, read more about that). With that being said, the reason why this doesn’t work is thatphpUridoes not behave like an object and only produces(returns) objects after the static call:can be simplified to:
the first line is the static call which returns an object to
$parsedvariable and then you can play with that.In singleton, you can’t make a ‘classes parent’ by defining a class as an objects attribute. That’s why to use this library, you should rewrite all the static calls first.
But it is much easier to write an abstraction layer library in CodeIgniter that uses static calls in it’s object’s non-static methods:
Then in your library
That is what an abstract class is – the one that gives you an interface.