Browse Source

Refactoring du plugin YAML:

- mise à jour de la librairie sfyaml. sfyaml passe de 1.0.0 (à priori) à 1.0.6 (dernière version possible car plus maintenue). Les améliorations faites pour textwheel ont été reportées dans cette nouvelle version.
- mise à jour de la librairie spyc. spyc passe de 0.4.5 à 0.6.2. Contrairement à la branche v1 il est possible d'utiliser cette librairie qui est rapide et qui fonctionne très bien sur un ensemble conséquent d'écritures YAML.
- ajout de la nouvelle librairie symfony/yaml dans sa version la plus récente 4.2.
- ajout de la librairie libYAML. En fait, libYAML est une extension PECL à installer sur le serveur. Une fois installée il est possible de l'activer par l'API du plugin YAML. C'est la librairie la plus rapide et de loin!
Le choix de la librairie se fait par la constante _LIB_YAML mais peut être écrasé par une option d'appel de l'API du plugin.
La version PHP 4 a été supprimée et le plugin est compatible SPIP 3. Néanmoins, il faut à minima un PHP 5.3.3. La librairie symfony/yaml requiert PHP 7.1. L'extension PECL libYAML nécessite PHP 7 en v2 et PHP 5.3 en v1.
Ajout de démos et de fichiers de tests YAML qui permettent de visualiser les cas non supportés par chacune des librairies.
svn/root/tags/v2.0.11
eric@smellup.net 4 years ago
parent
commit
17c3860c72
  1. 6
      .gitattributes
  2. 3
      composer.json
  3. 64
      composer.lock
  4. 49
      demo/inc-test_inclure.yaml
  5. 222
      demo/libyaml.yaml
  6. 222
      demo/sfyaml.yaml
  7. 219
      demo/spyc.yaml
  8. 222
      demo/symfony.yaml
  9. 18
      demo/test_inclure.yaml
  10. 27
      demo/yaml.html
  11. 96
      demo/yaml_fonctions.php
  12. 9
      experimental/README
  13. 5
      experimental/yaml.html
  14. 17
      experimental/yaml_fonctions.php
  15. 192
      inc/yaml.php
  16. 54
      inc/yaml_libyaml.php
  17. 75
      inc/yaml_sfyaml.php
  18. 53
      inc/yaml_spyc.php
  19. 76
      inc/yaml_symfony.php
  20. 8
      paquet.xml
  21. 19
      plugin.xml
  22. 3
      sfyaml/sfYaml.php
  23. 101
      sfyaml/sfYamlInline.php
  24. 126
      sfyaml/sfYamlParser.php
  25. 2
      vendor/autoload.php
  26. 1
      vendor/composer/autoload_files.php
  27. 14
      vendor/composer/autoload_real.php
  28. 7
      vendor/composer/autoload_static.php
  29. 66
      vendor/composer/installed.json
  30. 21
      vendor/mustangostang/spyc/COPYING
  31. 30
      vendor/mustangostang/spyc/README.md
  32. 273
      vendor/mustangostang/spyc/Spyc.php
  33. 30
      vendor/mustangostang/spyc/composer.json
  34. 25
      vendor/mustangostang/spyc/examples/yaml-dump.php
  35. 21
      vendor/mustangostang/spyc/examples/yaml-load.php
  36. 17
      vendor/mustangostang/spyc/php4/5to4.php
  37. 3
      vendor/mustangostang/spyc/php4/spyc.php4
  38. 162
      vendor/mustangostang/spyc/php4/test.php4
  39. 219
      vendor/mustangostang/spyc/spyc.yaml
  40. 196
      vendor/mustangostang/spyc/tests/DumpTest.php
  41. 70
      vendor/mustangostang/spyc/tests/IndentTest.php
  42. 19
      vendor/mustangostang/spyc/tests/LoadTest.php
  43. 401
      vendor/mustangostang/spyc/tests/ParseTest.php
  44. 78
      vendor/mustangostang/spyc/tests/RoundTripTest.php
  45. 3
      vendor/mustangostang/spyc/tests/comments.yaml
  46. 2
      vendor/mustangostang/spyc/tests/failing1.yaml
  47. 70
      vendor/mustangostang/spyc/tests/indent_1.yaml
  48. 8
      vendor/mustangostang/spyc/tests/quotes.yaml
  49. 2
      vendor/symfony/yaml/composer.json
  50. 4
      yaml_fonctions.php

6
.gitattributes vendored

@ -1,8 +1,5 @@
* text=auto !eol
demo/iter_data_yaml.html -text
experimental/README -text
experimental/yaml.html -text
experimental/yaml_fonctions.php -text
inc/yaml.php -text
inc/yaml_sfyaml.php -text
inc/yaml_to_array.php -text
@ -17,13 +14,10 @@ lang/paquet-yaml_pt_br.php -text
lang/paquet-yaml_ru.php -text
lang/paquet-yaml_sk.php -text
/paquet.xml -text
/plugin.xml -text
sfyaml/sfYaml.php -text
sfyaml/sfYamlDumper.php -text
sfyaml/sfYamlInline.php -text
sfyaml/sfYamlParser.php -text
spyc/spyc-php4.php -text
spyc/spyc.php -text
vendor/symfony/yaml/Tests/Fixtures/arrow.gif -text
/yaml.png -text
/yaml_fonctions.php -text

3
composer.json

@ -1,5 +1,6 @@
{
"require": {
"symfony/yaml": "^4.0"
"symfony/yaml": "^4.1",
"mustangostang/spyc": "^0.6.2"
}
}

64
composer.lock generated

@ -4,8 +4,58 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fb52181affa40fc3712bea49df08062e",
"content-hash": "32b90cc729ca956d54b6eb9ab0cd8044",
"packages": [
{
"name": "mustangostang/spyc",
"version": "0.6.2",
"source": {
"type": "git",
"url": "https://github.com/mustangostang/spyc.git",
"reference": "23c35ae854d835f2d7bcc3e3ad743d7e57a8c14d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mustangostang/spyc/zipball/23c35ae854d835f2d7bcc3e3ad743d7e57a8c14d",
"reference": "23c35ae854d835f2d7bcc3e3ad743d7e57a8c14d",
"shasum": ""
},
"require": {
"php": ">=5.3.1"
},
"require-dev": {
"phpunit/phpunit": "4.3.*@dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.5.x-dev"
}
},
"autoload": {
"files": [
"Spyc.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "mustangostang",
"email": "vlad.andersen@gmail.com"
}
],
"description": "A simple YAML loader/dumper class for PHP",
"homepage": "https://github.com/mustangostang/spyc/",
"keywords": [
"spyc",
"yaml",
"yml"
],
"time": "2017-02-24T16:06:33+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.8.0",
@ -63,16 +113,16 @@
},
{
"name": "symfony/yaml",
"version": "v4.0.11",
"version": "v4.1.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "048b1be5fb96e73ff1d065f5e7e23f84415ac907"
"reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/048b1be5fb96e73ff1d065f5e7e23f84415ac907",
"reference": "048b1be5fb96e73ff1d065f5e7e23f84415ac907",
"url": "https://api.github.com/repos/symfony/yaml/zipball/80e4bfa9685fc4a09acc4a857ec16974a9cd944e",
"reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e",
"shasum": ""
},
"require": {
@ -91,7 +141,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "4.1-dev"
}
},
"autoload": {
@ -118,7 +168,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2018-05-07T07:12:24+00:00"
"time": "2018-05-30T07:26:09+00:00"
}
],
"packages-dev": [],

49
demo/inc-test_inclure.yaml

@ -0,0 +1,49 @@
-
saisie: 'selection_selon_plugin'
options:
nom: 'branche'
label: '<:aveline:label_liste_articles:>'
defaut: 'tous'
cacher_option_intro: 'oui'
datas:
tous: '<:aveline:item_articles_tous:>'
meme_rubrique: '<:aveline:item_meme_rubrique:>'
meme_rubrique_indirects: '<:aveline:item_meme_rubrique_indirects:>'
meme_rubrique_complete: '<:aveline:item_meme_rubrique_complete:>'
rubrique_specifique: '<:aveline:item_rubrique_specifique:>'
rubrique_specifique_indirects: '<:aveline:item_rubrique_specifique_indirects:>'
rubrique_specifique_complete: '<:aveline:item_rubrique_specifique_complete:>'
branche_actuelle: '<:aveline:item_branche_actuelle:>'
branche_complete: '<:aveline:item_branche_complete:>'
branche_specifique: '<:aveline:item_branche_specifique:>'
branche_specifique_complete: '<:aveline:item_branche_specifique_complete:>'
meme_secteur: '<:aveline:item_meme_secteur:>'
secteur_specifique: '<:aveline:item_secteur_specifique:>'
datas-necessite:
meme_rubrique_indirects: 'polyhier'
meme_rubrique_complete: 'polyhier'
rubrique_specifique_indirects: 'polyhier'
rubrique_specifique_complete: 'polyhier'
branche_complete: 'polyhier'
branche_specifique_complete: 'polyhier'
-
saisie: 'selecteur_rubrique'
options:
nom: 'rubrique_specifique'
label: '<:aveline:label_rubrique_specifique:>'
multiple: 'oui'
afficher_si: '@branche@ == "rubrique_specifique" | @branche@ == "rubrique_specifique_complete" | @branche@ == "rubrique_specifique_indirects"'
-
saisie: 'selecteur_rubrique'
options:
nom: 'branche_specifique'
label: '<:aveline:label_branche_specifique:>'
multiple: 'oui'
afficher_si: '@branche@ == "branche_specifique" | @branche@ == "branche_specifique_complete"'
-
saisie: 'secteur'
options:
nom: 'secteur_specifique'
label: '<:aveline:label_secteur_specifique:>'
multiple: 'oui'
afficher_si: '@branche@ == "secteur_specifique"'

222
demo/libyaml.yaml

@ -0,0 +1,222 @@
#
# S P Y C
# a simple php yaml class
#
# authors: [vlad andersen (vlad.andersen@gmail.com), chris wanstrath (chris@ozmm.org)]
# websites: [http://www.yaml.org, http://spyc.sourceforge.net/]
# license: [MIT License, http://www.opensource.org/licenses/mit-license.php]
# copyright: (c) 2005-2006 Chris Wanstrath, 2006-2014 Vlad Andersen
#
# spyc.yaml - A file containing the YAML that Spyc understands.
#
# ----------------------------------------------------------------------------------------
# Tests pour la librairie libYAML : les cas qui ne fonctionnent pas sont mis en commentaire
---
# Mappings - with proper types
String: Anyone's name, really.
Int: 13
BadHex: f0xf3
Hex: 0xf3
True: true
False: false
Zero: 0
Null: NULL
NotNull: 'null'
NotTrue: 'y'
NotBoolTrue: 'true'
NotInt: '5'
Float: 5.34
Negative: -90
SmallFloat: 0.7
NewLine: \n
QuotedNewLine: "\n"
# A sequence
#- PHP Class
#- Basic YAML Loader
#- Very Basic YAML Dumper
# A sequence of a sequence
#-
# - YAML is so easy to learn.
# - Your config files will never be the same.
# Sequence of mappings
#-
# cpu: 1.5ghz
# ram: 1 gig
# os : os x 10.4.1
# Mapped sequence
domains:
- yaml.org
- php.net
# A sequence like this.
#- program: Adium
# platform: OS X
# type: Chat Client
# A folded block as a mapped value
no time: >
There isn't any time
for your tricks!
Do you understand?
# A literal block as a mapped value
some time: |
There is nothing but time
for your tricks.
# Crazy combinations
databases:
- name: spartan
notes:
- Needs to be backed up
- Needs to be normalized
type: mysql
# You can be a bit tricky
"if: you'd": like
# Inline sequences
#- [One, Two, Three, Four]
# Nested Inline Sequences
#- [One, [Two, And, Three], Four, Five]
# Nested Nested Inline Sequences
#- [This, [Is, Getting, [Ridiculous, Guys]], Seriously, [Show, Mercy]]
# Inline mappings
#- {name: chris, age: young, brand: lucky strike}
# Nested inline mappings
#- {name: mark, age: older than chris, brand: [marlboro, lucky strike]}
# References -- they're shaky, but functional
dynamic languages: &DLANGS
- Perl
- Python
- PHP
- Ruby
compiled languages: &CLANGS
- C/C++
- Java
all languages:
- *DLANGS
- *CLANGS
# Added in .2.2: Escaped quotes
#- you know, this shouldn't work. but it does.
#- 'that''s my value.'
#- 'again, that\'s my value.'
#- "here's to \"quotes\", boss."
# added in .2.3
#- {name: "Foo, Bar's", age: 20}
# Added in .2.4: bug [ 1418193 ] Quote Values in Nested Arrays
#- [a, ['1', "2"], b]
# Add in .5.2: Quoted new line values.
#- "First line\nSecond line\nThird line"
# Added in .2.4: malformed YAML
#all
# javascripts: [dom1.js, dom.js]
# Added in .2
1040: Ooo, a numeric key! # And working comments? Wow! Colons in comments: a menace (0.3).
hash_1: Hash #and a comment
hash_2: "Hash #and a comment"
"hash#3": "Hash (#) can appear in key too"
float_test: 1.0
float_test_with_quotes: '1.0'
float_inverse_test: 001
a_really_large_number: 115792089237316195423570985008687907853269984665640564039457584007913129639936 # 2^256
int array: [ 1, 2, 3 ]
array on several lines:
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
morelesskey: "<value>"
array_of_zero: [0]
sophisticated_array_of_zero: {rx: {tx: [0]} }
switches:
- { row: 0, col: 0, func: {tx: [0, 1]} }
empty_sequence: [ ]
empty_hash: { }
special_characters: "[{]]{{]]"
asterisks: "*"
#empty_key:
# :
# key: value
trailing_colon: "foo:"
multiline_items:
- type: SomeItem
values: [blah, blah, blah,
blah]
ints: [2, 54, 12,
2143]
many_lines: |
A quick
fox
jumped
over
a lazy
dog
werte:
1: nummer 1
0: Stunde 0
noindent_records:
- record1: value1
- record2: value2
"a:1": [1000]
"a:2":
- 2000
a:3: [3000]
complex_unquoted_key:
a:b:''test': value
array with commas:
["0","1"]
invoice: ["Something", "", '', "Something else"]
quotes: ['Something', "Nothing", 'Anything', "Thing"]
# [Endloop]
endloop: |
Does this line in the end indeed make Spyc go to an infinite loop?

222
demo/sfyaml.yaml

@ -0,0 +1,222 @@
#
# S P Y C
# a simple php yaml class
#
# authors: [vlad andersen (vlad.andersen@gmail.com), chris wanstrath (chris@ozmm.org)]
# websites: [http://www.yaml.org, http://spyc.sourceforge.net/]
# license: [MIT License, http://www.opensource.org/licenses/mit-license.php]
# copyright: (c) 2005-2006 Chris Wanstrath, 2006-2014 Vlad Andersen
#
# spyc.yaml - A file containing the YAML that Spyc understands.
#
# ----------------------------------------------------------------------------------------
# Tests pour la librairie sfyaml : les cas qui ne fonctionnent pas sont mis en commentaire
#---
# Mappings - with proper types
String: Anyone's name, really.
Int: 13
BadHex: f0xf3
Hex: 0xf3
True: true
False: false
Zero: 0
Null: NULL
NotNull: 'null'
NotTrue: 'y'
NotBoolTrue: 'true'
NotInt: '5'
Float: 5.34
Negative: -90
SmallFloat: 0.7
NewLine: \n
QuotedNewLine: "\n"
# A sequence
- PHP Class
- Basic YAML Loader
- Very Basic YAML Dumper
# A sequence of a sequence
-
- YAML is so easy to learn.
- Your config files will never be the same.
# Sequence of mappings
-
cpu: 1.5ghz
ram: 1 gig
os : os x 10.4.1
# Mapped sequence
domains:
- yaml.org
- php.net
# A sequence like this.
- program: Adium
platform: OS X
type: Chat Client
# A folded block as a mapped value
no time: >
There isn't any time
for your tricks!
Do you understand?
# A literal block as a mapped value
some time: |
There is nothing but time
for your tricks.
# Crazy combinations
databases:
- name: spartan
notes:
- Needs to be backed up
- Needs to be normalized
type: mysql
# You can be a bit tricky
"if: you'd": like
# Inline sequences
- [One, Two, Three, Four]
# Nested Inline Sequences
- [One, [Two, And, Three], Four, Five]
# Nested Nested Inline Sequences
- [This, [Is, Getting, [Ridiculous, Guys]], Seriously, [Show, Mercy]]
# Inline mappings
- {name: chris, age: young, brand: lucky strike}
# Nested inline mappings
- {name: mark, age: older than chris, brand: [marlboro, lucky strike]}
# References -- they're shaky, but functional
dynamic languages: &DLANGS
- Perl
- Python
- PHP
- Ruby
compiled languages: &CLANGS
- C/C++
- Java
all languages:
- *DLANGS
- *CLANGS
# Added in .2.2: Escaped quotes
- you know, this shouldn't work. but it does.
- 'that''s my value.'
- 'again, that\'s my value.'
- "here's to \"quotes\", boss."
# added in .2.3
- {name: "Foo, Bar's", age: 20}
# Added in .2.4: bug [ 1418193 ] Quote Values in Nested Arrays
- [a, ['1', "2"], b]
# Add in .5.2: Quoted new line values.
- "First line\nSecond line\nThird line"
# Added in .2.4: malformed YAML
#all
# javascripts: [dom1.js, dom.js]
# Added in .2
1040: Ooo, a numeric key! # And working comments? Wow! Colons in comments: a menace (0.3).
hash_1: Hash #and a comment
hash_2: "Hash #and a comment"
"hash#3": "Hash (#) can appear in key too"
float_test: 1.0
float_test_with_quotes: '1.0'
float_inverse_test: 001
a_really_large_number: 115792089237316195423570985008687907853269984665640564039457584007913129639936 # 2^256
int array: [ 1, 2, 3 ]
#array on several lines:
# [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
# 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
morelesskey: "<value>"
array_of_zero: [0]
sophisticated_array_of_zero: {rx: {tx: [0]} }
switches:
- { row: 0, col: 0, func: {tx: [0, 1]} }
empty_sequence: [ ]
empty_hash: { }
special_characters: "[{]]{{]]"
asterisks: "*"
#empty_key:
# :
# key: value
trailing_colon: "foo:"
#multiline_items:
# - type: SomeItem
# values: [blah, blah, blah,
# blah]
# ints: [2, 54, 12,
# 2143]
many_lines: |
A quick
fox
jumped
over
a lazy
dog
werte:
1: nummer 1
0: Stunde 0
noindent_records:
- record1: value1
- record2: value2
"a:1": [1000]
"a:2":
- 2000
a:3: [3000]
complex_unquoted_key:
a:b:''test': value
array with commas:
["0","1"]
invoice: ["Something", "", '', "Something else"]
quotes: ['Something', "Nothing", 'Anything', "Thing"]
# [Endloop]
endloop: |
Does this line in the end indeed make Spyc go to an infinite loop?

219
demo/spyc.yaml

@ -0,0 +1,219 @@
#
# S P Y C
# a simple php yaml class
#
# authors: [vlad andersen (vlad.andersen@gmail.com), chris wanstrath (chris@ozmm.org)]
# websites: [http://www.yaml.org, http://spyc.sourceforge.net/]
# license: [MIT License, http://www.opensource.org/licenses/mit-license.php]
# copyright: (c) 2005-2006 Chris Wanstrath, 2006-2014 Vlad Andersen
#
# spyc.yaml - A file containing the YAML that Spyc understands.
---
# Mappings - with proper types
String: Anyone's name, really.
Int: 13
BadHex: f0xf3
Hex: 0xf3
True: true
False: false
Zero: 0
Null: NULL
NotNull: 'null'
NotTrue: 'y'
NotBoolTrue: 'true'
NotInt: '5'
Float: 5.34
Negative: -90
SmallFloat: 0.7
NewLine: \n
QuotedNewLine: "\n"
# A sequence
- PHP Class
- Basic YAML Loader
- Very Basic YAML Dumper
# A sequence of a sequence
-
- YAML is so easy to learn.
- Your config files will never be the same.
# Sequence of mappings
-
cpu: 1.5ghz
ram: 1 gig
os : os x 10.4.1
# Mapped sequence
domains:
- yaml.org
- php.net
# A sequence like this.
- program: Adium
platform: OS X
type: Chat Client
# A folded block as a mapped value
no time: >
There isn't any time
for your tricks!
Do you understand?
# A literal block as a mapped value
some time: |
There is nothing but time
for your tricks.
# Crazy combinations
databases:
- name: spartan
notes:
- Needs to be backed up
- Needs to be normalized
type: mysql
# You can be a bit tricky
"if: you'd": like
# Inline sequences
- [One, Two, Three, Four]
# Nested Inline Sequences
- [One, [Two, And, Three], Four, Five]
# Nested Nested Inline Sequences
- [This, [Is, Getting, [Ridiculous, Guys]], Seriously, [Show, Mercy]]
# Inline mappings
- {name: chris, age: young, brand: lucky strike}
# Nested inline mappings
- {name: mark, age: older than chris, brand: [marlboro, lucky strike]}
# References -- they're shaky, but functional
dynamic languages: &DLANGS
- Perl
- Python
- PHP
- Ruby
compiled languages: &CLANGS
- C/C++
- Java
all languages:
- *DLANGS
- *CLANGS
# Added in .2.2: Escaped quotes
- you know, this shouldn't work. but it does.
- 'that''s my value.'
- 'again, that\'s my value.'
- "here's to \"quotes\", boss."
# added in .2.3
- {name: "Foo, Bar's", age: 20}
# Added in .2.4: bug [ 1418193 ] Quote Values in Nested Arrays
- [a, ['1', "2"], b]
# Add in .5.2: Quoted new line values.
- "First line\nSecond line\nThird line"
# Added in .2.4: malformed YAML
all
javascripts: [dom1.js, dom.js]
# Added in .2
1040: Ooo, a numeric key! # And working comments? Wow! Colons in comments: a menace (0.3).
hash_1: Hash #and a comment
hash_2: "Hash #and a comment"
"hash#3": "Hash (#) can appear in key too"
float_test: 1.0
float_test_with_quotes: '1.0'
float_inverse_test: 001
a_really_large_number: 115792089237316195423570985008687907853269984665640564039457584007913129639936 # 2^256
int array: [ 1, 2, 3 ]
array on several lines:
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
morelesskey: "<value>"
array_of_zero: [0]
sophisticated_array_of_zero: {rx: {tx: [0]} }
switches:
- { row: 0, col: 0, func: {tx: [0, 1]} }
empty_sequence: [ ]
empty_hash: { }
special_characters: "[{]]{{]]"
asterisks: "*"
empty_key:
:
key: value
trailing_colon: "foo:"
multiline_items:
- type: SomeItem
values: [blah, blah, blah,
blah]
ints: [2, 54, 12,
2143]
many_lines: |
A quick
fox
jumped
over
a lazy
dog
werte:
1: nummer 1
0: Stunde 0
noindent_records:
- record1: value1
- record2: value2
"a:1": [1000]
"a:2":
- 2000
a:3: [3000]
complex_unquoted_key:
a:b:''test': value
array with commas:
["0","1"]
invoice: ["Something", "", '', "Something else"]
quotes: ['Something', "Nothing", 'Anything', "Thing"]
# [Endloop]
endloop: |
Does this line in the end indeed make Spyc go to an infinite loop?

222
demo/symfony.yaml

@ -0,0 +1,222 @@
#
# S P Y C
# a simple php yaml class
#
# authors: [vlad andersen (vlad.andersen@gmail.com), chris wanstrath (chris@ozmm.org)]
# websites: [http://www.yaml.org, http://spyc.sourceforge.net/]
# license: [MIT License, http://www.opensource.org/licenses/mit-license.php]
# copyright: (c) 2005-2006 Chris Wanstrath, 2006-2014 Vlad Andersen
#
# spyc.yaml - A file containing the YAML that Spyc understands.
#
# ----------------------------------------------------------------------------------------------
# Tests pour la librairie symfony/yaml : les cas qui ne fonctionnent pas sont mis en commentaire
#---
# Mappings - with proper types
String: Anyone's name, really.
Int: 13
BadHex: f0xf3
Hex: 0xf3
#True: true
#False: false
Zero: 0
#Null: NULL
NotNull: 'null'
NotTrue: 'y'
NotBoolTrue: 'true'
NotInt: '5'
Float: 5.34
Negative: -90
SmallFloat: 0.7
NewLine: \n
QuotedNewLine: "\n"
# A sequence
#- PHP Class
#- Basic YAML Loader
#- Very Basic YAML Dumper
# A sequence of a sequence
#-
# - YAML is so easy to learn.
# - Your config files will never be the same.
# Sequence of mappings
#-
# cpu: 1.5ghz
# ram: 1 gig
# os : os x 10.4.1
# Mapped sequence
domains:
- yaml.org
- php.net
# A sequence like this.
#- program: Adium
# platform: OS X
# type: Chat Client
# A folded block as a mapped value
no time: >
There isn't any time
for your tricks!
Do you understand?
# A literal block as a mapped value
some time: |
There is nothing but time
for your tricks.
# Crazy combinations
databases:
- name: spartan
notes:
- Needs to be backed up
- Needs to be normalized
type: mysql
# You can be a bit tricky
"if: you'd": like
# Inline sequences
#- [One, Two, Three, Four]
# Nested Inline Sequences
#- [One, [Two, And, Three], Four, Five]
# Nested Nested Inline Sequences
#- [This, [Is, Getting, [Ridiculous, Guys]], Seriously, [Show, Mercy]]
# Inline mappings
#- {name: chris, age: young, brand: lucky strike}
# Nested inline mappings
#- {name: mark, age: older than chris, brand: [marlboro, lucky strike]}
# References -- they're shaky, but functional
dynamic languages: &DLANGS
- Perl
- Python
- PHP
- Ruby
compiled languages: &CLANGS
- C/C++
- Java
all languages:
- *DLANGS
- *CLANGS
# Added in .2.2: Escaped quotes
#- you know, this shouldn't work. but it does.
#- 'that''s my value.'
#- 'again, that\'s my value.'
#- "here's to \"quotes\", boss."
# added in .2.3
#- {name: "Foo, Bar's", age: 20}
# Added in .2.4: bug [ 1418193 ] Quote Values in Nested Arrays
#- [a, ['1', "2"], b]
# Add in .5.2: Quoted new line values.
#- "First line\nSecond line\nThird line"
# Added in .2.4: malformed YAML
#all
# javascripts: [dom1.js, dom.js]
# Added in .2
1040: Ooo, a numeric key! # And working comments? Wow! Colons in comments: a menace (0.3).
hash_1: Hash #and a comment
hash_2: "Hash #and a comment"
"hash#3": "Hash (#) can appear in key too"
float_test: 1.0
float_test_with_quotes: '1.0'
float_inverse_test: 001
a_really_large_number: 115792089237316195423570985008687907853269984665640564039457584007913129639936 # 2^256
int array: [ 1, 2, 3 ]
array on several lines:
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
morelesskey: "<value>"
array_of_zero: [0]
sophisticated_array_of_zero: {rx: {tx: [0]} }
switches:
- { row: 0, col: 0, func: {tx: [0, 1]} }
empty_sequence: [ ]
empty_hash: { }
special_characters: "[{]]{{]]"
asterisks: "*"
empty_key:
:
key: value
trailing_colon: "foo:"
multiline_items:
- type: SomeItem
values: [blah, blah, blah,
blah]
ints: [2, 54, 12,
2143]
many_lines: |
A quick
fox
jumped
over
a lazy
dog
werte:
1: nummer 1
0: Stunde 0
noindent_records:
- record1: value1
- record2: value2
"a:1": [1000]
"a:2":
- 2000
a:3: [3000]
complex_unquoted_key:
a:b:''test': value
array with commas:
["0","1"]
invoice: ["Something", "", '', "Something else"]
quotes: ['Something', "Nothing", 'Anything', "Thing"]
# [Endloop]
endloop: |
Does this line in the end indeed make Spyc go to an infinite loop?

18
demo/test_inclure.yaml

@ -0,0 +1,18 @@
nom: '<:aveline:nom_anythingslider_liste_articles:>'
description: '<:aveline:description_anythingslider_liste_articles:>'
icon: 'article-24.png'
necessite:
- 'anythingslider'
contexte:
- 'id_rubrique'
- 'id_secteur'
- 'id_article'
- 'lang'
parametres:
- 'inclure:inc-test_inclure.yaml'
- 'inclure:demo/inc-test_inclure.yaml'
-
saisie: 'hidden'
options:
nom: 'selection'
defaut: 'limite'

27
demo/yaml.html

@ -4,19 +4,26 @@
<body dir="#LANG_DIR">
<div id="container">
#SET{librairies, #LISTE{sfyaml, symfony, spyc}}
#SET{librairies, #GET{librairies}|ajouter_libyaml}
<h1>YAML TESTS</h1>
[<p>(#VAL|verifier_libyaml)</p>]
<BOUCLE_parse_demo(DATA) {source table, #GET{librairies}}>
#SET{fichier, demo/#VALEUR.yaml}
<h1>YAML PARSE DEMO FILE : [(#VALEUR) - ]#GET{fichier}</h1>
[<p>(#CHEMIN{#GET{fichier}}|decoder_fichier_yaml{#ARRAY{library, #VALEUR, include, #EVAL{true}, show_error, #EVAL{true}}}|bel_env)</p>]
</BOUCLE_parse_demo>
<h1>YAML PARSE FILE</h1>
[<p>(#CHEMIN{noisettes/conteneur.yaml}|libyaml_parse_file|bel_env)</p>]
[<p>(#CHEMIN{noisettes/conteneur.yaml}|sfyaml_parse_file|bel_env)</p>]
[<p>(#CHEMIN{noisettes/conteneur.yaml}|symfony_parse_file|bel_env)</p>]
#SET{fichier, demo/test_inclure.yaml}
<BOUCLE_parse_inclure(DATA) {source table, #GET{librairies}}>
<h1>YAML PARSE INCLURE FILE : [(#VALEUR) - ]#GET{fichier}</h1>
[<p>(#CHEMIN{#GET{fichier}}|decoder_fichier_yaml{#ARRAY{library, #VALEUR, include, #EVAL{true}, show_error, #EVAL{true}}}|bel_env)</p>]
</BOUCLE_parse_inclure>
<h1>YAML PARSE STRING</h1>
[<p>(#CHEMIN{noisettes/conteneur.yaml}|libyaml_parse|bel_env)</p>]
[<p>(#CHEMIN{noisettes/conteneur.yaml}|sfyaml_parse|bel_env)</p>]
[<p>(#CHEMIN{noisettes/conteneur.yaml}|symfony_parse|bel_env)</p>]
#SET{fichier, noisettes/conteneur.yaml}
<BOUCLE_parse_noisette(DATA) {source table, #GET{librairies}}>
<h1>YAML PARSE NOISETTE FILE : [(#VALEUR) - ]#GET{fichier}</h1>
[<p>(#CHEMIN{#GET{fichier}}|decoder_fichier_yaml{#ARRAY{library, #VALEUR, include, #EVAL{true}, show_error, #EVAL{true}}}|bel_env)</p>]
</BOUCLE_parse_noisette>
</div>
</body>

96
demo/yaml_fonctions.php

@ -3,105 +3,37 @@ if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function verifier_libyaml() {
if (function_exists('yaml_parse')) {
$message = 'libYAML dispo';
} else {
$message = 'libYAML indispo';
}
return $message;
}
function libyaml_parse_file($file) {
$timestamp_debut = microtime(true);
$parsed = yaml_parse_file($file, 0);
$timestamp_fin = microtime(true);
$duree = $timestamp_fin - $timestamp_debut;
var_dump('libyaml : ', $duree*1000);
function ajouter_libyaml($librairies) {
return $parsed;
}
function sfyaml_parse_file($file) {
$timestamp_debut = microtime(true);
include_spip('inc/flock');
lire_fichier($file, $yaml);
// Si on recupere bien quelque chose
if ($yaml) {
include_spip('inc/yaml_sfyaml');
$parsed = yaml_sfyaml_decode($yaml);
if (function_exists('yaml_parse')) {
$librairies[] = 'libyaml';
}
$timestamp_fin = microtime(true);
$duree = $timestamp_fin - $timestamp_debut;
var_dump('sfyaml : ', $duree*1000);
return $parsed;
return $librairies;
}
function symfony_parse_file($file) {
function decoder_fichier_yaml($filename, $options = array()) {
$timestamp_debut = microtime(true);
include_spip('inc/yaml_symfony');
$parsed = yaml_symfony_decode_file($file);
include_spip('inc/yaml');
$file = find_in_path($filename);
$parsed = yaml_decode_file($file, $options);
$timestamp_fin = microtime(true);
$duree = $timestamp_fin - $timestamp_debut;
var_dump('symfony : ', $duree*1000);
return $parsed;
return array('lib' => sinon($options['library'], 'sfyaml'), 'duree' => $duree*1000, 'yaml' => $parsed);
}
function libyaml_parse($file) {
function decoder_fichier_yaml_avec_inclusions($filename, $options = array()) {
$timestamp_debut = microtime(true);
include_spip('inc/flock');
lire_fichier($file, $input);
$parsed = yaml_parse($input, 0);
include_spip('inc/yaml');
$file = find_in_path($filename);
$parsed = yaml_charger_inclusions(yaml_decode_file($file, $options));
$timestamp_fin = microtime(true);
$duree = $timestamp_fin - $timestamp_debut;
var_dump('libyaml : ', $duree*1000);
return $parsed;
return array('lib' => sinon($options['library'], 'sfyaml'), 'duree' => $duree*1000, 'yaml' => $parsed);
}
function sfyaml_parse($file) {
$timestamp_debut = microtime(true);
include_spip('inc/flock');
lire_fichier($file, $input);
// Si on recupere bien quelque chose
include_spip('inc/yaml_sfyaml');
$parsed = yaml_sfyaml_decode($input);
$timestamp_fin = microtime(true);
$duree = $timestamp_fin - $timestamp_debut;
var_dump('sfyaml : ', $duree*1000);
return $parsed;
}
function symfony_parse($file) {
$timestamp_debut = microtime(true);
include_spip('inc/flock');
lire_fichier($file, $input);
include_spip('inc/yaml_symfony');
$parsed = yaml_symfony_decode($input);
$timestamp_fin = microtime(true);
$duree = $timestamp_fin - $timestamp_debut;
var_dump('symfony : ', $duree*1000);
return $parsed;
}

9
experimental/README

@ -1,9 +0,0 @@
Installer ces deux fichiers dans les squelettes
Puis appeler spip.php?page=yaml&id_article=X
ou alors dans .htaccess ajouter :
RewriteRule ^article([0-9]+)[\.,]yaml$ spip.php?page=yaml&id_article=$1 [QSA,L]
puis appeler articleXXX,yaml

5
experimental/yaml.html

@ -1,5 +0,0 @@
#HTTP_HEADER{Content-Type: text/plain; charset=#CHARSET}
<BOUCLE_a(ARTICLES){id_article}>
# Article #ID_ARTICLE du site #URL_SITE_SPIP*
[(#ID_ARTICLE|yaml_article)]
</BOUCLE_a>

17
experimental/yaml_fonctions.php

@ -1,17 +0,0 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function yaml_article($id_article) {
include_spip('inc/yaml');
$a = array_filter(sql_fetsel('*', 'spip_articles', 'id_article='.$id_article));
$a['rubrique'] = array_filter(sql_fetsel('*', 'spip_rubriques', 'id_rubrique='.$a['id_rubrique']));
foreach (sql_allfetsel('*', 'spip_mots AS m LEFT JOIN spip_mots_articles AS c ON m.id_mot=c.id_mot', 'c.id_article='.$id_article) as $m) {
$a['mots'][] = array_filter($m);
}
return yaml_encode(array_filter($a));
}

192
inc/yaml.php

@ -1,5 +1,4 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
@ -14,98 +13,187 @@ if (!defined('_ECRIRE_INC_VERSION')) {
#
# Regle de dev: ne pas se rendre dependant de la lib sous-jacente
// Si on est en PHP4
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
define('_LIB_YAML', 'spyc-php4');
} else {
// temporaire le temps de tester spyc
if (!defined('_LIB_YAML')) {
/**
* Les valeurs possibles sont :
* - 'sfyaml' pour l'ancienne librairie symfony v1 (compatibilité ascendante, par défaut)
* - 'symfony' pour le composant YAML le plus récent de Symfony
* - 'spyc' pour la librairie YAML spyc la plus récente
* - 'libyaml' pour le composant PECL basé sur la librairie libYAML écrite en C.
*/
define('_LIB_YAML', 'sfyaml');
#define('_LIB_YAML','spyc');
}
/*
* Encode n'importe quelle structure en yaml
* @param $struct
/**
* @api
*
* @param mixed $structure
* Structure PHP, tableau, chaine... à convertir en YAML.
* @param array $options
* Tableau associatif d'options standard ou spécifique à une librairie donnée.
*
* @return string
* Chaîne YAML construite, prête pour être éventuellement écrite dans un fichier.
*/
function yaml_encode($struct, $opt = array()) {
// Si PHP4
if (_LIB_YAML == 'spyc-php4') {
require_once _DIR_PLUGIN_YAML.'spyc/spyc-php4.php';
return Spyc::YAMLDump($struct);
}
// test temporaire
if (_LIB_YAML == 'spyc') {
require_once _DIR_PLUGIN_YAML.'spyc/spyc.php';
return Spyc::YAMLDump($struct);
function yaml_encode($structure, $options = array()) {
// Déterminer la librairie à utiliser
$librairie = _LIB_YAML;
if (!empty($options['library'])) {
$librairie = $options['library'];
}
require_once _DIR_PLUGIN_YAML.'inc/yaml_sfyaml.php';
return yaml_sfyaml_encode($struct, $opt);
// Déterminer la fonction à appeler à partir de la librairie utilisée.
require_once _DIR_PLUGIN_YAML . 'inc/yaml_' . $librairie . '.php';
$encoder = 'yaml_' . $librairie . '_encode';
return $encoder($structure, $options);
}
/*
* Decode un texte yaml, renvoie la structure
* @param string $input
* boolean $show_error true: arrete le parsing et retourne erreur en cas d'echec - false: retourne un simple false en cas d'erreur de parsing
*/
if (!function_exists('yaml_decode')) {
function yaml_decode($input, $show_error = true) {
// Si PHP4
if (_LIB_YAML == 'spyc-php4') {
require_once _DIR_PLUGIN_YAML.'spyc/spyc-php4.php';
return Spyc::YAMLLoad($input);
}
// test temporaire
if (_LIB_YAML == 'spyc') {
require_once _DIR_PLUGIN_YAML.'spyc/spyc.php';
return Spyc::YAMLLoad($input);
}
/**
* @api
*
* @param string $input
* La chaîne YAML à décoder.
* @param array $options
* Tableau associatif des options du parsing.
* - 'show_error' : indicateur d'affichage des erreurs de parsing, false par défaut.
*
* @return mixed
*/
function yaml_decode($input, $options = array()) {
require_once _DIR_PLUGIN_YAML.'inc/yaml_sfyaml.php';
return yaml_sfyaml_decode($input, $show_error);
}
// Déterminer la librairie à utiliser
$librairie = _LIB_YAML;
if (!empty($options['library'])) {
$librairie = $options['library'];
}
// Déterminer la fonction à appeler à partir de la librairie utilisée.
require_once _DIR_PLUGIN_YAML . 'inc/yaml_' . $librairie . '.php';
$decoder = 'yaml_' . $librairie . '_decode';
return $decoder($input, $options);
}
}
/*
* @api
*
* Decode un fichier en utilisant yaml_decode
* @param string $fichier
*/
function yaml_decode_file($fichier) {
$yaml = '';
$retour = false;
/**
* @param $fichier
*
* @return array|mixed
*/
function yaml_decode_file($fichier, $options = array()) {
$retour = array();
// Traitement des options
if (empty($options['include'])) {
$options['include'] = false;
}
// Lecture du fichier YAML.
lire_fichier($fichier, $yaml);
// Si on recupere bien quelque chose
// Décodage du contenu YAML en structure de données PHP.
if ($yaml) {
$retour = yaml_decode($yaml);
$retour = yaml_decode($yaml, $options);
if ($options['include']) {
$retour = yaml_decode_inclusions($retour, $options);
}
}
return $retour;
}
/*
* @internal
*
* Charge les inclusions de YAML dans un tableau
* Les inclusions sont indiquees dans le tableau via la valeur 'inclure:rep/fichier.yaml' ou rep indique le chemin relatif.
* On passe donc par find_in_path() pour trouver le fichier
* @param array $tableau
*/
function yaml_decode_inclusions($parsed, $options = array()) {
if (is_array($parsed)) {
$retour = array();
foreach ($parsed as $cle => $valeur) {
if (is_string($valeur) && substr($valeur, 0, 8) == 'inclure:' && substr($valeur, -5) == '.yaml') {
$inclusion = find_in_path(substr($valeur, 8));
if ($inclusion) {
$retour = array_merge($retour, yaml_decode_file($inclusion, $options));
} else {
$retour = array_merge($retour, array($cle => $valeur));
}
} elseif (is_array($valeur)) {
$retour = array_merge($retour, array($cle => yaml_decode_inclusions($valeur, $options)));
} else {
$retour = array_merge($retour, array($cle => $valeur));
}
}
} elseif (is_string($parsed) && substr($parsed, 0, 8) == 'inclure:' && substr($parsed, -5) == '.yaml') {
$inclusion = find_in_path(substr($parsed, 8));
if ($inclusion) {
$retour = yaml_decode_file($inclusion, $options);
} else {
$retour = $parsed;
}
} else {
$retour = $parsed;
}
return $retour;
}
/*
* @api
*
* Charge les inclusions de YAML dans un tableau
* Les inclusions sont indiquees dans le tableau via la valeur 'inclure:rep/fichier.yaml' ou rep indique le chemin relatif.
* On passe donc par find_in_path() pour trouver le fichier
* @param array $tableau
*/
function yaml_charger_inclusions($tableau) {
function yaml_charger_inclusions($tableau, $options = array()) {
// Eviter de traiter l'inclure avec la nouvelle approche
if (isset($options['include'])) {
unset($options['include']);
}
if (is_array($tableau)) {
$retour = array();
foreach ($tableau as $cle => $valeur) {
if (is_string($valeur) && substr($valeur, 0, 8) == 'inclure:' && substr($valeur, -5) == '.yaml') {
$retour = array_merge($retour, yaml_charger_inclusions(yaml_decode_file(find_in_path(substr($valeur, 8)))));
$inclusion = find_in_path(substr($valeur, 8));
if ($inclusion) {
$retour = array_merge($retour, yaml_charger_inclusions(yaml_decode_file($inclusion), $options));
} else {
$retour = array_merge($retour, array($cle => $valeur));
}
} elseif (is_array($valeur)) {
$retour = array_merge($retour, array($cle => yaml_charger_inclusions($valeur)));
$retour = array_merge($retour, array($cle => yaml_charger_inclusions($valeur, $options)));
} else {
$retour = array_merge($retour, array($cle => $valeur));
}
}
return $retour;
} elseif (is_string($tableau) && substr($tableau, 0, 8) == 'inclure:' && substr($tableau, -5) == '.yaml') {
return yaml_charger_inclusions(yaml_decode_file(find_in_path(substr($tableau, 8))));
$inclusion = find_in_path(substr($tableau, 8));
if ($inclusion) {
$retour = yaml_charger_inclusions(yaml_decode_file($inclusion, $options));
} else {
$retour = $tableau;
}
} else {
return $tableau;
$retour = $tableau;
}
return $retour;
}

54
inc/yaml_libyaml.php

@ -0,0 +1,54 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Encode une structure de données PHP en une chaîne YAML.
* Utilise pour cela la librairie PECL libYAML (encapsulation de la librairie C du même nom).
* Une fois installée l'extension Apache, les fonctions de la librairie s'utilise nativement en PHP.
*
* @param mixed $structure