Skip to content

Instantly share code, notes, and snippets.

@SebSept
Forked from PrestaEdit/composer.json
Created December 14, 2021 16:33
Show Gist options
  • Save SebSept/88ed2637c5b43279e0b7a030a2f99fdc to your computer and use it in GitHub Desktop.
Save SebSept/88ed2637c5b43279e0b7a030a2f99fdc to your computer and use it in GitHub Desktop.
PrestaShop Validator API (Example)
{
"name": "prestashop/validator",
"authors": [
{
"name": "Prestashop"
}
],
"require": {
"guzzlehttp/guzzle": "^7.0"
}
}
<?php
require_once __DIR__ . '/vendor/autoload.php';
CONST VALIDATOR_URL = 'https://validator.prestashop.com';
const VALIDATOR_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client = new \GuzzleHttp\Client([
'base_uri' => VALIDATOR_URL
]);
# If you want to validate a GitHub repository
$github_link = 'PrestaShop/ps_banner';
$github_branch = 'dev';
# As example,
$moduleName = 'modulename.zip';
$modulePath = 'https://localhost/'.$moduleName;
// Call validator
try {
$response = $client->post('/api/modules', [
'multipart' => [
# Use this part to validate a GitHub repository
/*
[
'name' => 'github_link',
'contents' => $github_link
],
[
'name' => 'github_branch',
'contents' => $github_branch,
],
*/
[
'name' => 'archive',
'contents' => file_get_contents($modulePath),
'filename' => $moduleName
],
[
'name' => 'key',
'contents' => VALIDATOR_API_KEY
]
]
]);
$stdResponse = json_decode($response->getBody()->getContents(), true);
} catch (\Throwable $th) {
die($th->getMessage());
}
# Results are an associate array with differents categories as Details, Errors, Optimizations, ...
var_dump($stdResponse);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment