
#ifdef HAVE_CONFIG_H
#include "../../../ext_config.h"
#endif

#include <php.h>
#include "../../../php_ext.h"
#include "../../../ext.h"

#include <Zend/zend_operators.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>

#include "kernel/main.h"
#include "kernel/object.h"
#include "kernel/memory.h"
#include "kernel/operators.h"
#include "kernel/concat.h"


/**
 * This file is part of the Phalcon Framework.
 *
 * For the full copyright and license information, please view the LICENSE.md
 * file that was distributed with this source code.
 *
 * Implementation of this file has been influenced by AuraPHP
 * @link    https://github.com/auraphp/Aura.Html
 * @license https://github.com/auraphp/Aura.Html/blob/2.x/LICENSE
 */
/**
 * Creates Doctype tags
 */
ZEPHIR_INIT_CLASS(Phalcon_Html_Helper_Doctype)
{
	ZEPHIR_REGISTER_CLASS(Phalcon\\Html\\Helper, Doctype, phalcon, html_helper_doctype, phalcon_html_helper_doctype_method_entry, 0);

	/**
	 * @var string
	 */
	zend_declare_property_null(phalcon_html_helper_doctype_ce, SL("delimiter"), ZEND_ACC_PRIVATE);
	/**
	 * @var int
	 */
	zend_declare_property_null(phalcon_html_helper_doctype_ce, SL("type"), ZEND_ACC_PRIVATE);
	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("HTML32"), 1);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("HTML401_STRICT"), 2);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("HTML401_TRANSITIONAL"), 3);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("HTML401_FRAMESET"), 4);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("HTML5"), 5);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("XHTML10_STRICT"), 6);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("XHTML10_TRANSITIONAL"), 7);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("XHTML10_FRAMESET"), 8);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("XHTML11"), 9);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("XHTML20"), 10);

	/**
	 * @var int
	 */
	zephir_declare_class_constant_long(phalcon_html_helper_doctype_ce, SL("XHTML5"), 11);

	return SUCCESS;
}

PHP_METHOD(Phalcon_Html_Helper_Doctype, __construct)
{
	zval _0, _1;
	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
	zval *this_ptr = getThis();

	ZVAL_UNDEF(&_0);
	ZVAL_UNDEF(&_1);
	static zend_string *_zephir_prop_0 = NULL;
	static zend_string *_zephir_prop_1 = NULL;
	if (UNEXPECTED(!_zephir_prop_0)) {
		_zephir_prop_0 = zend_string_init("type", 4, 1);
	}
	if (UNEXPECTED(!_zephir_prop_1)) {
		_zephir_prop_1 = zend_string_init("delimiter", 9, 1);
	}
	ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0);
	zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__);

	ZVAL_UNDEF(&_0);
	ZVAL_LONG(&_0, 5);
	zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 833, &_0);
	ZEPHIR_INIT_VAR(&_1);
	ZEPHIR_GET_CONSTANT(&_1, "PHP_EOL");
	zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 834, &_1);
	ZEPHIR_MM_RESTORE();
}

/**
 * Produce a <doctype> tag
 */
PHP_METHOD(Phalcon_Html_Helper_Doctype, __invoke)
{
	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
	zend_string *delimiter = NULL;
	zval *type_param = NULL, delimiter_zv, _0;
	zend_long type;
	zval *this_ptr = getThis();

	ZVAL_UNDEF(&delimiter_zv);
	ZVAL_UNDEF(&_0);
	static zend_string *_zephir_prop_0 = NULL;
	static zend_string *_zephir_prop_1 = NULL;
	if (UNEXPECTED(!_zephir_prop_0)) {
		_zephir_prop_0 = zend_string_init("type", 4, 1);
	}
	if (UNEXPECTED(!_zephir_prop_1)) {
		_zephir_prop_1 = zend_string_init("delimiter", 9, 1);
	}

	ZEND_PARSE_PARAMETERS_START(0, 2)
		Z_PARAM_OPTIONAL
		Z_PARAM_LONG(type)
		Z_PARAM_STR(delimiter)
	ZEND_PARSE_PARAMETERS_END();
	ZEPHIR_METHOD_GLOBALS_PTR = pecalloc(1, sizeof(zephir_method_globals), 0);
	zephir_memory_grow_stack(ZEPHIR_METHOD_GLOBALS_PTR, __func__);
	if (ZEND_NUM_ARGS() > 0) {
		type_param = ZEND_CALL_ARG(execute_data, 1);
	}
	if (!type_param) {
		type = 5;
	} else {
		}
	if (!delimiter) {
		delimiter = zend_string_init(ZEND_STRL("\n"), 0);
		zephir_memory_observe(&delimiter_zv);
		ZVAL_STR(&delimiter_zv, delimiter);
	} else {
		zephir_memory_observe(&delimiter_zv);
	ZVAL_STR_COPY(&delimiter_zv, delimiter);
	}
	ZVAL_UNDEF(&_0);
	ZVAL_LONG(&_0, type);
	zephir_update_property_zval_cached(this_ptr, _zephir_prop_0, 833, &_0);
	zephir_update_property_zval_cached(this_ptr, _zephir_prop_1, 834, &delimiter_zv);
	RETURN_THIS();
}

PHP_METHOD(Phalcon_Html_Helper_Doctype, __toString)
{
	zval _0, _18, _1$$3, _2$$4, _3$$4, _4$$5, _5$$5, _6$$6, _7$$6, _8$$7, _9$$7, _10$$8, _11$$8, _12$$9, _13$$9, _14$$10, _15$$10, _16$$11, _17$$11;
	zval *this_ptr = getThis();

	ZVAL_UNDEF(&_0);
	ZVAL_UNDEF(&_18);
	ZVAL_UNDEF(&_1$$3);
	ZVAL_UNDEF(&_2$$4);
	ZVAL_UNDEF(&_3$$4);
	ZVAL_UNDEF(&_4$$5);
	ZVAL_UNDEF(&_5$$5);
	ZVAL_UNDEF(&_6$$6);
	ZVAL_UNDEF(&_7$$6);
	ZVAL_UNDEF(&_8$$7);
	ZVAL_UNDEF(&_9$$7);
	ZVAL_UNDEF(&_10$$8);
	ZVAL_UNDEF(&_11$$8);
	ZVAL_UNDEF(&_12$$9);
	ZVAL_UNDEF(&_13$$9);
	ZVAL_UNDEF(&_14$$10);
	ZVAL_UNDEF(&_15$$10);
	ZVAL_UNDEF(&_16$$11);
	ZVAL_UNDEF(&_17$$11);
	static zend_string *_zephir_prop_0 = NULL;
	static zend_string *_zephir_prop_1 = NULL;
	if (UNEXPECTED(!_zephir_prop_0)) {
		_zephir_prop_0 = zend_string_init("type", 4, 1);
	}
	if (UNEXPECTED(!_zephir_prop_1)) {
		_zephir_prop_1 = zend_string_init("delimiter", 9, 1);
	}
	zephir_read_property_cached(&_0, this_ptr, _zephir_prop_0, 833, PH_NOISY_CC | PH_READONLY);
	if (ZEPHIR_IS_LONG(&_0, 1)) { goto zephir_switch_0_clause_0; }
	if (ZEPHIR_IS_LONG(&_0, 2)) { goto zephir_switch_0_clause_1; }
	if (ZEPHIR_IS_LONG(&_0, 3)) { goto zephir_switch_0_clause_2; }
	if (ZEPHIR_IS_LONG(&_0, 4)) { goto zephir_switch_0_clause_3; }
	if (ZEPHIR_IS_LONG(&_0, 6)) { goto zephir_switch_0_clause_4; }
	if (ZEPHIR_IS_LONG(&_0, 7)) { goto zephir_switch_0_clause_5; }
	if (ZEPHIR_IS_LONG(&_0, 8)) { goto zephir_switch_0_clause_6; }
	if (ZEPHIR_IS_LONG(&_0, 9)) { goto zephir_switch_0_clause_7; }
	if (ZEPHIR_IS_LONG(&_0, 10)) { goto zephir_switch_0_clause_8; }
	goto zephir_switch_0_end;
	zephir_switch_0_clause_0: ;
		zephir_read_property_cached(&_1$$3, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">", &_1$$3);
		return;
	zephir_switch_0_clause_1: ;
		zephir_read_property_cached(&_2$$4, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_3$$4, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"", &_2$$4, "\t\"http://www.w3.org/TR/html4/strict.dtd\">", &_3$$4);
		return;
	zephir_switch_0_clause_2: ;
		zephir_read_property_cached(&_4$$5, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_5$$5, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"", &_4$$5, "\t\"http://www.w3.org/TR/html4/loose.dtd\">", &_5$$5);
		return;
	zephir_switch_0_clause_3: ;
		zephir_read_property_cached(&_6$$6, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_7$$6, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"", &_6$$6, "\t\"http://www.w3.org/TR/html4/frameset.dtd\">", &_7$$6);
		return;
	zephir_switch_0_clause_4: ;
		zephir_read_property_cached(&_8$$7, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_9$$7, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"", &_8$$7, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">", &_9$$7);
		return;
	zephir_switch_0_clause_5: ;
		zephir_read_property_cached(&_10$$8, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_11$$8, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"", &_10$$8, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">", &_11$$8);
		return;
	zephir_switch_0_clause_6: ;
		zephir_read_property_cached(&_12$$9, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_13$$9, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"", &_12$$9, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">", &_13$$9);
		return;
	zephir_switch_0_clause_7: ;
		zephir_read_property_cached(&_14$$10, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_15$$10, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"", &_14$$10, "\t\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">", &_15$$10);
		return;
	zephir_switch_0_clause_8: ;
		zephir_read_property_cached(&_16$$11, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		zephir_read_property_cached(&_17$$11, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
		ZEPHIR_CONCAT_SVSV(return_value, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 2.0//EN\"", &_16$$11, "\t\"http://www.w3.org/MarkUp/DTD/xhtml2.dtd\">", &_17$$11);
		return;
	zephir_switch_0_end: ;

	zephir_read_property_cached(&_18, this_ptr, _zephir_prop_1, 834, PH_NOISY_CC | PH_READONLY);
	ZEPHIR_CONCAT_SV(return_value, "<!DOCTYPE html>", &_18);
	return;
}

PHP_METHOD(Phalcon_Html_Helper_Doctype, getType)
{

	RETURN_MEMBER_TYPED(getThis(), "type", IS_LONG);
}

