如何在Phalcon PHP内部设置新类?

时间:2012-09-13 20:08:41

标签: php-extension phalcon

我决定通过制作一个简单的验证器让我的脚在Phalcon内部受伤。我几乎逐字地遵循了其他验证器的定义。所以这就是我在phalcon.c和phalcon.h中所拥有的:

phalcon.c:
zend_class_entry *phalcon_mvc_model_validator_stringlength_ce;
...
PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, StringLength, mvc_model_validator_stringlength, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_stringlength_method_entry, 0);

phalcon.h:
extern zend_class_entry *phalcon_mvc_model_validator_stringlength_ce;
...
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_validator_stringlength_validate, 0, 0, 1)
    ZEND_ARG_INFO(0, record)
ZEND_END_ARG_INFO()
...
PHALCON_INIT_FUNCS(phalcon_mvc_model_validator_stringlength_method_entry){
    PHP_ME(Phalcon_Mvc_Model_Validator_StringLength, validate, arginfo_phalcon_mvc_model_validator_stringlength_validate, ZEND_ACC_PUBLIC)
    PHP_FE_END
};

在运行时,我收到以下警告:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/phalcon.so' - /usr/lib/php5/20090626/phalcon.so: undefined symbol: zim_Phalcon_Mvc_Model_Validator_StringLength_validate in Unknown on line 0

我错过了什么?

1 个答案:

答案 0 :(得分:2)

还需要将方法(函数)原型添加到phalcon.h:

https://github.com/phalcon/cphalcon/blob/master/dev/phalcon.h#L391

将.c文件添加到config.m4(如果您使用的是Unix / Linux平台):

https://github.com/phalcon/cphalcon/blob/master/dev/config.m4#L5

之后,需要完整的重新编译:

phpize --clean
export CFLAGS="-g -O2 -fno-delete-null-pointer-checks"
phpize
./configure --enable-phalcon
make
sudo make install