summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-07-26 14:38:59 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-07-26 14:38:59 +0200
commit90f2c44a8dedc53de351d42107a40f56d6184899 (patch)
tree8475cd5f7eb95fefd71c48e563f905a77d6393c4
parent65448269cc98e88f9da138847e7603f189713abd (diff)
parent78c5a1463d51d8a1e92545d4dfda18845e1f23c4 (diff)
Merge branch 'class_exists' of https://github.com/andot/PHP-CPP
-rw-r--r--include/fastcall.h13
-rw-r--r--phpcpp.h3
-rw-r--r--zend/fastcall.cpp43
-rw-r--r--zend/includes.h1
4 files changed, 59 insertions, 1 deletions
diff --git a/include/fastcall.h b/include/fastcall.h
new file mode 100644
index 0000000..a5a8e1c
--- /dev/null
+++ b/include/fastcall.h
@@ -0,0 +1,13 @@
+/**
+ * fastcall.h
+ *
+ * This file holds some PHP functions implementation in C directly.
+ *
+ */
+
+namespace Php {
+
+ bool class_exists(const std::string &classname, bool autoload = true);
+
+}
+
diff --git a/phpcpp.h b/phpcpp.h
index c3f3365..8be1a25 100644
--- a/phpcpp.h
+++ b/phpcpp.h
@@ -2,7 +2,7 @@
* phpcpp.h
*
* Library to build PHP extensions with CPP
- *
+ *
* @copyright 2013 CopernicA BV
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
*/
@@ -60,6 +60,7 @@
#include <phpcpp/namespace.h>
#include <phpcpp/extension.h>
#include <phpcpp/call.h>
+#include <phpcpp/fastcall.h>
/**
* Macro to export a function
diff --git a/zend/fastcall.cpp b/zend/fastcall.cpp
new file mode 100644
index 0000000..359c3ad
--- /dev/null
+++ b/zend/fastcall.cpp
@@ -0,0 +1,43 @@
+/**
+ * fastcall.cpp
+ *
+ * This file holds some PHP functions implementation in C directly.
+ *
+ */
+
+#include "includes.h"
+
+namespace Php {
+
+ bool class_exists(const std::string &classname, bool autoload) {
+ // we need the tsrm_ls variable
+ TSRMLS_FETCH();
+
+ zend_class_entry **ce;
+ int found;
+ const char * str = classname.c_str();
+ int32_t len = (int32_t)classname.length();
+
+
+ if (autoload) {
+ char *lc_name = new char[len + 1];
+ zend_str_tolower_copy(lc_name, str, len);
+
+ char *name = lc_name;
+ if (lc_name[0] == '\\') {
+ name = &lc_name[1];
+ --len;
+ }
+
+ found = zend_hash_find(EG(class_table), name, len + 1, (void **) &ce);
+ delete [] lc_name;
+ return (found == SUCCESS && !(((*ce)->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS));
+ }
+
+ if (zend_lookup_class(str, len, &ce TSRMLS_CC) == SUCCESS) {
+ return (((*ce)->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0);
+ }
+ return false;
+ }
+
+} \ No newline at end of file
diff --git a/zend/includes.h b/zend/includes.h
index 63b435e..8af557c 100644
--- a/zend/includes.h
+++ b/zend/includes.h
@@ -79,6 +79,7 @@
#include "../include/namespace.h"
#include "../include/extension.h"
#include "../include/call.h"
+#include "../include/fastcall.h"
/**
* Common header files for internal use only