package.xml0000644000076600000240000005340514700763734011726 0ustar bd808staff yaml pecl.php.net YAML-1.1 parser and emitter Support for YAML 1.1 (YAML Ain't Markup Language) serialization using the LibYAML library. Bryan Davis bd808 bd808@bd808.com yes 2024-10-07 2.2.4 2.0.0 stable stable MIT Bugs Fixed: - #85: PHP 8.4.0 beta4 test yaml_parse_file_002.phpt fails (andypost) - emit.c: fix -Wsign-compare (bd808) - #75: yaml_parse_file does not set &$ndoc as expected (tomterl) - Fix [-Wincompatible-pointer-types] warning (remicollet) 7.1.0 1.4.0b1 date yaml 2023-03-05 2.2.3 2.0.0 Bugs Fixed: - Fixed memory release on error handling (negram) - Fix test for PHP 8.2 (andypost) - #65: Fix #65 yaml_parse_url method not working (remicollet) 2021-10-24 2.2.2 2.0.0 stable stable Bugs Fixed: - PHP 8.1 compilation fixes (remicollet) 2020-12-20 2.2.1 2.0.0 stable stable Bugs Fixed: - #80324: Segfault in YAML with anonymous functions (cmb69) - Fix memory leak in y_write_object_callback() (cmb69) - Fix memory leak in handle_mapping() (cmb69) 2020-11-28 2.2.0 2.0.0 stable stable New Features: - PHP 8.0 compatibility Bugs Fixed: - #79866 Use serialize_precision when encoding double values (bd808) - yaml_parse_file_002.phpt: Fix expectations for PHP 8.0.0beta1 (bd808) - Remove use of call_user_function_ex() for compat with PHP 8.0.0a2 (andypost) - Adjust test values for compat with 32bit platforms (bd808) - Fix memory leaks (cmb69) - #79567 Parsing long long values leads to truncation on LLP64 platforms (bd808) - #77720 Out of memory error when parsing yaml file (bd808) - [-Wformat=] issue on 32-bit (remicollet) - relax test on 32-bit (overflow to float) (remicollet) 2020-09-13 2.2.0b2 2.0.0 beta stable New Features: - PHP 8.0.0b3+ compatibility 2020-08-16 2.2.0b1 2.0.0 beta stable New Features: - PHP 8.0.0b1 compatibility Bugs Fixed: - #79866 Use serialize_precision when encoding double values (bd808) - yaml_parse_file_002.phpt: Fix expectations for PHP 8.0.0beta1 (bd808) - Remove use of call_user_function_ex() for compat with PHP 8.0.0a2 (andypost) - Adjust test values for compat with 32bit platforms (bd808) - Fix memory leaks (cmb69) - #79567 Parsing long long values leads to truncation on LLP64 platforms (bd808) - #77720 Out of memory error when parsing yaml file (bd808) - [-Wformat=] issue on 32-bit (remicollet) - relax test on 32-bit (overflow to float) (remicollet) 2020-04-22 2.1.0 2.0.0 stable stable New Features: - Basic PHP8 (master branch) compatiblity Bugs Fixed: - #79494: The 64-bit YAML ext uses 32-bit signed integer arithmetics (cmb69) - Use ZEND_LONG_FMT to fix -Wformat warnings (carusogabriel) - Fix memory leaks when writing timestamps (cmb69) - Update tests/yaml_parse_file_002.phpt for PHP8 (carusogabriel) - #78353: Remove deprecated TSRM macros (a.dankovtsev) 2018-11-24 2.0.4 2.0.0 stable stable Bugs Fixed: - #72540 yaml_parse_url: check php_stream_copy_to_mem return value 2018-11-13 2.0.3 2.0.0 stable stable Bugs Fixed: - #75029 Empty documents are valid (bd808) - #75213 Fix float parsing on Alpine (neclimdul) - #76309 Quote strings like "0." when emitting (bd808) - #76522 PHP 7.3 compilation fixes (dktapps, remicollet) - CRLF and whitespace fixes (petk) 2017-07-29 2.0.2 2.0.0 stable stable Same as 2.0.1, but marked correctly as a stable release Bugs Fixed: - relax tests to pass with 7.1.4RC1 (remicollet) - #74799 fix memory leak in apply_filter function (gleb-svitelskiy) - #72540 fix crash in yaml_parse_url when stream/file is empty (bd808) 2016-09-24 2.0.0 2.0.0 stable stable Breaking changes: - #69617 yaml.decode_php ini setting now defaults to false. New Features: - PHP7 compatible - 2.x series will no longer support PHP5 Bugs Fixed: - Premature free in y_write_object (remicollet) - Uninitialized smart_str in convert_to_char (remicollet) - Missing free in convert_to_char (remicollet) - Use zend_* datatypes (weltling) - Fix handling of optional encoding argument to yaml_emit_file (weltling) - Removed PHP6 compat IS_UNICODE support (bd808) - Fixed parameter parsing for yaml_emit_file() - Fixed callback usage for yaml_emit_file() - Use smart_str_free() instead of smart_string_free() (remicollet) - #71045 zend_mm_alloc_small crashes with zend_string_alloc - Fix handling of tag callbacks for aliased values (ranvis) - Quick fix on handle_mapping. arrval should be used instead of retval (jabiinfante) - #71696 Bad datetime management (bocharov) - Fix memory leak in mapping with sequence (bocharov) - Fix anchor in anchor problemo (bocharov) - Fix tests bug_64019.phpt, bug_parsing_alias.phpt (bocharov) - #72204 Crash when try to parse yaml file 2015-05-18 1.2.0 1.1.0 stable stable New Features: - #69617 Allow unserialize for !php/object to be disabled New yaml.decode_php ini setting to enable/disable serialized php object processing. Deployments relying on !php/object are encouraged to explicitly set yaml.decode_php=1 as default will change to disabled in a future release. Bugs Fixed: - Honour --with-libdir - Fix package.xml schema validation - Add const for pointers where possible - Explicitly cast emalloc returns - #69465 Resolve quoted and non-specific scalars as strings - #69616 Fix double free when unserialize fails 2013-11-19 1.1.1 1.1.0 stable stable New Features: - Removed "not yet implemented" warning and deliberate abort from yaml_emit_file() Bugs Fixed: - #61770 Crash on nonunicode character - #61923 Detect_scalar_type() is not aware of base 60 representation - #63086 Compiling PHP with YAML as static extension fails - #64019 Segmentation fault if yaml anchor ends with a colon - #64694 Segfault when array used as mapping key 2011-04-15 1.1.0 1.1.0 stable stable Marking 1.1.0 branch as stable. No change from 1.1.0RC2. 2011-03-27 1.1.0RC2 1.1.0 beta beta Bugs Fixed: - #61477 memset sizeof(struct) instead of sizeof(pointer) - #61475 config.m4 honors `php-config --prefix` 2011-03-12 1.1.0RC1 1.1.0 beta beta New Features: - #59860 Callback support when parsing implicit tags - #60711 Callback support when emitting objects Bugs Fixed: - #59765 Build process does not honour custom CFLAGS - #60628 Mystery circular references after tag callback 2011-02-20 1.0.1 1.0.0 stable stable - Bug #21995: fixed double free bug when a callback mapping is provided - corrected string length issue with callback "tag" argument - added "tag" and "flags" arguments to sequence and map callbacks 2011-02-20 1.0.0 1.0.0 stable stable Marking package as stable after 12 months of daily production usage. 2010-02-09 0.6.3 0.6.3 beta beta Fixed packaging problem that broke install via pecl channel. 0.6.2 0.6.2 beta beta 2010-02-06 First release from new hosting at svn.php.net via pecl.php.net 0.6.1 0.6.1 beta beta 2010-01-25 Fixed bad pecl package. 0.6.0 0.6.0 beta beta 2010-01-25 Support for '<<' (merge) in mappings. Fixed issues with php 5.3 and ZTS compilation. Added support for emitting recursive arrays. 0.5.0 0.5.0 alpha alpha 2009-11-24 Implemented yaml_emit and yaml_emit_file. Wrote basic phpdoc content. Lots and lots of new unit tests. 0.4.0 0.4.0 devel devel 2009-11-12 Initial release of fork from rsky's 0.3.0 tarball found at http://www.opendogs.org/pub/php_yaml-0.3.0.tgz yaml-2.2.4/tests/bug_21995.phpt0000644000076600000240000000061114700763734014570 0ustar bd808staff--TEST-- Test PECL bug #21995 --SKIPIF-- --FILE-- "yaml_cbk", )); ?> --EXPECT-- string(3) "boo" string(3) "doo" string(1) "a" string(1) "d" yaml-2.2.4/tests/bug_59860.phpt0000644000076600000240000000316414700763734014600 0ustar bd808staff--TEST-- Test PECL bug #59860 --SKIPIF-- --FILE-- 'tag_callback', YAML_SEQ_TAG => 'tag_callback', )); ?> --EXPECT-- array(3) { [0]=> array(1) { ["a"]=> string(1) "b" } [1]=> string(21) "tag:yaml.org,2002:map" [2]=> int(0) } array(3) { [0]=> array(1) { ["c"]=> string(1) "d" } [1]=> string(21) "tag:yaml.org,2002:map" [2]=> int(0) } array(3) { [0]=> array(2) { [0]=> string(1) "e" [1]=> string(1) "f" } [1]=> string(21) "tag:yaml.org,2002:seq" [2]=> int(0) } array(3) { [0]=> array(2) { [0]=> string(1) "g" [1]=> string(1) "h" } [1]=> string(21) "tag:yaml.org,2002:seq" [2]=> int(0) } array(3) { [0]=> array(4) { ["implicit_map"]=> string(21) "tag:yaml.org,2002:map" ["explicit_map"]=> string(21) "tag:yaml.org,2002:map" ["implicit_seq"]=> string(21) "tag:yaml.org,2002:seq" ["explicit_seq"]=> string(21) "tag:yaml.org,2002:seq" } [1]=> string(21) "tag:yaml.org,2002:map" [2]=> int(0) } yaml-2.2.4/tests/bug_60628.phpt0000644000076600000240000000275114700763734014573 0ustar bd808staff--TEST-- Test PECL bug #260628 --SKIPIF-- --FILE-- $value, 'another' => 'test', ); } /* baseline. do like operation in native php. */ $native = array( "data" => array("look upper"), ); $native["data"] = tag_callback($native["data"], "!mytag", 0); echo "-- native value --\n"; var_dump($native); echo "-- end native value --\n"; $cnt = null; $array = yaml_parse($data, 0, $cnt, array( '!mytag' => 'tag_callback', )); echo "-- parsed value --\n"; var_dump($array); echo "-- end parsed value --\n"; ?> --EXPECT-- -- callback value -- array(1) { [0]=> string(10) "look upper" } string(6) "!mytag" int(0) -- end callback value -- -- native value -- array(1) { ["data"]=> array(2) { ["data"]=> array(1) { [0]=> string(10) "look upper" } ["another"]=> string(4) "test" } } -- end native value -- -- callback value -- array(1) { [0]=> string(10) "look upper" } string(6) "!mytag" int(0) -- end callback value -- -- parsed value -- array(1) { ["data"]=> array(2) { ["data"]=> array(1) { [0]=> string(10) "look upper" } ["another"]=> string(4) "test" } } -- end parsed value -- yaml-2.2.4/tests/bug_61770.phpt0000644000076600000240000000040314700763734014562 0ustar bd808staff--TEST-- Test PECL bug #61770 --SKIPIF-- --FILE-- --EXPECTF-- Warning: yaml_emit(): Invalid UTF-8 sequence in argument in %sbug_61770.php on line 2 bool(false) yaml-2.2.4/tests/bug_61923.phpt0000644000076600000240000000223414700763734014566 0ustar bd808staff--TEST-- Test PECL bug #61923 --SKIPIF-- --INI-- serialize_precision=-1 --FILE-- --EXPECT-- array(2) { ["strings"]=> array(8) { [0]=> string(3) "1:0" [1]=> string(3) "0:1" [2]=> string(5) "1:0:0" [3]=> string(6) "+1:0:0" [4]=> string(6) "-1:0:0" [5]=> string(3) ":01" [6]=> string(2) ":1" [7]=> string(14) "18:53:17.00037" } ["numbers"]=> array(8) { [0]=> int(60) [1]=> int(1) [2]=> int(3600) [3]=> int(3600) [4]=> int(-3600) [5]=> int(1) [6]=> int(1) [7]=> float(67997.00037) } } string(161) "--- strings: - "1:0" - "0:1" - "1:0:0" - "+1:0:0" - "-1:0:0" - ":01" - ":1" - "18:53:17.00037" numbers: - 60 - 1 - 3600 - 3600 - -3600 - 1 - 1 - 67997.00037 ... " yaml-2.2.4/tests/bug_64019.phpt0000644000076600000240000000125414700763734014566 0ustar bd808staff--TEST-- Test PECL bug #64019 --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["configAnchors"]=> array(1) { [0]=> array(2) { [""]=> NULL ["configKey"]=> string(11) "configValue" } } ["config"]=> array(1) { ["<<"]=> NULL } } array(1) { ["config"]=> array(1) { ["<<"]=> NULL } } yaml-2.2.4/tests/bug_64694.phpt0000644000076600000240000000064314700763734014600 0ustar bd808staff--TEST-- Test PECL bug #64694 --SKIPIF-- --FILE-- --EXPECTF-- array(1) { ["[a]"]=> int(1) } Warning: yaml_parse(): Illegal offset type array (line 1, column 7) in %sbug_64694.php on line 12 array(0) { } yaml-2.2.4/tests/bug_69465.phpt0000644000076600000240000000144214700763734014577 0ustar bd808staff--TEST-- Test PECL bug #69465 --SKIPIF-- --INI-- yaml.decode_timestamp=1 date.timezone=UTC --FILE-- --EXPECT-- array(12) { ["date1"]=> int(1431648000) ["date2"]=> string(10) "2015-05-15" ["date3"]=> string(10) "2015-05-15" ["bool1"]=> bool(true) ["bool2"]=> string(4) "true" ["bool3"]=> string(4) "true" ["int1"]=> int(1) ["int2"]=> string(1) "1" ["int3"]=> string(1) "1" ["float1"]=> float(1.5) ["float2"]=> string(3) "1.5" ["float3"]=> string(3) "1.5" } yaml-2.2.4/tests/bug_69616.phpt0000644000076600000240000000064214700763734014576 0ustar bd808staff--TEST-- Test PECL bug #69616 --SKIPIF-- --INI-- yaml.decode_php=1 --FILE-- --EXPECTF-- Notice: yaml_parse(): Failed to unserialize class in %sbug_69616.php on line 10 Notice: yaml_parse(): Failed to unserialize class in %sbug_69616.php on line 10 yaml-2.2.4/tests/bug_69617.phpt0000644000076600000240000000047214700763734014600 0ustar bd808staff--TEST-- Test PECL bug #69617 --SKIPIF-- --FILE-- --EXPECT-- array(1) { ["a"]=> string(26) "O:1:"A":1:{s:3:"one";i:1;}" } yaml-2.2.4/tests/bug_72204.phpt0000644000076600000240000000062014700763734014555 0ustar bd808staff--TEST-- Test PECL bug #72204 --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["foo"]=> array(1) { ["bar"]=> bool(true) } ["baz"]=> array(1) { ["bar"]=> bool(false) } } yaml-2.2.4/tests/bug_72540.phpt0000644000076600000240000000040214700763734014556 0ustar bd808staff--TEST-- Test PECL bug #72540 --SKIPIF-- --FILE-- --EXPECT-- bool(false) yaml-2.2.4/tests/bug_74799.phpt0000644000076600000240000000150114700763734014601 0ustar bd808staff--TEST-- Memory leak check --CREDITS-- Gleb Svitelskiy --SKIPIF-- --FILE-- 'tag_callback']); unset($yamlString, $ndocs); $ndocs = null; yaml_parse_file(__DIR__.'/bug_74799.yaml', 0, $ndocs, ['!value' => 'tag_callback']); unset($ndocs); $array = ['key' => 'value']; yaml_emit($array); unset($array); $array = ['key' => 'value']; yaml_emit_file(__DIR__.'/bug_74799.tmp', $array); unset($array); var_dump($base_memory == memory_get_usage()); ?> --CLEAN-- --EXPECT-- bool(true) yaml-2.2.4/tests/bug_74799.yaml0000644000076600000240000000002514700763734014570 0ustar bd808staff--- key: !value ...yaml-2.2.4/tests/bug_75029.phpt0000644000076600000240000000063214700763734014570 0ustar bd808staff--TEST-- Test PECL bug #75029 --SKIPIF-- --FILE-- --EXPECT-- NULL array(1) { [0]=> NULL } array(3) { [0]=> string(3) "doc" [1]=> NULL [2]=> string(3) "doc" } NULL yaml-2.2.4/tests/bug_76309.phpt0000644000076600000240000000051614700763734014573 0ustar bd808staff--TEST-- Test PECL bug #76309 --SKIPIF-- --INI-- serialize_precision=-1 --FILE-- '1.0', 'b' => '2.', 'c' => '3', 'd' => '.', 'e' => 1.0, 'f' => 2., 'g' => 3, ] ); ?> --EXPECT-- --- a: "1.0" b: "2." c: "3" d: . e: 1 f: 2 g: 3 ... yaml-2.2.4/tests/bug_77720.phpt0000644000076600000240000003051314700763734014571 0ustar bd808staff--TEST-- Test PECL bug #77720 --SKIPIF-- --FILE-- --EXPECTF-- Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 2, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 3, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 4, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 5, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 6, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 7, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 8, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 9, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 10, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 2) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 73) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 11, column 79) in %sbug_77720.php on line 15 Warning: yaml_parse(): Illegal offset type array (line 12, column 1) in %sbug_77720.php on line 15 array(11) { [0]=> array(9) { [0]=> string(3) "lol" [1]=> string(3) "lol" [2]=> string(3) "lol" [3]=> string(3) "lol" [4]=> string(3) "lol" [5]=> string(3) "lol" [6]=> string(3) "lol" [7]=> string(3) "lol" [8]=> string(3) "lol" } [1]=> array(0) { } [2]=> array(0) { } [3]=> array(0) { } [4]=> array(0) { } [5]=> array(0) { } [6]=> array(0) { } [7]=> array(0) { } [8]=> array(0) { } [9]=> array(0) { } [10]=> array(0) { } } yaml-2.2.4/tests/bug_79494.phpt0000644000076600000240000000114114700763734014576 0ustar bd808staff--TEST-- Test PECL bug #74949 --SKIPIF-- --INI-- serialize_precision=-1 --FILE-- array ( 'audioEnabled' => array ( 0 => 132317787432502136, 1 => 0, ), 'eveampGain' => array ( 0 => 132316833510704299, 1 => 0.25, ), ), ); print yaml_emit($data); ?> --EXPECTF-- --- audio: audioEnabled: - %r(132317787432502136|1\.3231778743250214E\+17)%r - 0 eveampGain: - %r(132316833510704299|1\.323168335107043E\+17)%r - 0.25 ... yaml-2.2.4/tests/bug_79567.phpt0000644000076600000240000000051314700763734014601 0ustar bd808staff--TEST-- Test PECL bug #79567 --SKIPIF-- --FILE-- [ 0 => 132317787432502136, 1 => 0, ], ]; $yaml = yaml_emit($data); $result = yaml_parse($yaml); print $result == $data ? "Yes!\n" : "No...\n"; ?> --EXPECT-- Yes! yaml-2.2.4/tests/bug_79866.phpt0000644000076600000240000000165314700763734014611 0ustar bd808staff--TEST-- Test PECL bug #79866 --SKIPIF-- --INI-- precision=14 serialize_precision=-1 --FILE-- 0, "1" => 1, "-1" => -1, "2." => 2., "2.0" => 2.0, "2.00" => 2.00, "2.000" => 2.000, "0.123456789" => 0.123456789, "-0.123456789" => -0.123456789, "2.3e6" => 2.3e6, "-2.3e6" => -2.3e6, "2.3e-6" => 2.3e-6, "-2.3e-6" => -2.3e-6, "INF" => INF, "NAN" => NAN, "0.000021" => 0.000021, ]; foreach( $floats as $idx => $float ) { $float = floatval($float); ob_start(); echo $float; $native = ob_get_clean(); $expect = "--- {$native}\n...\n"; $got = yaml_emit($float); if ( $got !== $expect ) { echo "== FAIL! {$idx} ==\n"; echo "expected:\n{$expect}\n"; echo "got:{$got}\n"; } } ?> --EXPECT-- yaml-2.2.4/tests/bug_80324.phpt0000644000076600000240000000067314700763734014567 0ustar bd808staff--TEST-- Bug #80324 (Segfault in YAML with anonymous functions) --SKIPIF-- --FILE-- function ($str) {return $str;}, '!path' => function ($str) {return $str;}, )); var_dump($result); ?> --EXPECT-- array(2) { [0]=> string(3) "ENV" [1]=> string(4) "PATH" } yaml-2.2.4/tests/bug_parsing_alias.phpt0000644000076600000240000000125414700763734016717 0ustar bd808staff--TEST-- Test PECL strange alias bug --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["basic"]=> array(1) { [0]=> array(1) { ["value"]=> int(22) } } ["keylevel0"]=> array(2) { ["keylevel1"]=> array(1) { ["value"]=> int(1) } ["keylevel1.1"]=> array(1) { ["keylevel2"]=> array(1) { ["value"]=> int(2) } } } } yaml-2.2.4/tests/yaml_001.phpt0000644000076600000240000000212114700763734014562 0ustar bd808staff--TEST-- yaml - emit -> parse roundtrip --SKIPIF-- --FILE-- "Chris", "family"=> "Dumars", "address"=> array( "lines"=> "458 Walkman Dr. Suite #292", "city"=> "Royal Oak", "state"=> "MI", "postal"=> 48046, ), ); $invoice = array ( "invoice"=> 34843, "date"=> 980208000, "bill-to"=> $addr, "ship-to"=> $addr, "product"=> array( array( "sku"=> "BL394D", "quantity"=> 4, "description"=> "Basketball", "price"=> 450, ), array( "sku"=> "BL4438H", "quantity"=> 1, "description"=> "Super Hoop", "price"=> 2392, ), ), "tax"=> 251.42, "total"=> 4443.52, "comments"=> "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.", "tags" => array("a","b","c"), ); $yaml = yaml_emit($invoice); $parsed = yaml_parse($yaml); var_dump($parsed == $invoice); ?> --EXPECT-- bool(true) yaml-2.2.4/tests/yaml_002.phpt0000644000076600000240000000210714700763734014567 0ustar bd808staff--TEST-- yaml - emit -> parse roundtrip with datetime --SKIPIF-- --INI-- date.timezone=GMT yaml.decode_timestamp=2 --FILE-- new DateTime("2001-12-15T02:59:43.1Z"), "valid iso8601" => new DateTime("2001-12-14t21:59:43.10-05:00"), "alternate iso8601" => new DateTime("2001-12-14T21:59:43.10-0500"), "space separated" => new DateTime("2001-12-14 21:59:43.10 -5"), "no time zone (Z)" => new DateTime("2001-12-15 2:59:43.10"), "date (0000:00Z)" => new DateTime("2002-12-14"), ); $yaml = yaml_emit($original); var_dump($yaml); $parsed = yaml_parse($yaml); var_dump($parsed == $original); ?> --EXPECT-- string(303) "--- canonical: 2001-12-15T02:59:43.100000+00:00 valid iso8601: 2001-12-14T21:59:43.100000-05:00 alternate iso8601: 2001-12-14T21:59:43.100000-05:00 space separated: 2001-12-14T21:59:43.100000-05:00 no time zone (Z): 2001-12-15T02:59:43.100000+00:00 date (0000:00Z): 2002-12-14T00:00:00.000000+00:00 ... " bool(true) yaml-2.2.4/tests/yaml_emit_001.phpt0000644000076600000240000000434114700763734015606 0ustar bd808staff--TEST-- yaml_emit - scalars --SKIPIF-- --INI-- serialize_precision=-1 --FILE-- ,.?/ These are extended characters: Iñtërnâtiônàlizætiøn EOD; var_dump(yaml_emit($str)); ?> --EXPECT-- string(10) "--- ~ ... " string(13) "--- true ... " string(14) "--- false ... " string(11) "--- 10 ... " string(12) "--- -10 ... " string(16) "--- 123.456 ... " string(17) "--- -123.456 ... " string(14) "--- "yes" ... " string(13) "--- "no" ... " string(12) "--- "~" ... " string(12) "--- '-' ... " string(13) "--- '''' ... " string(12) "--- '"' ... " string(50) "--- I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n ... " string(33) "--- '# looks like a comment' ... " string(28) "--- '@looks_like_a_ref' ... " string(30) "--- '&looks_like_a_alias' ... " string(16) "--- '!!str' ... " string(41) "--- '%TAG ! tag:looks.like.one,999:' ... " string(21) "--- '!something' ... " string(21) "--- Hello world! ... " string(58) "--- |- This is a string with an embedded newline. ... " string(267) "--- "This string was made with a here doc.\n\nIt contains embedded newlines.\n \t\tIt also has some embedded tabs.\n\nHere are some symbols:\n`~!@#$%^&*()_-+={}[]|\\:\";'<>,.?/\n\nThese are extended characters: I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\n\n" ... " yaml-2.2.4/tests/yaml_emit_002.phpt0000644000076600000240000000364414700763734015614 0ustar bd808staff--TEST-- yaml_emit - sequences --SKIPIF-- --INI-- serialize_precision=-1 --FILE-- ,.?/ These are extended characters: Iñtërnâtiônàlizætiøn EOD; $doc = array( null, true, false, 10, -10, 123.456, -123.456, "yes", "no", "~", "-", "'", '"', "I\\xF1t\\xEBrn\\xE2ti\\xF4n\\xE0liz\\xE6ti\\xF8n", "# looks like a comment", "@looks_like_a_ref", "&looks_like_a_alias", "!!str", "%TAG ! tag:looks.like.one,999:", "!something", "Hello world!", "This is a string with\nan embedded newline.", $str, ); echo "=== Array of scalars ===\n"; var_dump(yaml_emit($doc)); echo "=== Nested ===\n"; var_dump(yaml_emit(array( "top level", array( "in array", ), array( "in array", array( "in array", ), ), ))); echo "=== Degenerate ===\n"; var_dump(yaml_emit(array())); ?> --EXPECT-- === Array of scalars === string(604) "--- - ~ - true - false - 10 - -10 - 123.456 - -123.456 - "yes" - "no" - "~" - '-' - '''' - '"' - I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n - '# looks like a comment' - '@looks_like_a_ref' - '&looks_like_a_alias' - '!!str' - '%TAG ! tag:looks.like.one,999:' - '!something' - Hello world! - |- This is a string with an embedded newline. - "This string was made with a here doc.\n\nIt contains embedded newlines.\n \t\tIt also has some embedded tabs.\n\nHere are some symbols:\n`~!@#$%^&*()_-+={}[]|\\:\";'<>,.?/\n\nThese are extended characters: I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\n\n" ... " === Nested === string(61) "--- - top level - - in array - - in array - - in array ... " === Degenerate === string(11) "--- [] ... " yaml-2.2.4/tests/yaml_emit_003.phpt0000644000076600000240000000317214700763734015611 0ustar bd808staff--TEST-- yaml_emit - mappings --SKIPIF-- --INI-- serialize_precision=-1 --FILE-- "Chris", "family"=> "Dumars", "address"=> array( "lines"=> "458 Walkman Dr. Suite #292", "city"=> "Royal Oak", "state"=> "MI", "postal"=> 48046, ), ); $invoice = array ( "invoice"=> 34843, "date"=> 980208000, "bill-to"=> $addr, "ship-to"=> $addr, "product"=> array( array( "sku"=> "BL394D", "quantity"=> 4, "description"=> "Basketball", "price"=> 450, ), array( "sku"=> "BL4438H", "quantity"=> 1, "description"=> "Super Hoop", "price"=> 2392, ), ), "tax"=> 251.42, "total"=> 4443.52, "comments"=> "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.", ); var_dump(yaml_emit($invoice)); ?> --EXPECT-- string(620) "--- invoice: 34843 date: 980208000 bill-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 ship-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 product: - sku: BL394D quantity: 4 description: Basketball price: 450 - sku: BL4438H quantity: 1 description: Super Hoop price: 2392 tax: 251.42 total: 4443.52 comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. ... " yaml-2.2.4/tests/yaml_emit_004.phpt0000644000076600000240000000052014700763734015604 0ustar bd808staff--TEST-- yaml_emit - datetime --SKIPIF-- --INI-- date.timezone=GMT --FILE-- --EXPECT-- string(41) "--- 2008-08-03T14:52:10.000000+00:00 ... " yaml-2.2.4/tests/yaml_emit_005.phpt0000644000076600000240000000053114700763734015607 0ustar bd808staff--TEST-- yaml_emit - serializable --SKIPIF-- --FILE-- one; } } $a = new A; var_dump(yaml_emit(array('a' => $a))); ?> --EXPECT-- string(56) "--- a: !php/object "O:1:\"A\":1:{s:3:\"one\";i:1;}" ... " yaml-2.2.4/tests/yaml_emit_006.phpt0000644000076600000240000000725014700763734015615 0ustar bd808staff--TEST-- yaml_emit - ini settings --SKIPIF-- --INI-- yaml.output_canonical=0 yaml.output_indent=2 yaml.output_width=80 serialize_precision=-1 --FILE-- "Chris", "family"=> "Dumars", "address"=> array( "lines"=> "458 Walkman Dr. Suite #292", "city"=> "Royal Oak", "state"=> "MI", "postal"=> 48046, ), ); $invoice = array ( "invoice"=> 34843, "date"=> 980208000, "bill-to"=> $addr, "ship-to"=> $addr, "product"=> array( array( "sku"=> "BL394D", "quantity"=> 4, "description"=> "Basketball", "price"=> 450, ), array( "sku"=> "BL4438H", "quantity"=> 1, "description"=> "Super Hoop", "price"=> 2392, ), ), "tax"=> 251.42, "total"=> 4443.52, "comments"=> "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.", ); var_dump(yaml_emit($invoice)); ini_set("yaml.output_canonical", "1"); ini_set("yaml.output_indent", "4"); ini_set("yaml.output_width", "40"); echo "== CANONICAL ==\n"; var_dump(yaml_emit($invoice)); ?> --EXPECT-- string(620) "--- invoice: 34843 date: 980208000 bill-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 ship-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 product: - sku: BL394D quantity: 4 description: Basketball price: 450 - sku: BL4438H quantity: 1 description: Super Hoop price: 2392 tax: 251.42 total: 4443.52 comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. ... " == CANONICAL == string(1822) "--- !!map { ? !!str "invoice" : !!int "34843", ? !!str "date" : !!int "980208000", ? !!str "bill-to" : !!map { ? !!str "given" : !!str "Chris", ? !!str "family" : !!str "Dumars", ? !!str "address" : !!map { ? !!str "lines" : !!str "458 Walkman Dr.\n Suite #292", ? !!str "city" : !!str "Royal Oak", ? !!str "state" : !!str "MI", ? !!str "postal" : !!int "48046", }, }, ? !!str "ship-to" : !!map { ? !!str "given" : !!str "Chris", ? !!str "family" : !!str "Dumars", ? !!str "address" : !!map { ? !!str "lines" : !!str "458 Walkman Dr.\n Suite #292", ? !!str "city" : !!str "Royal Oak", ? !!str "state" : !!str "MI", ? !!str "postal" : !!int "48046", }, }, ? !!str "product" : !!seq [ !!map { ? !!str "sku" : !!str "BL394D", ? !!str "quantity" : !!int "4", ? !!str "description" : !!str "Basketball", ? !!str "price" : !!int "450", }, !!map { ? !!str "sku" : !!str "BL4438H", ? !!str "quantity" : !!int "1", ? !!str "description" : !!str "Super Hoop", ? !!str "price" : !!int "2392", }, ], ? !!str "tax" : !!float "251.42", ? !!str "total" : !!float "4443.52", ? !!str "comments" : !!str "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.", } ... " yaml-2.2.4/tests/yaml_emit_007.phpt0000644000076600000240000000062514700763734015615 0ustar bd808staff--TEST-- yaml_emit - recursive structures --SKIPIF-- --FILE-- "a", "b" => "b", "c" => &$recursive, ); var_dump(yaml_emit($recursive)); // clean up a little or we may see false memory leak reports unset($recursive['c']); ?> --EXPECT-- string(56) "--- a: a b: b c: &refid1 a: a b: b c: *refid1 ... " yaml-2.2.4/tests/yaml_emit_008.phpt0000644000076600000240000000272014700763734015614 0ustar bd808staff--TEST-- yaml_emit - custom tags --SKIPIF-- --FILE-- '!emit008', 'data' => $obj->data, ); } } $emit_callbacks = array( 'Emit008Example' => array('Emit008Example', 'yamlEmit') ); $t = new Emit008Example(); $t->data = array ('a','b','c'); $yaml = yaml_emit( array( 'callback' => $t, ), YAML_ANY_ENCODING, YAML_ANY_BREAK, $emit_callbacks ); var_dump($yaml); /* make sure you can undo the custome serialization */ function parse_008 ($value, $tag, $flags) { $ret = new Emit008Example(); $ret->data = $value; return $ret; } $parse_callbacks = array( '!emit008' => 'parse_008', ); $array = yaml_parse($yaml, 0, $cnt, $parse_callbacks); var_dump($array['callback'] == $t); /* roundtrip with raw object */ var_dump($t == yaml_parse( yaml_emit($t, YAML_ANY_ENCODING, YAML_ANY_BREAK, $emit_callbacks), 0, $cnt, $parse_callbacks)); ?> --EXPECT-- string(39) "--- callback: !emit008 - a - b - c ... " bool(true) bool(true) yaml-2.2.4/tests/yaml_emit_009.phpt0000644000076600000240000000230014700763734015607 0ustar bd808staff--TEST-- yaml_emit - custom tags with closures --SKIPIF-- --FILE-- function ($o) { return array( 'tag' => '!emit009', 'data' => $o->data, ); }, ); class Emit009Example { public $data; // data may be in any pecl/yaml suitable type } $t = new Emit009Example(); $t->data = array ('a','b','c'); $yaml = yaml_emit( array( 'callback' => $t, ), YAML_ANY_ENCODING, YAML_ANY_BREAK, $emit_callbacks ); var_dump($yaml); /* make sure you can undo the custome serialization */ function parse_009 ($value, $tag, $flags) { $ret = new Emit009Example(); $ret->data = $value; return $ret; } $parse_callbacks = array( '!emit009' => 'parse_009', ); $array = yaml_parse($yaml, 0, $cnt, $parse_callbacks); var_dump($array['callback'] == $t); /* roundtrip with raw object */ var_dump($t == yaml_parse( yaml_emit($t, YAML_ANY_ENCODING, YAML_ANY_BREAK, $emit_callbacks), 0, $cnt, $parse_callbacks)); ?> --EXPECT-- string(39) "--- callback: !emit009 - a - b - c ... " bool(true) bool(true) yaml-2.2.4/tests/yaml_emit_file_basic.phpt0000644000076600000240000000357414700763734017375 0ustar bd808staff--TEST-- Test Github pull request #1 --SKIPIF-- --INI-- serialize_precision=-1 --FILE-- "Chris", "family"=> "Dumars", "address"=> array( "lines"=> "458 Walkman Dr. Suite #292", "city"=> "Royal Oak", "state"=> "MI", "postal"=> 48046, ), ); $invoice = array ( "invoice"=> 34843, "date"=> 980208000, "bill-to"=> $addr, "ship-to"=> $addr, "product"=> array( array( "sku"=> "BL394D", "quantity"=> 4, "description"=> "Basketball", "price"=> 450, ), array( "sku"=> "BL4438H", "quantity"=> 1, "description"=> "Super Hoop", "price"=> 2392, ), ), "tax"=> 251.42, "total"=> 4443.52, "comments"=> "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.", ); $temp_filename = dirname(__FILE__) . 'yaml_emit_file_basic.tmp'; var_dump(yaml_emit_file($temp_filename, $invoice)); var_dump(file_get_contents($temp_filename)); ?> --CLEAN-- --EXPECT-- bool(true) string(620) "--- invoice: 34843 date: 980208000 bill-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 ship-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 product: - sku: BL394D quantity: 4 description: Basketball price: 450 - sku: BL4438H quantity: 1 description: Super Hoop price: 2392 tax: 251.42 total: 4443.52 comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. ... " yaml-2.2.4/tests/yaml_parse_001.phpt0000644000076600000240000000670614700763734015771 0ustar bd808staff--TEST-- yaml_parse - general --SKIPIF-- --INI-- yaml.decode_timestamp=1 date.timezone=GMT --FILE-- invoice: 34843 date : 2001-01-23 bill-to: &id001 given : Chris family : Dumars address: lines: | 458 Walkman Dr. Suite #292 city : Royal Oak state : MI postal : 48046 ship-to: *id001 product: - sku : BL394D quantity : 4 description : Basketball price : 450.00 - sku : BL4438H quantity : 1 description : Super Hoop price : 2392.00 tax : 251.42 total: 4443.52 comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. ')); var_dump(yaml_parse(' --- Time: 2001-11-23 15:01:42 -5 User: ed Warning: This is an error message for the log file --- Time: 2001-11-23 15:02:31 -5 User: ed Warning: A slightly different error message. --- Date: 2001-11-23 15:03:17 -5 User: ed Fatal: Unknown variable "bar" Stack: - file: TopClass.py line: 23 code: | x = MoreObject("345\n") - file: MoreClass.py line: 58 code: |- foo = bar ', -1)); ?> --EXPECT-- array(8) { ["invoice"]=> int(34843) ["date"]=> int(980208000) ["bill-to"]=> &array(3) { ["given"]=> string(5) "Chris" ["family"]=> string(6) "Dumars" ["address"]=> array(4) { ["lines"]=> string(27) "458 Walkman Dr. Suite #292 " ["city"]=> string(9) "Royal Oak" ["state"]=> string(2) "MI" ["postal"]=> int(48046) } } ["ship-to"]=> &array(3) { ["given"]=> string(5) "Chris" ["family"]=> string(6) "Dumars" ["address"]=> array(4) { ["lines"]=> string(27) "458 Walkman Dr. Suite #292 " ["city"]=> string(9) "Royal Oak" ["state"]=> string(2) "MI" ["postal"]=> int(48046) } } ["product"]=> array(2) { [0]=> array(4) { ["sku"]=> string(6) "BL394D" ["quantity"]=> int(4) ["description"]=> string(10) "Basketball" ["price"]=> float(450) } [1]=> array(4) { ["sku"]=> string(7) "BL4438H" ["quantity"]=> int(1) ["description"]=> string(10) "Super Hoop" ["price"]=> float(2392) } } ["tax"]=> float(251.42) ["total"]=> float(4443.52) ["comments"]=> string(68) "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338." } array(3) { [0]=> array(3) { ["Time"]=> int(1006545702) ["User"]=> string(2) "ed" ["Warning"]=> string(41) "This is an error message for the log file" } [1]=> array(3) { ["Time"]=> int(1006545751) ["User"]=> string(2) "ed" ["Warning"]=> string(35) "A slightly different error message." } [2]=> array(4) { ["Date"]=> int(1006545797) ["User"]=> string(2) "ed" ["Fatal"]=> string(22) "Unknown variable "bar"" ["Stack"]=> array(2) { [0]=> array(3) { ["file"]=> string(11) "TopClass.py" ["line"]=> int(23) ["code"]=> string(24) "x = MoreObject("345\n") " } [1]=> array(3) { ["file"]=> string(12) "MoreClass.py" ["line"]=> int(58) ["code"]=> string(9) "foo = bar" } } } } yaml-2.2.4/tests/yaml_parse_002.phpt0000644000076600000240000000120514700763734015757 0ustar bd808staff--TEST-- yaml_parse - multiple documents --SKIPIF-- --FILE-- --EXPECT-- array(2) { [0]=> array(3) { ["time"]=> string(8) "20:03:20" ["player"]=> string(10) "Sammy Sosa" ["action"]=> string(13) "strike (miss)" } [1]=> array(3) { ["time"]=> string(8) "20:03:47" ["player"]=> string(10) "Sammy Sosa" ["action"]=> string(10) "grand slam" } } yaml-2.2.4/tests/yaml_parse_003.phpt0000644000076600000240000000132314700763734015761 0ustar bd808staff--TEST-- yaml_parse - parse errors --SKIPIF-- --FILE-- --EXPECTF-- Warning: yaml_parse(): scanning error encountered during parsing: found character that cannot start any token (line 2, column 16), context while scanning for the next token (line 2, column 16) in %syaml_parse_003.php on line %d bool(false) Warning: yaml_parse(): scanning error encountered during parsing: found character that cannot start any token (line 2, column 15), context while scanning for the next token (line 2, column 15) in %syaml_parse_003.php on line %d bool(false) yaml-2.2.4/tests/yaml_parse_004.phpt0000644000076600000240000000072714700763734015771 0ustar bd808staff--TEST-- yaml_parse - syck bug #11585 --CREDITS-- From syck bug #11585 http://pecl.php.net/bugs/bug.php?id=11585 --SKIPIF-- --FILE-- --EXPECTF-- Warning: yaml_parse(): alias broken_pointer_to_define is not registered (line 6, column 37) in %syaml_parse_004.php on line %d bool(false) yaml-2.2.4/tests/yaml_parse_005.phpt0000644000076600000240000000370114700763734015765 0ustar bd808staff--TEST-- yaml_parse - syck bug #12656 --CREDITS-- From syck bug #12656 http://pecl.php.net/bugs/bug.php?id=12656 --SKIPIF-- --FILE-- --EXPECT-- array(9) { ["models"]=> array(1) { [0]=> string(53) "/usr/home/enovodk/data/core/easyworks/current/models/" } ["behaviors"]=> array(1) { [0]=> string(63) "/usr/home/enovodk/data/core/easyworks/current/models/behaviors/" } ["controllers"]=> array(1) { [0]=> string(58) "/usr/home/enovodk/data/core/easyworks/current/controllers/" } ["components"]=> array(1) { [0]=> string(69) "/usr/home/enovodk/data/core/easyworks/current/controllers/components/" } ["apis"]=> array(1) { [0]=> string(62) "/usr/home/enovodk/data/core/easyworks/current/controllers/api/" } ["views"]=> array(1) { [0]=> string(52) "/usr/home/enovodk/data/core/easyworks/current/views/" } ["helpers"]=> array(1) { [0]=> string(60) "/usr/home/enovodk/data/core/easyworks/current/views/helpers/" } ["libs"]=> array(1) { [0]=> string(51) "/usr/home/enovodk/data/core/easyworks/current/libs/" } ["plugins"]=> array(1) { [0]=> string(54) "/usr/home/enovodk/data/core/easyworks/current/plugins/" } } yaml-2.2.4/tests/yaml_parse_006.phpt0000644000076600000240000000317214700763734015770 0ustar bd808staff--TEST-- yaml_parse - syck bug #14384 --CREDITS-- From syck bug #14384 http://pecl.php.net/bugs/bug.php?id=14384 --SKIPIF-- --FILE-- --EXPECTF-- Warning: yaml_parse(): scanning error encountered during parsing: found character that cannot start any token (line 2, column 1), context while scanning for the next token (line 2, column 1) in %syaml_parse_006.php on line %d bool(false) Warning: yaml_parse(): scanning error encountered during parsing: found character that cannot start any token (line 2, column 3), context while scanning for the next token (line 2, column 3) in %syaml_parse_006.php on line %d bool(false) array(1) { ["key"]=> string(16) "tab before value" } array(1) { ["key"]=> string(26) "space and tab before value" } Warning: yaml_parse(): scanning error encountered during parsing: found character that cannot start any token (line 2, column 2), context while scanning for the next token (line 2, column 2) in %syaml_parse_006.php on line %d bool(false) Warning: yaml_parse(): scanning error encountered during parsing: found character that cannot start any token (line 2, column 4), context while scanning for the next token (line 2, column 4) in %syaml_parse_006.php on line %d bool(false) yaml-2.2.4/tests/yaml_parse_007.phpt0000644000076600000240000000063014700763734015765 0ustar bd808staff--TEST-- yaml_parse - serializable --SKIPIF-- --INI-- yaml.decode_php=1 --FILE-- one; } } var_dump(yaml_parse(' --- a: !php/object "O:1:\"A\":1:{s:3:\"one\";i:1;}" ... ')); ?> --EXPECTF-- array(1) { ["a"]=> object(A)#%d (1) { ["one"]=> int(1) } } yaml-2.2.4/tests/yaml_parse_008.phpt0000644000076600000240000000445314700763734015775 0ustar bd808staff--TEST-- yaml_parse - callbacks --SKIPIF-- --FILE-- $v) { $new_value .= "'{$k}' => '{$v}', "; } $value = trim($new_value, ', '); } return ""; } // yaml with some custom tags $yaml_str = << "value_c" key_d : !tag_d | some text key_e : !tag_e > some text key_f : !tag_f [ one, two ] key_g : !tag_g { sky: blue, sea: green } key_h : !tag_h - one - two key_i : !tag_i sky: blue sea: green ... YAML; $yaml = yaml_parse($yaml_str, 0, $ndocs, array( "test-tag_a" => "tag_callback", "test2-tag_b" => "tag_callback", "tag:example.com,2011:test/tag_c" => "tag_callback", "test-tag_d" => "tag_callback", "test-tag_e" => "tag_callback", "test-tag_f" => "tag_callback", "test-tag_g" => "tag_callback", "test-tag_h" => "tag_callback", "test-tag_i" => "tag_callback", )); var_dump($yaml); var_dump($ndocs); ?> --EXPECT-- array(9) { ["key_a"]=> string(46) "" ["key_b"]=> string(47) "" ["key_c"]=> string(67) "" ["key_d"]=> string(49) "" ["key_e"]=> string(49) "" ["key_f"]=> string(65) " 'one', '1' => 'two'], tag=[test-tag_f], flags=[0]>" ["key_g"]=> string(72) " 'blue', 'sea' => 'green'], tag=[test-tag_g], flags=[0]>" ["key_h"]=> string(65) " 'one', '1' => 'two'], tag=[test-tag_h], flags=[0]>" ["key_i"]=> string(72) " 'blue', 'sea' => 'green'], tag=[test-tag_i], flags=[0]>" } int(1) yaml-2.2.4/tests/yaml_parse_file_001.phpt0000644000076600000240000000305214700763734016757 0ustar bd808staff--TEST-- yaml_parse_file - general --SKIPIF-- --INI-- yaml.decode_timestamp=1 date.timezone=GMT --FILE-- int(34843) ["date"]=> int(980208000) ["bill-to"]=> &array(3) { ["given"]=> string(5) "Chris" ["family"]=> string(6) "Dumars" ["address"]=> array(4) { ["lines"]=> string(27) "458 Walkman Dr. Suite #292 " ["city"]=> string(9) "Royal Oak" ["state"]=> string(2) "MI" ["postal"]=> int(48046) } } ["ship-to"]=> &array(3) { ["given"]=> string(5) "Chris" ["family"]=> string(6) "Dumars" ["address"]=> array(4) { ["lines"]=> string(27) "458 Walkman Dr. Suite #292 " ["city"]=> string(9) "Royal Oak" ["state"]=> string(2) "MI" ["postal"]=> int(48046) } } ["product"]=> array(2) { [0]=> array(4) { ["sku"]=> string(6) "BL394D" ["quantity"]=> int(4) ["description"]=> string(10) "Basketball" ["price"]=> float(450) } [1]=> array(4) { ["sku"]=> string(7) "BL4438H" ["quantity"]=> int(1) ["description"]=> string(10) "Super Hoop" ["price"]=> float(2392) } } ["tax"]=> float(251.42) ["total"]=> float(4443.52) ["comments"]=> string(68) "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338." } yaml-2.2.4/tests/yaml_parse_file_001.yaml0000644000076600000240000000120414700763734016743 0ustar bd808staff--- ! invoice: 34843 date : 2001-01-23 bill-to: &id001 given : Chris family : Dumars address: lines: | 458 Walkman Dr. Suite #292 city : Royal Oak state : MI postal : 48046 ship-to: *id001 product: - sku : BL394D quantity : 4 description : Basketball price : 450.00 - sku : BL4438H quantity : 1 description : Super Hoop price : 2392.00 tax : 251.42 total: 4443.52 comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. yaml-2.2.4/tests/yaml_parse_file_002.phpt0000644000076600000240000000251414700763734016762 0ustar bd808staff--TEST-- yaml_parse_file - error cases --SKIPIF-- --INI-- yaml.decode_timestamp=1 date.timezone=GMT ; E_ALL - E_DEPRECATED to hide Deprecated: yaml_parse_file(): Passing null to parameter #1... error_reporting=24575 --FILE-- getMessage()} in " . __FILE__ . " on line 4\n"; } try { // PHP7 emits a Warning here yaml_parse_file(''); } catch (ValueError $e) { // PHP8 raises this exception echo "\nWarning: yaml_parse_file(): {$e->getMessage()} in " . __FILE__ . " on line 11\n"; } yaml_parse_file('invalid'); try { // PHP7 emits a Warning here yaml_parse_file(); } catch (ArgumentCountError $e) { // PHP8 raises this exception echo "\nWarning: {$e->getMessage()} in " . __FILE__ . " on line 19\n"; } --EXPECTF-- Warning: yaml_parse_file(): %r(Filename|Path)%r %r(cannot|must not)%r be empty in %s on line %d Warning: yaml_parse_file(): %r(Filename|Path)%r %r(cannot|must not)%r be empty in %s on line %d Warning: yaml_parse_file(invalid): %r[Ff]%railed to open stream: No such file or directory in %s on line %d Warning: yaml_parse_file() expects at least 1 %r(argument|parameter)%r, 0 given in %s on line %d yaml-2.2.4/tests/yaml_parse_file_003.phpt0000644000076600000240000000034314700763734016761 0ustar bd808staff--TEST-- yaml_parse_file - ndocs --SKIPIF-- --FILE-- --INI-- yaml.decode_binary=1 --FILE-- --EXPECT-- bool(true) string(32) "a8363b3d0e4e39d9e77e244e216c7840" yaml-2.2.4/tests/yaml_parse_spec_bool.phpt0000644000076600000240000000052314700763734017425 0ustar bd808staff--TEST-- Yaml 1.1 Spec - bool --SKIPIF-- --FILE-- --EXPECT-- array(4) { ["canonical"]=> bool(true) ["answer"]=> bool(false) ["logical"]=> bool(true) ["option"]=> bool(true) } yaml-2.2.4/tests/yaml_parse_spec_float.phpt0000644000076600000240000000103214700763734017573 0ustar bd808staff--TEST-- Yaml 1.1 Spec - float --SKIPIF-- --FILE-- --EXPECT-- array(6) { ["canonical"]=> float(685230.15) ["exponentioal"]=> float(685230.15) ["fixed"]=> float(685230.15) ["sexagesimal"]=> float(685230.15) ["negative infinity"]=> float(-INF) ["not a number"]=> float(NAN) } yaml-2.2.4/tests/yaml_parse_spec_int.phpt0000644000076600000240000000075614700763734017274 0ustar bd808staff--TEST-- Yaml 1.1 Spec - int --SKIPIF-- --FILE-- --EXPECT-- array(6) { ["canonical"]=> int(685230) ["decimal"]=> int(685230) ["octal"]=> int(685230) ["hexadecimal"]=> int(685230) ["binary"]=> int(685230) ["sexagesimal"]=> int(685230) } yaml-2.2.4/tests/yaml_parse_spec_map.phpt0000644000076600000240000000122514700763734017247 0ustar bd808staff--TEST-- Yaml 1.1 Spec - map --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["Block style"]=> array(3) { ["Clark"]=> string(5) "Evans" ["Brian"]=> string(8) "Ingerson" ["Oren"]=> string(8) "Ben-Kiki" } ["Flow style"]=> array(3) { ["Clark"]=> string(5) "Evans" ["Brian"]=> string(8) "Ingerson" ["Oren"]=> string(8) "Ben-Kiki" } } yaml-2.2.4/tests/yaml_parse_spec_merge.phpt0000644000076600000240000000252214700763734017572 0ustar bd808staff--TEST-- Yaml 1.1 Spec - merge --SKIPIF-- --FILE-- --EXPECT-- array(8) { [0]=> array(2) { ["x"]=> int(1) ["y"]=> int(2) } [1]=> array(2) { ["x"]=> int(0) ["y"]=> int(2) } [2]=> array(1) { ["r"]=> int(10) } [3]=> array(1) { ["r"]=> int(1) } [4]=> array(4) { ["x"]=> int(1) ["y"]=> int(2) ["r"]=> int(10) ["label"]=> string(10) "center/big" } [5]=> array(4) { ["x"]=> int(1) ["y"]=> int(2) ["r"]=> int(10) ["label"]=> string(10) "center/big" } [6]=> array(4) { ["x"]=> int(1) ["y"]=> int(2) ["r"]=> int(10) ["label"]=> string(10) "center/big" } [7]=> array(4) { ["r"]=> int(10) ["x"]=> int(1) ["y"]=> int(2) ["label"]=> string(10) "center/big" } } yaml-2.2.4/tests/yaml_parse_spec_null.phpt0000644000076600000240000000142314700763734017444 0ustar bd808staff--TEST-- Yaml 1.1 Spec - null --SKIPIF-- --FILE-- --EXPECT-- array(3) { [0]=> NULL [1]=> array(4) { ["empty"]=> NULL ["canonical"]=> NULL ["english"]=> NULL [""]=> string(8) "null key" } [2]=> array(1) { ["sparse"]=> array(5) { [0]=> NULL [1]=> string(9) "2nd entry" [2]=> NULL [3]=> string(9) "4th entry" [4]=> NULL } } } yaml-2.2.4/tests/yaml_parse_spec_omap.phpt0000644000076600000240000000201314700763734017422 0ustar bd808staff--TEST-- Yaml 1.1 Spec - omap --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["Bestiary"]=> array(3) { [0]=> array(1) { ["aardvark"]=> string(33) "African pig-like ant eater. Ugly." } [1]=> array(1) { ["anteater"]=> string(38) "South-American ant eater. Two species." } [2]=> array(1) { ["anaconda"]=> string(40) "South-American constrictor snake. Scaly." } } ["Numbers"]=> array(3) { [0]=> array(1) { ["one"]=> int(1) } [1]=> array(1) { ["two"]=> int(2) } [2]=> array(1) { ["three"]=> int(3) } } } yaml-2.2.4/tests/yaml_parse_spec_pairs.phpt0000644000076600000240000000163614700763734017616 0ustar bd808staff--TEST-- Yaml 1.1 Spec - pairs --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["Block tasks"]=> array(4) { [0]=> array(1) { ["meeting"]=> string(10) "with team." } [1]=> array(1) { ["meeting"]=> string(10) "with boss." } [2]=> array(1) { ["break"]=> string(6) "lunch." } [3]=> array(1) { ["meeting"]=> string(12) "with client." } } ["Flow tasks"]=> array(2) { [0]=> array(1) { ["meeting"]=> string(9) "with team" } [1]=> array(1) { ["meeting"]=> string(9) "with boss" } } } yaml-2.2.4/tests/yaml_parse_spec_seq.phpt0000644000076600000240000000252614700763734017267 0ustar bd808staff--TEST-- Yaml 1.1 Spec - seq --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["Block style"]=> array(9) { [0]=> string(7) "Mercury" [1]=> string(5) "Venus" [2]=> string(5) "Earth" [3]=> string(4) "Mars" [4]=> string(7) "Jupiter" [5]=> string(6) "Saturn" [6]=> string(6) "Uranus" [7]=> string(7) "Neptune" [8]=> string(5) "Pluto" } ["Flow style"]=> array(9) { [0]=> string(7) "Mercury" [1]=> string(5) "Venus" [2]=> string(5) "Earth" [3]=> string(4) "Mars" [4]=> string(7) "Jupiter" [5]=> string(6) "Saturn" [6]=> string(6) "Uranus" [7]=> string(7) "Neptune" [8]=> string(5) "Pluto" } } yaml-2.2.4/tests/yaml_parse_spec_set.phpt0000644000076600000240000000057214700763734017271 0ustar bd808staff--TEST-- Yaml 1.1 Spec - set --SKIPIF-- --FILE-- --EXPECT-- array(1) { ["baseball players"]=> array(3) { ["Mark McGwire"]=> NULL ["Sammy Sosa"]=> NULL ["Ken Griffey"]=> NULL } } yaml-2.2.4/tests/yaml_parse_spec_str.phpt0000644000076600000240000000033314700763734017301 0ustar bd808staff--TEST-- Yaml 1.1 Spec - str --SKIPIF-- --FILE-- --EXPECT-- array(1) { ["string"]=> string(4) "abcd" } yaml-2.2.4/tests/yaml_parse_spec_timestamp.phpt0000644000076600000240000000133114700763734020473 0ustar bd808staff--TEST-- Yaml 1.1 Spec - timestamp --SKIPIF-- --INI-- yaml.decode_timestamp=1 date.timezone=GMT --FILE-- --EXPECT-- array(6) { ["canonical"]=> int(1008385183) ["valid iso8601"]=> int(1008385183) ["alternate iso8601"]=> int(1008385183) ["space separated"]=> int(1008385183) ["no time zone (Z)"]=> int(1008385183) ["date (00:00:00Z)"]=> int(1039824000) } yaml-2.2.4/tests/yaml_parse_url_001.phpt0000644000076600000240000000306714700763734016650 0ustar bd808staff--TEST-- yaml_parse_url - general --SKIPIF-- --INI-- yaml.decode_timestamp=1 date.timezone=GMT --FILE-- --EXPECT-- array(8) { ["invoice"]=> int(34843) ["date"]=> int(980208000) ["bill-to"]=> &array(3) { ["given"]=> string(5) "Chris" ["family"]=> string(6) "Dumars" ["address"]=> array(4) { ["lines"]=> string(27) "458 Walkman Dr. Suite #292 " ["city"]=> string(9) "Royal Oak" ["state"]=> string(2) "MI" ["postal"]=> int(48046) } } ["ship-to"]=> &array(3) { ["given"]=> string(5) "Chris" ["family"]=> string(6) "Dumars" ["address"]=> array(4) { ["lines"]=> string(27) "458 Walkman Dr. Suite #292 " ["city"]=> string(9) "Royal Oak" ["state"]=> string(2) "MI" ["postal"]=> int(48046) } } ["product"]=> array(2) { [0]=> array(4) { ["sku"]=> string(6) "BL394D" ["quantity"]=> int(4) ["description"]=> string(10) "Basketball" ["price"]=> float(450) } [1]=> array(4) { ["sku"]=> string(7) "BL4438H" ["quantity"]=> int(1) ["description"]=> string(10) "Super Hoop" ["price"]=> float(2392) } } ["tax"]=> float(251.42) ["total"]=> float(4443.52) ["comments"]=> string(68) "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338." } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_001.phpt0000644000076600000240000000101714700763734021626 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Simple Sequence --DESCRIPTION-- You can specify a list in YAML by placing each member of the list on a new line with an opening dash. These lists are called sequences. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(3) { [0]=> string(5) "apple" [1]=> string(6) "banana" [2]=> string(6) "carrot" } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_002.phpt0000644000076600000240000000103114700763734021623 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Nested Sequences --DESCRIPTION-- You can include a sequence within another sequence by giving the sequence an empty dash, followed by an indented list. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { [0]=> array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(3) "baz" } } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_003.phpt0000644000076600000240000000113714700763734021633 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Mixed Sequences --DESCRIPTION-- Sequences can contain any YAML data, including strings and other sequences. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(4) { [0]=> string(5) "apple" [1]=> array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [2]=> string(4) "x123" } [2]=> string(6) "banana" [3]=> string(6) "carrot" } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_004.phpt0000644000076600000240000000102314700763734021626 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Deeply Nested Sequences --DESCRIPTION-- Sequences can be nested even deeper, with each level of indentation representing a level of depth. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { [0]=> array(1) { [0]=> array(2) { [0]=> string(3) "uno" [1]=> string(3) "dos" } } } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_005.phpt0000644000076600000240000000112414700763734021631 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Simple Mapping --DESCRIPTION-- You can add a keyed list "also known as a dictionary or hash" to your document by placing each member of the list on a new line, with a colon seperating the key from its value. In YAML, this type of list is called a mapping. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["foo"]=> string(8) "whatever" ["bar"]=> string(5) "stuff" } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_006.phpt0000644000076600000240000000074214700763734021637 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Sequence in a Mapping --DESCRIPTION-- A value in a mapping can be a sequence. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["foo"]=> string(8) "whatever" ["bar"]=> array(2) { [0]=> string(3) "uno" [1]=> string(3) "dos" } } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_007.phpt0000644000076600000240000000106714700763734021641 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Nested Mappings --DESCRIPTION-- A value in a mapping can be another mapping. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["foo"]=> string(8) "whatever" ["bar"]=> array(3) { ["fruit"]=> string(5) "apple" ["name"]=> string(5) "steve" ["sport"]=> string(8) "baseball" } } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_008.phpt0000644000076600000240000000160214700763734021635 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Mixed Mapping --DESCRIPTION-- A mapping can contain any assortment of mappings and sequences as values. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(2) { ["foo"]=> string(8) "whatever" ["bar"]=> array(3) { [0]=> array(3) { ["fruit"]=> string(5) "apple" ["name"]=> string(5) "steve" ["sport"]=> string(8) "baseball" } [1]=> string(4) "more" [2]=> array(3) { ["python"]=> string(5) "rocks" ["perl"]=> string(6) "papers" ["ruby"]=> string(10) "scissorses" } } } yaml-2.2.4/tests/yaml_parse_wiki_YtsBasicTests_009.phpt0000644000076600000240000000105514700763734021640 0ustar bd808staff--TEST-- Yaml YtsBasicTests - Sequence-Mapping Shortcut --DESCRIPTION-- If you are adding a mapping to a sequence, you can place the mapping on the same line as the dash as a shortcut. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { [0]=> array(1) { ["work on YAML.py"]=> array(1) { [0]=> string(13) "work on Store" } } } yaml-2.2.4/tests/yaml_parse_wiki_YtsBlockMapping_001.phpt0000644000076600000240000000055214700763734022133 0ustar bd808staff--TEST-- Yaml YtsBlockMapping - One Element Mapping --DESCRIPTION-- A mapping with one key/value pair --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { ["foo"]=> string(3) "bar" } yaml-2.2.4/tests/yaml_parse_wiki_YtsBlockMapping_002.phpt0000644000076600000240000000071314700763734022133 0ustar bd808staff--TEST-- Yaml YtsBlockMapping - Multi Element Mapping --DESCRIPTION-- More than one key/value pair --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(3) { ["red"]=> string(5) "baron" ["white"]=> string(5) "walls" ["blue"]=> string(7) "berries" } yaml-2.2.4/tests/yaml_parse_wiki_YtsBlockMapping_003.phpt0000644000076600000240000000102214700763734022126 0ustar bd808staff--TEST-- Yaml YtsBlockMapping - Values aligned --DESCRIPTION-- Often times human editors of documents will align the values even though YAML emitters generally don't. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(3) { ["red"]=> string(5) "baron" ["white"]=> string(5) "walls" ["blue"]=> string(7) "berries" } yaml-2.2.4/tests/yaml_parse_wiki_YtsBlockMapping_004.phpt0000644000076600000240000000074214700763734022137 0ustar bd808staff--TEST-- Yaml YtsBlockMapping - Colons aligned --DESCRIPTION-- Spaces can come before the ': ' key/value separator. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(3) { ["red"]=> string(5) "baron" ["white"]=> string(5) "walls" ["blue"]=> string(7) "berries" } yaml-2.2.4/tests/yaml_parse_wiki_YtsMapInSeq_001.phpt0000644000076600000240000000067514700763734021250 0ustar bd808staff--TEST-- Yaml YtsMapInSeq - Single key --DESCRIPTION-- Test maps with just one key. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(2) { [0]=> array(1) { ["foo"]=> string(3) "bar" } [1]=> array(1) { ["baz"]=> string(3) "bug" } } yaml-2.2.4/tests/yaml_parse_wiki_YtsMapInSeq_002.phpt0000644000076600000240000000065114700763734021243 0ustar bd808staff--TEST-- Yaml YtsMapInSeq - Multiple keys --DESCRIPTION-- Test a map with multiple keys. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { [0]=> array(2) { ["foo"]=> string(3) "bar" ["baz"]=> string(3) "bug" } } yaml-2.2.4/tests/yaml_parse_wiki_YtsMapInSeq_003.phpt0000644000076600000240000000066614700763734021252 0ustar bd808staff--TEST-- Yaml YtsMapInSeq - Strange keys --DESCRIPTION-- Test a map with "line noise" keys. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { [0]=> array(2) { ["!@#$"]=> string(3) "foo" ["-+!@"]=> string(3) "bar" } } yaml-2.2.4/tests/yaml_parse_wiki_YtsStrangeKeys_001.phpt0000644000076600000240000000060214700763734022020 0ustar bd808staff--TEST-- Yaml YtsStrangeKeys - Quoted line noise key --DESCRIPTION-- Check that quoted line noise parses as key. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { ["!@#%"]=> string(7) "bar baz" } yaml-2.2.4/tests/yaml_parse_wiki_YtsStrangeKeys_002.phpt0000644000076600000240000000072614700763734022030 0ustar bd808staff--TEST-- Yaml YtsStrangeKeys - Unquoted line noise key --DESCRIPTION-- Check that unquoted line noise parses as key. This requires the line noise be tame enough to pass as an implicit plain key. --CREDITS-- Bryan Davis bd808@bd808.com # yaml.kwiki.org import/conversion --SKIPIF-- --FILE-- --EXPECT-- array(1) { ["-+!@#%"]=> string(7) "bar baz" } yaml-2.2.4/CREDITS0000644000076600000240000000004314700763734012222 0ustar bd808staffyaml Bryan Davis, Ryusuke Sekiyama yaml-2.2.4/LICENSE0000644000076600000240000000221414700763734012211 0ustar bd808staffThe MIT License (MIT) Copyright (c) 2007 Ryusuke SEKIYAMA Copyright (c) 2009 Keynetics Inc Copyright (c) 2015 Bryan Davis and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. yaml-2.2.4/README0000644000076600000240000000564614700763734012100 0ustar bd808staffThe Yaml PHP Extension provides a wrapper to the LibYAML library. It gives the user the ability to parse YAML document streams into PHP constructs and emit PHP constructs as valid YAML 1.1 documents. For more information about LibYAML see http://pyyaml.org/wiki/LibYAML. For more information about YAML see http://yaml.org/ Requirements: * libyaml 0.1.x BUILDING ON UNIX etc. ===================== To compile your new extension, you will have to execute the following steps: 1. $ phpize 2. $ ./configure [--with-yaml] 3. $ make 4. $ sudo make install BUILDING ON WINDOWS =================== The extension provides the VisualStudio V6 project file yaml.dsp To compile the extension you open this file using VisualStudio, select the apropriate configuration for your installation (either "Release_TS" or "Debug_TS") and create "php_yaml.dll" After successfull compilation you have to copy the newly created "php_yaml.dll" to the PHP extension directory (default: C:\PHP\extensions). TESTING ======== You can now load the extension using a php.ini directive extension="php_yaml.[so|dll]" or load it at runtime using the dl() function dl("php_yaml.[so|dll]"); The extension should now be available, you can test this using the extension_loaded() function: if (extension_loaded(yaml)) echo "yaml loaded :)"; else echo "something is wrong :("; The extension will also add its own block to the output of phpinfo(); CONFIGURATION ============= ini settings: yaml.decode_timestamp=0 for no timestamp parsing yaml.decode_timestamp=1 for strtotime parsing yaml.decode_timestamp=2 for date_create parsing yaml.decode_binary=0 for no binary decoding yaml.decode_binary=1 for base64 binary decoding yaml.decode_php=0 for no serialized object parsing yaml.decode_php=1 for serialized object parsing /** * @param string $input String to parse as YAML document stream * @param int $pos Document to extract from stream (-1 for all, 0 for first, ...) * @param int $ndocs Number of documents found in stream * @param array $callbacks Content handlers for YAML nodes. Array of tag => handler * @return mixed Parsed data */ yaml_parse ($input, $pos=0, &$ndocs=null, $callbacks=null) /** * @param mixed $data Data to encode * @param int $encoding Output encoding * @param int $linebreak Output linebreak * @return string Encoded data */ yaml_emit ($data, $encoding=YAML_ANY_ENCODING, $linebreak=YAML_ANY_BREAK) CREDITS ======== php-yaml v0.1.0 through v0.3.0 was developed by Ryusuke Sekiyama. Starting with v0.4.0 the extension has been maintained by Bryan Davis. Development of versions v0.4.0 - v1.1.0 funded by Keynetics Inc [http://keynetics.com/]. Inspiration and some implementation details have been taken from: * php-syck [http://pecl.php.net/package/syck] * MacRuby's libyaml wrapper [http://www.macruby.org/trac/browser/MacRuby/trunk/ext/libyaml] * LibYAML's examples [http://pyyaml.org/wiki/LibYAML] yaml-2.2.4/config.m40000644000076600000240000000215514700763734012717 0ustar bd808staffPHP_ARG_WITH(yaml, [whether to enable LibYAML suppot], [ --with-yaml[[=DIR]] Enable LibYAML support. DIR is the path to LibYAML install prefix]) if test "$PHP_YAML" != "no"; then AC_MSG_CHECKING([for yaml headers]) for i in "$PHP_YAML" "$prefix" /usr /usr/local; do if test -r "$i/include/yaml.h"; then PHP_YAML_DIR=$i AC_MSG_RESULT([found in $i]) break fi done if test -z "$PHP_YAML_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please install libyaml]) fi PHP_ADD_INCLUDE($PHP_YAML_DIR/include) dnl recommended flags for compilation with gcc dnl CFLAGS="$CFLAGS -Wall -fno-strict-aliasing" export OLD_CPPFLAGS="$CPPFLAGS" export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_YAML" AC_CHECK_HEADER([yaml.h], [], AC_MSG_ERROR(['yaml.h' header not found])) PHP_SUBST(YAML_SHARED_LIBADD) PHP_ADD_LIBRARY_WITH_PATH(yaml, $PHP_YAML_DIR/$PHP_LIBDIR, YAML_SHARED_LIBADD) export CPPFLAGS="$OLD_CPPFLAGS" PHP_SUBST(YAML_SHARED_LIBADD) AC_DEFINE(HAVE_YAML, 1, [ ]) PHP_NEW_EXTENSION(yaml, yaml.c parse.c emit.c detect.c , $ext_shared) fi yaml-2.2.4/config.w320000644000076600000240000000102614700763734013006 0ustar bd808staff// vim:ft=javascript ARG_WITH("yaml", "The YAML parser and emitter PHP extension", "no"); if (PHP_YAML != "no") { if ((lib=CHECK_LIB("libyaml_a.lib;libyaml.lib;yaml.lib", "yaml", PHP_YAML)) && CHECK_HEADER_ADD_INCLUDE("yaml.h", "CFLAGS_YAML")) { AC_DEFINE("HAVE_YAML", 1, "Yaml support"); if (lib.substr(lib.length - 6, 6) == '_a.lib') { ADD_FLAG("CFLAGS_YAML", "/D YAML_DECLARE_STATIC"); } EXTENSION("yaml", "yaml.c parse.c emit.c detect.c"); } else { WARNING("yaml not enabled; library or header not found"); } } yaml-2.2.4/detect.c0000644000076600000240000003712714700763734012633 0ustar bd808staff/** * YAML parser and emitter PHP extension * * Copyright (c) 2007 Ryusuke SEKIYAMA. All rights reserved. * Copyright (c) 2009 Keynetics Inc. All rights reserved. * Copyright (c) 2015 Bryan Davis and contributors. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @package php_yaml * @author Ryusuke SEKIYAMA * @author Bryan Davis * @copyright 2007 Ryusuke SEKIYAMA * @copyright 2009 Keynetics Inc * @copyright 2015 Bryan Davis and contributors * @license http://www.opensource.org/licenses/mit-license.php MIT License */ #include "php_yaml.h" #include "php_yaml_int.h" /* {{{ local macros */ #define ts_skip_space() \ while (ptr < end && (*ptr == ' ' || *ptr == '\t')) { \ ptr++; \ } #define ts_skip_number() \ while (ptr < end && *ptr >= '0' && *ptr <= '9') { \ ptr++; \ } /* }}} */ /* {{{ local prototypes */ static zend_long eval_sexagesimal_l(zend_long lval, const char *sg, const char *eos); static double eval_sexagesimal_d(double dval, const char *sg, const char *eos); /* }}} */ /* {{{ detect_scalar_type(const char *, size_t, yaml_event_t) * Guess what datatype the scalar encodes */ const char *detect_scalar_type(const char *value, size_t length, const yaml_event_t *event) { int flags = 0; zend_long lval = 0; double dval = 0.0; /* is value a null? */ if (0 == length || scalar_is_null(value, length, event)) { return YAML_NULL_TAG; } /* is value numeric? */ flags = scalar_is_numeric(value, length, &lval, &dval, NULL); if (flags != Y_SCALAR_IS_NOT_NUMERIC) { return (flags & Y_SCALAR_IS_FLOAT) ? YAML_FLOAT_TAG : YAML_INT_TAG; } /* is value boolean? */ flags = scalar_is_bool(value, length, event); if (-1 != flags) { return YAML_BOOL_TAG; } /* is value a timestamp? */ if (scalar_is_timestamp(value, length)) { return YAML_TIMESTAMP_TAG; } /* no guess */ return NULL; } /* }}} */ /* {{{ scalar_is_null(const char *,size_t,yaml_event_t) * Does this scalar encode a NULL value? * * specification is found at http://yaml.org/type/null.html. */ int scalar_is_null(const char *value, size_t length, const yaml_event_t *event) { if (NULL != event && event->data.scalar.quoted_implicit) { return 0; } if (NULL == event || event->data.scalar.plain_implicit) { if (length == 0 || (length == 1 && *value == '~') || STR_EQ("NULL", value) || STR_EQ("Null", value) || STR_EQ("null", value)) { return 1; } } else if (NULL != event && SCALAR_TAG_IS((*event), YAML_NULL_TAG)) { return 1; } return 0; } /* }}} */ /* {{{ scalar_is_bool(const char *,size_t,yaml_event_t) * Does this scalar encode a BOOL value? * * specification is found at http://yaml.org/type/bool.html. */ int scalar_is_bool(const char *value, size_t length, const yaml_event_t *event) { /* TODO: add ini setting to turn 'y'/'n' checks on/off */ if (NULL == event || IS_NOT_QUOTED_OR_TAG_IS((*event), YAML_BOOL_TAG)) { if ((length == 1 && (*value == 'Y' || *value == 'y')) || STR_EQ("YES", value) || STR_EQ("Yes", value) || STR_EQ("yes", value) || STR_EQ("TRUE", value) || STR_EQ("True", value) || STR_EQ("true", value) || STR_EQ("ON", value) || STR_EQ("On", value) || STR_EQ("on", value)) { return 1; } if ((length == 1 && (*value == 'N' || *value == 'n')) || STR_EQ("NO", value) || STR_EQ("No", value) || STR_EQ("no", value) || STR_EQ("FALSE", value) || STR_EQ("False", value) || STR_EQ("false", value) || STR_EQ("OFF", value) || STR_EQ("Off", value) || STR_EQ("off", value)) { return 0; } } else if (NULL != event && IS_NOT_IMPLICIT_AND_TAG_IS((*event), YAML_BOOL_TAG)) { if (0 == length || (1 == length && '0' == *value)) { return 0; } else { return 1; } } return -1; } /* }}} */ /* {{{ scalar_is_numeric() * Does this scalar encode a NUMERIC value? * * specification is found at http://yaml.org/type/float.html. * specification is found at http://yaml.org/type/int.html. */ int scalar_is_numeric(const char *value, size_t length, zend_long *lval, double *dval, char **str) { const char *end = value + length; char *buf = { 0 }, *ptr = { 0 }; int negative = 0; int type = 0; if (0 == length) { goto not_numeric; } /* trim */ while (value < end && (*(end - 1) == ' ' || *(end - 1) == '\t')) { end--; } while (value < end && (*value == ' ' || *value == '\t')) { value++; } if (value == end) { goto not_numeric; } /* not a number */ if (STR_EQ(".NAN", value) || STR_EQ(".NaN", value) || STR_EQ(".nan", value)) { type = Y_SCALAR_IS_FLOAT | Y_SCALAR_IS_NAN; goto finish; } /* catch the degenerate case of `.` as input */ if (STR_EQ(".", value)) { goto not_numeric; } /* sign */ if (*value == '+') { value++; } else if (*value == '-') { negative = 1; value++; } if (value == end) { goto not_numeric; } /* infinity */ if (STR_EQ(".INF", value) || STR_EQ(".Inf", value) || STR_EQ(".inf", value)) { type = Y_SCALAR_IS_FLOAT; type |= (negative ? Y_SCALAR_IS_INFINITY_N : Y_SCALAR_IS_INFINITY_P); goto finish; } /* alloc */ buf = (char *) emalloc(length + 3); ptr = buf; if (negative) { *ptr++ = '-'; } /* parse */ if (*value == '0') { *ptr++ = *value++; if (value == end) { goto return_zero; } if (*value == 'b') { /* binary integer */ *ptr++ = *value++; if (value == end) { goto not_numeric; } while (value < end && (*value == '_' || *value == '0')) { value++; } if (value == end) { goto return_zero; } /* check the sequence */ while (value < end) { if (*value == '_') { value++; } else if (*value == '0' || *value == '1') { *ptr++ = *value++; } else { goto not_numeric; } } type = Y_SCALAR_IS_INT | Y_SCALAR_IS_BINARY; } else if (*value == 'x') { /* hexadecimal integer */ *ptr++ = *value++; if (value == end) { goto not_numeric; } while (value < end && (*value == '_' || *value == '0')) { value++; } if (value == end) { goto return_zero; } /* check the sequence */ while (value < end) { if (*value == '_') { value++; } else if ((*value >= '0' && *value <= '9') || (*value >= 'A' && *value <= 'F') || (*value >= 'a' && *value <= 'f')) { *ptr++ = *value++; } else { goto not_numeric; } } type = Y_SCALAR_IS_INT | Y_SCALAR_IS_HEXADECIMAL; } else if (*value == '_' || (*value >= '0' && *value <= '7')) { /* octal integer */ while (value < end) { if (*value == '_') { value++; } else if (*value >= '0' && *value <= '7') { *ptr++ = *value++; } else { goto not_numeric; } } type = Y_SCALAR_IS_INT | Y_SCALAR_IS_OCTAL; } else if (*value == '.') { goto check_float; } else if (*value == ':') { goto check_sexa; } else { goto not_numeric; } } else if (*value >= '1' && *value <= '9') { /* integer */ *ptr++ = *value++; while (value < end) { if (*value == '_' || *value == ',') { value++; } else if (*value >= '0' && *value <= '9') { *ptr++ = *value++; } else if (*value == ':') { goto check_sexa; } else if (*value == '.') { goto check_float; } else { goto not_numeric; } } type = Y_SCALAR_IS_INT | Y_SCALAR_IS_DECIMAL; } else if (*value == ':') { /* sexagecimal */ check_sexa: while (value < end) { if (*value == '.') { type = Y_SCALAR_IS_FLOAT | Y_SCALAR_IS_SEXAGECIMAL; goto check_float; } if (*value != ':') { goto not_numeric; } *ptr++ = *value++; if (*(value + 1) == ':' || *(value + 1) == '.' || (value + 1) == end) { if (*value >= '0' && *value <= '9') { *ptr++ = *value++; } else { goto not_numeric; } } else { if ((*value >= '0' && *value <= '5') && (*(value + 1) >= '0' && *(value + 1) <= '9')) { *ptr++ = *value++; *ptr++ = *value++; } else { goto not_numeric; } } } if (*value == '.') { type = Y_SCALAR_IS_FLOAT | Y_SCALAR_IS_SEXAGECIMAL; goto check_float; } else if (value == end) { type = Y_SCALAR_IS_INT | Y_SCALAR_IS_SEXAGECIMAL; } else { goto not_numeric; } } else if (*value == '.') { /* float */ *ptr++ = '0'; check_float: *ptr++ = *value++; if (type == (Y_SCALAR_IS_FLOAT | Y_SCALAR_IS_SEXAGECIMAL)) { /* sexagecimal float */ while (value < end && (*(end - 1) == '_' || *(end - 1) == '0')) { end--; } if (value == end) { *ptr++ = '0'; } while (value < end) { if (*value == '_') { value++; } else if (*value >= '0' && *value <= '9') { *ptr++ = *value++; } else { goto not_numeric; } } } else { /* decimal float */ int is_exp = 0; while (value < end) { if (*value == '_') { value++; } else if (*value >= '0' && *value <= '9') { *ptr++ = *value++; } else if (*value == 'E' || *value == 'e') { /* exponential */ is_exp = 1; *ptr++ = *value++; if (value == end || (*value != '+' && *value != '-')) { goto not_numeric; } *ptr++ = *value++; if (value == end || *value < '0' || *value > '9' || (*value == '0' && value + 1 == end)) { goto not_numeric; } *ptr++ = *value++; while (value < end) { if (*value >= '0' && *value <= '9') { *ptr++ = *value++; } else { goto not_numeric; } } } else { goto not_numeric; } } /* trim */ if (!is_exp) { while (*(ptr - 1) == '0') { ptr--; } if (*(ptr - 1) == '.') { *ptr++ = '0'; } } type = Y_SCALAR_IS_FLOAT | Y_SCALAR_IS_DECIMAL; } } else { goto not_numeric; } /* terminate */ *ptr = '\0'; finish: /* convert & assign */ if ((type & Y_SCALAR_IS_INT) && lval != NULL) { switch (type & Y_SCALAR_FORMAT_MASK) { case Y_SCALAR_IS_BINARY: ptr = buf + 2; if (*ptr == 'b') { ptr++; } *lval = ZEND_STRTOL(ptr, (char **) NULL, 2); if (*buf == '-') { *lval *= -1L; } break; case Y_SCALAR_IS_OCTAL: *lval = ZEND_STRTOL(buf, (char **) NULL, 8); break; case Y_SCALAR_IS_HEXADECIMAL: *lval = ZEND_STRTOL(buf, (char **) NULL, 16); break; case Y_SCALAR_IS_SEXAGECIMAL: *lval = eval_sexagesimal_l(0, buf, ptr); if (*buf == '-') { *lval *= -1L; } break; default: #if PHP_VERSION_ID < 80100 ZEND_ATOL(*lval, buf); #else *lval = ZEND_ATOL(buf); #endif break; } } else if ((type & Y_SCALAR_IS_FLOAT) && dval != NULL) { switch (type & Y_SCALAR_FORMAT_MASK) { case Y_SCALAR_IS_SEXAGECIMAL: *dval = eval_sexagesimal_d(0.0, buf, ptr); if (*buf == '-') { *dval *= -1.0; } break; case Y_SCALAR_IS_INFINITY_P: *dval = php_get_inf(); break; case Y_SCALAR_IS_INFINITY_N: *dval = -php_get_inf(); break; case Y_SCALAR_IS_NAN: *dval = php_get_nan(); break; default: *dval = zend_strtod(buf, (const char **) NULL); break; } } if (buf != NULL) { if (str != NULL) { *str = buf; } else { efree(buf); } } /* return */ return type; return_zero: if (lval != NULL) { *lval = 0; } if (dval != NULL) { *dval = 0.0; } if (buf != NULL) { efree(buf); } return (Y_SCALAR_IS_INT | Y_SCALAR_IS_ZERO); not_numeric: if (buf != NULL) { efree(buf); } return Y_SCALAR_IS_NOT_NUMERIC; } /* }}} */ /* {{{ scalar_is_timestamp(const char *,size_t) * Does this scalar encode a TIMESTAMP value? * * specification is found at http://yaml.org/type/timestamp.html. */ int scalar_is_timestamp(const char *value, size_t length) { const char *ptr = value; const char *end = value + length; const char *pos1, *pos2; if (ptr == NULL || ptr == end) { return 0; } /* skip leading space */ ts_skip_space(); /* check 4 digit year and separator */ pos1 = pos2 = ptr; ts_skip_number(); if (ptr == pos1 || ptr == end || ptr - pos1 != 4 || *ptr != '-') { return 0; } /* check 1 or 2 month and separator */ pos2 = ++ptr; ts_skip_number(); if (ptr == pos2 || ptr == end || ptr - pos2 > 2 || *ptr != '-') { return 0; } /* check 1 or 2 digit day */ pos2 = ++ptr; ts_skip_number(); if (ptr == pos2 || ptr - pos2 > 2) { return 0; } /* check separator */ pos2 = ptr; if (ptr == end) { /* date only format requires YYYY-MM-DD */ return (pos2 - pos1 == 10) ? 1 : 0; } /* time separator is T or whitespace */ if (*ptr == 'T' || *ptr == 't') { ptr++; } else if (*ptr == ' ' || *ptr == '\t') { ts_skip_space(); } else { return 0; } /* check 1 or 2 digit hour and separator */ pos1 = ptr; ts_skip_number(); if (ptr == pos1 || ptr == end || ptr - pos1 > 2 || *ptr != ':') { return 0; } /* check 2 digit minute and separator */ pos1 = ++ptr; ts_skip_number(); if (ptr == end || ptr - pos1 != 2 || *ptr != ':') { return 0; } /* check 2 digit second */ pos1 = ++ptr; ts_skip_number(); if (ptr == end) { return (ptr - pos1 == 2) ? 1 : 0; } /* check optional fraction */ if (*ptr == '.') { ptr++; ts_skip_number(); } /* skip optional separator space */ ts_skip_space(); if (ptr == end) { return 1; } /* check time zone */ if (*ptr == 'Z') { ptr++; ts_skip_space(); return (ptr == end) ? 1 : 0; } /* check time zone offset sign */ if (*ptr != '+' && *ptr != '-') { return 0; } /* check 1 or 2 digit time zone hour */ pos1 = ++ptr; ts_skip_number(); if (ptr == pos1 || ptr - pos1 == 3 || ptr - pos1 > 4) { return 0; } if (ptr == end) { return 1; } /* optional time zone minute */ if (*ptr != ':') { return 0; } pos1 = ++ptr; ts_skip_number(); if (ptr - pos1 != 2) { return 0; } /* skip following space */ ts_skip_space(); return (ptr == end) ? 1 : 0; } /* }}} */ /* {{{ eval_sexagesimal_l() * Convert a base 60 number to a long */ static zend_long eval_sexagesimal_l(zend_long lval, const char *sg, const char *eos) { const char *ep; while (sg < eos && (*sg < '0' || *sg > '9')) { sg++; } ep = sg; while (ep < eos && *ep >= '0' && *ep <= '9') { ep++; } if (sg == eos) { return lval; } return eval_sexagesimal_l( lval * 60 + ZEND_STRTOL(sg, (char **) NULL, 10), ep, eos); } /* }}} */ /* {{{ eval_sexagesimal_d() * Convert a base 60 number to a double */ static double eval_sexagesimal_d(double dval, const char *sg, const char *eos) { const char *ep; while (sg < eos && *sg != '.' && (*sg < '0' || *sg > '9')) { sg++; } ep = sg; while (ep < eos && *ep >= '0' && *ep <= '9') { ep++; } if (sg == eos || *sg == '.') { return dval; } return eval_sexagesimal_d( dval * 60.0 + zend_strtod(sg, (const char **) NULL), ep, eos); } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ yaml-2.2.4/emit.c0000644000076600000240000005623314700763734012320 0ustar bd808staff/** * YAML parser and emitter PHP extension * * Copyright (c) 2007 Ryusuke SEKIYAMA. All rights reserved. * Copyright (c) 2009 Keynetics Inc. All rights reserved. * Copyright (c) 2015 Bryan Davis and contributors. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @package php_yaml * @author Ryusuke SEKIYAMA * @author Bryan Davis * @copyright 2007 Ryusuke SEKIYAMA * @copyright 2009 Keynetics Inc * @copyright 2015 Bryan Davis and contributors * @license http://www.opensource.org/licenses/mit-license.php MIT License */ #include "php_yaml.h" #include "php_yaml_int.h" /* {{{ local macros */ #define y_event_init_failed(e) \ yaml_event_delete(e); \ php_error_docref(NULL, E_WARNING,\ "Memory error: Not enough memory for creating an event (libyaml)") #define Y_ARRAY_SEQUENCE 1 #define Y_ARRAY_MAP 2 /* }}} */ /* {{{ local prototypes */ static int y_event_emit( const y_emit_state_t *state, yaml_event_t *event); static void y_handle_emitter_error(const y_emit_state_t *state); static int y_array_is_sequence(HashTable *ht); static void y_scan_recursion(const y_emit_state_t *state, zval *data); static zend_long y_search_recursive( const y_emit_state_t *state, const zend_ulong addr); static int y_write_zval( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_null( const y_emit_state_t *state, yaml_char_t *tag); static int y_write_bool( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_long( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_double( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_string( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_array( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_timestamp( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_object( const y_emit_state_t *state, zval *data, yaml_char_t *tag); static int y_write_object_callback ( const y_emit_state_t *state, zval *callback, zval *data, const char *clazz_name); static inline unsigned int get_next_char( const unsigned char *str, size_t str_len, size_t *cursor, int *status); /* }}} */ /* {{{ y_event_emit() * send an event to the emitter */ static int y_event_emit(const y_emit_state_t *state, yaml_event_t *event) { if (!yaml_emitter_emit(state->emitter, event)) { yaml_event_delete(event); y_handle_emitter_error(state); return FAILURE; } else { return SUCCESS; } } /* }}} */ /* {{{ y_handle_emitter_error() * Emit a warning about an emitter error */ static void y_handle_emitter_error(const y_emit_state_t *state) { switch (state->emitter->error) { case YAML_MEMORY_ERROR: php_error_docref(NULL, E_WARNING, "Memory error: Not enough memory for emitting"); break; case YAML_WRITER_ERROR: php_error_docref(NULL, E_WARNING, "Writer error: %s", state->emitter->problem); break; case YAML_EMITTER_ERROR: php_error_docref(NULL, E_WARNING, "Emitter error: %s", state->emitter->problem); break; default: php_error_docref(NULL, E_WARNING, "Internal error"); break; } } /* }}} */ /* {{{ y_array_is_sequence() * Does the array encode a sequence? */ static int y_array_is_sequence(HashTable *ht) { zend_ulong kidx, idx; zend_string *str_key; idx = 0; ZEND_HASH_FOREACH_KEY(ht, kidx, str_key) { if (str_key) { /* non-numeric key found */ return Y_ARRAY_MAP; } else if (kidx != idx) { /* gap in sequence found */ return Y_ARRAY_MAP; } idx++; } ZEND_HASH_FOREACH_END(); return Y_ARRAY_SEQUENCE; } /* }}} */ /* {{{ y_scan_recursion() * walk an object graph looking for recursive references */ static void y_scan_recursion(const y_emit_state_t *state, zval *data) { HashTable *ht; zval *elm; ZVAL_DEREF(data); ht = HASH_OF(data); if (!ht) { /* data isn't an array or object, so we're done */ return; } #if PHP_VERSION_ID >= 70300 if (!(GC_FLAGS(ht) & GC_IMMUTABLE) && GC_IS_RECURSIVE(ht)) { #else if (ZEND_HASH_APPLY_PROTECTION(ht) && ht->u.v.nApplyCount > 0) { #endif zval tmp; ZVAL_LONG(&tmp, (zend_ulong) ht); /* we've seen this before, so record address */ zend_hash_next_index_insert(state->recursive, &tmp); return; } #if PHP_VERSION_ID >= 70300 if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { GC_PROTECT_RECURSION(ht); } #else if (ZEND_HASH_APPLY_PROTECTION(ht)) { ht->u.v.nApplyCount++; } #endif ZEND_HASH_FOREACH_VAL(ht, elm) { y_scan_recursion(state, elm); } ZEND_HASH_FOREACH_END(); #if PHP_VERSION_ID >= 70300 if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(ht); } #else if (ZEND_HASH_APPLY_PROTECTION(ht)) { ht->u.v.nApplyCount--; } #endif return; } /* }}} */ /* {{{ y_search_recursive() * Search the recursive state hash for an address */ static zend_long y_search_recursive( const y_emit_state_t *state, const zend_ulong addr) { zval *entry; zend_ulong num_key; zend_ulong found; ZEND_HASH_FOREACH_NUM_KEY_VAL(state->recursive, num_key, entry) { found = Z_LVAL_P(entry); if (addr == found) { return num_key; } } ZEND_HASH_FOREACH_END(); return -1; } /* }}} */ /* {{{ y_write_zval() * Write a php zval to the emitter */ static int y_write_zval( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { int status = FAILURE; switch (Z_TYPE_P(data)) { case IS_REFERENCE: status = y_write_zval(state, Z_REFVAL_P(data), tag); break; case IS_NULL: status = y_write_null(state, tag); break; case IS_TRUE: case IS_FALSE: status = y_write_bool(state, data, tag); break; case IS_LONG: status = y_write_long(state, data, tag); break; case IS_DOUBLE: status = y_write_double(state, data, tag); break; case IS_STRING: status = y_write_string(state, data, tag); break; case IS_ARRAY: status = y_write_array(state, data, tag); break; case IS_OBJECT: status = y_write_object(state, data, tag); break; case IS_RESOURCE: /* unsupported object */ php_error_docref(NULL, E_NOTICE, "Unable to emit PHP resources."); break; default: /* something we didn't think of */ php_error_docref(NULL, E_NOTICE, "Unsupported php zval type %d.", Z_TYPE_P(data)); break; } return status; } /* }}} */ /* {{{ y_write_null() */ static int y_write_null(const y_emit_state_t *state, yaml_char_t *tag) { yaml_event_t event; int omit_tag = 0; int status; if (NULL == tag) { tag = (yaml_char_t *) YAML_NULL_TAG; omit_tag = 1; } status = yaml_scalar_event_initialize(&event, NULL, tag, (yaml_char_t *) "~", strlen("~"), omit_tag, omit_tag, YAML_PLAIN_SCALAR_STYLE); if (!status) { y_event_init_failed(&event); return FAILURE; } return y_event_emit(state, &event); } /* }}} */ /* {{{ y_write_bool() */ static int y_write_bool( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { yaml_event_t event; int omit_tag = 0; int status; const char *res = Z_TYPE_P(data) == IS_TRUE ? "true" : "false"; if (NULL == tag) { tag = (yaml_char_t *) YAML_BOOL_TAG; omit_tag = 1; } status = yaml_scalar_event_initialize(&event, NULL, tag, (yaml_char_t *) res, strlen(res), omit_tag, omit_tag, YAML_PLAIN_SCALAR_STYLE); if (!status) { y_event_init_failed(&event); return FAILURE; } return y_event_emit(state, &event); } /* }}} */ /* {{{ y_write_long() */ static int y_write_long( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { yaml_event_t event; int omit_tag = 0; int status; char *res = { 0 }; size_t res_size; if (NULL == tag) { tag = (yaml_char_t *) YAML_INT_TAG; omit_tag = 1; } res_size = snprintf(res, 0, ZEND_LONG_FMT, Z_LVAL_P(data)); res = (char*) emalloc(res_size + 1); snprintf(res, res_size + 1, ZEND_LONG_FMT, Z_LVAL_P(data)); status = yaml_scalar_event_initialize(&event, NULL, tag, (yaml_char_t *) res, strlen(res), omit_tag, omit_tag, YAML_PLAIN_SCALAR_STYLE); efree(res); if (!status) { y_event_init_failed(&event); return FAILURE; } return y_event_emit(state, &event); } /* }}} */ /* {{{ y_write_double() */ static int y_write_double( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { yaml_event_t event; int omit_tag = 0; int status; char res[PHP_DOUBLE_MAX_LENGTH]; if (NULL == tag) { tag = (yaml_char_t *) YAML_FLOAT_TAG; omit_tag = 1; } // Bug 79866: let PHP determine output precision php_gcvt(Z_DVAL_P(data), (int)PG(serialize_precision), '.', 'E', res); status = yaml_scalar_event_initialize(&event, NULL, tag, (yaml_char_t *) res, strlen(res), omit_tag, omit_tag, YAML_PLAIN_SCALAR_STYLE); if (!status) { y_event_init_failed(&event); return FAILURE; } return y_event_emit(state, &event); } /* }}} */ /* {{{ y_write_string() */ static int y_write_string( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { yaml_event_t event; int omit_tag = 0; int status; yaml_scalar_style_t style = YAML_PLAIN_SCALAR_STYLE; if (NULL == tag) { tag = (yaml_char_t *) YAML_STR_TAG; omit_tag = 1; } if (NULL != detect_scalar_type(Z_STRVAL_P(data), Z_STRLEN_P(data), NULL)) { /* looks like some other type to us, make sure it's quoted */ style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; } else { size_t pos = 0, us; int j; const unsigned char *s = (const unsigned char *)Z_STRVAL_P(data); size_t len = Z_STRLEN_P(data); for (j = 0; pos < len; j++) { us = get_next_char(s, len, &pos, &status); if (status != SUCCESS) { /* invalid UTF-8 character found */ php_error_docref(NULL, E_WARNING, "Invalid UTF-8 sequence in argument"); return FAILURE; } else if ('\n' == us) { /* has newline(s), make sure they are preserved */ style = YAML_LITERAL_SCALAR_STYLE; } } } status = yaml_scalar_event_initialize(&event, NULL, tag, (yaml_char_t *) Z_STRVAL_P(data), Z_STRLEN_P(data), omit_tag, omit_tag, style); if (!status) { y_event_init_failed(&event); return FAILURE; } return y_event_emit(state, &event); } /* }}} */ /* {{{ y_write_array() */ static int y_write_array( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { yaml_event_t event; int omit_tag = 0; int status; HashTable *ht = Z_ARRVAL_P(data); zval *elm; int array_type; zval key_zval; zend_ulong kidx; zend_string *kstr; zend_long recursive_idx = -1; char *anchor = { 0 }; size_t anchor_size; array_type = y_array_is_sequence(ht); if (NULL == tag) { if (Y_ARRAY_SEQUENCE == array_type) { tag = (yaml_char_t *) YAML_SEQ_TAG; } else { tag = (yaml_char_t *) YAML_MAP_TAG; } omit_tag = 1; } /* syck does a check to see if the array is small and all scalars * if it is then it outputs in inline form */ /* search state->recursive for this ht. * if it exists: * anchor = "id%04d" % index * if ht->nApplyCount > 0: * emit a ref */ recursive_idx = y_search_recursive(state, (zend_ulong) ht); if (-1 != recursive_idx) { /* create anchor to refer to this structure */ anchor_size = snprintf(anchor, 0, "refid" ZEND_LONG_FMT, recursive_idx + 1); anchor = (char*) emalloc(anchor_size + 1); snprintf(anchor, anchor_size + 1, "refid" ZEND_LONG_FMT, recursive_idx + 1); #if PHP_VERSION_ID >= 70300 if (!(GC_FLAGS(ht) & GC_IMMUTABLE) && GC_IS_RECURSIVE(ht)) { #else if (ZEND_HASH_APPLY_PROTECTION(ht) && ht->u.v.nApplyCount > 0) { #endif /* node has been visited before */ status = yaml_alias_event_initialize( &event, (yaml_char_t *) anchor); if (!status) { y_event_init_failed(&event); efree(anchor); return FAILURE; } status = y_event_emit(state, &event); efree(anchor); return status; } } if (Y_ARRAY_SEQUENCE == array_type) { status = yaml_sequence_start_event_initialize(&event, (yaml_char_t *) anchor, tag, omit_tag, YAML_ANY_SEQUENCE_STYLE); } else { status = yaml_mapping_start_event_initialize(&event, (yaml_char_t *) anchor, tag, omit_tag, YAML_ANY_MAPPING_STYLE); } if (!status) { y_event_init_failed(&event); if (anchor) { efree(anchor); } return FAILURE; } status = y_event_emit(state, &event); if (anchor) { efree(anchor); } if (FAILURE == status) { return FAILURE; } #if PHP_VERSION_ID >= 70300 if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { /* increment access count for hash */ GC_PROTECT_RECURSION(ht); } #else if (ZEND_HASH_APPLY_PROTECTION(ht)) { /* increment access count for hash */ ht->u.v.nApplyCount++; } #endif /* emit array elements */ ZEND_HASH_FOREACH_KEY_VAL(ht, kidx, kstr, elm) { ZVAL_DEREF(elm); if (Y_ARRAY_MAP == array_type) { /* create zval for key */ if (kstr) { ZVAL_STR(&key_zval, kstr); } else { ZVAL_LONG(&key_zval, kidx); } /* emit key */ status = y_write_zval(state, &key_zval, NULL); if (SUCCESS != status) { return FAILURE; } } status = y_write_zval(state, elm, NULL); if (SUCCESS != status) { return FAILURE; } } ZEND_HASH_FOREACH_END(); #if PHP_VERSION_ID >= 70300 if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(ht); } #else if (ZEND_HASH_APPLY_PROTECTION(ht)) { ht->u.v.nApplyCount--; } #endif if (Y_ARRAY_SEQUENCE == array_type) { status = yaml_sequence_end_event_initialize(&event); } else { status = yaml_mapping_end_event_initialize(&event); } if (!status) { y_event_init_failed(&event); return FAILURE; } return y_event_emit(state, &event); } /* }}} */ /* y_write_timestamp() */ static int y_write_timestamp( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { yaml_event_t event; int omit_tag = 0; int status; zend_class_entry *clazz = Z_OBJCE_P(data); zval timestamp = {{0} }; zval dtfmt; if (NULL == tag) { tag = (yaml_char_t *) YAML_TIMESTAMP_TAG; omit_tag = 1; } /* iso-8601 format specifier including milliseconds */ ZVAL_STRING(&dtfmt, "Y-m-d\\TH:i:s.uP"); /* format date as iso-8601 string */ #if PHP_VERSION_ID >= 80000 zend_call_method_with_1_params(Z_OBJ_P(data), clazz, NULL, "format", ×tamp, &dtfmt); #else zend_call_method_with_1_params(data, clazz, NULL, "format", ×tamp, &dtfmt); #endif zval_ptr_dtor(&dtfmt); /* emit formatted date */ status = yaml_scalar_event_initialize(&event, NULL, tag, (yaml_char_t *) Z_STRVAL_P(×tamp), Z_STRLEN_P(×tamp), omit_tag, omit_tag, YAML_PLAIN_SCALAR_STYLE); zval_ptr_dtor(×tamp); if (!status) { y_event_init_failed(&event); return FAILURE; } return y_event_emit(state, &event); } /* }}} */ /* {{{ y_write_object() */ static int y_write_object( const y_emit_state_t *state, zval *data, yaml_char_t *tag) { yaml_event_t event; int status; zend_string *clazz_name; zval *callback; clazz_name = Z_OBJCE_P(data)->name; /* TODO check for a "yamlSerialize()" instance method */ if (NULL != state->callbacks && (callback = zend_hash_find( state->callbacks, clazz_name)) != NULL) { /* found a registered callback for this class */ status = y_write_object_callback( state, callback, data, clazz_name->val); } else if (0 == strncmp(clazz_name->val, "DateTime", clazz_name->len)) { status = y_write_timestamp(state, data, tag); } else { /* tag and emit serialized version of object */ php_serialize_data_t var_hash; smart_str buf = { 0 }; PHP_VAR_SERIALIZE_INIT(var_hash); php_var_serialize(&buf, data, &var_hash); PHP_VAR_SERIALIZE_DESTROY(var_hash); status = yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *) YAML_PHP_TAG, (yaml_char_t *) buf.s->val, buf.s->len, 0, 0, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!status) { y_event_init_failed(&event); status = FAILURE; } else { status = y_event_emit(state, &event); } smart_str_free(&buf); } return status; } /* }}} */ /* {{{ y_write_object_callback() */ static int y_write_object_callback ( const y_emit_state_t *state, zval *callback, zval *data, const char *clazz_name) { zval argv[1]; argv[0] = *data; zval zret; zval *ztag; zval *zdata; zend_string *str_key; int result; /* call the user function */ if (FAILURE == call_user_function(EG(function_table), NULL, callback, &zret, 1, argv) || Z_TYPE_P(&zret) == IS_UNDEF) { php_error_docref(NULL, E_WARNING, "Failed to apply callback for class '%s'" " with user defined function", clazz_name); return FAILURE; } /* return val should be array */ if (IS_ARRAY != Z_TYPE_P(&zret)) { php_error_docref(NULL, E_WARNING, "Expected callback for class '%s'" " to return an array", clazz_name); zval_ptr_dtor(&zret); return FAILURE; } /* pull out the tag and surrogate object */ str_key = zend_string_init("tag", sizeof("tag") - 1, 0); if ((ztag = zend_hash_find(Z_ARRVAL_P(&zret), str_key)) == NULL || Z_TYPE_P(ztag) != IS_STRING) { php_error_docref(NULL, E_WARNING, "Expected callback result for class '%s'" " to contain a key named 'tag' with a string value", clazz_name); zend_string_release(str_key); return FAILURE; } zend_string_release(str_key); str_key = zend_string_init("data", sizeof("data") - 1, 0); if ((zdata = zend_hash_find(Z_ARRVAL_P(&zret), str_key)) == NULL) { php_error_docref(NULL, E_WARNING, "Expected callback result for class '%s'" " to contain a key named 'data'", clazz_name); zend_string_release(str_key); return FAILURE; } zend_string_release(str_key); /* emit surrogate object and tag */ result = y_write_zval( state, zdata, (yaml_char_t *) Z_STRVAL_P(ztag)); zval_ptr_dtor(&zret); return result; } /* }}} */ /* {{{ php_yaml_write_impl() * Common stream writing logic shared by yaml_emit and yaml_emit_file. */ int php_yaml_write_impl( yaml_emitter_t *emitter, zval *data, yaml_encoding_t encoding, HashTable *callbacks) { y_emit_state_t state; yaml_event_t event; int status; state.emitter = emitter; /* scan for recursive objects */ ALLOC_HASHTABLE(state.recursive); zend_hash_init(state.recursive, 8, NULL, NULL, 0); y_scan_recursion(&state, data); state.callbacks = callbacks; /* start stream */ status = yaml_stream_start_event_initialize(&event, encoding); if (!status) { y_event_init_failed(&event); status = FAILURE; goto cleanup; } if (FAILURE == y_event_emit(&state, &event)) { status = FAILURE; goto cleanup; } /* start document */ status = yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0); if (!status) { y_event_init_failed(&event); status = FAILURE; goto cleanup; } if (FAILURE == y_event_emit(&state, &event)) { status = FAILURE; goto cleanup; } /* output data */ if (FAILURE == y_write_zval(&state, data, NULL)) { status = FAILURE; goto cleanup; } /* end document */ status = yaml_document_end_event_initialize(&event, 0); if (!status) { y_event_init_failed(&event); status = FAILURE; goto cleanup; } if (FAILURE == y_event_emit(&state, &event)) { status = FAILURE; goto cleanup; } /* end stream */ status = yaml_stream_end_event_initialize(&event); if (!status) { y_event_init_failed(&event); status = FAILURE; goto cleanup; } if (FAILURE == y_event_emit(&state, &event)) { status = FAILURE; goto cleanup; } yaml_emitter_flush(state.emitter); status = SUCCESS; cleanup: zend_hash_destroy(state.recursive); FREE_HASHTABLE(state.recursive); return status; } /* }}} */ /* {{{ php_yaml_write_to_buffer() * Emitter string buffer */ int php_yaml_write_to_buffer(void *data, unsigned char *buffer, size_t size) { smart_string_appendl((smart_string *) data, (char *) buffer, size); return 1; } /* }}} */ /* {{{ get_next_char * Copied from ext/standard/html.c @ a37ff1fa4bb149dc81fc812d03cdf7685c499403 * and trimmed to include only utf8 code branch. I would have liked to use * php_next_utf8_char() but it isn't available until php 5.4. * * Thank you cataphract@php.net! */ #define CHECK_LEN(pos, chars_need) ((str_len - (pos)) >= (chars_need)) #define MB_FAILURE(pos, advance) do { \ *cursor = pos + (advance); \ *status = FAILURE; \ return 0; \ } while (0) #define utf8_lead(c) ((c) < 0x80 || ((c) >= 0xC2 && (c) <= 0xF4)) #define utf8_trail(c) ((c) >= 0x80 && (c) <= 0xBF) static inline unsigned int get_next_char( const unsigned char *str, size_t str_len, size_t *cursor, int *status) { size_t pos = *cursor; unsigned int this_char = 0; unsigned char c; *status = SUCCESS; assert(pos <= str_len); if (!CHECK_LEN(pos, 1)) MB_FAILURE(pos, 1); /* We'll follow strategy 2. from section 3.6.1 of UTR #36: * "In a reported illegal byte sequence, do not include any * non-initial byte that encodes a valid character or is a leading * byte for a valid sequence." */ c = str[pos]; if (c < 0x80) { this_char = c; pos++; } else if (c < 0xc2) { MB_FAILURE(pos, 1); } else if (c < 0xe0) { if (!CHECK_LEN(pos, 2)) MB_FAILURE(pos, 1); if (!utf8_trail(str[pos + 1])) { MB_FAILURE(pos, utf8_lead(str[pos + 1]) ? 1 : 2); } this_char = ((c & 0x1f) << 6) | (str[pos + 1] & 0x3f); if (this_char < 0x80) { /* non-shortest form */ MB_FAILURE(pos, 2); } pos += 2; } else if (c < 0xf0) { size_t avail = str_len - pos; if (avail < 3 || !utf8_trail(str[pos + 1]) || !utf8_trail(str[pos + 2])) { if (avail < 2 || utf8_lead(str[pos + 1])) MB_FAILURE(pos, 1); else if (avail < 3 || utf8_lead(str[pos + 2])) MB_FAILURE(pos, 2); else MB_FAILURE(pos, 3); } this_char = ((c & 0x0f) << 12) | ((str[pos + 1] & 0x3f) << 6) | (str[pos + 2] & 0x3f); if (this_char < 0x800) { /* non-shortest form */ MB_FAILURE(pos, 3); } else if (this_char >= 0xd800 && this_char <= 0xdfff) { /* surrogate */ MB_FAILURE(pos, 3); } pos += 3; } else if (c < 0xf5) { size_t avail = str_len - pos; if (avail < 4 || !utf8_trail(str[pos + 1]) || !utf8_trail(str[pos + 2]) || !utf8_trail(str[pos + 3])) { if (avail < 2 || utf8_lead(str[pos + 1])) MB_FAILURE(pos, 1); else if (avail < 3 || utf8_lead(str[pos + 2])) MB_FAILURE(pos, 2); else if (avail < 4 || utf8_lead(str[pos + 3])) MB_FAILURE(pos, 3); else MB_FAILURE(pos, 4); } this_char = ((c & 0x07) << 18) | ((str[pos + 1] & 0x3f) << 12) | ((str[pos + 2] & 0x3f) << 6) | (str[pos + 3] & 0x3f); if (this_char < 0x10000 || this_char > 0x10FFFF) { /* non-shortest form or outside range */ MB_FAILURE(pos, 4); } pos += 4; } else { MB_FAILURE(pos, 1); } *cursor = pos; return this_char; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ yaml-2.2.4/parse.c0000644000076600000240000005500714700763734012472 0ustar bd808staff/** * YAML parser and emitter PHP extension * * Copyright (c) 2007 Ryusuke SEKIYAMA. All rights reserved. * Copyright (c) 2009 Keynetics Inc. All rights reserved. * Copyright (c) 2015 Bryan Davis and contributors. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @package php_yaml * @author Ryusuke SEKIYAMA * @author Bryan Davis * @copyright 2007 Ryusuke SEKIYAMA * @copyright 2009 Keynetics Inc * @copyright 2015 Bryan Davis and contributors * @license http://www.opensource.org/licenses/mit-license.php MIT License */ #include "php_yaml.h" #include "php_yaml_int.h" /* {{{ local macros */ #define Y_PARSER_CONTINUE 0 #define Y_PARSER_SUCCESS 1 #define Y_PARSER_FAILURE -1 #define Y_FILTER_NONE 0 #define Y_FILTER_SUCCESS 1 #define Y_FILTER_FAILURE -1 #define NEXT_EVENT() yaml_next_event(state) #define COPY_EVENT(dest, state) \ memcpy(&dest, &state->event, sizeof(yaml_event_t)); \ state->have_event = 0; \ memset(&state->event, 0, sizeof(yaml_event_t)) /* }}} */ /* {{{ local prototypes */ static void handle_parser_error(const yaml_parser_t *parser); static inline int yaml_next_event(parser_state_t *state); void get_next_element( parser_state_t *state, zval *retval); void handle_document(parser_state_t *state, zval *retval); void handle_mapping(parser_state_t *state, zval *retval); void handle_sequence(parser_state_t *state, zval *retval); void handle_scalar(parser_state_t *state, zval *retval); void handle_alias(parser_state_t *state, zval *retval); static zval *record_anchor_make_ref(zval *aliases, const char *anchor, zval *value); static int apply_filter( zval *zp, yaml_event_t event, HashTable *callbacks); static int eval_timestamp(zval **zpp, const char *ts, size_t ts_len); /* }}} */ /* {{{ php_yaml_read_all() * Process events from yaml parser */ void php_yaml_read_all(parser_state_t *state, zend_long *ndocs, zval *retval) { zval doc; int code = Y_PARSER_CONTINUE; /* create an empty array to hold results */ array_init(retval); while (Y_PARSER_CONTINUE == code) { if (!NEXT_EVENT()) { code = Y_PARSER_FAILURE; break; } else if (YAML_STREAM_END_EVENT == state->event.type) { code = Y_PARSER_SUCCESS; break; } else if (YAML_STREAM_START_EVENT == state->event.type) { if (!NEXT_EVENT()) { code = Y_PARSER_FAILURE; break; } if (YAML_STREAM_END_EVENT == state->event.type) { /* entire stream consisted of an empty document */ code = Y_PARSER_SUCCESS; ZVAL_NULL(&doc); add_next_index_zval(retval, &doc); (*ndocs)++; break; } } if (YAML_DOCUMENT_START_EVENT != state->event.type) { code = Y_PARSER_FAILURE; php_error_docref(NULL, E_WARNING, "expected DOCUMENT_START event, got %d " "(line %zd, column %zd)", state->event.type, state->parser.mark.line + 1, state->parser.mark.column + 1); break; } handle_document(state, &doc); if (Z_TYPE_P(&doc) == IS_UNDEF) { code = Y_PARSER_FAILURE; break; } add_next_index_zval(retval, &doc); (*ndocs)++; } if (state->have_event) { yaml_event_delete(&state->event); } if (Y_PARSER_FAILURE == code) { //TODO sdubois //zval_ptr_dtor(&retval); ZVAL_UNDEF(retval); } } /* }}} */ /* {{{ php_yaml_read_partial() * Read a particular document from the parser's document stream. */ void php_yaml_read_partial( parser_state_t *state, zend_long pos, zend_long *ndocs, zval *retval) { int code = Y_PARSER_CONTINUE; while (Y_PARSER_CONTINUE == code) { if (!NEXT_EVENT()) { code = Y_PARSER_FAILURE; } else if (YAML_STREAM_END_EVENT == state->event.type) { if (pos != 0) { /* reached end of stream without finding what we wanted */ php_error_docref(NULL, E_WARNING, "end of stream reached without finding document " ZEND_LONG_FMT, pos); code = Y_PARSER_FAILURE; } else { /* an empty document is valid YAML */ code = Y_PARSER_SUCCESS; ZVAL_NULL(retval); } } else if (YAML_DOCUMENT_START_EVENT == state->event.type) { if (*ndocs == pos) { handle_document(state, retval); if (Z_TYPE_P(retval) == IS_UNDEF) { code = Y_PARSER_FAILURE; break; } code = Y_PARSER_SUCCESS; } /* count each document as we pass */ (*ndocs)++; } } if (state->have_event) { yaml_event_delete(&state->event); } if (Y_PARSER_FAILURE == code) { //TODO sdubois if (Z_TYPE_P(retval) != IS_UNDEF) { ZVAL_UNDEF(retval); } } } /* }}} */ /* {{{ handle_parser_error() * Emit a warning about a parser error */ static void handle_parser_error(const yaml_parser_t *parser) { const char *error_type; switch (parser->error) { case YAML_MEMORY_ERROR: error_type = "memory allocation"; break; case YAML_READER_ERROR: error_type = "reading"; break; case YAML_SCANNER_ERROR: error_type = "scanning"; break; case YAML_PARSER_ERROR: error_type = "parsing"; break; default: /* Shouldn't happen. */ error_type = "unknown"; break; } if (NULL != parser->problem) { if (parser->context) { php_error_docref(NULL, E_WARNING, "%s error encountered during parsing: %s " "(line %zd, column %zd), " "context %s (line %zd, column %zd)", error_type, parser->problem, parser->problem_mark.line + 1, parser->problem_mark.column + 1, parser->context, parser->context_mark.line + 1, parser->context_mark.column + 1); } else { php_error_docref(NULL, E_WARNING, "%s error encountered during parsing: %s " "(line %zd, column %zd)", error_type, parser->problem, parser->problem_mark.line + 1, parser->problem_mark.column + 1); } } else { php_error_docref(NULL, E_WARNING, "%s error encountred during parsing", error_type); } } /* }}} */ /* {{{ yaml_next_event() * Load the next parser event */ static inline int yaml_next_event(parser_state_t *state) { if (state->have_event) { /* free prior event */ yaml_event_delete(&state->event); state->have_event = 0; } if (!yaml_parser_parse(&state->parser, &state->event)) { /* error encountered parsing input */ state->have_event = 0; handle_parser_error(&state->parser); } else { state->have_event = 1; } return state->have_event; } /* }}} */ /* {{{ get_next_element() * Extract the next whole element from the parse stream */ void get_next_element(parser_state_t *state, zval *retval) { if (!NEXT_EVENT()) { /* check state->event if you need to know the difference between * this error and a halt event */ ZVAL_UNDEF(retval); return; } switch (state->event.type) { case YAML_DOCUMENT_END_EVENT: case YAML_MAPPING_END_EVENT: case YAML_SEQUENCE_END_EVENT: case YAML_STREAM_END_EVENT: /* halting events */ break; case YAML_DOCUMENT_START_EVENT: handle_document(state, retval); break; case YAML_MAPPING_START_EVENT: handle_mapping(state, retval); break; case YAML_SEQUENCE_START_EVENT: handle_sequence(state, retval); break; case YAML_SCALAR_EVENT: handle_scalar(state, retval); break; case YAML_ALIAS_EVENT: handle_alias(state, retval); break; default: /* any other event is an error */ php_error_docref(NULL, E_WARNING, "Unexpected event type %d " "(line %zd, column %zd)", state->event.type, state->parser.mark.line + 1, state->parser.mark.column + 1); break; } } /* }}} */ /* {{{ handle_document() * Handle a document event */ void handle_document(parser_state_t *state, zval *retval) { /* make a new array to hold aliases */ array_init(&state->aliases); /* document consists of next element */ get_next_element(state, retval); /* clean up aliases */ zval_ptr_dtor(&state->aliases); /* assert that end event is next in stream */ if (NULL != retval && NEXT_EVENT() && YAML_DOCUMENT_END_EVENT != state->event.type) { zval_ptr_dtor(retval); ZVAL_UNDEF(retval); //retval = NULL; } } /* }}} */ /* {{{ handle_mapping() * Handle a mapping event */ void handle_mapping(parser_state_t *state, zval *retval) { yaml_event_t src_event = { YAML_NO_EVENT }, key_event = { YAML_NO_EVENT }; zval key = {{0} }; zval value = {{0} }; zval *arrval = retval; zval *valptr; /* save copy of mapping start event */ COPY_EVENT(src_event, state); /* make a new array to hold mapping */ array_init(retval); if (NULL != src_event.data.mapping_start.anchor) { /* record anchors in current alias table */ arrval = record_anchor_make_ref(&state->aliases, (char *) src_event.data.mapping_start.anchor, retval); } for (get_next_element(state, &key); Z_TYPE(key) != IS_UNDEF; get_next_element(state, &key)) { COPY_EVENT(key_event, state); get_next_element(state, &value); if (Z_TYPE(value) == IS_UNDEF) { yaml_event_delete(&src_event); yaml_event_delete(&key_event); zval_ptr_dtor(&key); return; } valptr = Z_ISREF(value) ? Z_REFVAL(value) : &value; /* check for '<<' and handle merge */ if (key_event.type == YAML_SCALAR_EVENT && IS_NOT_QUOTED_OR_TAG_IS(key_event, YAML_MERGE_TAG) && Z_TYPE(key) == IS_STRING && Z_TYPE_P(valptr) == IS_ARRAY && STR_EQ("<<", Z_STRVAL(key))) { /* zend_hash_merge */ /* * value is either a single ref or a simple array of refs */ if (YAML_ALIAS_EVENT == state->event.type) { /* single ref */ zend_hash_merge(Z_ARRVAL_P(arrval), Z_ARRVAL_P(valptr), zval_add_ref, 0); } else { /* array of refs */ zval *zvalp; ZEND_HASH_FOREACH_VAL(HASH_OF(valptr), zvalp) { if (Z_ISREF_P(zvalp)) { ZVAL_DEREF(zvalp); zend_hash_merge( Z_ARRVAL_P(arrval), Z_ARRVAL_P(zvalp), zval_add_ref, 0); } else { php_error_docref(NULL, E_WARNING, "expected a mapping for merging, but found scalar " "(line %zd, column %zd)", state->parser.mark.line + 1, state->parser.mark.column + 1); } } ZEND_HASH_FOREACH_END(); } zval_ptr_dtor(&value); } else { /* add key => value to arrval */ zval *offset = &key; ZVAL_DEREF(offset); switch(Z_TYPE_P(offset)) { case IS_DOUBLE: case IS_FALSE: case IS_LONG: case IS_NULL: case IS_RESOURCE: case IS_STRING: case IS_TRUE: array_set_zval_key(Z_ARRVAL_P(arrval), offset, &value); Z_TRY_DELREF(value); break; case IS_UNDEF: zend_hash_update(Z_ARRVAL_P(arrval), ZSTR_EMPTY_ALLOC(), &value); break; default: php_error_docref( NULL, E_WARNING, "Illegal offset type %s (line %zd, column %zd)", zend_zval_type_name(offset), state->parser.mark.line + 1, state->parser.mark.column + 1 ); zval_ptr_dtor(&value); break; } } yaml_event_delete(&key_event); zval_ptr_dtor(&key); ZVAL_UNDEF(&key); } if (YAML_MAPPING_END_EVENT != state->event.type) { //TODO Sean-Der ZVAL_UNDEF(retval); } if (NULL != retval && NULL != state->callbacks) { /* apply callbacks to the collected node */ if (Y_FILTER_FAILURE == apply_filter( retval, src_event, state->callbacks)) { //TODO Sean-Der ZVAL_UNDEF(retval); } } yaml_event_delete(&src_event); } /* }}} */ /* {{{ handle_sequence * Handle a sequence event */ void handle_sequence (parser_state_t *state, zval *retval) { yaml_event_t src_event = { YAML_NO_EVENT }; zval value = {{0} }; zval *arrval = retval; /* save copy of sequence start event */ COPY_EVENT(src_event, state); /* make a new array to hold mapping */ array_init(retval); if (NULL != src_event.data.sequence_start.anchor) { arrval = record_anchor_make_ref(&state->aliases, (char *) src_event.data.sequence_start.anchor, retval); } for (get_next_element(state, &value); Z_TYPE_P(&value) != IS_UNDEF; get_next_element(state, &value)) { add_next_index_zval(arrval, &value); ZVAL_UNDEF(&value); } if (YAML_SEQUENCE_END_EVENT != state->event.type) { zval_ptr_dtor(retval); ZVAL_UNDEF(retval); goto done; //TODO Sean-Der //zval_ptr_dtor(&retval); //retval = NULL; } if (NULL != retval && NULL != state->callbacks) { /* apply callbacks to the collected node */ if (Y_FILTER_FAILURE == apply_filter( retval, src_event, state->callbacks)) { zval_ptr_dtor(retval); ZVAL_UNDEF(retval); goto done; //TODO Sean-Der //retval = NULL; } } done: yaml_event_delete(&src_event); } /* }}} */ /* {{{ handle_scalar() * Handle a scalar event */ void handle_scalar(parser_state_t *state, zval *retval) { state->eval_func(state->event, state->callbacks, retval); if (NULL != retval && NULL != state->event.data.scalar.anchor) { record_anchor_make_ref(&state->aliases, (char *) state->event.data.scalar.anchor, retval); } } /* }}} */ /* {{{ handle_alias() * Handle an alias event */ void handle_alias(parser_state_t *state, zval *retval) { char *anchor = (char *) state->event.data.alias.anchor; zend_string *anchor_zstring = zend_string_init(anchor, strlen(anchor), 0); zval *alias; if ((alias = zend_hash_find(Z_ARRVAL_P(&state->aliases), anchor_zstring)) == NULL) { php_error_docref(NULL, E_WARNING, "alias %s is not registered " "(line %zd, column %zd)", anchor, state->parser.mark.line + 1, state->parser.mark.column + 1); zend_string_release(anchor_zstring); ZVAL_UNDEF(retval); return; } zend_string_release(anchor_zstring); /* add a reference to retval's internal counter */ Z_TRY_ADDREF_P(alias); ZVAL_COPY_VALUE(retval, alias); } /* }}} */ /* {{{ record_anchor_make_ref() * Record an anchor in alias table */ static zval *record_anchor_make_ref(zval *aliases, const char *anchor, zval *value) { ZVAL_MAKE_REF(value); Z_TRY_ADDREF_P(value); add_assoc_zval(aliases, anchor, value); return Z_REFVAL_P(value); } /* }}} */ /* {{{ apply_filter() * Apply user supplied hander to node */ static int apply_filter(zval *zp, yaml_event_t event, HashTable *callbacks) { char *tag = { 0 }; zend_string *tag_zstring; zval *callback = { 0 }; /* detect event type and get tag */ switch (event.type) { case YAML_SEQUENCE_START_EVENT: if (event.data.sequence_start.implicit) { tag = YAML_SEQ_TAG; } else { tag = (char *) event.data.sequence_start.tag; } break; case YAML_MAPPING_START_EVENT: if (event.data.sequence_start.implicit) { tag = YAML_MAP_TAG; } else { tag = (char *) event.data.mapping_start.tag; } break; default: /* don't care about other event types */ break; } if (NULL == tag) { return Y_FILTER_NONE; } /* find and apply the filter function */ tag_zstring = zend_string_init(tag, strlen(tag), 0); if ((callback = zend_hash_find(callbacks, tag_zstring)) != NULL) { int callback_result; zval callback_args[3]; zval retval; callback_args[0] = *zp; ZVAL_STRINGL(&callback_args[1], tag, strlen(tag)); ZVAL_LONG(&callback_args[2], 0); /* call the user function */ callback_result = call_user_function(EG(function_table), NULL, callback, &retval, 3, callback_args); /* cleanup our temp variables */ zval_ptr_dtor(&callback_args[1]); zval_ptr_dtor(&callback_args[2]); zend_string_release(tag_zstring); if (FAILURE == callback_result || Z_TYPE_P(&retval) == IS_UNDEF) { php_error_docref(NULL, E_WARNING, "Failed to apply filter for tag '%s'" " with user defined function", tag); return Y_FILTER_FAILURE; } else { if (&retval == zp) { /* throw away duplicate response */ zval_ptr_dtor(&retval); } else { /* copy result into our return var */ if (Z_ISREF_P(zp)) { zval *tmp = Z_REFVAL_P(zp); zval_ptr_dtor(tmp); ZVAL_COPY_VALUE(tmp, &retval); } else { zval_ptr_dtor(zp); ZVAL_COPY_VALUE(zp, &retval); } } return Y_FILTER_SUCCESS; } } else { zend_string_release(tag_zstring); return Y_FILTER_NONE; } } /* }}} */ /* {{{ eval_scalar() * Convert a scalar node to the proper PHP data type. * * All YAML scalar types found at http://yaml.org/type/index.html. */ void eval_scalar(yaml_event_t event, HashTable * callbacks, zval *retval) { char *value = (char *) event.data.scalar.value; size_t length = event.data.scalar.length; int flags = 0; ZVAL_NULL(retval); /* check for non-specific tag (treat as a string) */ if (SCALAR_TAG_IS(event, YAML_NONSPECIFIC_TAG) || event.data.scalar.quoted_implicit) { ZVAL_STRINGL(retval, value, length); return; } /* check for null */ if (scalar_is_null(value, length, &event)) { return; } /* check for bool */ if (-1 != (flags = scalar_is_bool(value, length, &event))) { ZVAL_BOOL(retval, (zend_bool) flags); return; } /* check for numeric (int or float) */ if (!event.data.scalar.quoted_implicit && (event.data.scalar.plain_implicit || SCALAR_TAG_IS(event, YAML_INT_TAG) || SCALAR_TAG_IS(event, YAML_FLOAT_TAG))) { zend_long lval = 0; double dval = 0.0; flags = scalar_is_numeric( value, length, &lval, &dval, NULL); if (flags != Y_SCALAR_IS_NOT_NUMERIC) { if (flags & Y_SCALAR_IS_FLOAT) { ZVAL_DOUBLE(retval, dval); } else { ZVAL_LONG(retval, lval); } if (event.data.scalar.plain_implicit) { /* pass */ } else if (SCALAR_TAG_IS(event, YAML_FLOAT_TAG) && (flags & Y_SCALAR_IS_INT)) { convert_to_double(retval); } else if (SCALAR_TAG_IS(event, YAML_INT_TAG) && (flags & Y_SCALAR_IS_FLOAT)) { convert_to_long(retval); } return; } else if (IS_NOT_IMPLICIT_AND_TAG_IS(event, YAML_FLOAT_TAG)) { ZVAL_STRINGL(retval, value, length); convert_to_double(retval); return; } else if (IS_NOT_IMPLICIT_AND_TAG_IS(event, YAML_INT_TAG)) { ZVAL_STRINGL(retval, value, length); convert_to_long(retval); return; } } /* check for timestamp */ if (IS_NOT_IMPLICIT_AND_TAG_IS(event, YAML_TIMESTAMP_TAG) || scalar_is_timestamp(value, length)) { if (FAILURE == eval_timestamp( &retval, value, (int) length)) { ZVAL_NULL(retval); } return; } /* check for binary */ if (YAML_G(decode_binary) && IS_NOT_IMPLICIT_AND_TAG_IS(event, YAML_BINARY_TAG)) { zend_string *data; data = php_base64_decode((const unsigned char *) value, (int) length); if (NULL == data) { php_error_docref(NULL, E_WARNING, "Failed to decode binary"); ZVAL_NULL(retval); } else { ZVAL_STR(retval, data); } return; } /* check for php object */ if (YAML_G(decode_php) && IS_NOT_IMPLICIT_AND_TAG_IS(event, YAML_PHP_TAG)) { const unsigned char *p; php_unserialize_data_t var_hash; p = (const unsigned char *) value; PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize( retval, &p, p + (int) length, &var_hash)) { php_error_docref(NULL, E_NOTICE, "Failed to unserialize class"); /* return the serialized string directly */ ZVAL_STRINGL(retval, value, length); } PHP_VAR_UNSERIALIZE_DESTROY(var_hash); return; } /* others (treat as a string) */ ZVAL_STRINGL(retval, value, length); return; } /* }}} */ /* {{{ eval_scalar_with_callbacks() * Convert a scalar node to the proper PHP data type using user supplied input * filters if available. */ void eval_scalar_with_callbacks(yaml_event_t event, HashTable *callbacks, zval *retval) { const char *tag = (char *) event.data.scalar.tag; zend_string *tag_zstring; zval *callback; if (YAML_PLAIN_SCALAR_STYLE == event.data.scalar.style && NULL == tag) { /* plain scalar with no specified type */ tag = detect_scalar_type( (char *) event.data.scalar.value, event.data.scalar.length, &event); } if (NULL == tag) { /* couldn't/wouldn't detect tag type, assume string */ tag = YAML_STR_TAG; } tag_zstring = zend_string_init(tag, strlen(tag), 0); /* find and apply the evaluation function */ if ((callback = zend_hash_find(callbacks, tag_zstring)) != NULL) { zval argv[3]; ZVAL_STRINGL(&argv[0], (const char *) event.data.scalar.value, event.data.scalar.length); ZVAL_STRINGL(&argv[1], tag, strlen(tag)); ZVAL_LONG(&argv[2], event.data.scalar.style); if (FAILURE == call_user_function(EG(function_table), NULL, callback, retval, 3, argv) || Z_TYPE_P(retval) == IS_UNDEF) { php_error_docref(NULL, E_WARNING, "Failed to evaluate value for tag '%s'" " with user defined function", tag); } zval_ptr_dtor(&argv[0]); zval_ptr_dtor(&argv[1]); zval_ptr_dtor(&argv[2]); } else { /* no mapping, so handle raw */ eval_scalar(event, NULL, retval); } zend_string_release(tag_zstring); } /* }}} */ /* {{{ eval_timestamp() * Convert a timestamp * * This is switched on/off by the `yaml.decode_timestamp` ini setting. * - yaml.decode_timestamp=0 for no timestamp parsing * - yaml.decode_timestamp=1 for strtotime parsing * - yaml.decode_timestamp=2 for date_create parsing */ static int eval_timestamp(zval **zpp, const char *ts, size_t ts_len) { if (NULL != YAML_G(timestamp_decoder) || 1L == YAML_G(decode_timestamp) || 2L == YAML_G(decode_timestamp)) { zval argv[1]; zval arg, retval, *func, afunc; const char *funcs[] = { "strtotime", "date_create" }; if (NULL == YAML_G(timestamp_decoder)) { if (2L == YAML_G(decode_timestamp)) { ZVAL_STRING(&afunc, funcs[1]); } else { ZVAL_STRING(&afunc, funcs[0]); } func = &afunc; } else { func = YAML_G(timestamp_decoder); } ZVAL_STRINGL(&arg, ts, ts_len); argv[0] = arg; if (FAILURE == call_user_function(EG(function_table), NULL, func, &retval, 1, argv) || Z_TYPE_P(&retval) == IS_UNDEF) { php_error_docref(NULL, E_WARNING, "Failed to evaluate string '%s' as timestamp", ts); if (func != NULL) { zval_ptr_dtor(func); } zval_ptr_dtor(&arg); return FAILURE; } else { if (func != NULL) { zval_ptr_dtor(func); } zval_ptr_dtor(&arg); ZVAL_COPY_VALUE(*zpp, &retval); return SUCCESS; } } else { zval_dtor(*zpp); ZVAL_STRINGL(*zpp, ts, ts_len); return SUCCESS; } } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ yaml-2.2.4/php_yaml.h0000644000076600000240000000605714700763734013177 0ustar bd808staff/** * YAML parser and emitter PHP extension * * Copyright (c) 2007 Ryusuke SEKIYAMA. All rights reserved. * Copyright (c) 2009 Keynetics Inc. All rights reserved. * Copyright (c) 2015 Bryan Davis and contributors. All rights reserved. * * Permission is hereby granted, free of charge, to any personobtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @package php_yaml * @author Ryusuke SEKIYAMA * @author Bryan Davis * @copyright 2007 Ryusuke SEKIYAMA * @copyright 2009 Keynetics Inc * @copyright 2015 Bryan Davis and contributors * @license http://www.opensource.org/licenses/mit-license.php MIT License */ #ifndef PHP_YAML_H #define PHP_YAML_H #ifdef __cplusplus extern "C" { #endif #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #ifdef ZTS # include "TSRM.h" #endif #include #include #include #include #include #include #include #include #include #include #include #ifdef __cplusplus } /* extern "C" */ #endif #include #ifdef __cplusplus extern "C" { #endif #define PHP_YAML_VERSION "2.2.4" extern zend_module_entry yaml_module_entry; #define phpext_yaml_ptr &yaml_module_entry /* {{{ module globals */ ZEND_BEGIN_MODULE_GLOBALS(yaml) zend_bool decode_binary; zend_long decode_timestamp; zend_bool decode_php; zval *timestamp_decoder; zend_bool output_canonical; zend_long output_indent; zend_long output_width; ZEND_END_MODULE_GLOBALS(yaml) ZEND_EXTERN_MODULE_GLOBALS(yaml) #ifdef ZTS # define YAML_G(v) TSRMG(yaml_globals_id, zend_yaml_globals *, v) #else # define YAML_G(v) (yaml_globals.v) #endif /* }}} */ #ifdef __cplusplus } /* extern "C" */ #endif #endif /* PHP_YAML_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ yaml-2.2.4/php_yaml_int.h0000644000076600000240000001232214700763734014041 0ustar bd808staff/** * YAML parser and emitter PHP extension * * Copyright (c) 2007 Ryusuke SEKIYAMA. All rights reserved. * Copyright (c) 2009 Keynetics Inc. All rights reserved. * Copyright (c) 2015 Bryan Davis and contributors. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @package php_yaml * @author Ryusuke SEKIYAMA * @author Bryan Davis * @copyright 2007 Ryusuke SEKIYAMA * @copyright 2009 Keynetics Inc * @copyright 2015 Bryan Davis and contributors * @license http://www.opensource.org/licenses/mit-license.php MIT License */ #ifndef PHP_YAML_INT_H #define PHP_YAML_INT_H #ifdef __cplusplus extern "C" { #endif /* {{{ backcompat macros */ #ifndef ZVAL_OPT_DEREF /* Taken from php-src/Zend/zend_types.h @ 95ff285 */ #define Z_OPT_ISREF(zval) (Z_OPT_TYPE(zval) == IS_REFERENCE) #define Z_OPT_ISREF_P(zval_p) Z_OPT_ISREF(*(zval_p)) #define ZVAL_OPT_DEREF(z) do { \ if (UNEXPECTED(Z_OPT_ISREF_P(z))) { \ (z) = Z_REFVAL_P(z); \ } \ } while (0) #endif /* }}} */ /* {{{ ext/yaml types */ typedef void (*eval_scalar_func_t)(yaml_event_t event, HashTable *callbacks, zval *retval); typedef struct parser_state_s { yaml_parser_t parser; yaml_event_t event; int have_event; zval aliases; eval_scalar_func_t eval_func; HashTable *callbacks; } parser_state_t; typedef struct y_emit_state_s { yaml_emitter_t *emitter; HashTable *recursive; HashTable *callbacks; } y_emit_state_t; /* }}} */ /* {{{ ext/yaml macros */ #define YAML_BINARY_TAG "tag:yaml.org,2002:binary" #define YAML_MERGE_TAG "tag:yaml.org,2002:merge" #define YAML_PHP_TAG "!php/object" #define YAML_NONSPECIFIC_TAG "!" #define Y_SCALAR_IS_NOT_NUMERIC 0x00 #define Y_SCALAR_IS_INT 0x10 #define Y_SCALAR_IS_FLOAT 0x20 #define Y_SCALAR_IS_ZERO 0x00 #define Y_SCALAR_IS_BINARY 0x01 #define Y_SCALAR_IS_OCTAL 0x02 #define Y_SCALAR_IS_DECIMAL 0x03 #define Y_SCALAR_IS_HEXADECIMAL 0x04 #define Y_SCALAR_IS_SEXAGECIMAL 0x05 #define Y_SCALAR_IS_INFINITY_P 0x06 #define Y_SCALAR_IS_INFINITY_N 0x07 #define Y_SCALAR_IS_NAN 0x08 #define Y_SCALAR_FORMAT_MASK 0x0F #define STR_EQ(a, b)\ (a != NULL && b != NULL && 0 == strcmp(a, b)) #define SCALAR_TAG_IS(event, name) \ STR_EQ(name, (const char *)event.data.scalar.tag) #define IS_NOT_IMPLICIT(event) \ (!event.data.scalar.quoted_implicit && !event.data.scalar.plain_implicit) #define IS_NOT_IMPLICIT_AND_TAG_IS(event, name) \ (IS_NOT_IMPLICIT(event) && SCALAR_TAG_IS(event, name)) #define IS_NOT_QUOTED(event) \ (YAML_PLAIN_SCALAR_STYLE == event.data.scalar.style || YAML_ANY_SCALAR_STYLE == event.data.scalar.style) #define IS_NOT_QUOTED_OR_TAG_IS(event, name) \ (IS_NOT_QUOTED(event) && (event.data.scalar.plain_implicit || SCALAR_TAG_IS(event, name))) #define SCALAR_IS_QUOTED(event) \ (YAML_SINGLE_QUOTED_SCALAR_STYLE == event.data.scalar.style || YAML_DOUBLE_QUOTED_SCALAR_STYLE == event.data.scalar.style) /* }}} */ /* {{{ ext/yaml prototypes */ void php_yaml_read_all(parser_state_t *state, zend_long *ndocs, zval *retval); void php_yaml_read_partial( parser_state_t *state, zend_long pos, zend_long *ndocs, zval *retval); void eval_scalar(yaml_event_t event, HashTable * callbacks, zval *retval); void eval_scalar_with_callbacks( yaml_event_t event, HashTable *callbacks, zval *retval); const char *detect_scalar_type( const char *value, size_t length, const yaml_event_t *event); int scalar_is_null( const char *value, size_t length, const yaml_event_t *event); int scalar_is_bool( const char *value, size_t length, const yaml_event_t *event); int scalar_is_numeric( const char *value, size_t length, zend_long *lval, double *dval, char **str); int scalar_is_timestamp(const char *value, size_t length); int php_yaml_write_impl(yaml_emitter_t *emitter, zval *data, yaml_encoding_t encoding, HashTable *callbacks); int php_yaml_write_to_buffer( void *data, unsigned char *buffer, size_t size); /* }}} */ #ifdef __cplusplus } /* extern "C" */ #endif #endif /* PHP_YAML_INT_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ yaml-2.2.4/yaml.c0000644000076600000240000004211114700763734012312 0ustar bd808staff/** * YAML parser and emitter PHP extension * * Copyright (c) 2007 Ryusuke SEKIYAMA. All rights reserved. * Copyright (c) 2009 Keynetics Inc. All rights reserved. * Copyright (c) 2015 Bryan Davis and contributors. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @package php_yaml * @author Ryusuke SEKIYAMA * @author Bryan Davis * @copyright 2007 Ryusuke SEKIYAMA * @copyright 2009 Keynetics Inc * @copyright 2015 Bryan Davis and contributors * @license http://www.opensource.org/licenses/mit-license.php MIT License */ #include "php_yaml.h" #include "php_yaml_int.h" /* {{{ local prototypes */ static int php_yaml_check_callbacks(HashTable *callbacks); static PHP_MINIT_FUNCTION(yaml); static PHP_MSHUTDOWN_FUNCTION(yaml); static PHP_MINFO_FUNCTION(yaml); static PHP_GINIT_FUNCTION(yaml); static PHP_FUNCTION(yaml_parse); static PHP_FUNCTION(yaml_parse_file); static PHP_FUNCTION(yaml_parse_url); static PHP_FUNCTION(yaml_emit); static PHP_FUNCTION(yaml_emit_file); /* }}} */ /* {{{ globals */ ZEND_DECLARE_MODULE_GLOBALS(yaml); /* }}} */ /* {{{ ini entries */ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("yaml.decode_binary", "0", PHP_INI_ALL, OnUpdateBool, decode_binary, zend_yaml_globals, yaml_globals) STD_PHP_INI_ENTRY("yaml.decode_timestamp", "0", PHP_INI_ALL, OnUpdateLong, decode_timestamp, zend_yaml_globals, yaml_globals) STD_PHP_INI_ENTRY("yaml.decode_php", "0", PHP_INI_ALL, OnUpdateBool, decode_php, zend_yaml_globals, yaml_globals) STD_PHP_INI_ENTRY("yaml.output_canonical", "0", PHP_INI_ALL, OnUpdateBool, output_canonical, zend_yaml_globals, yaml_globals) STD_PHP_INI_ENTRY("yaml.output_indent", "2", PHP_INI_ALL, OnUpdateLong, output_indent, zend_yaml_globals, yaml_globals) STD_PHP_INI_ENTRY("yaml.output_width", "80", PHP_INI_ALL, OnUpdateLong, output_width, zend_yaml_globals, yaml_globals) PHP_INI_END() /* }}} */ /* {{{ argument informations */ #ifdef ZEND_BEGIN_ARG_INFO ZEND_BEGIN_ARG_INFO_EX(arginfo_yaml_parse, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_INFO(0, input) ZEND_ARG_INFO(0, pos) ZEND_ARG_INFO(1, ndocs) ZEND_ARG_ARRAY_INFO(0, callbacks, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_yaml_parse_file, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, pos) ZEND_ARG_INFO(1, ndocs) ZEND_ARG_ARRAY_INFO(0, callbacks, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_yaml_parse_url, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_INFO(0, url) ZEND_ARG_INFO(0, pos) ZEND_ARG_INFO(1, ndocs) ZEND_ARG_ARRAY_INFO(0, callbacks, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_yaml_emit, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_INFO(0, data) ZEND_ARG_INFO(0, encoding) ZEND_ARG_INFO(0, linebreak) ZEND_ARG_ARRAY_INFO(0, callbacks, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_yaml_emit_file, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, data) ZEND_ARG_INFO(0, encoding) ZEND_ARG_INFO(0, linebreak) ZEND_ARG_ARRAY_INFO(0, callbacks, 0) ZEND_END_ARG_INFO() #else #define arginfo_yaml_parse third_arg_force_ref #define arginfo_yaml_parse_file third_arg_force_ref #define arginfo_yaml_parse_url third_arg_force_ref #endif static zend_function_entry yaml_functions[] = { PHP_FE(yaml_parse, arginfo_yaml_parse) PHP_FE(yaml_parse_file, arginfo_yaml_parse_file) PHP_FE(yaml_parse_url, arginfo_yaml_parse_url) PHP_FE(yaml_emit, arginfo_yaml_emit) PHP_FE(yaml_emit_file, arginfo_yaml_emit_file) PHP_FE_END }; /* }}} */ /* {{{ cross-extension dependencies */ static zend_module_dep yaml_deps[] = { ZEND_MOD_OPTIONAL("date") {NULL, NULL, NULL, 0} }; /* }}} */ zend_module_entry yaml_module_entry = { /* {{{ */ STANDARD_MODULE_HEADER_EX, NULL, yaml_deps, "yaml", yaml_functions, PHP_MINIT(yaml), PHP_MSHUTDOWN(yaml), NULL, /* RINIT */ NULL, /* RSHUTDOWN */ PHP_MINFO(yaml), PHP_YAML_VERSION, PHP_MODULE_GLOBALS(yaml), PHP_GINIT(yaml), NULL, NULL, STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ #ifdef COMPILE_DL_YAML ZEND_GET_MODULE(yaml) #endif /* {{{ PHP_MINIT_FUNCTION */ static PHP_MINIT_FUNCTION(yaml) { REGISTER_INI_ENTRIES(); /* node style constants */ REGISTER_LONG_CONSTANT("YAML_ANY_SCALAR_STYLE", YAML_ANY_SCALAR_STYLE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_PLAIN_SCALAR_STYLE", YAML_PLAIN_SCALAR_STYLE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_SINGLE_QUOTED_SCALAR_STYLE", YAML_SINGLE_QUOTED_SCALAR_STYLE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_DOUBLE_QUOTED_SCALAR_STYLE", YAML_DOUBLE_QUOTED_SCALAR_STYLE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_LITERAL_SCALAR_STYLE", YAML_LITERAL_SCALAR_STYLE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_FOLDED_SCALAR_STYLE", YAML_FOLDED_SCALAR_STYLE, CONST_PERSISTENT | CONST_CS); /* tag constants */ REGISTER_STRING_CONSTANT("YAML_NULL_TAG", YAML_NULL_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_BOOL_TAG", YAML_BOOL_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_STR_TAG", YAML_STR_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_INT_TAG", YAML_INT_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_FLOAT_TAG", YAML_FLOAT_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_TIMESTAMP_TAG", YAML_TIMESTAMP_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_SEQ_TAG", YAML_SEQ_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_MAP_TAG", YAML_MAP_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_PHP_TAG", YAML_PHP_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_MERGE_TAG", YAML_MERGE_TAG, CONST_PERSISTENT | CONST_CS); REGISTER_STRING_CONSTANT("YAML_BINARY_TAG", YAML_BINARY_TAG, CONST_PERSISTENT | CONST_CS); /* encoding constants */ REGISTER_LONG_CONSTANT("YAML_ANY_ENCODING", YAML_ANY_ENCODING, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_UTF8_ENCODING", YAML_UTF8_ENCODING, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_UTF16LE_ENCODING", YAML_UTF16LE_ENCODING, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_UTF16BE_ENCODING", YAML_UTF16BE_ENCODING, CONST_PERSISTENT | CONST_CS); /* linebreak constants */ REGISTER_LONG_CONSTANT("YAML_ANY_BREAK", YAML_ANY_BREAK, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_CR_BREAK", YAML_CR_BREAK, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_LN_BREAK", YAML_LN_BREAK, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("YAML_CRLN_BREAK", YAML_CRLN_BREAK, CONST_PERSISTENT | CONST_CS); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ static PHP_MSHUTDOWN_FUNCTION(yaml) { UNREGISTER_INI_ENTRIES(); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(yaml) { php_info_print_table_start(); php_info_print_table_row(2, "LibYAML Support", "enabled"); php_info_print_table_row(2, "Module Version", PHP_YAML_VERSION); php_info_print_table_row(2, "LibYAML Version", yaml_get_version_string()); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } /* }}} */ /* {{{ PHP_GINIT_FUNCTION() */ static PHP_GINIT_FUNCTION(yaml) { yaml_globals->decode_binary = 0; yaml_globals->decode_timestamp = 0; yaml_globals->decode_php = 0; yaml_globals->timestamp_decoder = NULL; yaml_globals->output_canonical = 0; yaml_globals->output_indent = 2; yaml_globals->output_width = 80; } /* }}} */ /* {{{ php_yaml_check_callbacks() * Validate user supplied callback array contents */ static int php_yaml_check_callbacks(HashTable *callbacks) { zval *entry; zend_string *key; ZEND_HASH_FOREACH_STR_KEY_VAL(callbacks, key, entry) { if (key) { zend_string *name; if (!zend_is_callable(entry, 0, &name)) { if (name != NULL) { php_error_docref(NULL, E_WARNING, "Callback for tag '%s', '%s' is not valid", key->val, name->val); zend_string_release(name); } else { php_error_docref(NULL, E_WARNING, "Callback for tag '%s' is not valid", key->val); } return FAILURE; } else { zend_string_release(name); } if (zend_string_equals_literal(key, YAML_TIMESTAMP_TAG)) { YAML_G(timestamp_decoder) = entry; } } else { php_error_docref(NULL, E_NOTICE, "Callback key should be a string"); } } ZEND_HASH_FOREACH_END(); return SUCCESS; } /* }}} */ /* {{{ proto mixed yaml_parse(string input[, int pos[, int &ndocs[, array callbacks]]]) Takes a YAML encoded string and converts it to a PHP variable. */ PHP_FUNCTION(yaml_parse) { zend_string *input; zend_long pos = 0; zval *zndocs = { 0 }; zval *zcallbacks = { 0 }; parser_state_t state; zval yaml; zend_long ndocs = 0; memset(&state, 0, sizeof(state)); state.have_event = 0; state.callbacks = NULL; YAML_G(timestamp_decoder) = NULL; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "S|lz/a/", &input, &pos, &zndocs, &zcallbacks)) { return; } if (zcallbacks != NULL) { state.callbacks = Z_ARRVAL_P(zcallbacks); if (FAILURE == php_yaml_check_callbacks(state.callbacks)) { RETURN_FALSE; } state.eval_func = eval_scalar_with_callbacks; } else { state.eval_func = eval_scalar; } yaml_parser_initialize(&state.parser); yaml_parser_set_input_string(&state.parser, (unsigned char *)input->val, input->len); if (pos < 0) { php_yaml_read_all(&state, &ndocs, &yaml); } else { php_yaml_read_partial(&state, pos, &ndocs, &yaml); } yaml_parser_delete(&state.parser); if (zndocs != NULL) { /* copy document count to var user sent in */ zval_ptr_dtor(zndocs); ZVAL_LONG(zndocs, ndocs); } if (Z_TYPE_P(&yaml) == IS_UNDEF) { RETURN_FALSE; } RETURN_ZVAL(&yaml, 1, 1); } /* }}} yaml_parse */ /* {{{ proto mixed yaml_parse_file(string filename[, int pos[, int &ndocs[, array callbacks]]]) */ PHP_FUNCTION(yaml_parse_file) { char *filename = { 0 }; size_t filename_len = 0; zend_long pos = 0; zval *zndocs = { 0 }; zval *zcallbacks = { 0 }; php_stream *stream = { 0 }; FILE *fp = { 0 }; parser_state_t state; zval yaml; zend_long ndocs = 0; memset(&state, 0, sizeof(state)); state.have_event = 0; state.callbacks = NULL; YAML_G(timestamp_decoder) = NULL; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|lz/a/", &filename, &filename_len, &pos, &zndocs, &zcallbacks)) { return; } if (zcallbacks != NULL) { state.callbacks = Z_ARRVAL_P(zcallbacks); if (FAILURE == php_yaml_check_callbacks(state.callbacks)) { RETURN_FALSE; } state.eval_func = eval_scalar_with_callbacks; } else { state.eval_func = eval_scalar; } if (NULL == (stream = php_stream_open_wrapper(filename, "rb", IGNORE_URL | REPORT_ERRORS | STREAM_WILL_CAST, NULL))) { RETURN_FALSE; } if (FAILURE == php_stream_cast( stream, PHP_STREAM_AS_STDIO, (void **) &fp, 1)) { php_stream_close(stream); RETURN_FALSE; } yaml_parser_initialize(&state.parser); yaml_parser_set_input_file(&state.parser, fp); if (pos < 0) { php_yaml_read_all(&state, &ndocs, &yaml); } else { php_yaml_read_partial(&state, pos, &ndocs, &yaml); } yaml_parser_delete(&state.parser); php_stream_close(stream); if (zndocs != NULL) { /* copy document count to var user sent in */ zval_ptr_dtor(zndocs); ZVAL_LONG(zndocs, ndocs); } if (Z_TYPE_P(&yaml) == IS_UNDEF) { RETURN_FALSE; } RETURN_ZVAL(&yaml, 1, 1); } /* }}} yaml_parse_file */ /* {{{ proto mixed yaml_parse_url(string url[, int pos[, int &ndocs[, array callbacks]]]) */ PHP_FUNCTION(yaml_parse_url) { char *url = { 0 }; size_t url_len = 0; zend_long pos = 0; zval *zndocs = { 0 }; zval *zcallbacks = { 0 }; php_stream *stream = { 0 }; zend_string *input; parser_state_t state; zval yaml; zend_long ndocs = 0; memset(&state, 0, sizeof(state)); state.have_event = 0; state.callbacks = NULL; YAML_G(timestamp_decoder) = NULL; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|lza/", &url, &url_len, &pos, &zndocs, &zcallbacks)) { return; } if (zcallbacks != NULL) { state.callbacks = Z_ARRVAL_P(zcallbacks); if (FAILURE == php_yaml_check_callbacks(state.callbacks)) { RETURN_FALSE; } state.eval_func = eval_scalar_with_callbacks; } else { state.eval_func = eval_scalar; } if (NULL == (stream = php_stream_open_wrapper(url, "rb", REPORT_ERRORS, NULL))) { RETURN_FALSE; } input = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); php_stream_close(stream); if (input == NULL) { RETURN_FALSE; } yaml_parser_initialize(&state.parser); yaml_parser_set_input_string(&state.parser, (unsigned char *)ZSTR_VAL(input), ZSTR_LEN(input)); if (pos < 0) { php_yaml_read_all(&state, &ndocs, &yaml); } else { php_yaml_read_partial(&state, pos, &ndocs, &yaml); } yaml_parser_delete(&state.parser); zend_string_release(input); if (zndocs != NULL) { /* copy document count to var user sent in */ zval_dtor(zndocs); ZVAL_LONG(zndocs, ndocs); } if (Z_TYPE_P(&yaml) == IS_UNDEF) { RETURN_FALSE; } RETURN_ZVAL(&yaml, 1, 1); } /* }}} yaml_parse_url */ /* {{{ proto string yaml_emit(mixed data[, int encoding[, int linebreak[, array callbacks]]]) */ PHP_FUNCTION(yaml_emit) { zval *data = { 0 }; zend_long encoding = YAML_ANY_ENCODING; zend_long linebreak = YAML_ANY_BREAK; zval *zcallbacks = { 0 }; HashTable *callbacks = { 0 }; yaml_emitter_t emitter = { 0 }; smart_string str = { 0 }; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "z/|lla/", &data, &encoding, &linebreak, &zcallbacks)) { return; } if (zcallbacks != NULL) { callbacks = Z_ARRVAL_P(zcallbacks); if (FAILURE == php_yaml_check_callbacks(callbacks)) { RETURN_FALSE; } } yaml_emitter_initialize(&emitter); yaml_emitter_set_output( &emitter, &php_yaml_write_to_buffer, (void *) &str); yaml_emitter_set_encoding(&emitter, (yaml_encoding_t) encoding); yaml_emitter_set_break(&emitter, (yaml_break_t) linebreak); yaml_emitter_set_canonical(&emitter, YAML_G(output_canonical)); yaml_emitter_set_indent(&emitter, YAML_G(output_indent)); yaml_emitter_set_width(&emitter, YAML_G(output_width)); yaml_emitter_set_unicode(&emitter, YAML_ANY_ENCODING != encoding); if (SUCCESS == php_yaml_write_impl( &emitter, data, (yaml_encoding_t) encoding, callbacks)) { RETVAL_STRINGL(str.c, str.len); } else { RETVAL_FALSE; } yaml_emitter_delete(&emitter); smart_string_free(&str); } /* }}} yaml_emit */ /* {{{ proto bool yaml_emit_file(string filename, mixed data[, int encoding[, int linebreak[, array callbacks]]]) */ PHP_FUNCTION(yaml_emit_file) { zend_string *filename = { 0 }; php_stream *stream = { 0 }; FILE *fp = { 0 }; zval *data = { 0 }; zend_long encoding = YAML_ANY_ENCODING; zend_long linebreak = YAML_ANY_BREAK; zval *zcallbacks = { 0 }; HashTable *callbacks = { 0 }; yaml_emitter_t emitter = { 0 }; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "Sz/|lla/", &filename, &data, &encoding, &linebreak, &zcallbacks)) { return; } if (zcallbacks != NULL) { callbacks = Z_ARRVAL_P(zcallbacks); if (FAILURE == php_yaml_check_callbacks(callbacks)) { RETURN_FALSE; } } if (NULL == (stream = php_stream_open_wrapper(filename->val, "wb", IGNORE_URL | REPORT_ERRORS | STREAM_WILL_CAST, NULL))) { RETURN_FALSE; } if (FAILURE == php_stream_cast( stream, PHP_STREAM_AS_STDIO, (void **) &fp, 1)) { php_stream_close(stream); RETURN_FALSE; } yaml_emitter_initialize(&emitter); yaml_emitter_set_output_file(&emitter, fp); yaml_emitter_set_encoding(&emitter, (yaml_encoding_t) encoding); yaml_emitter_set_break(&emitter, (yaml_break_t) linebreak); yaml_emitter_set_canonical(&emitter, YAML_G(output_canonical)); yaml_emitter_set_indent(&emitter, YAML_G(output_indent)); yaml_emitter_set_width(&emitter, YAML_G(output_width)); yaml_emitter_set_unicode(&emitter, YAML_ANY_ENCODING != encoding); RETVAL_BOOL((SUCCESS == php_yaml_write_impl( &emitter, data, YAML_ANY_ENCODING, callbacks))); yaml_emitter_delete(&emitter); php_stream_close(stream); } /* }}} yaml_emit_file */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */