Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Update to version 3 #10

Merged
merged 51 commits into from
Jun 1, 2014
Merged

Update to version 3 #10

merged 51 commits into from
Jun 1, 2014

Conversation

nyamsprod
Copy link
Member

Immutable Value Object

League\Url\Url is now a Immutable Value Object. This means that any change made to the object will return a new object with the changed property and will leave the original object unchanged.

use League\Url\Factory as Url;
$original_url = Url::createFromString('http://www.example.com');
$modified_url = $original_url->setQuery(array('foo' => 'bar'));
echo $original_url; // output http://www.example.com/
echo $modified_url; // output http://www.example.com/?foo=bar

Prior to version 3, some url component properties where returned as string and other as object. Now all component property are returned:

  • as object that implement a common Interface which includes the __toString method;
  • as cloned from the internal property to avoid breaking the League\Url\Url Immutable state;
use League\Url\Factory as Url;
$original_url = Url::createFromString('http://www.example.com');
$host = $original_url->getHost();
$host->remove('www');
$host->prepend('test');
echo $original_url; // output http://www.example.com/
echo $host; // output test.example.com

Url parsing has been improved as well as League\Url\Url::__toString() methods.

adding validateComponent method
refactoring removeSegment method
typehinting callback to Closure to support PHP 5.3
the constructor can accept a string OR an object that implements the __toString method
moving classes method so that no duplication of code remain
nyamsprod added a commit that referenced this pull request Jun 1, 2014
Merging dev branch to update the library to version 3
@nyamsprod nyamsprod merged commit 70b91e0 into master Jun 1, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant