summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-05 18:17:09 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-05 18:17:09 +0200
commit5d84ff5483f2db57762311714ff3c779db1e0f96 (patch)
tree0691e7395a292b152af3525b1e65a11b15bad46f /src
parent5973954b7428aa95ec8f0b2424b5725d2815049f (diff)
removed zend code from the argument.h header file
Diffstat (limited to 'src')
-rw-r--r--src/argument.cpp171
-rw-r--r--src/callable.h50
2 files changed, 48 insertions, 173 deletions
diff --git a/src/argument.cpp b/src/argument.cpp
deleted file mode 100644
index a2aa8d5..0000000
--- a/src/argument.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- * Argument.cpp
- *
- * Implementation for the Argument class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-#include "includes.h"
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-/**
- * Constructor
- * @param name Name of the argument
- * @param type Argument type
- * @param required Is this argument required?
- * @param byref Is this a reference argument
- */
-Argument::Argument(const char *name, Type type, bool required, bool byref)
-{
- // construct object
- _info = new zend_arg_info;
-
- // fill members
- _info->name = name;
- _info->name_len = strlen(name);
-
-#if PHP_VERSION_ID >= 50400
-
- // since php 5.4 there is a type-hint
- _info->type_hint = (unsigned char)(type == Type::Array || type == Type::Callable ? type : Type::Null);
-
-# if PHP_VERSION_ID >= 50600
-
- // from PHP 5.6 and onwards, an is_variadic property can be set, this
- // specifies whether this argument is the first argument that specifies
- // the type for a variable length list of arguments. For now we only
- // support methods and functions with a fixed number of arguments.
- _info->is_variadic = false;
-
-# endif
-
-#else
-
- // php 5.3 code
- _info->array_type_hint = type == Type::Array;
- _info->return_reference = false;
- _info->required_num_args = 0; // @todo is this correct?
-
-#endif
-
- // this parameter is a regular type
- _info->class_name = NULL;
- _info->class_name_len = 0;
- _info->allow_null = false;
- _info->pass_by_reference = byref;
-
- // store if required
- _required = required;
-}
-
-/**
- * Constructor
- * @param name Name of the argument
- * @param classname Name of the class
- * @param nullable Can it be null?
- * @param required Is this argument required?
- * @param byref Is this a reference argument?
- */
-Argument::Argument(const char *name, const char *classname, bool nullable, bool required, bool byref)
-{
- // construct object
- _info = new zend_arg_info;
-
- // fill members
- _info->name = name;
- _info->name_len = strlen(name);
-
-#if PHP_VERSION_ID >= 50400
-
- // since php 5.4 there is a type hint
- _info->type_hint = (unsigned char)Type::Object;
-
-# if PHP_VERSION_ID >= 50600
-
- // from PHP 5.6 and onwards, an is_variadic property can be set, this
- // specifies whether this argument is the first argument that specifies
- // the type for a variable length list of arguments. For now we only
- // support methods and functions with a fixed number of arguments.
- _info->is_variadic = false;
-
-# endif
-
-#else
-
- // php 5.3 code
- _info->array_type_hint = false;
- _info->return_reference = false;
- _info->required_num_args = 0; // @todo is this correct?
-
-#endif
-
- // the parameter is a class
- _info->class_name = classname;
- _info->class_name_len = strlen(classname);
- _info->allow_null = nullable;
- _info->pass_by_reference = byref;
-
- // store if required
- _required = required;
-}
-
-/**
- * Copy constructor
- * @param argument
- */
-Argument::Argument(const Argument &argument)
-{
- // construct object
- _info = new zend_arg_info;
-
- // fill members
- *_info = *argument._info;
-
- // store if required
- _required = argument._required;
-}
-
-/**
- * Move constructor
- * @param argument
- */
-Argument::Argument(Argument &&argument)
-{
- // copy memory pointer
- _info = argument._info;
-
- // forget in other object
- argument._info = nullptr;
-
- // store if required
- _required = argument._required;
-}
-
-/**
- * Destructor
- */
-Argument::~Argument()
-{
- if (_info) delete _info;
-}
-
-/**
- * Fill an arg_info structure with data
- * @param info
- * @internal
- */
-void Argument::fill(struct _zend_arg_info *info) const
-{
- // copy all data
- *info = *_info;
-}
-
-/**
- * End of namespace
- */
-}
diff --git a/src/callable.h b/src/callable.h
index f123c8b..aef5649 100644
--- a/src/callable.h
+++ b/src/callable.h
@@ -43,11 +43,11 @@ public:
// loop through the arguments
for (auto it = arguments.begin(); it != arguments.end(); it++)
{
- // increment required
+ // increment counter with number of required parameters
if (it->required()) _required++;
// fill the arg info
- it->fill(&_argv[i++]);
+ fill(&_argv[i], *it);
}
}
@@ -140,7 +140,53 @@ protected:
* @var zend_arg_info[]
*/
struct _zend_arg_info *_argv = nullptr;
+
+ /**
+ * Private helper method to fill an argument object
+ * @param info object from the zend engine
+ * @param arg original object
+ */
+ void fill(zend_arg_info *info, const Argument &arg) const
+ {
+ // fill members
+ info->name = arg.name().c_str();
+ info->name_len = arg.name().size();
+
+#if PHP_VERSION_ID >= 50400
+
+ // since php 5.4 there is a type-hint, but we only support arrays, objects and callables
+ switch (arg.type()) {
+ case Type::Array: info->type_hint = IS_ARRAY; break;
+ case Type::Callable: info->type_hint = IS_CALLABLE; break;
+ case Type::Object: info->type_hint = IS_OBJECT; break;
+ default: info->type_hint = IS_NULL; break;
+ }
+
+# if PHP_VERSION_ID >= 50600
+
+ // from PHP 5.6 and onwards, an is_variadic property can be set, this
+ // specifies whether this argument is the first argument that specifies
+ // the type for a variable length list of arguments. For now we only
+ // support methods and functions with a fixed number of arguments.
+ info->is_variadic = false;
+
+# endif
+
+#else
+ // php 5.3 code
+ info->array_type_hint = type == Type::Array;
+ info->return_reference = false;
+ info->required_num_args = 0; // @todo is this correct?
+
+#endif
+
+ // this parameter is a regular type
+ info->class_name = arg.type() == Type::Object ? arg.classname().c_str() : nullptr;
+ info->class_name_len = arg.type() == Type::Object ? arg.classname().size() : 0;
+ info->allow_null = arg.allowNull();
+ info->pass_by_reference = arg.byReference();
+ }
};
/**