Skip to content
Extraits de code Groupes Projets
Valider f742e118 rédigé par bricebou's avatar bricebou
Parcourir les fichiers

feat: conversion des documents aux formats .doc, .docx, ou .html...

...en proposant diverses méthodes :
    - un exécutable libreoffice sur le serveur ;
    - un appel à un serveur de conversion externe ;
    - la librairie PHPWord (https://github.com/PHPOffice/PHPWord) dont les résultats ne sont pas forcément à la hauteur (du moins pour le moment).
parent 1c305bba
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 914 ajouts et 30 suppressions
......@@ -3,3 +3,4 @@ vendor/*
# Mais on veut tout de même notre autoloader
!vendor/composer/
!vendor/phpoffice/
<?php
use SpipContrib\Odt2Spip\Converter;
use SpipContrib\Odt2Spip\Utils\ConverterUtils;
use SpipContrib\Odt2Spip\Utils\FileUtils;
use SpipLeague\Bridge\Filesystem\Filesystem;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
require_once(_DIR_PLUGIN_ODT2SPIP . 'vendor/autoload.php');
/**
* Convertit un fichier dans un autre format en utilisant libreoffice
*
......@@ -15,40 +22,41 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* @return bool|string
*/
function action_api_convert_to_dist($fichier_source = null, $format = 'odt') {
$fs = new Filesystem();
// Définition du répertoire de travail et création si besoin
$workingDir = _DIR_TMP . 'libreoffice/';
$fs->mkdir($workingDir);
include_spip('inc/odt2spip');
include_spip('inc/convertir_avec_libreoffice');
include_spip('inc/flock');
// Instanciation du Converter
$method = ConverterUtils::getMethod();
$converter = Converter::getInstance($method);
// Si fichier passé en paramètre...
if ($fichier_source) {
$fichier = convertir_avec_libreoffice($fichier_source, $format);
return $fichier;
return $converter->convert($fichier_source, $workingDir);
}
// Tester l’autorisation d’accès
$key = _request('api_key');
if (!odt2spip_cle_autorisee($key)) {
spip_logger('odt2spip')->debug($key);
if (!ConverterUtils::checkApiKey($key)) {
return false;
}
// Récupérer le fichier posté
$fichier_source = odt2spip_deplacer_fichier_upload('file');
if (!$fichier_source) {
return false;
}
$fileUtils = new FileUtils();
try {
spip_logger('odt2spip')->info("Déplacement du fichier récupéré");
$fichier_source = $fileUtils->move($workingDir, 'file');
spip_logger('odt2spip')->info('Déplacement du fichier récupéré réussi : ' . $fichier_source);
// Convertir dans le format demandé
if (_request('arg')) {
$format = (string)_request('arg');
}
spip_log('Conversion API : ' . $fichier_source, 'odtspip.' . _LOG_INFO);
$fichier = convertir_avec_libreoffice($fichier_source, $format);
supprimer_fichier($fichier_source);
if (!$fichier) {
spip_logger('odt2spip')->info('Conversion via l\'API du fichier ' . $fichier_source);
$fichier = $converter->convert($fichier_source, $workingDir);
spip_logger('odt2spip')->info('Conversion via l\'API réussie du fichier ' . $fichier);
} catch (Exception) {
return false;
}
spip_log('Conversion réussie API : ' . $fichier, 'odtspip.' . _LOG_INFO);
// Envoyer le fichier
header('Content-Description: File Transfer');
......@@ -59,6 +67,10 @@ function action_api_convert_to_dist($fichier_source = null, $format = 'odt') {
header('Pragma: public');
header('Content-Length: ' . filesize($fichier));
readfile($fichier);
supprimer_fichier($fichier);
// Faire le ménage
$fs->remove($fichier_source);
$fs->remove($fichier);
exit;
}
\ No newline at end of file
}
......@@ -14,7 +14,8 @@
},
"require": {
"php": "^8.2",
"ext-dom": "*"
"ext-dom": "*",
"phpoffice/phpword": "^1.3"
},
"require-dev": {
"phpstan/phpstan": "^2.0",
......
......@@ -4,8 +4,170 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "22d003cea2db7d41a1344b7506a94871",
"packages": [],
"content-hash": "fb79a48ced922b576753e2d992c56a47",
"packages": [
{
"name": "phpoffice/math",
"version": "0.2.0",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/Math.git",
"reference": "fc2eb6d1a61b058d5dac77197059db30ee3c8329"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/Math/zipball/fc2eb6d1a61b058d5dac77197059db30ee3c8329",
"reference": "fc2eb6d1a61b058d5dac77197059db30ee3c8329",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xml": "*",
"php": "^7.1|^8.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
"phpunit/phpunit": "^7.0 || ^9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"PhpOffice\\Math\\": "src/Math/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Progi1984",
"homepage": "https://lefevre.dev"
}
],
"description": "Math - Manipulate Math Formula",
"homepage": "https://phpoffice.github.io/Math/",
"keywords": [
"MathML",
"officemathml",
"php"
],
"support": {
"issues": "https://github.com/PHPOffice/Math/issues",
"source": "https://github.com/PHPOffice/Math/tree/0.2.0"
},
"time": "2024-08-12T07:30:45+00:00"
},
{
"name": "phpoffice/phpword",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PHPWord.git",
"reference": "8392134ce4b5dba65130ba956231a1602b848b7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/8392134ce4b5dba65130ba956231a1602b848b7f",
"reference": "8392134ce4b5dba65130ba956231a1602b848b7f",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-json": "*",
"ext-xml": "*",
"php": "^7.1|^8.0",
"phpoffice/math": "^0.2"
},
"require-dev": {
"dompdf/dompdf": "^2.0",
"ext-gd": "*",
"ext-libxml": "*",
"ext-zip": "*",
"friendsofphp/php-cs-fixer": "^3.3",
"mpdf/mpdf": "^8.1",
"phpmd/phpmd": "^2.13",
"phpstan/phpstan-phpunit": "@stable",
"phpunit/phpunit": ">=7.0",
"symfony/process": "^4.4 || ^5.0",
"tecnickcom/tcpdf": "^6.5"
},
"suggest": {
"dompdf/dompdf": "Allows writing PDF",
"ext-gd2": "Allows adding images",
"ext-xmlwriter": "Allows writing OOXML and ODF",
"ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template",
"ext-zip": "Allows writing OOXML and ODF"
},
"type": "library",
"autoload": {
"psr-4": {
"PhpOffice\\PhpWord\\": "src/PhpWord"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0"
],
"authors": [
{
"name": "Mark Baker"
},
{
"name": "Gabriel Bull",
"email": "me@gabrielbull.com",
"homepage": "http://gabrielbull.com/"
},
{
"name": "Franck Lefevre",
"homepage": "https://rootslabs.net/blog/"
},
{
"name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org"
},
{
"name": "Roman Syroeshko",
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
},
{
"name": "Antoine de Troostembergh"
}
],
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)",
"homepage": "https://phpoffice.github.io/PHPWord/",
"keywords": [
"ISO IEC 29500",
"OOXML",
"Office Open XML",
"OpenDocument",
"OpenXML",
"PhpOffice",
"PhpWord",
"Rich Text Format",
"WordprocessingML",
"doc",
"docx",
"html",
"odf",
"odt",
"office",
"pdf",
"php",
"reader",
"rtf",
"template",
"template processor",
"word",
"writer"
],
"support": {
"issues": "https://github.com/PHPOffice/PHPWord/issues",
"source": "https://github.com/PHPOffice/PHPWord/tree/1.3.0"
},
"time": "2024-08-30T18:03:42+00:00"
}
],
"packages-dev": [
{
"name": "myclabs/deep-copy",
......
<?php
namespace SpipContrib\Odt2Spip;
use SpipContrib\Odt2Spip\Interfaces\ConverterInterface;
class Converter
{
private static $_instance;
public static function getInstance(string $method): ConverterInterface {
if (self::$_instance === null) {
$converter = 'SpipContrib\Odt2Spip\Converters\\' . $method . 'Converter';
self::$_instance = new $converter();
}
return self::$_instance;
}
}
<?php
/** @noinspection PhpComposerExtensionStubsInspection */
namespace SpipContrib\Odt2Spip\Converters;
use Exception;
use SpipContrib\Odt2Spip\Interfaces\ConverterInterface;
class ApiConverter implements ConverterInterface
{
/**
* @throws Exception
*/
public function convert(string $file, string $workingDir): string {
include_spip('inc/config');
$api_url = lire_config('odt2spip/serveur_api_url');
$api_key = lire_config('odt2spip/serveur_api_cle');
if (!$api_url or !$api_key) {
throw (new Exception(_T('odt2spip:erreur_api_conversion_non_configuree')));
}
$api_url = rtrim($api_url, '/') . '/convert_to.api/odt';
spip_logger('odt2spip')
->debug($api_url);
$post = [
'api_key' => $api_key,
'file' => curl_file_create(realpath($file)),
];
// Poster la requête et récupérer le contenu du fichier
// FIXME: idéalement il faudrait streamer le fichier retourné… mais comment ?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$content = curl_exec($ch);
curl_close($ch);
spip_logger('odt2spip')
->debug($content);
if (!$content) {
throw (new Exception(_T('odt2spip:erreur_api_conversion_echec')));
}
$fichier = realpath($workingDir) . DIRECTORY_SEPARATOR . pathinfo($file, PATHINFO_FILENAME) . '.odt';
if (file_put_contents($fichier, $content)) {
spip_logger('odt2spip')->debug('Fichier converti dans : ' . $fichier);
return $fichier;
}
throw (new Exception(_T('odt2spip:erreur_api_conversion_echec_ecriture')));
}
}
<?php
namespace SpipContrib\Odt2Spip\Converters;
use Exception;
use SpipContrib\Odt2Spip\Interfaces\ConverterInterface;
use SpipContrib\Odt2Spip\Utils\ConverterUtils;
use const PATHINFO_FILENAME;
class LibreofficeConverter implements ConverterInterface
{
public const APP_DEFAULT_PARAMS = '--headless --convert-to odt:writer8';
/**
* @throws Exception
*/
public function convert(string $file, string $workingDir): string {
$command = $this->buildCommand($file, $workingDir);
spip_logger('odt2spip')
->debug("Commande exécutée : '$command'");
exec($command, $output, $err);
$file = realpath($workingDir) . DIRECTORY_SEPARATOR . pathinfo($file, PATHINFO_FILENAME) . '.odt';
if (
$err || !file_exists($file)
) {
spip_logger('odt2spip')->debug($err ? "Erreur de conversion : $err" : "Le fichier $file n'existe pas");
throw (new Exception(_T('odt2spip:erreur_conversion_libreoffice')));
}
return $file;
}
private function buildCommand(string $file, string $workingDir): string {
if (defined('_LIBREOFFICE_PATH') && _LIBREOFFICE_PATH) {
$command = _LIBREOFFICE_PATH;
} else {
$command = ConverterUtils::getCommand('libreoffice');
}
$params = defined('_LIBREOFFICE_DEFAULT_PARAMS') ? _LIBREOFFICE_DEFAULT_PARAMS : static::APP_DEFAULT_PARAMS;
if ($params) {
$command .= ' ' . $params;
}
$command .= ' ' . str_replace(' ', '\ ', realpath($file));
$command .= ' --outdir ' . (_LIBREOFFICE_HOME ?? realpath($workingDir));
return $command;
}
}
<?php
namespace SpipContrib\Odt2Spip\Converters;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\IOFactory;
use SpipContrib\Odt2Spip\Interfaces\ConverterInterface;
class PhpWordConverter implements ConverterInterface
{
/**
* @throws Exception
*/
public function convert(string $file, string $workingDir): string {
$odt = $workingDir . pathinfo($file, PATHINFO_FILENAME) . '.odt';
$word = IOFactory::load($file);
$writer = IOFactory::createWriter($word, 'ODText');
$writer->save($odt);
if (!file_exists($odt)) {
throw (new Exception(_T('odt2spip:erreur_conversion_phpword@')));
}
return $odt;
}
}
......@@ -3,6 +3,7 @@
namespace SpipContrib\Odt2Spip;
use Exception;
use SpipContrib\Odt2Spip\Utils\ConverterUtils;
use SpipContrib\Odt2Spip\Utils\FileUtils;
class Handler
......@@ -23,8 +24,8 @@ class Handler
* @throws Exception
*/
public function handle(bool $keep = false, string $imageMode = 'image'): int {
$this->prepareFile();
$this->prepareFile();
include_spip('action/editer_objet');
include_spip('inc/config');
......@@ -80,8 +81,19 @@ class Handler
$utils = new FileUtils();
$this->workingDir = $utils->getWorkingDir();
$this->file = $utils->move($this->workingDir, $this->key);
// Si le fichier n'est pas au format OpenDocument, alors, on tente de le convertir
$extension = strtolower(pathinfo($this->file, PATHINFO_EXTENSION));
if ($extension !== 'odt') {
$method = ConverterUtils::getMethod();
if ($method) {
$converter = Converter::getInstance($method);
$this->file = $converter->convert($this->file, $this->workingDir);
}
}
$utils->unzip($this->file, $this->workingDir);
}
}
/**
* Identifier les images au sein du contenu et supprimer les images ne pouvant être récupérées
......
<?php
namespace SpipContrib\Odt2Spip\Interfaces;
interface ConverterInterface
{
public function convert(string $file, string $workingDir): string;
}
<?php
namespace SpipContrib\Odt2Spip\Utils;
class ConverterUtils
{
private static array $commands = [];
private static ?bool $isLocallyAvailable = null;
private static ?string $method = null;
public static function checkApiKey(string $key): bool {
include_spip('inc/config');
// récupérer la liste des clés
$keys = lire_config('odt2spip/authorized_keys');
$keys = explode("\n", trim($keys));
$keys = array_filter(array_map('trim', $keys));
$liste = [];
foreach ($keys as $line) {
list($k, $nom) = explode(':', $line, 2);
$liste[trim($k)] = trim($nom);
}
// tester si la clé est correcte
$ok = in_array($key, array_keys($liste));
if ($ok) {
spip_log('Cle autorisée du site : ' . $liste[$key], 'odtspip.' . _LOG_INFO);
} else {
spip_log('Cle invalide utilisée : ' . $key, 'odtspip.' . _LOG_INFO);
}
// maintenir un temps fixe d’exécution, si possible
if (function_exists('hash_equals')) {
hash_equals($key, $key);
}
return $ok;
}
public static function getCommand(string $command): string {
if (array_key_exists($command, self::$commands)) {
return self::$commands[$command];
}
if (function_exists('exec')) {
@exec('which libreoffice', $output, $err);
if (
!$err
&& is_array($output)
&& count($output)
&& $cmd = trim($output[0])
) {
spip_logger('odt2spip')->debug("Commande '$command' trouvée dans $cmd");
return self::$commands[$command] = $cmd;
}
spip_logger('odt2spip')
->debug("Commande '$command' introuvable sur ce serveur…");
} else {
spip_logger('odt2spip')->debug("La fonction 'exec' est désactivée sur ce serveur…");
}
return self::$commands[$command] ?? '';
}
public static function getMethod(): ?string {
if (self::$method === null) {
include_spip('inc/config');
spip_logger('odt2spip')
->debug(lire_config('odt2spip/serveur_api_url'));
if (self::isLocallyAvailable()) {
self::$method = 'Libreoffice';
} elseif (
function_exists('curl_file_create')
&& !empty(lire_config('odt2spip/serveur_api_url'))
&& !empty(lire_config('odt2spip/serveur_api_cle'))
) {
self::$method = 'Api';
} elseif ((int) lire_config('odt2spip/phpword')) {
self::$method = 'PhpWord';
}
}
spip_logger('odt2spip')
->debug('Méthode = ' . self::$method);
return self::$method;
}
private static function isLocallyAvailable(): ?bool {
if (self::$isLocallyAvailable === null) {
if (function_exists('exec')) {
if (defined('_LIBREOFFICE_PATH') && _LIBREOFFICE_PATH) {
self::$isLocallyAvailable = true;
} else {
self::$isLocallyAvailable = (bool) self::getCommand('libreoffice');
}
}
}
return self::$isLocallyAvailable;
}
}
......@@ -11,5 +11,7 @@ return array(
'SpipLeague\\Component\\Rector\\' => array($vendorDir . '/spip-league/rector/src', $vendorDir . '/spip-league/rector/rules'),
'SpipContrib\\Odt2Spip\\' => array($baseDir . '/src'),
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
'PhpOffice\\PhpWord\\' => array($vendorDir . '/phpoffice/phpword/src/PhpWord'),
'PhpOffice\\Math\\' => array($vendorDir . '/phpoffice/math/src/Math'),
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
);
......@@ -25,6 +25,8 @@ class ComposerStaticInit0dc68f83736829d02bafc39cacb2a308
'P' =>
array (
'PhpParser\\' => 10,
'PhpOffice\\PhpWord\\' => 18,
'PhpOffice\\Math\\' => 15,
),
'D' =>
array (
......@@ -54,6 +56,14 @@ class ComposerStaticInit0dc68f83736829d02bafc39cacb2a308
array (
0 => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser',
),
'PhpOffice\\PhpWord\\' =>
array (
0 => __DIR__ . '/..' . '/phpoffice/phpword/src/PhpWord',
),
'PhpOffice\\Math\\' =>
array (
0 => __DIR__ . '/..' . '/phpoffice/math/src/Math',
),
'DeepCopy\\' =>
array (
0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy',
......
......@@ -248,6 +248,173 @@
},
"install-path": "../phar-io/version"
},
{
"name": "phpoffice/math",
"version": "0.2.0",
"version_normalized": "0.2.0.0",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/Math.git",
"reference": "fc2eb6d1a61b058d5dac77197059db30ee3c8329"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/Math/zipball/fc2eb6d1a61b058d5dac77197059db30ee3c8329",
"reference": "fc2eb6d1a61b058d5dac77197059db30ee3c8329",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xml": "*",
"php": "^7.1|^8.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
"phpunit/phpunit": "^7.0 || ^9.0"
},
"time": "2024-08-12T07:30:45+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"PhpOffice\\Math\\": "src/Math/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Progi1984",
"homepage": "https://lefevre.dev"
}
],
"description": "Math - Manipulate Math Formula",
"homepage": "https://phpoffice.github.io/Math/",
"keywords": [
"MathML",
"officemathml",
"php"
],
"support": {
"issues": "https://github.com/PHPOffice/Math/issues",
"source": "https://github.com/PHPOffice/Math/tree/0.2.0"
},
"install-path": "../phpoffice/math"
},
{
"name": "phpoffice/phpword",
"version": "1.3.0",
"version_normalized": "1.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PHPWord.git",
"reference": "8392134ce4b5dba65130ba956231a1602b848b7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/8392134ce4b5dba65130ba956231a1602b848b7f",
"reference": "8392134ce4b5dba65130ba956231a1602b848b7f",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-json": "*",
"ext-xml": "*",
"php": "^7.1|^8.0",
"phpoffice/math": "^0.2"
},
"require-dev": {
"dompdf/dompdf": "^2.0",
"ext-gd": "*",
"ext-libxml": "*",
"ext-zip": "*",
"friendsofphp/php-cs-fixer": "^3.3",
"mpdf/mpdf": "^8.1",
"phpmd/phpmd": "^2.13",
"phpstan/phpstan-phpunit": "@stable",
"phpunit/phpunit": ">=7.0",
"symfony/process": "^4.4 || ^5.0",
"tecnickcom/tcpdf": "^6.5"
},
"suggest": {
"dompdf/dompdf": "Allows writing PDF",
"ext-gd2": "Allows adding images",
"ext-xmlwriter": "Allows writing OOXML and ODF",
"ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template",
"ext-zip": "Allows writing OOXML and ODF"
},
"time": "2024-08-30T18:03:42+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"PhpOffice\\PhpWord\\": "src/PhpWord"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0"
],
"authors": [
{
"name": "Mark Baker"
},
{
"name": "Gabriel Bull",
"email": "me@gabrielbull.com",
"homepage": "http://gabrielbull.com/"
},
{
"name": "Franck Lefevre",
"homepage": "https://rootslabs.net/blog/"
},
{
"name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org"
},
{
"name": "Roman Syroeshko",
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
},
{
"name": "Antoine de Troostembergh"
}
],
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)",
"homepage": "https://phpoffice.github.io/PHPWord/",
"keywords": [
"ISO IEC 29500",
"OOXML",
"Office Open XML",
"OpenDocument",
"OpenXML",
"PhpOffice",
"PhpWord",
"Rich Text Format",
"WordprocessingML",
"doc",
"docx",
"html",
"odf",
"odt",
"office",
"pdf",
"php",
"reader",
"rtf",
"template",
"template processor",
"word",
"writer"
],
"support": {
"issues": "https://github.com/PHPOffice/PHPWord/issues",
"source": "https://github.com/PHPOffice/PHPWord/tree/1.3.0"
},
"install-path": "../phpoffice/phpword"
},
{
"name": "phpstan/phpstan",
"version": "2.1.7",
......
......@@ -3,7 +3,7 @@
'name' => 'spip-contrib/odt2spip',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '5e6be7dfc025b83f194a4a6f60f80e8e45979edd',
'reference' => '22c52f14a23188c7e2bad71898cd1210e8594175',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......@@ -46,6 +46,24 @@
'aliases' => array(),
'dev_requirement' => true,
),
'phpoffice/math' => array(
'pretty_version' => '0.2.0',
'version' => '0.2.0.0',
'reference' => 'fc2eb6d1a61b058d5dac77197059db30ee3c8329',
'type' => 'library',
'install_path' => __DIR__ . '/../phpoffice/math',
'aliases' => array(),
'dev_requirement' => false,
),
'phpoffice/phpword' => array(
'pretty_version' => '1.3.0',
'version' => '1.3.0.0',
'reference' => '8392134ce4b5dba65130ba956231a1602b848b7f',
'type' => 'library',
'install_path' => __DIR__ . '/../phpoffice/phpword',
'aliases' => array(),
'dev_requirement' => false,
),
'phpstan/phpstan' => array(
'pretty_version' => '2.1.7',
'version' => '2.1.7.0',
......@@ -256,7 +274,7 @@
'spip-contrib/odt2spip' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '5e6be7dfc025b83f194a4a6f60f80e8e45979edd',
'reference' => '22c52f14a23188c7e2bad71898cd1210e8594175',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
\ No newline at end of file
name: Deploy
on:
push:
branches:
- master
pull_request:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
### MkDocs
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install Python Dependencies
run: pip install mkdocs-material autolink-references-mkdocs-plugin
- name: Build documentation
run: mkdocs build --site-dir public
### PHPUnit
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, xml
coverage: xdebug
- name: Create directory public/coverage
run: mkdir ./public/coverage
- name: Install PHP Dependencies
run: composer install --ansi --prefer-dist --no-interaction --no-progress
- name: Build Coverage Report
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit -c ./ --coverage-text --coverage-html ./public/coverage
### PHPDoc
- name: Create directory public/docs
run: mkdir ./public/docs
- name: Install PhpDocumentor
run: wget https://phpdoc.org/phpDocumentor.phar && chmod +x phpDocumentor.phar
- name: Build Documentation
run: ./phpDocumentor.phar run -d ./src -t ./public/docs
### Deploy
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
if: github.ref == 'refs/heads/master'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
\ No newline at end of file
name: PHP
on:
push:
branches:
- master
pull_request:
jobs:
php-cs-fixer:
name: PHP CS Fixer
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: xml
- uses: actions/checkout@v4
- name: Validate composer config
run: composer validate --strict
- name: Composer Install
run: composer global require friendsofphp/php-cs-fixer
- name: Add environment path
run: export PATH="$PATH:$HOME/.composer/vendor/bin"
- name: Run PHPCSFixer
run: php-cs-fixer fix --dry-run --diff
phpstan:
name: PHP Static Analysis
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: xml
- uses: actions/checkout@v4
- name: Composer Install
run: composer install --ansi --prefer-dist --no-interaction --no-progress
- name: Run phpstan
run: ./vendor/bin/phpstan analyse -c phpstan.neon.dist
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: xml
coverage: ${{ (matrix.php == '8.1') && 'xdebug' || 'none' }}
- uses: actions/checkout@v4
- name: Install dependencies
run: composer install --ansi --prefer-dist --no-interaction --no-progress
- name: Run PHPUnit
if: matrix.php != '8.1'
run: ./vendor/bin/phpunit -c phpunit.xml.dist
- name: Run PHPUnit (w CodeCoverage)
if: matrix.php == '8.1'
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/clover.xml
- name: Upload coverage results to Coveralls
if: matrix.php == '8.1'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
chmod +x php-coveralls.phar
php php-coveralls.phar --coverage_clover=build/clover.xml --json_path=build/coveralls-upload.json -vvv
roave-backwards-compatibility-check:
name: Roave Backwards Compatibility Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Check for BC breaks"
run: docker run -u $(id -u) -v $(pwd):/app nyholm/roave-bc-check-ga
.php_cs.cache
.php-cs-fixer.cache
.phpunit.cache
.phpunit.result.cache
composer.lock
phpDocumentor.phar
public/
vendor/
<?php
$config = new PhpCsFixer\Config();
$config
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'array_indentation' => true,
'cast_spaces' => [
'space' => 'single',
],
'combine_consecutive_issets' => true,
'concat_space' => [
'spacing' => 'one',
],
'error_suppression' => [
'mute_deprecation_error' => false,
'noise_remaining_usages' => false,
'noise_remaining_usages_exclude' => [],
],
'function_to_constant' => false,
'global_namespace_import' => true,
'method_chaining_indentation' => true,
'no_alias_functions' => false,
'no_superfluous_phpdoc_tags' => false,
'non_printable_character' => [
'use_escape_sequences_in_strings' => true,
],
'phpdoc_align' => [
'align' => 'left',
],
'phpdoc_summary' => false,
'protected_to_private' => false,
'self_accessor' => false,
'yoda_style' => false,
'single_line_throw' => false,
'no_alias_language_construct_call' => false,
])
->getFinder()
->in(__DIR__)
->exclude('vendor');
return $config;
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter