Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
S
stats-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
stats-facil
Validations
0e03cf55
Valider
0e03cf55
rédigé
11 years ago
par
Thomas Steur
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
throw an exception in case a plugin contains a malformed json translation file
parent
7090ace9
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
core/Common.php
+35
-0
35 ajouts, 0 suppression
core/Common.php
core/Plugin/Manager.php
+24
-4
24 ajouts, 4 suppressions
core/Plugin/Manager.php
avec
59 ajouts
et
4 suppressions
core/Common.php
+
35
−
0
Voir le fichier @
0e03cf55
...
...
@@ -584,6 +584,41 @@ class Common
return
json_decode
(
$json
,
$assoc
);
}
/**
* Detects whether an error occurred during the last json encode/decode.
* @return bool
*/
public
static
function
hasJsonErrorOccurred
()
{
return
json_last_error
()
!=
JSON_ERROR_NONE
;
}
/**
* Returns a human readable error message in case an error occcurred during the last json encode/decode.
* Returns an empty string in case there was no error.
*
* @return string
*/
public
static
function
getLastJsonError
()
{
switch
(
json_last_error
())
{
case
JSON_ERROR_NONE
:
return
''
;
case
JSON_ERROR_DEPTH
:
return
'Maximum stack depth exceeded'
;
case
JSON_ERROR_STATE_MISMATCH
:
return
'Underflow or the modes mismatch'
;
case
JSON_ERROR_CTRL_CHAR
:
return
'Unexpected control character found'
;
case
JSON_ERROR_SYNTAX
:
return
'Syntax error, malformed JSON'
;
case
JSON_ERROR_UTF8
:
return
'Malformed UTF-8 characters, possibly incorrectly encoded'
;
}
return
'Unknown error'
;
}
/**
* Returns the list of parent classes for the given class.
*
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
core/Plugin/Manager.php
+
24
−
4
Voir le fichier @
0e03cf55
...
...
@@ -11,6 +11,7 @@
namespace
Piwik\Plugin
;
use
Piwik\Common
;
use
Piwik\Config
as
PiwikConfig
;
use
Piwik\EventDispatcher
;
use
Piwik\Filesystem
;
...
...
@@ -742,11 +743,9 @@ class Manager extends Singleton
$defaultEnglishLangPath
=
sprintf
(
$path
,
'en'
);
if
(
file_exists
(
$defaultLangPath
))
{
$data
=
file_get_contents
(
$defaultLangPath
);
$translations
=
json_decode
(
$data
,
true
);
$translations
=
$this
->
getTranslationsFromFile
(
$defaultLangPath
);
}
elseif
(
file_exists
(
$defaultEnglishLangPath
))
{
$data
=
file_get_contents
(
$defaultEnglishLangPath
);
$translations
=
json_decode
(
$data
,
true
);
$translations
=
$this
->
getTranslationsFromFile
(
$defaultEnglishLangPath
);
}
else
{
return
false
;
}
...
...
@@ -897,6 +896,27 @@ class Manager extends Singleton
}
}
}
/**
* @param string $pathToTranslationFile
* @throws \Exception
* @return mixed
*/
private
function
getTranslationsFromFile
(
$pathToTranslationFile
)
{
$data
=
file_get_contents
(
$pathToTranslationFile
);
$translations
=
json_decode
(
$data
,
true
);
if
(
is_null
(
$translations
)
&&
Common
::
hasJsonErrorOccurred
())
{
$jsonError
=
Common
::
getLastJsonError
();
$message
=
sprintf
(
'Not able to load translation file %s: %s'
,
$pathToTranslationFile
,
$jsonError
);
throw
new
\Exception
(
$message
);
}
return
$translations
;
}
}
/**
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter