Created
July 6, 2012 13:36
-
-
Save wdalmut/3060202 to your computer and use it in GitHub Desktop.
Example of PHP extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dnl lines starting with "dnl" are comments | |
PHP_ARG_ENABLE(simplemvc, whether to enable Rlyeh extension, [ --enable-simplemvc Enable simple-mvc extension]) | |
if test "$PHP_SIMPLEMVC" != "no"; then | |
dnl this defines the extension | |
PHP_NEW_EXTENSION(simplemvc, php_simplemvc.c view.c, $ext_shared) | |
dnl this is boilerplate to make the extension work on OS X | |
case $build_os in | |
darwin1*.*.*) | |
AC_MSG_CHECKING([whether to compile for recent osx architectures]) | |
CFLAGS="$CFLAGS -arch i386 -arch x86_64 -mmacosx-version-min=10.5" | |
AC_MSG_RESULT([yes]) | |
;; | |
darwin*) | |
AC_MSG_CHECKING([whether to compile for every osx architecture ever]) | |
CFLAGS="$CFLAGS -arch i386 -arch x86_64 -arch ppc -arch ppc64" | |
AC_MSG_RESULT([yes]) | |
;; | |
esac | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <php.h> | |
#include "php_simplemvc.h" | |
#include "view.h" | |
zend_module_entry simplemvc_module_entry = { | |
STANDARD_MODULE_HEADER, | |
PHP_SIMPLEMVC_EXTNAME, | |
NULL, | |
PHP_MINIT(simplemvc), | |
NULL, | |
NULL, | |
NULL, | |
NULL, | |
PHP_SIMPLEMVC_VERSION, | |
STANDARD_MODULE_PROPERTIES | |
}; | |
// our existing MINIT function from part 3 | |
PHP_MINIT_FUNCTION(simplemvc) { | |
simplemvc_init_view(TSRMLS_C); | |
} | |
// install module | |
ZEND_GET_MODULE(simplemvc) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PHP_SIMPLEMVC_EXTNAME "simplemvc" | |
#define PHP_SIMPLEMVC_VERSION "0.01" | |
PHP_MINIT_FUNCTION(simplemvc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <php.h> | |
#include "view.h" | |
zend_class_entry *simplemvc_ce_view; | |
static function_entry view_methods[] = { | |
PHP_ME(View, sacrifice, NULL, ZEND_ACC_PUBLIC) | |
{NULL, NULL, NULL} | |
}; | |
void simplemvc_init_view(TSRMLS_D) { | |
zend_class_entry ce; | |
INIT_CLASS_ENTRY(ce, "View", view_methods); | |
simplemvc_ce_view = zend_register_internal_class(&ce TSRMLS_CC); | |
/* fields */ | |
zend_declare_property_bool(simplemvc_ce_view, "alive", strlen("alive"), 1, ZEND_ACC_PUBLIC TSRMLS_CC); | |
} | |
PHP_METHOD(View, sacrifice) { | |
// TODO | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef VIEW_H | |
#define VIEW_H | |
void simplemvc_init_view(TSRMLS_D); | |
PHP_METHOD(View, sacrifice); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment