diff --git a/main.cpp b/main.cpp index b4f236e..d51b7e7 100644 --- a/main.cpp +++ b/main.cpp @@ -2637,4 +2637,41 @@ GValue phpgtk_get_gvalue(Php::Value phpgtk_value, GType type_column) return gtk_value; +} + + + +void phpgtk_throw_wrong_type(int param, Php::Type type) +{ + char *buffer; + int len; + std::string str_type; + + switch(type) { + case Php::Type::Undefined: str_type.assign("undefined"); break; + case Php::Type::Null: str_type.assign("Null"); break; + case Php::Type::False: str_type.assign("False"); break; + case Php::Type::True: str_type.assign("True"); break; + case Php::Type::Numeric: str_type.assign("Numeric"); break; + case Php::Type::Float: str_type.assign("Float"); break; + case Php::Type::String: str_type.assign("String"); break; + case Php::Type::Array: str_type.assign("Array"); break; + case Php::Type::Object: str_type.assign("Object"); break; + case Php::Type::Resource: str_type.assign("Resource"); break; + case Php::Type::Reference: str_type.assign("Reference"); break; + case Php::Type::Constant: str_type.assign("Constant"); break; + case Php::Type::ConstantAST: str_type.assign("ConstantAST"); break; + case Php::Type::Bool: str_type.assign("Bool"); break; + case Php::Type::Callable: str_type.assign("Callable"); break; + } + + // Get len of string + len = snprintf(NULL, 0, "expects at least %d parameters, %s given", param, str_type.c_str()); + buffer = (char *)malloc((len + 1) * sizeof(char)); + + // Save into buffer + snprintf(buffer, len+1, "expects at least %d parameters, %s given", param, str_type.c_str()); + + // throw + throw Php::Exception(buffer); } \ No newline at end of file diff --git a/main.h b/main.h index 1e0da0f..20ecd9f 100644 --- a/main.h +++ b/main.h @@ -1,10 +1,12 @@ -#ifndef _PHPGTK_H_ -#define _PHPGTK_H_ +#ifndef _PHPGTK_MAIN_H_ +#define _PHPGTK_MAIN_H_ #include #include #include + #include "php-gtk.h" + #include "src/GObject.h" #include "src/Gdk.h" @@ -189,5 +191,6 @@ GValue phpgtk_get_gvalue(Php::Value phpgtk_value, GType type_column); + void phpgtk_throw_wrong_type(int param, Php::Type type); #endif \ No newline at end of file diff --git a/php-gtk.cpp b/php-gtk.cpp new file mode 100644 index 0000000..4b1ee21 --- /dev/null +++ b/php-gtk.cpp @@ -0,0 +1,16 @@ + +#include "php-gtk.h" + +bool phpgtk_check_parameter(Php::Value value, Php::Type expected_type, bool required) +{ + Php::call("var_dump", "OK1"); + if(required) { + Php::call("var_dump", "OK2"); + if(value.type() == Php::Type::Null) { + Php::call("var_dump", "OK3"); + throw Php::Exception("tipo errado"); + } + Php::call("var_dump", "OK4"); + } + +} \ No newline at end of file diff --git a/php-gtk.h b/php-gtk.h new file mode 100644 index 0000000..882ce7f --- /dev/null +++ b/php-gtk.h @@ -0,0 +1,12 @@ +#ifndef _PHPGTK_H_ +#define _PHPGTK_H_ + + #include + #include + #include + + + bool phpgtk_check_parameter(Php::Value value, Php::Type expected_type, bool required); + + +#endif \ No newline at end of file diff --git a/src/GtkBox.cpp b/src/GtkBox.cpp index 72ff3d5..24bfd11 100644 --- a/src/GtkBox.cpp +++ b/src/GtkBox.cpp @@ -13,6 +13,8 @@ GtkBox_::~GtkBox_() = default; void GtkBox_::__construct(Php::Parameters ¶meters) { + //phpgtk_check_parameter(parameters[0], Php::Type::Numeric, TRUE); + int int_child = (int)parameters[0]; GtkOrientation child = (GtkOrientation)int_child; diff --git a/src/GtkBox.h b/src/GtkBox.h index b69638a..8a11e40 100644 --- a/src/GtkBox.h +++ b/src/GtkBox.h @@ -5,7 +5,9 @@ #include #include - #include "GtkContainer.h" + #include "../php-gtk.h" + + #include "GtkContainer.h" #include "GtkWidget.h" #include "GtkPackType.h" diff --git a/test.php b/test.php index 91d8734..7b2001a 100644 --- a/test.php +++ b/test.php @@ -94,11 +94,14 @@ function GtkCellRendererToggled($renderer=NULL, $path=NULL) // ---------------------- // Vertical box -$vbox = new GtkBox(GtkOrientation::VERTICAL); +$vbox = new GtkBox(); +die("OK"); + +// $vbox->pack_start(2.2, TRUE, TRUE); // ---------------------- // Menu -$vbox->pack_start($hlbl = new GtkLabel("- GtkMenuBar"), TRUE, TRUE, 1); $hlbl->set_xalign(0); +$vbox->pack_start(2, TRUE, TRUE, 1); $hlbl->set_xalign(0); $menubar = new GtkMenuBar(); $vbox->pack_start($menubar, FALSE, FALSE, 0);