From 06aa5fd5afaba69544b93654fb0a4f9c2651306e Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Fri, 14 Feb 2014 16:30:23 +0100 Subject: Merged pull request #14 --- Examples/ConstStaticProp/cpp/Makefile | 32 +++++++++++++++++ Examples/ConstStaticProp/cpp/mytestext.cpp | 56 ++++++++++++++++++++++++++++++ Examples/ConstStaticProp/cpp/mytestext.h | 25 +++++++++++++ Examples/ConstStaticProp/cpp/mytestext.ini | 4 +++ Examples/ConstStaticProp/readme | 0 Examples/ConstStaticProp/test.php | 15 ++++++++ 6 files changed, 132 insertions(+) create mode 100644 Examples/ConstStaticProp/cpp/Makefile create mode 100644 Examples/ConstStaticProp/cpp/mytestext.cpp create mode 100644 Examples/ConstStaticProp/cpp/mytestext.h create mode 100644 Examples/ConstStaticProp/cpp/mytestext.ini create mode 100644 Examples/ConstStaticProp/readme create mode 100644 Examples/ConstStaticProp/test.php (limited to 'Examples') diff --git a/Examples/ConstStaticProp/cpp/Makefile b/Examples/ConstStaticProp/cpp/Makefile new file mode 100644 index 0000000..8272434 --- /dev/null +++ b/Examples/ConstStaticProp/cpp/Makefile @@ -0,0 +1,32 @@ +CPP = g++ +RM = rm -f +CPP_FLAGS = -Wall -c -I. -O2 -std=c++11 + +PREFIX = /usr +#Edit these lines to correspond with your own directories +LIBRARY_DIR = ${PREFIX}/lib/php5/20121212 +PHP_CONFIG_DIR = /etc/php5/cli/conf.d + +LD = g++ +LD_FLAGS = -Wall -shared -O2 +RESULT = mytestext.so + +PHPINIFILE = mytestext.ini + +SOURCES = $(wildcard *.cpp) +OBJECTS = $(SOURCES:%.cpp=%.o) + +all: ${OBJECTS} ${RESULT} + +${RESULT}: ${OBJECTS} + ${LD} ${LD_FLAGS} -o $@ ${OBJECTS} -lphpcpp + +clean: + ${RM} *.obj *~* ${OBJECTS} ${RESULT} + +${OBJECTS}: + ${CPP} ${CPP_FLAGS} -fpic -o $@ ${@:%.o=%.cpp} + +install: + cp -f ${RESULT} ${LIBRARY_DIR} + cp -f ${PHPINIFILE} ${PHP_CONFIG_DIR} diff --git a/Examples/ConstStaticProp/cpp/mytestext.cpp b/Examples/ConstStaticProp/cpp/mytestext.cpp new file mode 100644 index 0000000..7d8dc95 --- /dev/null +++ b/Examples/ConstStaticProp/cpp/mytestext.cpp @@ -0,0 +1,56 @@ +/** + * cppclassinphp.cpp + * @author Jasper van Eck + * + * An example file to show the working of using a C++ class in PHP. + */ + +#include "mytestext.h" +/** + * Namespace to use + */ +using namespace std; + +class MyTestExt : public Php::Base +{ + +public: + MyTestExt() {} + + virtual ~MyTestExt() {} + + virtual void __construct() {} + +}; + + + +// Symbols are exported according to the "C" language +extern "C" +{ + // export the "get_module" function that will be called by the Zend engine + PHPCPP_EXPORT void *get_module() + { + // create extension + static Php::Extension extension("my_test_ext","0.1a"); + + // add the custom class ot the extension + extension.add( + "MyTestClass", + Php::Class({ + + // Private PHP constructor! You can't instance object of MyTestClass + Php::Private("__construct", Php::Method(&MyTestExt::__construct)), + + Php::Const("version", "v0.01-alpha"), + Php::Const("PI", 3.14159265), + Php::Const("IMISNULL"), + + Php::Static("exp", 2.71828182846), + }) + ); + + // return the extension module + return extension.module(); + } +} diff --git a/Examples/ConstStaticProp/cpp/mytestext.h b/Examples/ConstStaticProp/cpp/mytestext.h new file mode 100644 index 0000000..c268a61 --- /dev/null +++ b/Examples/ConstStaticProp/cpp/mytestext.h @@ -0,0 +1,25 @@ +/** + * The includes.h + */ + +/** + * Default Cpp libraries + */ + +#include +#include + +/** + * Our own library. + */ +#include + +/** + * Namespace to use + */ +using namespace std; + +/** + * The test class. + */ +//#include "mycustomclass.h" diff --git a/Examples/ConstStaticProp/cpp/mytestext.ini b/Examples/ConstStaticProp/cpp/mytestext.ini new file mode 100644 index 0000000..d503704 --- /dev/null +++ b/Examples/ConstStaticProp/cpp/mytestext.ini @@ -0,0 +1,4 @@ +; configuration for phpcpp module +; priority=30 +extension=mytestext.so + diff --git a/Examples/ConstStaticProp/readme b/Examples/ConstStaticProp/readme new file mode 100644 index 0000000..e69de29 diff --git a/Examples/ConstStaticProp/test.php b/Examples/ConstStaticProp/test.php new file mode 100644 index 0000000..5489461 --- /dev/null +++ b/Examples/ConstStaticProp/test.php @@ -0,0 +1,15 @@ +