jwage / purl Goto Github PK
View Code? Open in Web Editor NEWPurl is a simple Object Oriented URL manipulation library for PHP 7.2+
License: MIT License
Purl is a simple Object Oriented URL manipulation library for PHP 7.2+
License: MIT License
I'm getting the following errors. This is because jwage/purl requires jeremykendall/php-domain-parser "^1.3.1". Could you change to allow a newer version please.
PHP Deprecated: idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated in /var/www/vhosts/rubus.pineberry.com/vendor/jeremykendall/php-domain-parser/library/Pdp/Parser.php on line 209
PHP Deprecated: idn_to_utf8(): INTL_IDNA_VARIANT_2003 is deprecated in /var/www/vhosts/rubus.pineberry.com/vendor/jeremykendall/php-domain-parser/library/Pdp/Parser.php on line 192
Library should be able to create relative urls:
$url = new \Purl\Url('/events');
$url->query->set('param1', 'value1');
echo $url->getUrl();
Expected output should be:
/events?param1=value1
It would be great if PHPUnit would be added to dev package list in composer. For those who prefer local package install.
jwage\purl\src\Purl\Query.php line 71
How does Purl deal with malformed uris?
Would be nice have support for this URI schema.
As of PHP 8, __set()
must return void...
purl/src/Purl/AbstractPart.php
Line 114 in d1cf27f
Something along the lines of Purl\Url::fromCurrent() that would look at various $_SERVER variables and hand back an object based on the current request.
@jwage Your thoughts? I'd be happy to send a pull request for it.
Many sites now use protocol-relative urls (starting with //
) to link to dependencies, but joining these in Purl seems to ignore the given scheme.
For example:
$url = new \Purl\Url('https://example.com');
echo $url->scheme . PHP_EOL; // https
$url->join('//code.jquery.com/jquery-3.1.0.js');
echo $url->scheme . PHP_EOL; // http
echo $url->getUrl(); // http://code.jquery.com/jquery-3.1.0.js
The page at https://example.com
references jQuery using a protocol-relative url (//code.jquery.com/
). Browsers would request this using the scheme of the parent page - in this case https
, but Purl joins it as http
.
When you parse a url like: blahblah.com
.
It creates url like: :///blahblah.com
.
The problem with this, is that even if you set the protocol, you end up with:
http:///blahblah.com
.
This is because the Url::httpBuildUrl
adds a /
even when there is not $data['user'], $data['host'] or $data['port'].
This results in 3 slashes because it thinks blahblah.com is the path and not the host.
I have this Url 'http://www.myurl.com/#!/any_path/?param1=val1' and I want to add a new query parameter to it, so I did that:
$url = new \Purl\Url('http://www.myurl.com/#!/any_path/?param1=val1');
$url->getQuery()->set('param2', 'val2');
echo $url->getUrl(); //http://www.myurl.com/?param2=val2#!/any_path/?param1=val1
I'm expecting this url 'http://www.myurl.com/#!/any_path/?param1=val1¶m2=val2' as an output not 'http://www.myurl.com/?param2=val2#!/any_path/?param1=val1'
Any Idea!
I have a loop that runs around 75 times before all the memory on my system is allocated. Each loop purl consumes around 1.5mb by including the public suffix list. Is there a way around this?
function convert($size)
{
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
foreach ($domains as $domain)
{
echo \Purl\Url::parse($domain);
// echo convert(memory_get_usage(true));
// echo '<br />';
}
The memory usage output is below
16 mb
17.75 mb
19.5 mb
21 mb
22.5 mb
24 mb
25.5 mb
27 mb
28.5 mb
30 mb
31.5 mb
33 mb
34.5 mb
36 mb
37.5 mb
39 mb
40.5 mb
42 mb
43.5 mb
45 mb
46.5 mb
48 mb
49.5 mb
51 mb
52.5 mb
54 mb
55.5 mb
57 mb
58.5 mb
60 mb
61.5 mb
63 mb
64.5 mb
66 mb
67.5 mb
69 mb
70.5 mb
72 mb
73.5 mb
75 mb
76.5 mb
78 mb
79.5 mb
81 mb
82.5 mb
84 mb
85.5 mb
87 mb
88.5 mb
90 mb
91.5 mb
93 mb
94.5 mb
96 mb
97.5 mb
99 mb
100.5 mb
102 mb
103.5 mb
105 mb
106.5 mb
106.5 mb
108 mb
109.5 mb
111 mb
112.5 mb
114 mb
115.5 mb
117 mb
118.25 mb
119.75 mb
119.75 mb
121.25 mb
122.75 mb
124.25 mb
Would be nice have support for this URI schema.
It will be very cool to have something like this: http://nodejs.org/api/url.html#url_url_resolve_from_to
$url->resolve('/one/two/three', 'four') // '/one/two/four'
$url->resolve('http://example.com/', '/one') // 'http://example.com/one'
$url->resolve('http://example.com/one', '/two') // 'http://example.com/two'
Hello,
I think the library is not capable of handling the new and long(er) generic domain extensions, such as .photography, .club, .company, etc.
I think you have a restriction on the max length of the extension set to 3. I've found one here, but I'm not sure if it's the only one. I will take a look in the next days and maybe send a PR:
src/Purl/Url.php:107
Thanks,
J.
Test case:
<?php
require_once __DIR__ . "/vendor/autoload.php";
$url = new \Purl\Url('http://localhost/');
echo $url . "\n";
Expected output:
http://localhost/
Actual output:
http:///
This is using version 0.0.3.
Personally I am not a big fan of fluent interfaces, but I do think that in case one uses them, it should be done in a consistent way.
Is there any particular reason that remove()
(which is specific to this library) returns void
?
purl/src/Purl/AbstractPart.php
Line 89 in beb7175
When this is possible:
$url = \Purl\Url::parse('http://jwage.com')
->set('scheme', 'https')
->set('host', 'jwageMirror.com');
Then this should (?) also be possible?:
$url = \Purl\Url::parse('http://jwage.com')
->remove('scheme')
->remove('host');
A client has a website with different URLs depending on the locale. Is there a way to change the domain part without losing the subdomain part?
<?php
$englishUrl = new \Purl\Url('http://app.englishdomain.com/page/1');
$frenchUrl = clone($englishUrl);
$frenchUrl->set('host', 'frenchdomain.com');
echo $frenchUrl;
// I expect http://app.frenchdomain.com/page/1
// But I get http://frenchdomain.com/page/1
echo $frenchUrl->registerableDomain;
// I expect frenchdomain.com
// But I get englishdomain.com
// Ok ... maybe using ->set('registerableDomain') ?
$frenchUrl = clone($englishUrl);
$frenchUrl->set('registerableDomain', 'frenchdomain.com');
echo $frenchUrl->registerableDomain;
// Yay! I get frenchdomain.com
echo $frenchUrl;
// Dammit, I get http://app.englishdomain.com/page/1
// Hey, maybe I can build it piece by piece...right?
$frenchUrl = \Purl\Url::parse('http://frenchdomain.com')
->set('subdomain', $englishUrl->subdomain)
->setPath($englishUrl->getPath())
->set('query', $englishUrl->query);
echo $frenchUrl;
// I get http://frenchdomain.com/page/1
// Where's the subdomain again?
Thanks!
Hi,
Does Purl support "protocol relative"/"schemeless" URLs?
About schemeless protocol URIs:
http://www.paulirish.com/2010/the-protocol-relative-url/
http://tools.ietf.org/html/rfc3986#section-4.2
Judging by the Purl::httpBuildUrl() method, I'm not sure it does:
https://github.com/jwage/purl/blob/master/src/Purl/Url.php#L317
The use case for this:
Being able to get any URL instance in a schemeless format, so files can be loaded by either http or https, based on the current browser protocol.
Please add support for longer TLDs. Currently, only two- and tree-letter TLDs are supported (such as .org, .cz, .de) but there are longer TLDs (e.g. .info, .name, .museum and so on) this time and many more ones will be confirmed by ICANN in the near future.
At this time composer refuses to allow this package to be installed alongside PHP 8.
8.0
does not satisfy constraint ^7.2
Hello,
I had to change the composer.json.
"require": {
"php": ">=5.3.0",
"jeremykendall/php-domain-parser": "1.*"
}
to
"require": {
"php": ">=5.3.0",
"jeremykendall/php-domain-parser": "1.1.0"
}
To install this.
Version 1.2.0 does not seem to be compatible and the wildcard auto points at that one.
Any software package with a dev dependency on PhpUnit 7+ is incompatible with jwage/purl
:
jwage/purl dev-master requires phpunit/phpunit ^4.8|^5.5|^6.5
Conflicts with:
Installation request for phpunit/phpunit ~7.0
The problem is probably caused by phpunit being in require
rather than require -dev
.
Hi,
subdomain
and registerableDomain
no longer seem to work with version 1.0.0
but they did work fine before updating the lib, with version 0.7.0
.
This is apparently the canonical domain:
com.jwage.domain.sub/index.php?param1=value1
Also I noticed that the README doesn't mention that it also includes the query parameters. It's a bit confusing since it was part of the Domains section.
Would be good to note the new $resource parameter too!
I am using version 0.0.7
and tested this upto 0.0.9
$url = \Purl\Url::parse('https://naren.nz/');
echo $url->registerableDomain;
//produces null
//expected naren.nz
$url = \Purl\Url::parse('https://www.naren.nz/');
echo $url->registerableDomain;
//produces "www.naren.nz"
//expected naren.nz
Please let me know if you need additional information.
to remove host
from the url
$url->set('host', null) or $url->remove('host')
if i do $url->set('host', null) and $url->getUrl() gives me something like ://google.com. The "http" alone is gone.
and if set the host to 'http' to //google.com url, it gives http://://google.com
Purl tries to parse fragments, but does not check for errors. When it happens, the fragment is completely missing from the stringified URL:
$url = new Url('http://example.com/#hello:123');
echo (string) $url, "\n";
This script outputs this:
http://example.com/
The problem is that in Fragment.php, $this->data
is merged with the result of parse_url($this->fragment)
. If parse_url returns false, array_merge returns null, and $this->data is null:
Line 112 in 87bb711
Hi,
While those work fine:
http://anil.blogspot.com.tr :: $purl->subdomain is "anil"
http://anil.blogspot.com :: $purl->subdomain is "anil"
Those domain extensions doesn't work:
http://anil.blogspot.co.uk :: $purl->subdomain is NULL
http://anil.blogspot.nl :: $purl->subdomain is NULL
http://anil.blogspot.in :: $purl->subdomain is NULL
Could be a bug.
Is there any way I can extend domain extensions list for Blogspot and allow those domain extensions too?
if i try to set an IP address as host name it give an InvalidArgument exception.
$url = 'http://www.google.com';
$url = new Url($url);
$url->set('host', '8.8.8.8');
now $url->getUrl() results in InvalidArgumentException
This commit d1cf27f was done after 1.0.0
which is quite confusing when upgradting form 0.0.10
. So a new 1.0.1
might be useful
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.