Skip to content

Add new php Validator interface and test #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Zend/zend_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ZEND_API zend_class_entry *zend_ce_aggregate;
ZEND_API zend_class_entry *zend_ce_iterator;
ZEND_API zend_class_entry *zend_ce_arrayaccess;
ZEND_API zend_class_entry *zend_ce_serializable;
ZEND_API zend_class_entry *zend_ce_validator;

/* {{{ zend_call_method
Only returns the returned zval if retval_ptr != NULL */
Expand Down Expand Up @@ -514,6 +515,13 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e
}
/* }}}*/

/* {{{ zend_implement_validator */
static int zend_implement_validator(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC)
{
return SUCCESS;
}
/* }}}*/

/* {{{ function tables */
const zend_function_entry zend_funcs_aggregate[] = {
ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
Expand Down Expand Up @@ -561,6 +569,15 @@ const zend_function_entry zend_funcs_serializable[] = {
ZEND_FENTRY(unserialize, NULL, arginfo_serializable_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT|ZEND_ACC_CTOR)
{NULL, NULL, NULL}
};

ZEND_BEGIN_ARG_INFO(arginfo_validator_is_valid, 0)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

const zend_function_entry zend_funcs_validator[] = {
ZEND_ABSTRACT_ME(validator, isValid, arginfo_validator_is_valid)
{NULL, NULL, NULL}
};
/* }}} */

#define REGISTER_ITERATOR_INTERFACE(class_name, class_name_str) \
Expand Down Expand Up @@ -588,6 +605,8 @@ ZEND_API void zend_register_interfaces(TSRMLS_D)
REGISTER_ITERATOR_INTERFACE(arrayaccess, ArrayAccess);

REGISTER_ITERATOR_INTERFACE(serializable, Serializable)

REGISTER_ITERATOR_INTERFACE(validator, Validator)
}
/* }}} */

Expand Down
1 change: 1 addition & 0 deletions Zend/zend_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern ZEND_API zend_class_entry *zend_ce_aggregate;
extern ZEND_API zend_class_entry *zend_ce_iterator;
extern ZEND_API zend_class_entry *zend_ce_arrayaccess;
extern ZEND_API zend_class_entry *zend_ce_serializable;
extern ZEND_API zend_class_entry *zend_ce_validator;

typedef struct _zend_user_iterator {
zend_object_iterator it;
Expand Down
20 changes: 20 additions & 0 deletions tests/classes/validator_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
ZE2 Validator
--FILE--
<?php

class Test implements Validator
{
public function isValid($value)
{
return $value == 'test';
}
}

$test = new Test();
var_dump($test->isValid('test')) . PHP_EOL;
var_dump($test->isValid('test1')) . PHP_EOL;
?>
--EXPECT--
bool(true)
bool(false)