-
Notifications
You must be signed in to change notification settings - Fork 215
Support exceptions. #59
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c3426e5
support exceptions.
Timandes 06136af
fix existing test cases
Timandes 9c748f6
fix compiling errors under PHP with ZTS-enabled.
Timandes f96a5da
keep tests simple.
Timandes 7b1813f
add 001.phpt to trigger Travis-CI.
Timandes b37eee7
remove useless statement.
Timandes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2010 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt. | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Ryan Uber <[email protected]> | | ||
| Timandes White <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#include <php.h> | ||
|
||
#ifdef ZTS | ||
#include "TSRM.h" | ||
#endif | ||
|
||
#include "php_zookeeper.h" | ||
#include "php_zookeeper_exceptions.h" | ||
|
||
void php_zk_register_exceptions(TSRMLS_D) | ||
{ | ||
zend_class_entry ce; | ||
|
||
INIT_CLASS_ENTRY(ce, "ZookeeperException", NULL); | ||
zk_base_exception = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC); | ||
|
||
INIT_CLASS_ENTRY(ce, "ZookeeperOperationTimeoutException", NULL); | ||
zk_optimeout_exception = zend_register_internal_class_ex(&ce, zk_base_exception, "ZookeeperException" TSRMLS_CC); | ||
|
||
INIT_CLASS_ENTRY(ce, "ZookeeperConnectionException", NULL); | ||
zk_connection_exception = zend_register_internal_class_ex(&ce, zk_base_exception, "ZookeeperException" TSRMLS_CC); | ||
|
||
INIT_CLASS_ENTRY(ce, "ZookeeperMarshallingException", NULL); | ||
zk_marshalling_exception = zend_register_internal_class_ex(&ce, zk_base_exception, "ZookeeperException" TSRMLS_CC); | ||
|
||
INIT_CLASS_ENTRY(ce, "ZookeeperAuthenticationException", NULL); | ||
zk_auth_exception = zend_register_internal_class_ex(&ce, zk_base_exception, "ZookeeperException" TSRMLS_CC); | ||
|
||
INIT_CLASS_ENTRY(ce, "ZookeeperSessionException", NULL); | ||
zk_session_exception = zend_register_internal_class_ex(&ce, zk_base_exception, "ZookeeperException" TSRMLS_CC); | ||
|
||
INIT_CLASS_ENTRY(ce, "ZookeeperNoNodeException", NULL); | ||
zk_nonode_exception = zend_register_internal_class_ex(&ce, zk_base_exception, "ZookeeperException" TSRMLS_CC); | ||
} | ||
|
||
zend_class_entry * php_zk_get_exception_with_message(zend_class_entry *ce, char *message TSRMLS_DC) | ||
{ | ||
zend_declare_property_string(ce, "message", strlen("message"), message, ZEND_ACC_PUBLIC TSRMLS_CC); | ||
return ce; | ||
} | ||
|
||
void php_zk_throw_exception(int zk_status TSRMLS_DC) | ||
{ | ||
zend_class_entry *ce; | ||
char *message = NULL; | ||
|
||
switch(zk_status) { | ||
case PHPZK_CONNECTION_FAILURE: | ||
ce = zk_connection_exception; | ||
message = "Failed to connect to Zookeeper"; | ||
break; | ||
case PHPZK_CONNECT_NOT_CALLED: | ||
ce = zk_connection_exception; | ||
message = "Zookeeper->connect() was not called"; | ||
break; | ||
case ZCONNECTIONLOSS: | ||
ce = zk_connection_exception; | ||
break; | ||
case ZOPERATIONTIMEOUT: | ||
ce = zk_optimeout_exception; | ||
break; | ||
case ZMARSHALLINGERROR: | ||
ce = zk_marshalling_exception; | ||
break; | ||
case ZNOAUTH: | ||
case ZAUTHFAILED: | ||
ce = zk_auth_exception; | ||
break; | ||
case ZSESSIONEXPIRED: | ||
case ZSESSIONMOVED: | ||
ce = zk_session_exception; | ||
break; | ||
case ZNONODE: | ||
ce = zk_nonode_exception; | ||
break; | ||
default: | ||
ce = zk_base_exception; | ||
break; | ||
} | ||
|
||
if (!message) { | ||
message = (char *)zerror(zk_status); | ||
} | ||
|
||
zend_throw_exception(php_zk_get_exception_with_message(ce, message TSRMLS_CC), NULL, zk_status TSRMLS_CC); | ||
return; | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2010 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt. | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Ryan Uber <[email protected]> | | ||
| Timandes White <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#ifndef PHP_ZOOKEEPER_EXCEPTIONS | ||
#define PHP_ZOOKEEPER_EXCEPTIONS | ||
|
||
#include <Zend/zend_exceptions.h> | ||
|
||
zend_class_entry *zk_base_exception; | ||
zend_class_entry *zk_optimeout_exception; | ||
zend_class_entry *zk_connection_exception; | ||
zend_class_entry *zk_marshalling_exception; | ||
zend_class_entry *zk_auth_exception; | ||
zend_class_entry *zk_session_exception; | ||
zend_class_entry *zk_nonode_exception; | ||
|
||
/** | ||
* register exceptions | ||
*/ | ||
void php_zk_register_exceptions(TSRMLS_D); | ||
zend_class_entry * php_zk_get_exception_with_message(zend_class_entry *ce, char *message TSRMLS_DC); | ||
/** | ||
* throw exception according to status | ||
*/ | ||
void php_zk_throw_exception(int zk_status TSRMLS_DC); | ||
|
||
#endif /* PHP_ZOOKEEPER_EXCEPTIONS */ |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--TEST-- | ||
Check for zookeeper presence | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("zookeeper")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
echo "zookeeper extension is available"; | ||
?> | ||
--EXPECT-- | ||
zookeeper extension is available |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests must be more simple.
E.g:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
--EXPECT--
part support PHP code?like:
I'm worried about future changing of constant value.
Is this my over-worriness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, see these docs bellow and be a monster in making tests!
https://qa.php.net/write-test.php
https://qa.php.net/phpt_details.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Monster +_+....