diff options
author | Martijn Otto <martijn.otto@copernica.com> | 2014-02-14 16:30:23 +0100 |
---|---|---|
committer | Martijn Otto <martijn.otto@copernica.com> | 2014-02-14 16:30:23 +0100 |
commit | 06aa5fd5afaba69544b93654fb0a4f9c2651306e (patch) | |
tree | 99cd2ee120786a84531b450f9ef64e2319ef5192 /Examples | |
parent | 5c23fee5ce58ae66a70f3bd19a1dc2dff7220f13 (diff) |
Merged pull request #14
Diffstat (limited to 'Examples')
-rw-r--r-- | Examples/ConstStaticProp/cpp/Makefile | 32 | ||||
-rw-r--r-- | Examples/ConstStaticProp/cpp/mytestext.cpp | 56 | ||||
-rw-r--r-- | Examples/ConstStaticProp/cpp/mytestext.h | 25 | ||||
-rw-r--r-- | Examples/ConstStaticProp/cpp/mytestext.ini | 4 | ||||
-rw-r--r-- | Examples/ConstStaticProp/readme | 0 | ||||
-rw-r--r-- | Examples/ConstStaticProp/test.php | 15 |
6 files changed, 132 insertions, 0 deletions
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<jasper.vaneck@copernica.com> + * + * 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<MyTestExt>({ + + // Private PHP constructor! You can't instance object of MyTestClass + Php::Private("__construct", Php::Method<MyTestExt>(&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 <string> +#include <iostream> + +/** + * Our own library. + */ +#include <phpcpp.h> + +/** + * 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 --- /dev/null +++ b/Examples/ConstStaticProp/readme 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 @@ +<?php + + var_dump(MyTestClass::version); // print: string(11) "v0.01-alpha" + + var_dump(MyTestClass::PI); // print: float(3.14159265) + + var_dump(MyTestClass::IMISNULL); // print: NULL + + var_dump(MyTestClass::$exp); // print: float(2.71828182846) + + /** + * Fatal error! + * Private PHP constructor. You can't instance object of MyTestClass. + */ + //$mytest = new MyTestClass();
\ No newline at end of file |