Line data Source code
1 : /*
2 : +----------------------------------------------------------------------+
3 : | For PHP Version 8 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 2015 Elizabeth M Smith |
6 : +----------------------------------------------------------------------+
7 : | http://www.opensource.org/licenses/mit-license.php MIT License |
8 : | Also available in LICENSE |
9 : +----------------------------------------------------------------------+
10 : | Authors: Elizabeth M Smith <auroraeosrose@gmail.com> |
11 : | Swen Zanon <swen.zanon@geoglis.de> |
12 : +----------------------------------------------------------------------+
13 : */
14 :
15 : #ifdef HAVE_CONFIG_H
16 : #include "config.h"
17 : #endif
18 :
19 : #include <cairo.h>
20 : #include <php.h>
21 : #include <zend_exceptions.h>
22 :
23 : #include "php_cairo.h"
24 : #include "php_cairo_internal.h"
25 : #include "exception_arginfo.h"
26 :
27 : zend_class_entry *ce_cairo_exception;
28 : zend_class_entry *ce_cairo_status;
29 :
30 : /* ----------------------------------------------------------------
31 : Cairo C API
32 : ------------------------------------------------------------------*/
33 :
34 766 : bool php_cairo_throw_exception(cairo_status_t status)
35 : {
36 : char * error_message;
37 :
38 766 : if (status == CAIRO_STATUS_SUCCESS) {
39 760 : return false;
40 : }
41 :
42 6 : error_message = estrdup(cairo_status_to_string(status));
43 6 : zend_throw_exception(ce_cairo_exception, error_message, status);
44 6 : efree(error_message);
45 6 : return true;
46 : }
47 :
48 : /* ----------------------------------------------------------------
49 : Cairo\Status Class API
50 : ------------------------------------------------------------------*/
51 :
52 : /* {{{ proto string CairoStatus->getMessage
53 : Translates the current enums value to it's cairo status message value */
54 5 : PHP_METHOD(Cairo_Status, getMessage)
55 : {
56 5 : ZEND_PARSE_PARAMETERS_NONE();
57 :
58 12 : RETURN_STRING(cairo_status_to_string(
59 : Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(getThis())))
60 : ));
61 : }
62 : /* }}} */
63 :
64 : /* ----------------------------------------------------------------
65 : Cairo\Status and Cairo\Exception Definition and registration
66 : ------------------------------------------------------------------*/
67 :
68 : /* {{{ PHP_MINIT_FUNCTION */
69 424 : PHP_MINIT_FUNCTION(cairo_exception)
70 : {
71 424 : ce_cairo_exception = register_class_Cairo_Exception(zend_ce_exception);
72 :
73 424 : ce_cairo_status = register_class_Cairo_Status();
74 :
75 424 : return SUCCESS;
76 : }
77 : /* }}} */
|