Browse Source

feat(spip_loader): API v1 (stable) et v2 (expérimentale)

merge-requests/17/head
James 1 year ago
parent
commit
bd9394f10c
  1. 3
      CHANGELOG
  2. 13
      README.md
  3. 28
      action/api_spip_loader.php
  4. 25
      modeles/supportedversions_spiploaderlist_1.html
  5. 27
      modeles/supportedversions_spiploaderlist_2.html
  6. 1
      phpcs.xml.dist
  7. 2
      phpstan.neon.dist
  8. 5
      spip_loader_list.json.html
  9. 12
      supportedversions_fonctions.php
  10. 4
      supportedversions_options.php
  11. 45
      tests/SpipLoaderApiTest.php
  12. 15
      tests/sdk.php

3
CHANGELOG

@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- releases upgrades (SPIP 4.0.0-beta)
- `<supportedversions|spiploaderlist_X>` models (v1 and experimental v2)
- `spip_loader_list.json` page
- `spip_loader.api` pages for apache httpd server with rewrite mode and `.htaccess` default file behaviour
## [0.5.0] - 2021-05-19

13
README.md

@ -18,6 +18,7 @@ SPIP Plugin backport of [PHP Supported Versions](http://php.net/supported-versio
- `<supportedversions|release_notes>`: list of releases by date
- `<supportedversions|pre_releases>` : list of pre-releases in JSON
- `<supportedversions|stable>` : Gives informations of the last stable version released with `info` parameter (version, date or url)
- `<supportedversions|spiploaderlist_X>` : JSON for `spip_loader.php` where X is the API version.
## Filters
@ -32,6 +33,12 @@ Calling `/spip.php?page=releases.json` renders a JSON formatted of releases.
Calling `/spip.php?page=pre_releases.json` renders a JSON formatted of alpha, beta and RC pre-releases.
Calling `/spip.php?page=dev.json` renders a JSON formatted of development branches.
Calling `/spip.php?page=spip_loader_list.json` renders a JSON formatted for `spip_loader.php` purpose. It accepts a parameter `api` (defaults to 1).
Calling `/spip_loader.api` or `/spip_loader.api/1` for apache httpd server with rewrite mode and `.htaccess` default file exposes the `spip_loader_list.json` JSON. First argument, like `/1` is the `api` parameter.
## .htaccess
```apache
@ -52,6 +59,12 @@ RewriteRule ^pre_releases\.json$ spip.php?page=pre_releases.json [QSA,L]
and call : `/pre_releases.json`
```apache
RewriteRule ^spip-dev/INSTALL/spip_loader_list.json$ spip.php?page=spip_loader_list.json [QSA,L]
```
and call : `/spip-dev/INSTALL/spip_loader_list.json` or `/spip-dev/INSTALL/spip_loader_list.json?api=2` for experimental purpose
## Thanks
- Hanjo for the Dutch translation

28
action/api_spip_loader.php

@ -0,0 +1,28 @@
<?php
// spip_loader API
/**
* Action de consultation de l'API pour le script spip_loader.
*
* @codeCoverageIgnore
*/
function action_api_spip_loader_dist(): void {
include_spip('supportedversions_fonctions');
$arg = _request('arg');
$arg = explode('/', $arg);
$api = reset($arg);
$api = intval($api) ?: SupportedVersions::spipLoaderApi();
$reponse = ['api' => $api];
$modele = recuperer_fond('modeles/supportedversions_spiploaderlist_'.$api);
if ($modele) {
$reponse['versions'] = json_decode($modele, true);
}
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
echo json_encode($reponse);
exit(0);
}

25
modeles/supportedversions_spiploaderlist_1.html

@ -0,0 +1,25 @@
#SET{list, #ARRAY{dev,spip/dev/spip-master.zip}}
<BOUCLE_pre_releases(DATA){source json, #CHEMIN{data/pre_releases.json}}{branch=#VAL{future}|SupportedVersions::getBranchesFromState|table_valeur{0/branch}}>
<BOUCLE_releases(DATA){source table, #PRE_RELEASES}{par released_at}{inverse}{0,1}>
<BOUCLE_download(DATA){source table, #DOWNLOAD}>#SET{file, #URL|replace{https://files.spip.net/}}</BOUCLE_download>
#SET{list, #GET{list}|array_merge{#ARRAY{#VERSION, #GET{file}}}}
</BOUCLE_releases>
</BOUCLE_pre_releases>
<BOUCLE_stable(DATA){source table, #VAL{stable}|SupportedVersions::getBranchesFromState}{par last_date_release}{inverse}{0,1}>
<BOUCLE_release_stable(DATA){source table, #RELEASES}{version=#LAST_VERSION_RELEASE}>
<BOUCLE_download_stable(DATA){source table, #DOWNLOAD}>
#SET{file, #URL|replace{https://files.spip.net/}}
</BOUCLE_download_stable>
#SET{list, #GET{list}|array_merge{#ARRAY{#VERSION, #GET{file}}}}
</BOUCLE_release_stable>
</BOUCLE_stable>
<BOUCLE_security(DATA){source table, #VAL{security}|SupportedVersions::getBranchesFromState}{par last_date_release}{inverse}{0,1}>
<BOUCLE_release_security(DATA){source table, #RELEASES}{version=#LAST_VERSION_RELEASE}>
<BOUCLE_download_security(DATA){source table, #DOWNLOAD}>
#SET{file, #URL|replace{https://files.spip.net/}}
</BOUCLE_download_security>
#SET{list, #GET{list}|array_merge{#ARRAY{#VERSION, #GET{file}}}}
</BOUCLE_release_security>
</BOUCLE_security>
[(#GET{list}|json_encode)]
#FILTRE{trim}

27
modeles/supportedversions_spiploaderlist_2.html

@ -0,0 +1,27 @@
#SET{list, #ARRAY{dev, #ARRAY{url, https://files.spip.net/spip/dev/spip-master.zip, php, #LISTE{7.3,7.4,8.0}}}
<BOUCLE_pre_releases(DATA){source json, #CHEMIN{data/pre_releases.json}}{branch=#VAL{future}|SupportedVersions::getBranchesFromState|table_valeur{0/branch}}>
<BOUCLE_releases(DATA){source table, #PRE_RELEASES}{par released_at}{inverse}{0,1}>
<BOUCLE_download(DATA){source table, #DOWNLOAD}>
#SET{release, #ARRAY{url, #URL, php, #VERSION|SupportedVersions::getBranchValues|table_valeur{php}}}
</BOUCLE_download>
#SET{list, #GET{list}|array_merge{#ARRAY{#VERSION, #GET{release}}}}
</BOUCLE_releases>
</BOUCLE_pre_releases>
<BOUCLE_stable(DATA){source table, #VAL{stable}|SupportedVersions::getBranchesFromState}{par last_date_release}{inverse}{0,1}>
<BOUCLE_release_stable(DATA){source table, #RELEASES}{version=#LAST_VERSION_RELEASE}>
<BOUCLE_download_stable(DATA){source table, #DOWNLOAD}>
#SET{release, #ARRAY{url, #URL, php, #VERSION|SupportedVersions::getBranchValues|table_valeur{php}}}
</BOUCLE_download_stable>
#SET{list, #GET{list}|array_merge{#ARRAY{#VERSION, #GET{release}}}}
</BOUCLE_release_stable>
</BOUCLE_stable>
<BOUCLE_security(DATA){source table, #VAL{security}|SupportedVersions::getBranchesFromState}{par last_date_release}{inverse}{0,1}>
<BOUCLE_release_security(DATA){source table, #RELEASES}{version=#LAST_VERSION_RELEASE}>
<BOUCLE_download_security(DATA){source table, #DOWNLOAD}>
#SET{release, #ARRAY{url, #URL, php, #VERSION|SupportedVersions::getBranchValues|table_valeur{php}}}
</BOUCLE_download_security>
#SET{list, #GET{list}|array_merge{#ARRAY{#VERSION, #GET{release}}}}
</BOUCLE_release_security>
</BOUCLE_security>
[(#GET{list}|json_encode)]
#FILTRE{trim}

1
phpcs.xml.dist

@ -63,4 +63,5 @@
<arg name="report-checkstyle" value="php_cs.xml"/>
<arg name="report-full" value="php_cs.txt"/>
<arg name="report-summary"/>
<arg value="s"/>
</ruleset>

2
phpstan.neon.dist

@ -6,3 +6,5 @@ parameters:
level: 8
paths:
- ./
bootstrapFiles:
- tests/bootstrap.php

5
spip_loader_list.json.html

@ -0,0 +1,5 @@
#HTTP_HEADER{Content-Type: application/json}#HTTP_HEADER{Access-Control-Allow-Origin: *}[
{
"api": (#ENV{api}|intval|sinon{#SUPPORTED_VERSIONS{spip_loader_api_default}})[,
"versions": (#MODELE{supportedversions_spiploaderlist_#ENV{api}|intval|sinon{#SUPPORTED_VERSIONS{spip_loader_api_default}}})]
}]

12
supportedversions_fonctions.php

@ -727,4 +727,16 @@ class SupportedVersions
return $state;
}
//spip_loader API Part
public static function spipLoaderApi():int {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
return intval(self::$config['spip_loader_api_default'] ?? 0);
}
}

4
supportedversions_options.php

@ -2,6 +2,10 @@
// Sizing & Color constants.
$GLOBALS['supportedversions'] = [
/**
* Version de l'API pour le script spip_loader.php
*/
'spip_loader_api_default' => 1,
/**
* Partie mise en forme du calendrier au format SVG en pixels.
*

45
tests/SpipLoaderApiTest.php

@ -0,0 +1,45 @@
<?php
namespace JamesRezo\SupportedVersions\Test;
/**
* @covers \SupportedVersions
*/
class SpipLoaderApiTest extends TestCase
{
public function dataSpipLoaderApi()
{
return [
'No parameter' => [
0,
$this->calendarConfig,
],
'Malformed parameter' => [
0,
['spip_loader_api_default' => 'test'],
],
'Nominal parameter' => [
1,
['spip_loader_api_default' => 1],
],
];
}
/**
* @group api
* @dataProvider dataSpipLoaderApi
*/
public function testSpipLoaderApi($expected, $config)
{
//Given
SupportedVersions::setConfig(
$config,
);
//When
$actual = SupportedVersions::spipLoaderApi();
//Then
$this->assertEquals($expected, $actual);
}
}

15
tests/sdk.php

@ -11,3 +11,18 @@ function balise_ENV_dist($p, $src = '')
return $p;
}
function include_spip($fileName)
{
}
function _request($arg)
{
}
function recuperer_fond($fond)
{
}

Loading…
Cancel
Save