Commit 1a4b0749 authored by Ondrej Sury's avatar Ondrej Sury

Imported Upstream version 2.0.0RC8+1.3.0b1

parents
This diff is collapsed.
This diff is collapsed.
yaml
Bryan Davis, Ryusuke Sekiyama
The 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.
The 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]
dnl
dnl $Id$
dnl
PHP_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
// $Id$
// 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");
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* 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 <rsky0711@gmail.com>
* @author Bryan Davis <bd808@bd808.com>
* @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 <php.h>
#include <php_ini.h>
#include <SAPI.h>
#ifdef ZTS
# include "TSRM.h"
#endif
#include <ext/standard/info.h>
#include <ext/standard/base64.h>
#include <ext/standard/basic_functions.h>
#include <ext/standard/php_var.h>
#include <ext/standard/php_smart_str.h>
#include <Zend/zend_extensions.h>
#include <Zend/zend_hash.h>
#include <Zend/zend_interfaces.h>
#ifdef __cplusplus
} /* extern "C" */
#endif
#include <yaml.h>
#ifdef __cplusplus
extern "C" {
#endif
#define PHP_YAML_VERSION "1.3.0b1"
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;
long decode_timestamp;
zend_bool decode_php;
zval *timestamp_decoder;
zend_bool output_canonical;
long output_indent;
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 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 <rsky0711@gmail.com>
* @author Bryan Davis <bd808@bd808.com>
* @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
/* {{{ ext/yaml types
*/
typedef zval *(*eval_scalar_func_t)(yaml_event_t event, HashTable *callbacks TSRMLS_DC);
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 ZEND_IS_CALLABLE(a,b,c) zend_is_callable((a), (b), (c) TSRMLS_CC)
#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
*/
zval *php_yaml_read_all(parser_state_t *state, long *ndocs TSRMLS_DC);
zval *php_yaml_read_partial(
parser_state_t *state, long pos, long *ndocs TSRMLS_DC);
zval *eval_scalar(yaml_event_t event, HashTable *callbacks TSRMLS_DC);
zval *eval_scalar_with_callbacks(
yaml_event_t event, HashTable *callbacks TSRMLS_DC);
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, 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 TSRMLS_DC);
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
*/
--TEST--
Test PECL bug #21995
--SKIPIF--
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
--FILE--
<?php
function yaml_cbk ($a) {
var_dump($a);
return $a;
}
$yaml_code = <<<YAML
boo: doo
a: [1,2,3,4]
d: []
YAML;
$yaml = yaml_parse($yaml_code, 0, $ndocs, array(
YAML_STR_TAG => "yaml_cbk",
));
?>
--EXPECT--
string(3) "boo"
string(3) "doo"
string(1) "a"
string(1) "d"
--TEST--
Test PECL bug #59860
--SKIPIF--
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
--FILE--
<?php
/**
* Parsing callback for yaml tag.
* @param mixed $value Data from yaml file
* @param string $tag Tag that triggered callback
* @param int $flags Scalar entity style (see YAML_*_SCALAR_STYLE)
* @return mixed Value that YAML parser should emit for the given value
*/
function tag_callback ($value, $tag, $flags) {
var_dump(func_get_args());
return $tag;
}
$yaml = <<<YAML
implicit_map:
a: b
explicit_map: !!map
c: d
implicit_seq: [e, f]
explicit_seq: !!seq [g, h]
YAML;
yaml_parse($yaml, 0, $ndocs, array(
YAML_MAP_TAG => '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)
}
--TEST--
Test PECL bug #260628
--SKIPIF--
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
--FILE--
<?php
$data = <<<YAML
#yaml
---
data: !mytag
- look upper
...
YAML;
function tag_callback ($value, $tag, $flags) {
echo "-- callback value --\n";
var_dump($value);
var_dump($tag);
var_dump($flags);
echo "-- end callback value --\n";
return array(
'data' => $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 --
--TEST--
Test PECL bug #61770
--SKIPIF--
<?php if(!extension_loaded('yaml')) die('skip yaml n/a'); ?>
--FILE--
<?php
var_dump(yaml_emit("\xc2"));
?>
--EXPECTF--
Warning: yaml_emit(): Invalid UTF-8 sequence in argument in %sbug_61770.php on line 2
bool(false)