-
Notifications
You must be signed in to change notification settings - Fork 16
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
Support EDD #45
base: main
Are you sure you want to change the base?
Support EDD #45
Conversation
Hallo @drzraf! 👋🏻 The Gmail address you used in the commit is not registered here on GitHub. |
/** | ||
* Handle indirection process, like used by WP EDD | ||
* The "indirection" property can contain: | ||
* "http" and "ssl" object, as defined by https://github.com/composer/composer/blob/main/src/Composer/Util/Http/CurlDownloader.php | ||
* "parse": { | ||
* "format": "json" # only supported value | ||
* "key": # A string (or an object for specifying nested keys to fetch the package download URL from | ||
* } | ||
*/ | ||
public function fetchIndirection(PreFileDownloadEvent $event, string $url, array $extra): string | ||
{ | ||
$options = [ | ||
'http' => array_replace_recursive(['method' => 'GET'], $extra['indirection']['http'] ?? []), | ||
'ssl' => $extra['indirection']['ssl'] ?? [] | ||
]; | ||
|
||
$data = $event->getHttpDownloader()->get($url, $options); | ||
if ($extra['indirection']['parse']['format'] ?? false === 'json') { | ||
$response = $data->decodeJson(); | ||
$key = $extra['indirection']['parse']['key'] ?? false; | ||
if ($key) { | ||
// Look for a succession of (nested) keys within a recursive array (from the JSON) | ||
$jsonObj = $response; | ||
do { | ||
$index = is_string($key) ? $key : key($key); | ||
if (! isset($jsonObj[$index])) { | ||
break; | ||
} | ||
$jsonObj = $jsonObj[$index]; | ||
if (!is_array($key)) { | ||
break; | ||
} | ||
$key = $key[$index] ?? false; | ||
} while ($key); | ||
|
||
return is_array($jsonObj) ? json_encode($jsonObj) : $jsonObj; | ||
} | ||
|
||
// format=json but no key specified (!) | ||
return json_encode($response); | ||
} else { | ||
// raw HTML (future usage of regexp?) | ||
return $data->getBody(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* Handle indirection process, like used by WP EDD | |
* The "indirection" property can contain: | |
* "http" and "ssl" object, as defined by https://github.com/composer/composer/blob/main/src/Composer/Util/Http/CurlDownloader.php | |
* "parse": { | |
* "format": "json" # only supported value | |
* "key": # A string (or an object for specifying nested keys to fetch the package download URL from | |
* } | |
*/ | |
public function fetchIndirection(PreFileDownloadEvent $event, string $url, array $extra): string | |
{ | |
$options = [ | |
'http' => array_replace_recursive(['method' => 'GET'], $extra['indirection']['http'] ?? []), | |
'ssl' => $extra['indirection']['ssl'] ?? [] | |
]; | |
$data = $event->getHttpDownloader()->get($url, $options); | |
if ($extra['indirection']['parse']['format'] ?? false === 'json') { | |
$response = $data->decodeJson(); | |
$key = $extra['indirection']['parse']['key'] ?? false; | |
if ($key) { | |
// Look for a succession of (nested) keys within a recursive array (from the JSON) | |
$jsonObj = $response; | |
do { | |
$index = is_string($key) ? $key : key($key); | |
if (! isset($jsonObj[$index])) { | |
break; | |
} | |
$jsonObj = $jsonObj[$index]; | |
if (!is_array($key)) { | |
break; | |
} | |
$key = $key[$index] ?? false; | |
} while ($key); | |
return is_array($jsonObj) ? json_encode($jsonObj) : $jsonObj; | |
} | |
// format=json but no key specified (!) | |
return json_encode($response); | |
} else { | |
// raw HTML (future usage of regexp?) | |
return $data->getBody(); | |
} | |
} | |
/** | |
* Handle indirection process, like used by WP EDD | |
* | |
* The "indirection" property can contain: | |
* "http" and "ssl" object, as defined by https://github.com/composer/composer/blob/main/src/Composer/Util/Http/Curl | |
* "parse": { | |
* "format": "json" # only supported value | |
* "key": # A string (or an object for specifying nested keys to fetch the package download URL from | |
* } | |
*/ | |
public function fetchIndirection(PreFileDownloadEvent $event, string $url, array $extra): string | |
{ | |
$options = [ | |
'http' => array_replace_recursive(['method' => 'GET'], $extra['indirection']['http'] ?? []), | |
'ssl' => $extra['indirection']['ssl'] ?? [], | |
]; | |
$response = $event->getHttpDownloader()->get($url, $options); | |
if ($extra['indirection']['parse']['format'] ?? false !== 'json') { | |
// Raw HTML | |
// @TODO Future usage of regexp | |
return $response->getBody(); | |
} | |
$responseObject = $response->decodeJson(); | |
$key = $extra['indirection']['parse']['key'] ?? false; | |
if ($key === false) { | |
// format=json but no key specified | |
return json_encode($responseObject); | |
} | |
// Look for a succession of possibly nested keys within a recursive array from the JSON object | |
do { | |
$index = is_array($key) ? key($key) : $key; | |
if (! isset($responseObject[$index])) { | |
break; | |
} | |
// Go one level deeper | |
$responseObject = $responseObject[$index]; | |
if (! is_array($key)) { | |
break; | |
} | |
$key = $key[$index] ?? false; | |
} while (is_array($key) || is_string($key)); | |
return is_array($responseObject) ? json_encode($responseObject) : $responseObject; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What change is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does bail out early thus reducing indentations and making it easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I leave it 100% up to you.
Sounds like GH decided to drop my |
No. Not at all. This is just one of my policies. |
Hi @drzraf! Thank you for your pull request. I like the direction in which this is going. Here are some general considerations:
|
But if is that already the case if the extra property lives at the package-level ?
Neither do I, but would you tolerate a dependency on https://symfony.com/doc/current/components/property_access.html ?
But an URL without placeholder may still legitimately make use of this feature, isn't? |
Use a "dot" notation string instead of a multidimensional array to specify a key path. See: ffraenz#45 (comment) @ffraenz
Fix #22 by allowing a package URL indirection to take place.
PR supports:
May support out of the box (or with further tweaks):
User-Agent
, not tested, see$event->HttpDownloader
)$event->HttpDownloader
. Standard mechanism apply. May be possible out of the boxNot supported (but could be implemented)
Not supported:
curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, false)
Configuration:
This is the
extra
property (at the package-level):For nested keys, it could be
"key": {"foo": {"bar": "download_link"}}
A workflow is like:
activate_license
for a given website (only once)/?edd_action=activate_license&license=0123456789abcdf&name=package-slug&url=https%3A//my.domain.tld
dist.url
tohttps://package-provider.tld/edd_url?edd_action=get_version&license=0123456789abcdf&name=foobar&url=https%3A//my.domain.tld
(@junaidbhura? In case you think this PR, if generic enough, could make composer-wp-pro-plugins somehow redundant?)