Skip to content

Instantly share code, notes, and snippets.

@pgasiorowski
Created January 11, 2014 15:51
Show Gist options
  • Save pgasiorowski/8372551 to your computer and use it in GitHub Desktop.
Save pgasiorowski/8372551 to your computer and use it in GitHub Desktop.
32-bit from ext as of 11 Jan 2014
This file has been truncated, but you can view the full file.
/**
New BSD License
Copyright (c) 2011-2014, Phalcon Framework Team
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------
The Zend Engine License, Version 2.00
Copyright (c) 1999-2006 Zend Technologies Ltd. All rights reserved.
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, is permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
3. The names "Zend" and "Zend Engine" must not be used to endorse
or promote products derived from this software without prior
permission from Zend Technologies Ltd. For written permission,
please contact license@zend.com.
4. Zend Technologies Ltd. may publish revised and/or new versions
of the license from time to time. Each version will be given a
distinguishing version number.
Once covered code has been published under a particular version
of the license, you may always continue to use it under the
terms of that version. You may also choose to use such covered
code under the terms of any subsequent version of the license
published by Zend Technologies Ltd. No one other than Zend
Technologies Ltd. has the right to modify the terms applicable
to covered code created under this License.
5. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes the Zend Engine, freely available at
http://www.zend.com"
6. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
"The Zend Engine is freely available at http://www.zend.com"
THIS SOFTWARE IS PROVIDED BY ZEND TECHNOLOGIES LTD. ``AS IS'' AND
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ZEND
TECHNOLOGIES LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
--------------------------------------------------------------------
--------------------------------------------------------------------
The PHP License, version 3.01
Copyright (c) 1999 - 2010 The PHP Group. All rights reserved.
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, is permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name "PHP" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact group@php.net.
4. Products derived from this software may not be called "PHP", nor
may "PHP" appear in their name, without prior written permission
from group@php.net. You may indicate that your software works in
conjunction with PHP by saying "Foo for PHP" instead of calling
it "PHP Foo" or "phpfoo"
5. The PHP Group may publish revised and/or new versions of the
license from time to time. Each version will be given a
distinguishing version number.
Once covered code has been published under a particular version
of the license, you may always continue to use it under the terms
of that version. You may also choose to use such covered code
under the terms of any subsequent version of the license
published by the PHP Group. No one other than the PHP Group has
the right to modify the terms applicable to covered code created
under this License.
6. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes PHP software, freely available from
<http://www.php.net/software/>".
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------
This software consists of voluntary contributions made by many
individuals on behalf of the PHP Group.
The PHP Group can be contacted via Email at group@php.net.
For more information on the PHP Group and the PHP project,
please see <http://www.php.net>.
PHP includes the Zend Engine, freely available at
<http://www.zend.com>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <main/php.h>
#include "php_phalcon.h"
#include "phalcon.h"
#include <main/php_main.h>
#include <main/php_variables.h>
#include <main/php_streams.h>
#include <main/php_output.h>
#include <main/php_ini.h>
#include <main/SAPI.h>
#include <ext/standard/php_string.h>
#include <ext/standard/php_smart_str.h>
#include <ext/standard/info.h>
#include <ext/pdo/php_pdo_driver.h>
#include <ext/standard/file.h>
#include <ext/standard/php_filestat.h>
#include <ext/standard/php_rand.h>
#include <ext/standard/php_lcg.h>
#include <ext/standard/php_math.h>
#include <ext/standard/php_array.h>
#include <ext/standard/php_var.h>
#include <ext/standard/php_http.h>
#include <ext/standard/php_versioning.h>
#include <ext/standard/html.h>
#include <ext/standard/base64.h>
#include <ext/standard/md5.h>
#include <ext/standard/head.h>
#include <ext/standard/url.h>
#include <ext/hash/php_hash.h>
#include <ext/spl/spl_heap.h>
#include <ext/spl/spl_exceptions.h>
#include <ext/spl/spl_directory.h>
#include <ext/spl/spl_iterators.h>
#include <ext/date/php_date.h>
#ifdef PHALCON_USE_PHP_PCRE
#include <ext/pcre/php_pcre.h>
#endif
#ifdef PHALCON_USE_PHP_JSON
#include <ext/json/php_json.h>
#endif
#ifdef PHALCON_USE_PHP_SESSION
#include <ext/session/php_session.h>
#endif
#include <ext/pdo/php_pdo_driver.h>
#include <Zend/zend_API.h>
#include <Zend/zend_operators.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
#include <Zend/zend_execute.h>
#include <Zend/zend_extensions.h>
#include <Zend/zend_builtin_functions.h>
/* jsmin.c
2013-03-29
Copyright (c) 2002 Douglas Crockford (www.crockford.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef PHALCON_ASSETS_FILTERS_JSMINIFIER_H
#define PHALCON_ASSETS_FILTERS_JSMINIFIER_H
#include <Zend/zend.h>
static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC);
#endif /* PHALCON_ASSETS_FILTERS_JSMINIFIER_H */
/* jsmin.c
2013-03-29
Copyright (c) 2002 Douglas Crockford (www.crockford.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef PHALCON_ASSETS_FILTERS_CSSMINIFIER_H
#define PHALCON_ASSETS_FILTERS_CSSMINIFIER_H
#include <Zend/zend.h>
static int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC);
#endif /* PHALCON_ASSETS_FILTERS_CSSMINIFIER_H */
#define PHQL_AGAINST 1
#define PHQL_BETWEEN 2
#define PHQL_EQUALS 3
#define PHQL_NOTEQUALS 4
#define PHQL_LESS 5
#define PHQL_GREATER 6
#define PHQL_GREATEREQUAL 7
#define PHQL_LESSEQUAL 8
#define PHQL_AND 9
#define PHQL_OR 10
#define PHQL_LIKE 11
#define PHQL_ILIKE 12
#define PHQL_BITWISE_AND 13
#define PHQL_BITWISE_OR 14
#define PHQL_BITWISE_XOR 15
#define PHQL_DIVIDE 16
#define PHQL_TIMES 17
#define PHQL_MOD 18
#define PHQL_PLUS 19
#define PHQL_MINUS 20
#define PHQL_IS 21
#define PHQL_IN 22
#define PHQL_NOT 23
#define PHQL_BITWISE_NOT 24
#define PHQL_COMMA 25
#define PHQL_SELECT 26
#define PHQL_FROM 27
#define PHQL_DISTINCT 28
#define PHQL_ALL 29
#define PHQL_IDENTIFIER 30
#define PHQL_DOT 31
#define PHQL_AS 32
#define PHQL_INNER 33
#define PHQL_JOIN 34
#define PHQL_CROSS 35
#define PHQL_LEFT 36
#define PHQL_OUTER 37
#define PHQL_RIGHT 38
#define PHQL_FULL 39
#define PHQL_ON 40
#define PHQL_INSERT 41
#define PHQL_INTO 42
#define PHQL_VALUES 43
#define PHQL_PARENTHESES_OPEN 44
#define PHQL_PARENTHESES_CLOSE 45
#define PHQL_UPDATE 46
#define PHQL_SET 47
#define PHQL_DELETE 48
#define PHQL_WHERE 49
#define PHQL_ORDER 50
#define PHQL_BY 51
#define PHQL_ASC 52
#define PHQL_DESC 53
#define PHQL_GROUP 54
#define PHQL_HAVING 55
#define PHQL_LIMIT 56
#define PHQL_OFFSET 57
#define PHQL_INTEGER 58
#define PHQL_NPLACEHOLDER 59
#define PHQL_SPLACEHOLDER 60
#define PHQL_CAST 61
#define PHQL_CONVERT 62
#define PHQL_USING 63
#define PHQL_NULL 64
#define PHQL_STRING 65
#define PHQL_DOUBLE 66
#define PHQL_TRUE 67
#define PHQL_FALSE 68
#define PHQL_COLON 69
#ifndef PHALCON_MVC_MODEL_QUERY_SCANNER_H
#define PHALCON_MVC_MODEL_QUERY_SCANNER_H
#define PHQL_SCANNER_RETCODE_EOF -1
#define PHQL_SCANNER_RETCODE_ERR -2
#define PHQL_SCANNER_RETCODE_IMPOSSIBLE -3
#define PHQL_T_IGNORE 257
/* Literals & Identifiers */
#define PHQL_T_INTEGER 258
#define PHQL_T_DOUBLE 259
#define PHQL_T_STRING 260
#define PHQL_T_IDENTIFIER 265
/* Operators */
#define PHQL_T_ADD '+'
#define PHQL_T_SUB '-'
#define PHQL_T_MUL '*'
#define PHQL_T_DIV '/'
#define PHQL_T_MOD '%'
#define PHQL_T_BITWISE_AND '&'
#define PHQL_T_BITWISE_OR '|'
#define PHQL_T_BITWISE_XOR '^'
#define PHQL_T_BITWISE_NOT '~'
#define PHQL_T_AND 266
#define PHQL_T_OR 267
#define PHQL_T_LIKE 268
#define PHQL_T_ILIKE 275
#define PHQL_T_AGAINST 276
#define PHQL_T_DOT '.'
#define PHQL_T_COMMA 269
#define PHQL_T_COLON ':'
#define PHQL_T_EQUALS '='
#define PHQL_T_NOTEQUALS 270
#define PHQL_T_NOT '!'
#define PHQL_T_LESS '<'
#define PHQL_T_LESSEQUAL 271
#define PHQL_T_GREATER '>'
#define PHQL_T_GREATEREQUAL 272
#define PHQL_T_PARENTHESES_OPEN '('
#define PHQL_T_PARENTHESES_CLOSE ')'
/** Placeholders */
#define PHQL_T_NPLACEHOLDER 273
#define PHQL_T_SPLACEHOLDER 274
/** Reserved words */
#define PHQL_T_UPDATE 300
#define PHQL_T_SET 301
#define PHQL_T_WHERE 302
#define PHQL_T_DELETE 303
#define PHQL_T_FROM 304
#define PHQL_T_AS 305
#define PHQL_T_INSERT 306
#define PHQL_T_INTO 307
#define PHQL_T_VALUES 308
#define PHQL_T_SELECT 309
#define PHQL_T_ORDER 310
#define PHQL_T_BY 311
#define PHQL_T_LIMIT 312
#define PHQL_T_GROUP 313
#define PHQL_T_HAVING 314
#define PHQL_T_IN 315
#define PHQL_T_ON 316
#define PHQL_T_INNER 317
#define PHQL_T_JOIN 318
#define PHQL_T_LEFT 319
#define PHQL_T_RIGHT 320
#define PHQL_T_IS 321
#define PHQL_T_NULL 322
#define PHQL_T_NOTIN 323
#define PHQL_T_CROSS 324
#define PHQL_T_FULL 325
#define PHQL_T_OUTER 326
#define PHQL_T_ASC 327
#define PHQL_T_DESC 328
#define PHQL_T_OFFSET 329
#define PHQL_T_DISTINCT 330
#define PHQL_T_BETWEEN 331
#define PHQL_T_CAST 332
#define PHQL_T_TRUE 333
#define PHQL_T_FALSE 334
#define PHQL_T_CONVERT 335
#define PHQL_T_USING 336
#define PHQL_T_ALL 337
/** Special Tokens */
#define PHQL_T_FCALL 350
#define PHQL_T_NLIKE 351
#define PHQL_T_STARALL 352
#define PHQL_T_DOMAINALL 353
#define PHQL_T_EXPR 354
#define PHQL_T_QUALIFIED 355
#define PHQL_T_ENCLOSED 356
#define PHQL_T_NILIKE 357
#define PHQL_T_RAW_QUALIFIED 358
#define PHQL_T_INNERJOIN 360
#define PHQL_T_LEFTJOIN 361
#define PHQL_T_RIGHTJOIN 362
#define PHQL_T_CROSSJOIN 363
#define PHQL_T_FULLJOIN 364
#define PHQL_T_ISNULL 365
#define PHQL_T_ISNOTNULL 366
#define PHQL_T_MINUS 367
/* list of tokens and their names */
typedef struct _phql_token_names {
char *name;
unsigned int length;
unsigned int code;
} phql_token_names;
/* active token state */
typedef struct _phql_scanner_state {
int active_token;
unsigned int start_length;
char* start;
char* end;
} phql_scanner_state;
/* extra information tokens */
typedef struct _phql_scanner_token {
char *value;
int opcode;
unsigned int len;
} phql_scanner_token;
static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token);
const phql_token_names phql_tokens[];
#endif /* PHALCON_MVC_MODEL_QUERY_SCANNER_H */
#ifndef PHALCON_MVC_MODEL_QUERY_PHQL_H
#define PHALCON_MVC_MODEL_QUERY_PHQL_H
typedef struct _phql_parser_token {
char *token;
int opcode;
unsigned int token_len;
int free_flag;
} phql_parser_token;
typedef struct _phql_parser_status {
zval *ret;
char* phql;
unsigned int phql_length;
int status;
phql_scanner_state *scanner_state;
phql_scanner_token *token;
char *syntax_error;
zend_uint syntax_error_len;
zend_bool enable_literals;
} phql_parser_status;
#define PHQL_PARSING_OK 1
#define PHQL_PARSING_FAILED 0
static int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) PHALCON_ATTR_NONNULL;
static int phql_internal_parse_phql(zval **result, char *phql, unsigned int phql_length, zval **error_msg TSRMLS_DC) PHALCON_ATTR_NONNULL2(1, 4);
#endif /* PHALCON_MVC_MODEL_QUERY_PHQL_H */
#ifndef PHALCON_MVC_VIEW_ENGINE_VOLT_PARSER_H
#define PHALCON_MVC_VIEW_ENGINE_VOLT_PARSER_H
#define PHVOLT_OPEN_DELIMITER 1
#define PHVOLT_COMMA 2
#define PHVOLT_IN 3
#define PHVOLT_QUESTION 4
#define PHVOLT_COLON 5
#define PHVOLT_RANGE 6
#define PHVOLT_AND 7
#define PHVOLT_OR 8
#define PHVOLT_IS 9
#define PHVOLT_EQUALS 10
#define PHVOLT_NOTEQUALS 11
#define PHVOLT_LESS 12
#define PHVOLT_GREATER 13
#define PHVOLT_GREATEREQUAL 14
#define PHVOLT_LESSEQUAL 15
#define PHVOLT_IDENTICAL 16
#define PHVOLT_NOTIDENTICAL 17
#define PHVOLT_DIVIDE 18
#define PHVOLT_TIMES 19
#define PHVOLT_MOD 20
#define PHVOLT_PLUS 21
#define PHVOLT_MINUS 22
#define PHVOLT_CONCAT 23
#define PHVOLT_SBRACKET_OPEN 24
#define PHVOLT_PIPE 25
#define PHVOLT_NOT 26
#define PHVOLT_INCR 27
#define PHVOLT_DECR 28
#define PHVOLT_PARENTHESES_OPEN 29
#define PHVOLT_DOT 30
#define PHVOLT_IF 31
#define PHVOLT_CLOSE_DELIMITER 32
#define PHVOLT_ENDIF 33
#define PHVOLT_ELSE 34
#define PHVOLT_ELSEIF 35
#define PHVOLT_ELSEFOR 36
#define PHVOLT_FOR 37
#define PHVOLT_IDENTIFIER 38
#define PHVOLT_ENDFOR 39
#define PHVOLT_SET 40
#define PHVOLT_ASSIGN 41
#define PHVOLT_ADD_ASSIGN 42
#define PHVOLT_SUB_ASSIGN 43
#define PHVOLT_MUL_ASSIGN 44
#define PHVOLT_DIV_ASSIGN 45
#define PHVOLT_MACRO 46
#define PHVOLT_PARENTHESES_CLOSE 47
#define PHVOLT_ENDMACRO 48
#define PHVOLT_INTEGER 49
#define PHVOLT_STRING 50
#define PHVOLT_DOUBLE 51
#define PHVOLT_NULL 52
#define PHVOLT_FALSE 53
#define PHVOLT_TRUE 54
#define PHVOLT_CALL 55
#define PHVOLT_ENDCALL 56
#define PHVOLT_OPEN_EDELIMITER 57
#define PHVOLT_CLOSE_EDELIMITER 58
#define PHVOLT_BLOCK 59
#define PHVOLT_ENDBLOCK 60
#define PHVOLT_CACHE 61
#define PHVOLT_ENDCACHE 62
#define PHVOLT_EXTENDS 63
#define PHVOLT_INCLUDE 64
#define PHVOLT_WITH 65
#define PHVOLT_DO 66
#define PHVOLT_RETURN 67
#define PHVOLT_AUTOESCAPE 68
#define PHVOLT_ENDAUTOESCAPE 69
#define PHVOLT_BREAK 70
#define PHVOLT_CONTINUE 71
#define PHVOLT_RAW_FRAGMENT 72
#define PHVOLT_DEFINED 73
#define PHVOLT_SBRACKET_CLOSE 74
#define PHVOLT_CBRACKET_OPEN 75
#define PHVOLT_CBRACKET_CLOSE 76
#endif /* PHALCON_MVC_VIEW_ENGINE_VOLT_PARSER_H */
#ifndef PHALCON_MVC_VIEW_ENGINE_VOLT_SCANNER_H
#define PHALCON_MVC_VIEW_ENGINE_VOLT_SCANNER_H
#define PHVOLT_RAW_BUFFER_SIZE 256
#define PHVOLT_SCANNER_RETCODE_EOF -1
#define PHVOLT_SCANNER_RETCODE_ERR -2
#define PHVOLT_SCANNER_RETCODE_IMPOSSIBLE -3
/** Modes */
#define PHVOLT_MODE_RAW 0
#define PHVOLT_MODE_CODE 1
#define PHVOLT_MODE_COMMENT 2
#define PHVOLT_T_IGNORE 257
/* Literals & Identifiers */
#define PHVOLT_T_INTEGER 258
#define PHVOLT_T_DOUBLE 259
#define PHVOLT_T_STRING 260
#define PHVOLT_T_NULL 261
#define PHVOLT_T_FALSE 262
#define PHVOLT_T_TRUE 263
#define PHVOLT_T_IDENTIFIER 265
/* Operators */
#define PHVOLT_T_ADD '+'
#define PHVOLT_T_SUB '-'
#define PHVOLT_T_MUL '*'
#define PHVOLT_T_DIV '/'
#define PHVOLT_T_MOD '%'
#define PHVOLT_T_AND 266
#define PHVOLT_T_OR 267
#define PHVOLT_T_CONCAT '~'
#define PHVOLT_T_PIPE '|'
#define PHVOLT_T_DOT '.'
#define PHVOLT_T_COMMA 269
#define PHVOLT_T_NOT '!'
#define PHVOLT_T_LESS '<'
#define PHVOLT_T_LESSEQUAL 270
#define PHVOLT_T_GREATER '>'
#define PHVOLT_T_GREATEREQUAL 271
#define PHVOLT_T_EQUALS 272
#define PHVOLT_T_NOTEQUALS 273
#define PHVOLT_T_IDENTICAL 274
#define PHVOLT_T_NOTIDENTICAL 275
#define PHVOLT_T_RANGE 276
#define PHVOLT_T_ASSIGN '='
#define PHVOLT_T_COLON 277
#define PHVOLT_T_QUESTION '?'
#define PHVOLT_T_POW 278
#define PHVOLT_T_INCR 279
#define PHVOLT_T_DECR 280
#define PHVOLT_T_ADD_ASSIGN 281
#define PHVOLT_T_SUB_ASSIGN 282
#define PHVOLT_T_MUL_ASSIGN 283
#define PHVOLT_T_DIV_ASSIGN 284
#define PHVOLT_T_PARENTHESES_OPEN '('
#define PHVOLT_T_PARENTHESES_CLOSE ')'
#define PHVOLT_T_SBRACKET_OPEN '['
#define PHVOLT_T_SBRACKET_CLOSE ']'
#define PHVOLT_T_CBRACKET_OPEN '{'
#define PHVOLT_T_CBRACKET_CLOSE '}'
/** Reserved words */
#define PHVOLT_T_IF 300
#define PHVOLT_T_ELSE 301
#define PHVOLT_T_ELSEIF 302
#define PHVOLT_T_ENDIF 303
#define PHVOLT_T_FOR 304
#define PHVOLT_T_ENDFOR 305
#define PHVOLT_T_SET 306
#define PHVOLT_T_BLOCK 307
#define PHVOLT_T_ENDBLOCK 308
#define PHVOLT_T_IN 309
#define PHVOLT_T_EXTENDS 310
#define PHVOLT_T_IS 311
#define PHVOLT_T_DEFINED 312
#define PHVOLT_T_INCLUDE 313
#define PHVOLT_T_CACHE 314
#define PHVOLT_T_ENDCACHE 315
#define PHVOLT_T_DO 316
#define PHVOLT_T_AUTOESCAPE 317
#define PHVOLT_T_ENDAUTOESCAPE 318
#define PHVOLT_T_CONTINUE 319
#define PHVOLT_T_BREAK 320
#define PHVOLT_T_ELSEFOR 321
#define PHVOLT_T_MACRO 322
#define PHVOLT_T_ENDMACRO 323
#define PHVOLT_T_WITH 324
#define PHVOLT_T_CALL 325
#define PHVOLT_T_ENDCALL 326
#define PHVOLT_T_RETURN 327
/** Delimiters */
#define PHVOLT_T_OPEN_DELIMITER 330
#define PHVOLT_T_CLOSE_DELIMITER 331
#define PHVOLT_T_OPEN_EDELIMITER 332
#define PHVOLT_T_CLOSE_EDELIMITER 333
/** Special Tokens */
#define PHVOLT_T_FCALL 350
#define PHVOLT_T_EXPR 354
#define PHVOLT_T_QUALIFIED 355
#define PHVOLT_T_ENCLOSED 356
#define PHVOLT_T_RAW_FRAGMENT 357
#define PHVOLT_T_EMPTY 358
#define PHVOLT_T_ECHO 359
#define PHVOLT_T_ARRAY 360
#define PHVOLT_T_ARRAYACCESS 361
#define PHVOLT_T_NOT_ISSET 362
#define PHVOLT_T_ISSET 363
#define PHVOLT_T_RESOLVED_EXPR 364
#define PHVOLT_T_SLICE 365
#define PHVOLT_T_TERNARY 366
#define PHVOLT_T_NOT_IN 369
#define PHVOLT_T_MINUS 367
#define PHVOLT_T_PLUS 368
/* List of tokens and their names */
typedef struct _phvolt_token_names {
char *name;
int len;
unsigned int code;
} phvolt_token_names;
/* Active token state */
typedef struct _phvolt_scanner_state {
int active_token;
int mode;
char* start;
char* end;
unsigned int start_length;
unsigned int active_line;
zval *active_file;
unsigned int statement_position;
unsigned int extends_mode;
unsigned int block_level;
unsigned int macro_level;
char *raw_buffer;
unsigned int raw_buffer_cursor;
unsigned int raw_buffer_size;
unsigned int old_if_level;
unsigned int if_level;
unsigned int for_level;
int whitespace_control;
} phvolt_scanner_state;
/* Extra information tokens */
typedef struct _phvolt_scanner_token {
int opcode;
int len;
char *value;
} phvolt_scanner_token;
static int phvolt_get_token(phvolt_scanner_state *s, phvolt_scanner_token *token);
const phvolt_token_names phvolt_tokens[];
#endif /* PHALCON_MVC_VIEW_ENGINE_VOLT_SCANNER_H */
#ifndef PHALCON_MVC_VIEW_ENGINE_VOLT_VOLT_H
#define PHALCON_MVC_VIEW_ENGINE_VOLT_VOLT_H
typedef struct _phvolt_parser_token {
char *token;
int opcode;
int token_len;
int free_flag;
} phvolt_parser_token;
typedef struct _phvolt_parser_status {
zval *ret;
phvolt_scanner_state *scanner_state;
int status;
zend_uint syntax_error_len;
char *syntax_error;
phvolt_scanner_token *token;
} phvolt_parser_status;
#define PHVOLT_PARSING_OK 1
#define PHVOLT_PARSING_FAILED 0
static int phvolt_parse_view(zval *result, zval *view_code, zval *template_path TSRMLS_DC);
static int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_path, zval **error_msg TSRMLS_DC);
#endif /* PHALCON_MVC_VIEW_ENGINE_VOLT_VOLT_H */
#ifndef PHALCON_ANNOTATIONS_PARSER_H
#define PHALCON_ANNOTATIONS_PARSER_H
#define PHANNOT_COMMA 1
#define PHANNOT_AT 2
#define PHANNOT_IDENTIFIER 3
#define PHANNOT_PARENTHESES_OPEN 4
#define PHANNOT_PARENTHESES_CLOSE 5
#define PHANNOT_STRING 6
#define PHANNOT_EQUALS 7
#define PHANNOT_COLON 8
#define PHANNOT_INTEGER 9
#define PHANNOT_DOUBLE 10
#define PHANNOT_NULL 11
#define PHANNOT_FALSE 12
#define PHANNOT_TRUE 13
#define PHANNOT_BRACKET_OPEN 14
#define PHANNOT_BRACKET_CLOSE 15
#define PHANNOT_SBRACKET_OPEN 16
#define PHANNOT_SBRACKET_CLOSE 17
#endif /* PHALCON_ANNOTATIONS_PARSER_H */
#ifndef PHALCON_ANNOTATIONS_SCANNER_H
#define PHALCON_ANNOTATIONS_SCANNER_H
#define PHANNOT_SCANNER_RETCODE_EOF -1
#define PHANNOT_SCANNER_RETCODE_ERR -2
#define PHANNOT_SCANNER_RETCODE_IMPOSSIBLE -3
/** Modes */
#define PHANNOT_MODE_RAW 0
#define PHANNOT_MODE_ANNOTATION 1
#define PHANNOT_T_IGNORE 297
#define PHANNOT_T_DOCBLOCK_ANNOTATION 299
#define PHANNOT_T_ANNOTATION 300
/* Literals & Identifiers */
#define PHANNOT_T_INTEGER 301
#define PHANNOT_T_DOUBLE 302
#define PHANNOT_T_STRING 303
#define PHANNOT_T_NULL 304
#define PHANNOT_T_FALSE 305
#define PHANNOT_T_TRUE 306
#define PHANNOT_T_IDENTIFIER 307
#define PHANNOT_T_ARRAY 308
#define PHANNOT_T_ARBITRARY_TEXT 309
/* Operators */
#define PHANNOT_T_AT '@'
#define PHANNOT_T_DOT '.'
#define PHANNOT_T_COMMA ','
#define PHANNOT_T_EQUALS '='
#define PHANNOT_T_COLON ':'
#define PHANNOT_T_BRACKET_OPEN '{'
#define PHANNOT_T_BRACKET_CLOSE '}'
#define PHANNOT_T_SBRACKET_OPEN '['
#define PHANNOT_T_SBRACKET_CLOSE ']'
#define PHANNOT_T_PARENTHESES_OPEN '('
#define PHANNOT_T_PARENTHESES_CLOSE ')'
/* List of tokens and their names */
typedef struct _phannot_token_names {
char *name;
unsigned int code;
} phannot_token_names;
/* Active token state */
typedef struct _phannot_scanner_state {
char* start;
char* end;
int active_token;
unsigned int start_length;
int mode;
unsigned int active_line;
zval *active_file;
} phannot_scanner_state;
/* Extra information tokens */
typedef struct _phannot_scanner_token {
char *value;
int opcode;
int len;
} phannot_scanner_token;
static int phannot_get_token(phannot_scanner_state *s, phannot_scanner_token *token);
const phannot_token_names phannot_tokens[];
#endif /* PHALCON_ANNOTATIONS_SCANNER_H */
#ifndef PHALCON_ANNOTATIONS_ANNOT_H
#define PHALCON_ANNOTATIONS_ANNOT_H
#include <Zend/zend.h>
typedef struct _phannot_parser_token {
char *token;
int opcode;
int token_len;
int free_flag;
} phannot_parser_token;
typedef struct _phannot_parser_status {
zval *ret;
phannot_scanner_state *scanner_state;
phannot_scanner_token *token;
int status;
zend_uint syntax_error_len;
char *syntax_error;
} phannot_parser_status;
#define PHANNOT_PARSING_OK 1
#define PHANNOT_PARSING_FAILED 0
static int phannot_parse_annotations(zval *result, zval *view_code, zval *template_path, zval *line TSRMLS_DC);
static int phannot_internal_parse_annotations(zval **result, zval *view_code, zval *template_path, zval *line, zval **error_msg TSRMLS_DC);
#endif /* PHALCON_ANNOTATIONS_ANNOT_H */
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
#include <ext/spl/spl_exceptions.h>
#include <ext/spl/spl_iterators.h>
/** Main macros */
#define PH_DEBUG 0
#define PH_NOISY 0
#define PH_SILENT 1
#define PH_NOISY_CC PH_NOISY TSRMLS_CC
#define PH_SILENT_CC PH_SILENT TSRMLS_CC
#define PH_SEPARATE 256
#define PH_COPY 1024
#define PH_CTOR 4096
#define SL(str) ZEND_STRL(str)
#define SS(str) ZEND_STRS(str)
#define ISL(str) (phalcon_interned_##str), (sizeof(#str)-1)
#define ISS(str) (phalcon_interned_##str), (sizeof(#str))
/* Startup functions */
void php_phalcon_init_globals(zend_phalcon_globals *phalcon_globals TSRMLS_DC);
zend_class_entry *phalcon_register_internal_interface_ex(zend_class_entry *orig_ce, zend_class_entry *parent_ce TSRMLS_DC);
/* Globals functions */
static int phalcon_init_global(char *global, unsigned int global_length TSRMLS_DC);
static int phalcon_get_global(zval **arr, const char *global, unsigned int global_length TSRMLS_DC);
static int phalcon_is_callable(zval *var TSRMLS_DC);
static int phalcon_function_exists(const zval *function_name TSRMLS_DC);
static int phalcon_function_exists_ex(const char *func_name, unsigned int func_len TSRMLS_DC);
static int phalcon_function_quick_exists_ex(const char *func_name, unsigned int func_len, unsigned long key TSRMLS_DC);
/* Count */
long int phalcon_fast_count_int(zval *value TSRMLS_DC);
static void phalcon_fast_count(zval *result, zval *array TSRMLS_DC);
static int phalcon_fast_count_ev(zval *array TSRMLS_DC);
/* Utils functions */
static int phalcon_is_iterable_ex(zval *arr, HashTable **arr_hash, HashPosition *hash_position, int duplicate, int reverse);
static void phalcon_safe_zval_ptr_dtor(zval *pzval);
/* Fetch Parameters */
static int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, int optional_args, ...);
static int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);
/* Compatibility macros for PHP 5.3 */
#ifndef INIT_PZVAL_COPY
#define INIT_PZVAL_COPY(z, v) ZVAL_COPY_VALUE(z, v);\
Z_SET_REFCOUNT_P(z, 1);\
Z_UNSET_ISREF_P(z);
#endif
#ifndef ZVAL_COPY_VALUE
#define ZVAL_COPY_VALUE(z, v)\
(z)->value = (v)->value;\
Z_TYPE_P(z) = Z_TYPE_P(v);
#endif
/** Symbols */
#define PHALCON_READ_SYMBOL(var, auxarr, name) \
if (EG(active_symbol_table) && zend_hash_find(EG(active_symbol_table), name, sizeof(name), (void **)&auxarr) == SUCCESS) { \
var = *auxarr; \
} else { \
ZVAL_NULL(var); \
}
#define RETURN_CCTOR(var) { \
*(return_value) = *(var); \
if (Z_TYPE_P(var) > IS_BOOL) { \
phalcon_copy_ctor(return_value, var); \
} \
INIT_PZVAL(return_value) \
} \
PHALCON_MM_RESTORE(); \
return;
#define RETURN_CCTORW(var) { \
*(return_value) = *(var); \
if (Z_TYPE_P(var) > IS_BOOL) { \
phalcon_copy_ctor(return_value, var); \
} \
INIT_PZVAL(return_value) \
} \
return;
#define RETURN_CTOR(var) { \
RETVAL_ZVAL(var, 1, 0); \
} \
PHALCON_MM_RESTORE(); \
return;
#define RETURN_CTORW(var) { \
RETVAL_ZVAL(var, 1, 0); \
} \
return;
#define RETURN_THIS() { \
RETVAL_ZVAL(this_ptr, 1, 0); \
} \
PHALCON_MM_RESTORE(); \
return;
#define RETURN_THISW() \
RETURN_ZVAL(this_ptr, 1, 0);
#define RETURN_NCTOR(var) { \
*(return_value) = *(var); \
INIT_PZVAL(return_value) \
} \
PHALCON_MM_RESTORE(); \
return;
#define RETURN_NCTORW(var) { \
*(return_value) = *(var); \
INIT_PZVAL(return_value) \
} \
return;
#define RETURN_MEMBER(object, member_name) \
phalcon_return_property_quick(return_value, return_value_ptr, object, SL(member_name), zend_inline_hash_func(SS(member_name)) TSRMLS_CC); \
return;
#define RETURN_MEMBER_QUICK(object, member_name, key) \
phalcon_return_property_quick(return_value, return_value_ptr, object, SL(member_name), key TSRMLS_CC); \
return;
/** Return without change return_value */
#define RETURN_MM() PHALCON_MM_RESTORE(); return;
/** Return null restoring memory frame */
#define RETURN_MM_NULL() PHALCON_MM_RESTORE(); RETURN_NULL();
/** Return bool restoring memory frame */
#define RETURN_MM_FALSE PHALCON_MM_RESTORE(); RETURN_FALSE;
#define RETURN_MM_TRUE PHALCON_MM_RESTORE(); RETURN_TRUE;
/** Return string restoring memory frame */
#define RETURN_MM_STRING(str, copy) PHALCON_MM_RESTORE(); RETURN_STRING(str, copy);
#define RETURN_MM_EMPTY_STRING() PHALCON_MM_RESTORE(); RETURN_EMPTY_STRING();
/** Return empty array */
#define RETURN_EMPTY_ARRAY() array_init(return_value); return;
#define RETURN_MM_EMPTY_ARRAY() PHALCON_MM_RESTORE(); RETURN_EMPTY_ARRAY();
#ifndef IS_INTERNED
#define IS_INTERNED(key) 0
#define INTERNED_HASH(key) 0
#endif
/** Get the current hash key without copying the hash key */
#define PHALCON_GET_HKEY(var, hash, hash_position) \
phalcon_get_current_key(&var, hash, &hash_position TSRMLS_CC);
/** Get current hash key copying the hash_value if needed */
#define PHALCON_GET_HMKEY(var, hash, hash_pointer) \
{\
int hash_type; \
char *hash_index; \
uint hash_index_len; \
ulong hash_num; \
\
PHALCON_INIT_NVAR(var); \
hash_type = zend_hash_get_current_key_ex(hash, &hash_index, &hash_index_len, &hash_num, 0, &hash_pointer); \
if (hash_type == HASH_KEY_IS_STRING) { \
if (IS_INTERNED(hash_index)) { \
ZVAL_STRINGL(var, hash_index, hash_index_len - 1, 0); \
} else { \
ZVAL_STRINGL(var, hash_index, hash_index_len - 1, 1); \
} \
} else { \
if (hash_type == HASH_KEY_IS_LONG) { \
ZVAL_LONG(var, hash_num); \
}\
}\
}
/** Foreach */
#define PHALCON_GET_FOREACH_KEY(var, hash, hash_pointer) PHALCON_GET_HMKEY(var, hash, hash_pointer)
/** Check if an array is iterable or not */
#define phalcon_is_iterable(var, array_hash, hash_pointer, duplicate, reverse) \
if (!phalcon_is_iterable_ex(var, array_hash, hash_pointer, duplicate, reverse)) { \
zend_error(E_ERROR, "The argument is not iterable()"); \
PHALCON_MM_RESTORE(); \
return; \
}
#define PHALCON_GET_FOREACH_VALUE(var) \
PHALCON_OBS_NVAR(var); \
var = *hd; \
Z_ADDREF_P(var);
#define PHALCON_GET_HVALUE(var) \
PHALCON_OBS_NVAR(var); \
var = *hd; \
Z_ADDREF_P(var);
/** class/interface registering */
#define PHALCON_REGISTER_CLASS(ns, class_name, name, methods, flags) \
{ \
zend_class_entry ce; \
memset(&ce, 0, sizeof(zend_class_entry)); \
INIT_NS_CLASS_ENTRY(ce, #ns, #class_name, methods); \
phalcon_ ##name## _ce = zend_register_internal_class(&ce TSRMLS_CC); \
phalcon_ ##name## _ce->ce_flags |= flags; \
}
#define PHALCON_REGISTER_CLASS_EX(ns, class_name, lcname, parent_ce, methods, flags) \
{ \
zend_class_entry ce; \
memset(&ce, 0, sizeof(zend_class_entry)); \
INIT_NS_CLASS_ENTRY(ce, #ns, #class_name, methods); \
phalcon_ ##lcname## _ce = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC); \
if (!phalcon_ ##lcname## _ce) { \
fprintf(stderr, "Phalcon Error: Class to extend '%s' was not found when registering class '%s'\n", (parent_ce ? parent_ce->name : "(null)"), ZEND_NS_NAME(#ns, #class_name)); \
return FAILURE; \
} \
phalcon_ ##lcname## _ce->ce_flags |= flags; \
}
#define PHALCON_REGISTER_INTERFACE(ns, classname, name, methods) \
{ \
zend_class_entry ce; \
memset(&ce, 0, sizeof(zend_class_entry)); \
INIT_NS_CLASS_ENTRY(ce, #ns, #classname, methods); \
phalcon_ ##name## _ce = zend_register_internal_interface(&ce TSRMLS_CC); \
}
#define PHALCON_REGISTER_INTERFACE_EX(ns, classname, lcname, parent_ce, methods) \
{ \
zend_class_entry ce; \
memset(&ce, 0, sizeof(zend_class_entry)); \
INIT_NS_CLASS_ENTRY(ce, #ns, #classname, methods); \
phalcon_ ##lcname## _ce = phalcon_register_internal_interface_ex(&ce, parent_ce TSRMLS_CC); \
if (!phalcon_ ##lcname## _ce) { \
fprintf(stderr, "Can't register interface %s with parent %s\n", ZEND_NS_NAME(#ns, #classname), (parent_ce ? parent_ce->name : "(null)")); \
return FAILURE; \
} \
}
/** Method declaration for API generation */
#define PHALCON_DOC_METHOD(class_name, method)
/** Low overhead parse/fetch parameters */
#ifndef PHALCON_RELEASE
#define phalcon_fetch_params(memory_grow, required_params, optional_params, ...) \
if (memory_grow) { \
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL; \
ASSUME(phalcon_globals_ptr != NULL); \
if (unlikely(phalcon_globals_ptr->active_memory == NULL)) { \
fprintf(stderr, "phalcon_fetch_params is called with memory_grow=1 but there is no active memory frame!\n"); \
phalcon_print_backtrace(); \
} \
else if (unlikely(phalcon_globals_ptr->active_memory->func != __func__)) { \
fprintf(stderr, "phalcon_fetch_params is called with memory_grow=1 but the memory frame was not created!\n"); \
fprintf(stderr, "The frame was created by %s\n", phalcon_globals_ptr->active_memory->func); \
fprintf(stderr, "Calling function: %s\n", __func__); \
phalcon_print_backtrace(); \
} \
} \
if (phalcon_fetch_parameters(ZEND_NUM_ARGS() TSRMLS_CC, required_params, optional_params, __VA_ARGS__) == FAILURE) { \
if (memory_grow) { \
RETURN_MM_NULL(); \
} \
RETURN_NULL(); \
} \
#else
#define phalcon_fetch_params(memory_grow, required_params, optional_params, ...) \
if (phalcon_fetch_parameters(ZEND_NUM_ARGS() TSRMLS_CC, required_params, optional_params, __VA_ARGS__) == FAILURE) { \
if (memory_grow) { \
RETURN_MM_NULL(); \
} \
RETURN_NULL(); \
}
#endif
#define phalcon_fetch_params_ex(required_params, optional_params, ...) \
if (phalcon_fetch_parameters_ex(0 TSRMLS_CC, required_params, optional_params, __VA_ARGS__) == FAILURE) { \
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Wrong number of parameters"); \
return; \
}
#define PHALCON_VERIFY_INTERFACE_EX(instance, interface_ce, exception_ce, restore_stack) \
if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \
if (Z_TYPE_P(instance) != IS_OBJECT) { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \
} \
else { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \
} \
if (restore_stack) { \
PHALCON_MM_RESTORE(); \
} \
return; \
}
#define PHALCON_VERIFY_INTERFACE_OR_NULL_EX(pzv, interface_ce, exception_ce, restore_stack) \
if (Z_TYPE_P(pzv) != IS_NULL && (Z_TYPE_P(pzv) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(pzv), interface_ce, 1 TSRMLS_CC))) { \
if (Z_TYPE_P(pzv) != IS_OBJECT) { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s or NULL, %s given", interface_ce->name, zend_zval_type_name(pzv)); \
} \
else { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s or NULL, object of type %s given", interface_ce->name, Z_OBJCE_P(pzv)->name); \
} \
if (restore_stack) { \
PHALCON_MM_RESTORE(); \
} \
return; \
}
#define PHALCON_VERIFY_CLASS_EX(instance, class_ce, exception_ce, restore_stack) \
if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), class_ce, 0 TSRMLS_CC)) { \
if (Z_TYPE_P(instance) != IS_OBJECT) { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object of type %s, %s given", class_ce->name, zend_zval_type_name(instance)); \
} \
else { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object of type %s, object of type %s given", class_ce->name, Z_OBJCE_P(instance)->name); \
} \
if (restore_stack) { \
PHALCON_MM_RESTORE(); \
} \
return; \
}
#define PHALCON_VERIFY_CLASS_OR_NULL_EX(pzv, class_ce, exception_ce, restore_stack) \
if (Z_TYPE_P(pzv) != IS_NULL && (Z_TYPE_P(pzv) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(pzv), class_ce, 0 TSRMLS_CC))) { \
if (Z_TYPE_P(pzv) != IS_OBJECT) { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object of type %s, %s given", class_ce->name, zend_zval_type_name(pzv)); \
} \
else { \
zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object of type %s, object of type %s given", class_ce->name, Z_OBJCE_P(pzv)->name); \
} \
if (restore_stack) { \
PHALCON_MM_RESTORE(); \
} \
return; \
}
#define PHALCON_VERIFY_INTERFACE(instance, interface_ce) PHALCON_VERIFY_INTERFACE_EX(instance, interface_ce, spl_ce_LogicException, 1)
#define PHALCON_VERIFY_INTERFACE_OR_NULL(pzv, interface_ce) PHALCON_VERIFY_INTERFACE_OR_NULL_EX(pzv, interface_ce, spl_ce_LogicException, 1)
#define PHALCON_VERIFY_CLASS(instance, class_ce) PHALCON_VERIFY_CLASS_EX(instance, class_ce, spl_ce_LogicException, 1)
#define PHALCON_VERIFY_CLASS_OR_NULL(pzv, class_ce) PHALCON_VERIFY_CLASS_OR_NULL_EX(pzv, class_ce, spl_ce_LogicException, 1)
#define phalcon_convert_to_explicit_type_mm_ex(ppzv, str_type) \
if (Z_TYPE_PP(ppzv) != str_type) { \
if (!Z_ISREF_PP(ppzv)) { \
PHALCON_SEPARATE(*ppzv); \
} \
convert_to_explicit_type(*ppzv, str_type); \
}
#define PHALCON_ENSURE_IS_STRING(ppzv) convert_to_explicit_type_ex(ppzv, IS_STRING)
#define PHALCON_ENSURE_IS_LONG(ppzv) convert_to_explicit_type_ex(ppzv, IS_LONG)
#define PHALCON_ENSURE_IS_DOUBLE(ppzv) convert_to_explicit_type_ex(ppzv, IS_DOUBLE)
#define PHALCON_ENSURE_IS_BOOL(ppzv) convert_to_explicit_type_ex(ppzv, IS_BOOL)
#define PHALCON_ENSURE_IS_ARRAY(ppzv) convert_to_explicit_type_ex(ppzv, IS_ARRAY)
#ifndef PHALCON_KERNEL_MEMORY_H
#define PHALCON_KERNEL_MEMORY_H
#include <Zend/zend.h>
/* Memory Frames */
#ifndef PHALCON_RELEASE
static void phalcon_dump_current_frame(TSRMLS_D);
void ZEND_FASTCALL phalcon_memory_grow_stack(const char *func TSRMLS_DC);
int ZEND_FASTCALL phalcon_memory_restore_stack(const char *func TSRMLS_DC);
#define PHALCON_MM_GROW() phalcon_memory_grow_stack(__func__ TSRMLS_CC)
#define PHALCON_MM_RESTORE() phalcon_memory_restore_stack(__func__ TSRMLS_CC)
#else
void ZEND_FASTCALL phalcon_memory_grow_stack(TSRMLS_D);
int ZEND_FASTCALL phalcon_memory_restore_stack(TSRMLS_D);
#define PHALCON_MM_GROW() phalcon_memory_grow_stack(TSRMLS_C)
#define PHALCON_MM_RESTORE() phalcon_memory_restore_stack(TSRMLS_C)
#endif
void ZEND_FASTCALL phalcon_memory_observe(zval **var TSRMLS_DC);
void ZEND_FASTCALL phalcon_memory_remove(zval **var TSRMLS_DC);
void ZEND_FASTCALL phalcon_memory_alloc(zval **var TSRMLS_DC);
void ZEND_FASTCALL phalcon_memory_alloc_pnull(zval **var TSRMLS_DC);
int ZEND_FASTCALL phalcon_clean_restore_stack(TSRMLS_D);
/* Virtual symbol tables */
static void phalcon_create_symbol_table(TSRMLS_D);
/*extern void phalcon_restore_symbol_table(TSRMLS_D);*/
static void phalcon_clean_symbol_tables(TSRMLS_D);
/** Export symbols to active symbol table */
static int phalcon_set_symbol(zval *key_name, zval *value TSRMLS_DC);
static int phalcon_set_symbol_str(char *key_name, unsigned int key_length, zval *value TSRMLS_DC);
void ZEND_FASTCALL phalcon_copy_ctor(zval *destiny, zval *origin);
/* Memory macros */
#define PHALCON_ALLOC_GHOST_ZVAL(z) \
do { \
MAKE_STD_ZVAL(z); \
Z_SET_REFCOUNT_P(z, 0); \
} while (0)
#define PHALCON_INIT_VAR(z) \
phalcon_memory_alloc(&z TSRMLS_CC)
#define PHALCON_INIT_NVAR(z)\
if (z) { \
if (Z_REFCOUNT_P(z) > 1) { \
Z_DELREF_P(z); \
ALLOC_ZVAL(z); \
Z_SET_REFCOUNT_P(z, 1); \
Z_UNSET_ISREF_P(z); \
} else {\
zval_dtor(z); \
} \
ZVAL_NULL(z); \
} else { \
phalcon_memory_alloc(&z TSRMLS_CC); \
}
#define PHALCON_INIT_NVAR_PNULL(z)\
if (z) { \
if (Z_REFCOUNT_P(z) > 1) { \
Z_DELREF_P(z); \
if (Z_REFCOUNT_P(z) >= 1) { \
zval_copy_ctor(z); \
} \
ALLOC_ZVAL(z); \
Z_SET_REFCOUNT_P(z, 1); \
Z_UNSET_ISREF_P(z); \
} \
ZVAL_NULL(z); \
} else { \
phalcon_memory_alloc_pnull(&z TSRMLS_CC); \
}
#define PHALCON_CPY_WRT(d, v) \
if (d) { \
if (Z_REFCOUNT_P(d) > 0) { \
zval_ptr_dtor(&d); \
} \
} else { \
phalcon_memory_observe(&d TSRMLS_CC); \
} \
Z_ADDREF_P(v); \
d = v;
#define PHALCON_CPY_WRT_CTOR(d, v) \
if (d) { \
if (Z_REFCOUNT_P(d) > 0) { \
zval_ptr_dtor(&d); \
} \
} else { \
phalcon_memory_observe(&d TSRMLS_CC); \
} \
ALLOC_ZVAL(d); \
*d = *v; \
zval_copy_ctor(d); \
Z_SET_REFCOUNT_P(d, 1); \
Z_UNSET_ISREF_P(d);
/* */
#define PHALCON_OBS_VAR(z) \
phalcon_memory_observe(&z TSRMLS_CC)
#define PHALCON_OBS_NVAR(z)\
if (z) { \
if (Z_REFCOUNT_P(z) > 1) { \
Z_DELREF_P(z); \
} else {\
zval_ptr_dtor(&z); \
z = NULL; \
} \
} else { \
phalcon_memory_observe(&z TSRMLS_CC); \
}
#define PHALCON_SEPARATE_ARRAY(a) \
{ \
if (Z_REFCOUNT_P(a) > 1) { \
zval *new_zv; \
Z_DELREF_P(a); \
ALLOC_ZVAL(new_zv); \
INIT_PZVAL_COPY(new_zv, a); \
a = new_zv; \
zval_copy_ctor(new_zv); \
} \
}
#define PHALCON_SEPARATE_PARAM(z) \
do { \
zval *orig_ptr = z;\
phalcon_memory_observe(&z TSRMLS_CC);\
ALLOC_ZVAL(z);\
*z = *orig_ptr;\
zval_copy_ctor(z);\
Z_SET_REFCOUNT_P(z, 1);\
Z_UNSET_ISREF_P(z);\
} while (0)
static inline int phalcon_maybe_separate_zval(zval** z)
{
if (Z_REFCOUNT_PP(z) > 1 && !Z_ISREF_PP(z)) {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, *z);
*z = new_zv;
zval_copy_ctor(new_zv);
return 1;
}
return 0;
}
#endif /* PHALCON_KERNEL_MEMORY_H */
#ifndef PHALCON_KERNEL_BACKTRACE_H
#define PHALCON_KERNEL_BACKTRACE_H
static void phalcon_print_backtrace(void);
#endif /* PHALCON_KERNEL_BACKTRACE_H */
#ifndef PHALCON_KERNEL_FCALL_H
#define PHALCON_KERNEL_FCALL_H
#include <stdarg.h>
#include <Zend/zend_hash.h>
#include <Zend/zend.h>
#ifdef __GNUC__
#define PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func_name, nparams, ...) \
do { \
if (__builtin_constant_p(func_name)) { \
if (phalcon_call_func_params(return_value, return_value_ptr, func_name, sizeof(func_name)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_func_params(return_value, return_value_ptr, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_RETURN_CALL_FUNCTION(func_name, nparams, ...) \
do { \
if (__builtin_constant_p(func_name)) { \
if (phalcon_call_func_params(return_value, return_value_ptr, func_name, sizeof(func_name)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_func_params(return_value, return_value_ptr, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method, key, nparams, ...) \
do { \
register ulong _key = key; \
if (__builtin_constant_p(method)) { \
if (phalcon_call_method_params(return_value, return_value_ptr, object, method, sizeof(method)-1, (_key ? _key : zend_inline_hash_func(method, sizeof(method))) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), (_key ? _key : (IS_INTERNED(method) ? INTERNED_HASH(method) : 0)) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_RETURN_CALL_METHOD(object, method, key, nparams, ...) \
do { \
register ulong _key = key; \
if (__builtin_constant_p(method)) { \
if (phalcon_call_method_params(return_value, return_value_ptr, object, method, sizeof(method)-1, (_key ? _key : zend_inline_hash_func(method, sizeof(method))) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), (_key ? _key : (IS_INTERNED(method) ? INTERNED_HASH(method) : 0)) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_CALL_STATIC(return_value, return_value_ptr, class_name, method, nparams, ...) \
do { \
if (__builtin_constant_p(class_name) && __builtin_constant_p(method)) { \
if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, sizeof(class_name)-1, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_RETURN_CALL_STATIC(class_name, method, nparams, ...) \
do { \
if (__builtin_constant_p(class_name) && __builtin_constant_p(method)) { \
if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, sizeof(class_name)-1, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_CALL_PARENT(return_value, return_value_ptr, this_ptr, class_entry, method, nparams, ...) \
do { \
if (__builtin_constant_p(method)) { \
if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_RETURN_CALL_PARENT(this_ptr, class_entry, method, nparams, ...) \
do { \
if (__builtin_constant_p(method)) { \
if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_CALL_SELF(return_value, return_value_ptr, this_ptr, method, nparams, ...) \
do { \
if (__builtin_constant_p(method)) { \
if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_RETURN_CALL_SELF(this_ptr, method, nparams, ...) \
do { \
if (__builtin_constant_p(method)) { \
if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_CALL_ZSTATIC_STR(return_value, return_value_ptr, zclass, method, nparams, ...) \
do { \
if (__builtin_constant_p(method)) { \
if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#define PHALCON_RETURN_CALL_ZSTATIC_STR(zclass, method, nparams, ...) \
do { \
if (__builtin_constant_p(method)) { \
if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
else { \
if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} \
} while (0)
#else
#define PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func_name, nparams, ...) \
do { \
if (phalcon_call_func_params(return_value, return_value_ptr, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_FUNCTION(func_name, nparams, ...) \
do { \
if (phalcon_call_func_params(return_value, return_value_ptr, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method, key, nparams, ...) \
do { \
if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), key TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_METHOD(object, method, key, nparams, ...) \
do { \
if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), key TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_CALL_STATIC(return_value, return_value_ptr, class_name, method, nparams, ...) \
do { \
if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_STATIC(class_name, method, nparams, ...) \
do { \
if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_CALL_PARENT(return_value, return_value_ptr, this_ptr, class_entry, method, nparams, ...) \
do { \
if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_PARENT(this_ptr, class_entry, method, nparams, ...) \
do { \
if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_CALL_SELF(return_value, return_value_ptr, this_ptr, method, nparams, ...) \
do { \
if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_SELF(return_value, return_value_ptr, this_ptr, method, nparams, ...) \
do { \
if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_CALL_ZSTATIC_STR(return_value, return_value_ptr, zclass, method, nparams, ...) \
do { \
if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_ZSTATIC_STR(zclass, method, nparams, ...) \
do { \
if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#endif
#define PHALCON_CALL_ZMETHOD(return_value, return_value_ptr, object, method, nparams, ...) \
do { \
if (phalcon_call_method_zval_params(return_value, return_value_ptr, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_ZMETHOD(object, method, nparams, ...) \
do { \
if (phalcon_call_method_zval_params(return_value, return_value_ptr, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_CALL_ZSTATIC(return_value, return_value_ptr, object, method, nparams, ...) \
do { \
if (phalcon_call_static_zval_func_params(return_value, return_value_ptr, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_RETURN_CALL_ZSTATIC(return_value, return_value_ptr, object, method, nparams, ...) \
do { \
if (phalcon_call_static_zval_func_params(return_value, return_value_ptr, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \
if (return_value_ptr && EG(exception)) { \
ALLOC_INIT_ZVAL(*return_value_ptr); \
} \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
/** Use these functions to call functions in the PHP userland using an arbitrary zval as callable */
#define PHALCON_CALL_USER_FUNC(return_value, handler) PHALCON_CALL_USER_FUNC_ARRAY(return_value, handler, NULL)
#define PHALCON_CALL_USER_FUNC_ARRAY(return_value, handler, params) \
do { \
if (phalcon_call_user_func_array(return_value, handler, params TSRMLS_CC) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
#define PHALCON_CALL_USER_FUNC_ARRAY_NOEX(return_value, handler, params) \
do { \
if (phalcon_call_user_func_array_noex(return_value, handler, params TSRMLS_CC) == FAILURE) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
/** Macros to call functions in the PHP userland */
#define phalcon_call_func_p0_ex(return_value, return_value_ptr, func) \
do { \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 0, NULL); \
} while (0)
#define phalcon_call_func_p1_ex(return_value, return_value_ptr, func, p1) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 1, p1); \
} while (0)
#define phalcon_call_func_p2_ex(return_value, return_value_ptr, func, p1, p2) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 2, p1, p2); \
} while (0)
#define phalcon_call_func_p3_ex(return_value, return_value_ptr, func, p1, p2, p3) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 3, p1, p2, p3); \
} while (0)
#define phalcon_call_func_p4_ex(return_value, return_value_ptr, func, p1, p2, p3, p4) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
if (Z_TYPE_P(p4)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 4, p1, p2, p3, p4); \
} while (0)
#define phalcon_call_func_p5_ex(return_value, return_value_ptr, func, p1, p2, p3, p4, p5) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
if (Z_TYPE_P(p4)) {} \
if (Z_TYPE_P(p5)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 5, p1, p2, p3, p4, p5); \
} while (0)
#define phalcon_call_func_p6_ex(return_value, return_value_ptr, func, p1, p2, p3, p4, p5, p6) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
if (Z_TYPE_P(p4)) {} \
if (Z_TYPE_P(p5)) {} \
if (Z_TYPE_P(p6)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 6, p1, p2, p3, p4, p5, p6); \
} while (0)
#define phalcon_call_func_p7_ex(return_value, return_value_ptr, func, p1, p2, p3, p4, p5, p6, p7) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
if (Z_TYPE_P(p4)) {} \
if (Z_TYPE_P(p5)) {} \
if (Z_TYPE_P(p6)) {} \
if (Z_TYPE_P(p7)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 7, p1, p2, p3, p4, p5, p6, p7); \
} while (0)
#define phalcon_call_func_p8_ex(return_value, return_value_ptr, func, p1, p2, p3, p4, p5, p6, p7, p8) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
if (Z_TYPE_P(p4)) {} \
if (Z_TYPE_P(p5)) {} \
if (Z_TYPE_P(p6)) {} \
if (Z_TYPE_P(p7)) {} \
if (Z_TYPE_P(p8)) {} \
} \
PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 8, p1, p2, p3, p4, p5, p6, p7, p8); \
} while (0)
#define phalcon_return_call_func_p0(func) PHALCON_RETURN_CALL_FUNCTION(func, 0, NULL)
#define phalcon_return_call_func_p1(func, p1) PHALCON_RETURN_CALL_FUNCTION(func, 1, p1)
#define phalcon_return_call_func_p2(func, p1, p2) PHALCON_RETURN_CALL_FUNCTION(func, 2, p1, p2)
#define phalcon_return_call_func_p3(func, p1, p2, p3) PHALCON_RETURN_CALL_FUNCTION(func, 3, p1, p2, p3)
#define phalcon_return_call_func_p4(func, p1, p2, p3, p4) PHALCON_RETURN_CALL_FUNCTION(func, 4, p1, p2, p3, p4)
#define phalcon_return_call_func_p5(func, p1, p2, p3, p4, p5) PHALCON_RETURN_CALL_FUNCTION(func, 5, p1, p2, p3, p4, p5)
#define phalcon_call_func(return_value, func) phalcon_call_func_p0_ex(return_value, NULL, func)
#define phalcon_call_func_p1(return_value, func, p1) phalcon_call_func_p1_ex(return_value, NULL, func, p1)
#define phalcon_call_func_p2(return_value, func, p1, p2) phalcon_call_func_p2_ex(return_value, NULL, func, p1, p2)
#define phalcon_call_func_p3(return_value, func, p1, p2, p3) phalcon_call_func_p3_ex(return_value, NULL, func, p1, p2, p3)
#define phalcon_call_func_p4(return_value, func, p1, p2, p3, p4) phalcon_call_func_p4_ex(return_value, NULL, func, p1, p2, p3, p4)
#define phalcon_call_func_p5(return_value, func, p1, p2, p3, p4, p5) phalcon_call_func_p5_ex(return_value, NULL, func, p1, p2, p3, p4, p5)
#define phalcon_call_func_p6(return_value, func, p1, p2, p3, p4, p5, p6) phalcon_call_func_p6_ex(return_value, NULL, func, p1, p2, p3, p4, p5, p6)
#define phalcon_call_func_p7(return_value, func, p1, p2, p3, p4, p5, p6, p7) phalcon_call_func_p7_ex(return_value, NULL, func, p1, p2, p3, p4, p5, p6, p7)
#define phalcon_call_func_p8(return_value, func, p1, p2, p3, p4, p5, p6, p7, p8) phalcon_call_func_p8_ex(return_value, NULL, func, p1, p2, p3, p4, p5, p6, p7, p8)
#define phalcon_call_func_noret(func) phalcon_call_func_p0_ex(NULL, NULL, func)
#define phalcon_call_func_p1_noret(func, p1) phalcon_call_func_p1_ex(NULL, NULL, func, p1)
#define phalcon_call_func_p2_noret(func, p1, p2) phalcon_call_func_p2_ex(NULL, NULL, func, p1, p2)
#define phalcon_call_func_p3_noret(func, p1, p2, p3) phalcon_call_func_p3_ex(NULL, NULL, func, p1, p2, p3)
#define phalcon_call_func_p4_noret(func, p1, p2, p3, p4) phalcon_call_func_p4_ex(NULL, NULL, func, p1, p2, p3, p4)
#define phalcon_call_func_p5_noret(func, p1, p2, p3, p4, p5) phalcon_call_func_p5_ex(NULL, NULL, func, p1, p2, p3, p4, p5)
#define phalcon_call_func_p6_noret(func, p1, p2, p3, p4, p5, p6) phalcon_call_func_p6_ex(NULL, NULL, func, p1, p2, p3, p4, p5, p6)
#define phalcon_call_func_p7_noret(func, p1, p2, p3, p4, p5, p6, p7) phalcon_call_func_p7_ex(NULL, NULL, func, p1, p2, p3, p4, p5, p6, p7)
#define phalcon_call_func_p8_noret(func, p1, p2, p3, p4, p5, p6, p7, p8) phalcon_call_func_p8_ex(NULL, NULL, func, p1, p2, p3, p4, p5, p6, p7, p8)
/** Macros to call methods in the PHP userland */
#define phalcon_call_method_p0_key_ex(return_value, return_value_ptr, object, method_name, key) \
do { \
PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method_name, key, 0, NULL); \
} while (0)
#define phalcon_call_method_p1_key_ex(return_value, return_value_ptr, object, method_name, key, p1) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
} \
PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method_name, key, 1, p1); \
} while (0)
#define phalcon_call_method_p2_key_ex(return_value, return_value_ptr, object, method_name, key, p1, p2) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
} \
PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method_name, key, 2, p1, p2); \
} while (0)
#define phalcon_call_method_p3_key_ex(return_value, return_value_ptr, object, method_name, key, p1, p2, p3) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
} \
PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method_name, key, 3, p1, p2, p3); \
} while (0)
#define phalcon_call_method_p4_key_ex(return_value, return_value_ptr, object, method_name, key, p1, p2, p3, p4) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
if (Z_TYPE_P(p4)) {} \
} \
PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method_name, key, 4, p1, p2, p3, p4); \
} while (0)
#define phalcon_call_method_p5_key_ex(return_value, return_value_ptr, object, method_name, key, p1, p2, p3, p4, p5) \
do { \
if (0) { \
if (Z_TYPE_P(p1)) {} \
if (Z_TYPE_P(p2)) {} \
if (Z_TYPE_P(p3)) {} \
if (Z_TYPE_P(p4)) {} \
if (Z_TYPE_P(p5)) {} \
} \
PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method_name, key, 5, p1, p2, p3, p4, p5); \
} while (0)
#define phalcon_return_call_method_p0_key(object, method_name, key) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 0, NULL)
#define phalcon_return_call_method_p1_key(object, method_name, key, p1) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 1, p1)
#define phalcon_return_call_method_p2_key(object, method_name, key, p1, p2) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 2, p1, p2)
#define phalcon_return_call_method_p3_key(object, method_name, key, p1, p2, p3) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 3, p1, p2, p3)
#define phalcon_return_call_method_p4_key(object, method_name, key, p1, p2, p3, p4) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 4, p1, p2, p3, p4)
#define phalcon_return_call_method_p5_key(object, method_name, key, p1, p2, p3, p4, p5) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 5, p1, p2, p3, p4, p5)
#define phalcon_return_call_method_p0(object, method_name) phalcon_return_call_method_p0_key(object, method_name, 0)
#define phalcon_return_call_method_p1(object, method_name, p1) phalcon_return_call_method_p1_key(object, method_name, 0, p1)
#define phalcon_return_call_method_p2(object, method_name, p1, p2) phalcon_return_call_method_p2_key(object, method_name, 0, p1, p2)
#define phalcon_return_call_method_p3(object, method_name, p1, p2, p3) phalcon_return_call_method_p3_key(object, method_name, 0, p1, p2, p3)
#define phalcon_return_call_method_p4(object, method_name, p1, p2, p3, p4) phalcon_return_call_method_p4_key(object, method_name, 0, p1, p2, p3, p4)
#define phalcon_return_call_method_p5(object, method_name, p1, p2, p3, p4, p5) phalcon_return_call_method_p5_key(object, method_name, 0, p1, p2, p3, p4, p5)
#define phalcon_call_method_p0_ex(return_value, return_value_ptr, object, method_name) phalcon_call_method_p0_key_ex(return_value, return_value_ptr, object, method_name, 0)
#define phalcon_call_method_p1_ex(return_value, return_value_ptr, object, method_name, p1) phalcon_call_method_p1_key_ex(return_value, return_value_ptr, object, method_name, 0, p1)
#define phalcon_call_method_p2_ex(return_value, return_value_ptr, object, method_name, p1, p2) phalcon_call_method_p2_key_ex(return_value, return_value_ptr, object, method_name, 0, p1, p2)
#define phalcon_call_method_p3_ex(return_value, return_value_ptr, object, method_name, p1, p2, p3) phalcon_call_method_p3_key_ex(return_value, return_value_ptr, object, method_name, 0, p1, p2, p3)
#define phalcon_call_method_p4_ex(return_value, return_value_ptr, object, method_name, p1, p2, p3, p4) phalcon_call_method_p4_key_ex(return_value, return_value_ptr, object, method_name, 0, p1, p2, p3, p4)
#define phalcon_call_method_p5_ex(return_value, return_value_ptr, object, method_name, p1, p2, p3, p4, p5) phalcon_call_method_p5_key_ex(return_value, return_value_ptr, object, method_name, 0, p1, p2, p3, p4, p5)
#define phalcon_call_method(return_value, object, method_name) phalcon_call_method_p0_ex(return_value, NULL, object, method_name)
#define phalcon_call_method_p1(return_value, object, method_name, p1) phalcon_call_method_p1_ex(return_value, NULL, object, method_name, p1)
#define phalcon_call_method_p2(return_value, object, method_name, p1, p2) phalcon_call_method_p2_ex(return_value, NULL, object, method_name, p1, p2)
#define phalcon_call_method_p3(return_value, object, method_name, p1, p2, p3) phalcon_call_method_p3_ex(return_value, NULL, object, method_name, p1, p2, p3)
#define phalcon_call_method_p4(return_value, object, method_name, p1, p2, p3, p4) phalcon_call_method_p4_ex(return_value, NULL, object, method_name, p1, p2, p3, p4)
#define phalcon_call_method_p5(return_value, object, method_name, p1, p2, p3, p4, p5) phalcon_call_method_p5_ex(return_value, NULL, object, method_name, p1, p2, p3, p4, p5)
#define phalcon_call_method_noret(object, method_name) phalcon_call_method_p0_ex(NULL, NULL, object, method_name)
#define phalcon_call_method_p1_noret(object, method_name, p1) phalcon_call_method_p1_ex(NULL, NULL, object, method_name, p1)
#define phalcon_call_method_p2_noret(object, method_name, p1, p2) phalcon_call_method_p2_ex(NULL, NULL, object, method_name, p1, p2)
#define phalcon_call_method_p3_noret(object, method_name, p1, p2, p3) phalcon_call_method_p3_ex(NULL, NULL, object, method_name, p1, p2, p3)
#define phalcon_call_method_p4_noret(object, method_name, p1, p2, p3, p4) phalcon_call_method_p4_ex(NULL, NULL, object, method_name, p1, p2, p3, p4)
#define phalcon_call_method_p5_noret(object, method_name, p1, p2, p3, p4, p5) phalcon_call_method_p5_ex(NULL, NULL, object, method_name, p1, p2, p3, p4, p5)
#define phalcon_call_method_key(return_value, object, method_name, key) phalcon_call_method_p0_key_ex(return_value, NULL, object, method_name, key)
#define phalcon_call_method_p1_key(return_value, object, method_name, key, p1) phalcon_call_method_p1_key_ex(return_value, NULL, object, method_name, key, p1)
#define phalcon_call_method_p2_key(return_value, object, method_name, key, p1, p2) phalcon_call_method_p2_key_ex(return_value, NULL, object, method_name, key, p1, p2)
#define phalcon_call_method_p3_key(return_value, object, method_name, key, p1, p2, p3) phalcon_call_method_p3_key_ex(return_value, NULL, object, method_name, key, p1, p2, p3)
#define phalcon_call_method_p4_key(return_value, object, method_name, key, p1, p2, p3, p4) phalcon_call_method_p4_key_ex(return_value, NULL, object, method_name, key, p1, p2, p3, p4)
#define phalcon_call_method_p5_key(return_value, object, method_name, key, p1, p2, p3, p4, p5) phalcon_call_method_p5_key_ex(return_value, NULL, object, method_name, key, p1, p2, p3, p4, p5)
/** Macros to call methods with zvals as method names */
#define phalcon_call_method_zval(return_value, object, method) PHALCON_CALL_ZMETHOD(return_value, NULL, object, method, 0, NULL)
#define phalcon_call_method_zval_p1(return_value, object, method, p1) PHALCON_CALL_ZMETHOD(return_value, NULL, object, method, 1, p1)
#define phalcon_call_method_zval_p2(return_value, object, method, p1, p2) PHALCON_CALL_ZMETHOD(return_value, NULL, object, method, 2, p1, p2)
#define phalcon_call_method_zval_p3(return_value, object, method, p1, p2, p3) PHALCON_CALL_ZMETHOD(return_value, NULL, object, method, 3, p1, p2, p3)
#define phalcon_call_method_zval_noret(object, method) PHALCON_CALL_ZMETHOD(NULL, NULL, object, method, 0, NULL)
#define phalcon_call_method_zval_p1_noret(object, method, p1) PHALCON_CALL_ZMETHOD(NULL, NULL, object, method, 1, p1)
#define phalcon_call_method_zval_p2_noret(object, method, p1, p2) PHALCON_CALL_ZMETHOD(NULL, NULL, object, method, 2, p1, p2)
#define phalcon_call_method_zval_p3_noret(object, method, p1, p2, p3) PHALCON_CALL_ZMETHOD(NULL, NULL, object, method, 3, p1, p2, p3)
/** Use these macros to call functions in the parent class */
#define phalcon_call_parent(return_value, object, active_class, method) PHALCON_CALL_PARENT(return_value, NULL, object, active_class, method, 0, NULL)
#define phalcon_call_parent_p1(return_value, object, active_class, method, p1) PHALCON_CALL_PARENT(return_value, NULL, object, active_class, method, 1, p1)
#define phalcon_call_parent_p2(return_value, object, active_class, method, p1, p2) PHALCON_CALL_PARENT(return_value, NULL, object, active_class, method, 2, p1, p2)
#define phalcon_call_parent_noret(object, active_class, method) PHALCON_CALL_PARENT(NULL, NULL, object, active_class, method, 0, NULL)
#define phalcon_call_parent_p1_noret(object, active_class, method, p1) PHALCON_CALL_PARENT(NULL, NULL, object, active_class, method, 1, p1)
#define phalcon_call_parent_p2_noret(object, active_class, method, p1, p2) PHALCON_CALL_PARENT(NULL, NULL, object, active_class, method, 2, p1, p2)
#define phalcon_call_parent_p3_noret(object, active_class, method, p1, p2, p3) PHALCON_CALL_PARENT(NULL, NULL, object, active_class, method, 3, p1, p2, p3)
#define phalcon_call_parent_p4_noret(object, active_class, method, p1, p2, p3, p4) PHALCON_CALL_PARENT(NULL, NULL, object, active_class, method, 4, p1, p2, p3, p4)
#define phalcon_call_parent_p5_noret(object, active_class, method, p1, p2, p3, p4, p5) PHALCON_CALL_PARENT(NULL, NULL, object, active_class, method, 5, p1, p2, p3, p4, p5)
/** Use these functions to call static functions on the current class */
#define phalcon_call_self(return_value, object, method) PHALCON_CALL_SELF(return_value, NULL, object, method, 0, NULL)
#define phalcon_call_self_p1(return_value, object, method, p1) PHALCON_CALL_SELF(return_value, NULL, object, method, 1, p1)
#define phalcon_call_self_p2(return_value, object, method, p1, p2) PHALCON_CALL_SELF(return_value, NULL, object, method, 2, p1, p2)
#define phalcon_call_self_p3(return_value, object, method, p1, p2, p3) PHALCON_CALL_SELF(return_value, NULL, object, method, 3, p1, p2, p3)
#define phalcon_call_self_p4(return_value, object, method, p1, p2, p3, p4) PHALCON_CALL_SELF(return_value, NULL, object, method, 4, p1, p2, p3, p4)
#define phalcon_call_self_noret(object, method, param_count, params) PHALCON_CALL_SELF(NULL, NULL, object, method, 0, NULL)
#define phalcon_call_self_p1_noret(object, method, p1) PHALCON_CALL_SELF(NULL, NULL, object, method, 1, p1)
#define phalcon_call_self_p2_noret(object, method, p1, p2) PHALCON_CALL_SELF(NULL, NULL, object, method, 2, p1, p2)
#define phalcon_call_self_p3_noret(object, method, p1, p2, p3) PHALCON_CALL_SELF(NULL, NULL, object, method, 3, p1, p2, p3)
#define phalcon_call_self_p4_noret(object, method, p1, p2, p3, p4) PHALCON_CALL_SELF(NULL, NULL, object, method, 4, p1, p2, p3, p4)
/** Use these macros to call functions statically */
#define phalcon_return_call_static_p0(class_name, method_name) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 0, NULL)
#define phalcon_return_call_static_p1(class_name, method_name, p1) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 1, p1)
#define phalcon_return_call_static_p2(class_name, method_name, p1, p2) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 2, p1, p2)
#define phalcon_return_call_static_p3(class_name, method_name, p1, p2, p3) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 3, p1, p2, p3)
#define phalcon_return_call_static_p4(class_name, method_name, p1, p2, p3, p4) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 4, p1, p2, p3, p4)
#define phalcon_return_call_static_p5(class_name, method_name, p1, p2, p3, p4, p5) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 5, p1, p2, p3, p4, p5)
#define phalcon_call_static(return_value, class_name, method_name) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 0, NULL)
#define phalcon_call_static_p1(return_value, class_name, method_name, p1) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 1, p1)
#define phalcon_call_static_p2(return_value, class_name, method_name, p1, p2) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 2, p1, p2)
#define phalcon_call_static_p3(return_value, class_name, method_name, p1, p2, p3) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 3, p1, p2, p3)
#define phalcon_call_static_p4(return_value, class_name, method_name, p1, p2, p3, p4) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 4, p1, p2, p3, p4)
#define phalcon_call_static_p5(return_value, class_name, method_name, p1, p2, p3, p4, p5) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 5, p1, p2, p3, p4, p5)
#define phalcon_call_static_noret(class_name, method_name) PHALCON_CALL_STATIC(NULL, NULL, class_name, method_name, 0, NULL)
#define phalcon_call_static_p1_noret(class_name, method_name, p1) PHALCON_CALL_STATIC(NULL, NULL, class_name, method_name, 1, p1)
#define phalcon_call_static_p2_noret(class_name, method_name, p1, p2) PHALCON_CALL_STATIC(NULL, NULL, class_name, method_name, 2, p1, p2)
#define phalcon_call_static_p3_noret(class_name, method_name, p1, p2, p3) PHALCON_CALL_STATIC(NULL, NULL, class_name, method_name, 3, p1, p2, p3)
#define phalcon_call_static_p4_noret(class_name, method_name, p1, p2, p3, p4) PHALCON_CALL_STATIC(NULL, NULL, class_name, method_name, 4, p1, p2, p3, p4)
#define phalcon_call_static_p5_noret(class_name, method_name, p1, p2, p3, p4, p5) PHALCON_CALL_STATIC(NULL, NULL, class_name, method_name, 5, p1, p2, p3, p4, p5)
#define phalcon_call_zval_static(return_value, class_zval, method) PHALCON_CALL_ZSTATIC(return_value, NULL, class_zval, method, 0, NULL)
#define phalcon_call_zval_static_p1(return_value, class_zval, method, p1) PHALCON_CALL_ZSTATIC(return_value, NULL, class_zval, method, 1, p1)
#define phalcon_call_zval_str_static_p1(return_value, class_zval, method, p1) PHALCON_CALL_ZSTATIC_STR(return_value, NULL, class_zval, method, 1, p1)
static int phalcon_call_func_params(zval *return_value, zval **return_value_ptr, const char *func_name, int func_length TSRMLS_DC, int param_count, ...);
static int phalcon_call_method_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, ...);
static int phalcon_call_method_zval_params(zval *return_value, zval **return_value_ptr, zval *object, zval *method TSRMLS_DC, int param_count, ...);
static int phalcon_call_parent_func_params(zval *return_value, zval **return_value_ptr, zval *object, zend_class_entry *active_class_ce, const char *method_name, int method_len TSRMLS_DC, int param_count, ...);
static int phalcon_call_self_func_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len TSRMLS_DC, int param_count, ...);
static int phalcon_call_static_func_params(zval *return_value, zval **return_value_ptr, const char *class_name, int class_length, const char *method_name, int method_length TSRMLS_DC, int param_count, ...);
static int phalcon_call_static_zval_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, zval *method TSRMLS_DC, int param_count, ...);
static int phalcon_call_static_zval_str_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, const char *method_name, int method_len TSRMLS_DC, int param_count, ...);
static int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, va_list ap);
/** Fast call_user_func_array/call_user_func */
static int phalcon_call_user_func_array(zval *return_value, zval *handler, zval *params TSRMLS_DC);
static int phalcon_call_user_func_array_noex(zval *return_value, zval *handler, zval *params TSRMLS_DC);
/** Check constructors */
static int phalcon_has_constructor(const zval *object TSRMLS_DC);
static int phalcon_has_constructor_ce(zend_class_entry *ce);
/** PHP < 5.3.9 has problems with closures */
#if PHP_VERSION_ID <= 50309
static int phalcon_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC);
#define PHALCON_ZEND_CALL_FUNCTION_WRAPPER phalcon_call_function
#else
#define PHALCON_ZEND_CALL_FUNCTION_WRAPPER zend_call_function
#endif
#ifndef zend_error_noreturn
#define zend_error_noreturn zend_error
#endif
#endif /* PHALCON_KERNEL_FCALL_H */
#ifndef PHALCON_KERNEL_ARRAY_H
#define PHALCON_KERNEL_ARRAY_H
#include <Zend/zend.h>
static int phalcon_array_isset_fetch(zval **fetched, const zval *arr, zval *index) PHALCON_ATTR_NONNULL;
static int phalcon_array_isset_quick_string_fetch(zval **fetched, zval *arr, const char *index, uint index_length, ulong key) PHALCON_ATTR_NONNULL;
static int phalcon_array_isset_long_fetch(zval **fetched, zval *arr, ulong index) PHALCON_ATTR_NONNULL;
PHALCON_ATTR_NONNULL static inline int phalcon_array_isset_string_fetch(zval **fetched, zval *arr, const char *index, uint index_length)
{
#ifdef __GNUC__
if (__builtin_constant_p(index) && __builtin_constant_p(index_length)) {
return phalcon_array_isset_quick_string_fetch(fetched, arr, index, index_length, zend_inline_hash_func(index, index_length));
}
#endif
return phalcon_array_isset_quick_string_fetch(fetched, arr, index, index_length, zend_hash_func(index, index_length));
}
static int phalcon_array_isset(const zval *arr, zval *index) PHALCON_ATTR_NONNULL;
static int phalcon_array_isset_long(const zval *arr, ulong index) PHALCON_ATTR_NONNULL;
static int phalcon_array_isset_quick_string(const zval *arr, const char *index, uint index_length, ulong key) PHALCON_ATTR_NONNULL;
PHALCON_ATTR_NONNULL static inline int phalcon_array_isset_string(const zval *arr, const char *index, uint index_length)
{
#ifdef __GNUC__
if (__builtin_constant_p(index) && __builtin_constant_p(index_length)) {
return phalcon_array_isset_quick_string(arr, index, index_length, zend_inline_hash_func(index, index_length));
}
#endif
return phalcon_array_isset_quick_string(arr, index, index_length, zend_hash_func(index, index_length));
}
static int phalcon_array_unset(zval **arr, zval *index, int flags) PHALCON_ATTR_NONNULL;
static int phalcon_array_unset_long(zval **arr, ulong index, int flags) PHALCON_ATTR_NONNULL;
static int phalcon_array_unset_string(zval **arr, const char *index, uint index_length, int flags) PHALCON_ATTR_NONNULL;
static int phalcon_array_append(zval **arr, zval *value, int separate) PHALCON_ATTR_NONNULL;
PHALCON_ATTR_NONNULL static inline int phalcon_array_append_long(zval **arr, long value, int separate)
{
zval *zvalue;
PHALCON_ALLOC_GHOST_ZVAL(zvalue);
ZVAL_LONG(zvalue, value);
return phalcon_array_append(arr, zvalue, separate);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_append_string(zval **arr, char *value, uint value_length, int separate)
{
zval *zvalue;
PHALCON_ALLOC_GHOST_ZVAL(zvalue);
ZVAL_STRINGL(zvalue, value, value_length, 1);
return phalcon_array_append(arr, zvalue, separate);
}
static int phalcon_array_update_zval(zval **arr, zval *index, zval **value, int flags) PHALCON_ATTR_NONNULL;
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_zval_bool(zval **arr, zval *index, int value, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_BOOL(zvalue, value);
return phalcon_array_update_zval(arr, index, &zvalue, flags & PH_SEPARATE);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_zval_long(zval **arr, zval *index, long value, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_LONG(zvalue, value);
return phalcon_array_update_zval(arr, index, &zvalue, flags & PH_SEPARATE);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_zval_string(zval **arr, zval *index, char *value, uint value_length, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_STRINGL(zvalue, value, value_length, 1);
return phalcon_array_update_zval(arr, index, &zvalue, flags & PH_SEPARATE);
}
static int phalcon_array_update_quick_string(zval **arr, const char *index, uint index_length, ulong key, zval **value, int flags) PHALCON_ATTR_NONNULL;
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_string(zval **arr, const char *index, uint index_length, zval **value, int flags)
{
#ifdef __GNUC__
if (__builtin_constant_p(index) && __builtin_constant_p(index_length)) {
return phalcon_array_update_quick_string(arr, index, index_length + 1, zend_inline_hash_func(index, index_length + 1), value, flags);
}
#endif
return phalcon_array_update_quick_string(arr, index, index_length + 1, zend_hash_func(index, index_length + 1), value, flags);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_string_bool(zval **arr, const char *index, uint index_length, int value, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_BOOL(zvalue, value);
return phalcon_array_update_string(arr, index, index_length, &zvalue, flags & PH_SEPARATE);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_string_long(zval **arr, const char *index, uint index_length, long value, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_LONG(zvalue, value);
return phalcon_array_update_string(arr, index, index_length, &zvalue, flags & PH_SEPARATE);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_string_string(zval **arr, const char *index, uint index_length, char *value, uint value_length, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_STRINGL(zvalue, value, value_length, 1);
return phalcon_array_update_string(arr, index, index_length, &zvalue, flags & PH_SEPARATE);
}
static int phalcon_array_update_long(zval **arr, ulong index, zval **value, int flags) PHALCON_ATTR_NONNULL;
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_long_string(zval **arr, ulong index, char *value, uint value_length, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_STRINGL(zvalue, value, value_length, 1);
return phalcon_array_update_long(arr, index, &zvalue, flags & PH_SEPARATE);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_long_long(zval **arr, ulong index, long value, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_LONG(zvalue, value);
return phalcon_array_update_long(arr, index, &zvalue, flags & PH_SEPARATE);
}
PHALCON_ATTR_NONNULL static inline int phalcon_array_update_long_bool(zval **arr, ulong index, int value, int flags)
{
zval *zvalue;
MAKE_STD_ZVAL(zvalue);
ZVAL_BOOL(zvalue, value);
return phalcon_array_update_long(arr, index, &zvalue, flags & PH_SEPARATE);
}
static void phalcon_array_append_multi_2(zval **arr, zval *index, zval *value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_multi_2(zval **config, zval *index1, zval *index2, zval **value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_string_multi_2(zval **arr, zval *index1, char *index2, uint index2_length, zval **value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_long_long_multi_2(zval **arr, long index1, long index2, zval **value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_long_string_multi_2(zval **arr, long index1, char *index2, uint index2_length, zval **value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_append_multi_2(zval **arr, zval *index1, zval *value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_zval_string_append_multi_3(zval **arr, zval *index1, char *index2, uint index2_length, zval **value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_zval_zval_zval_multi_3(zval **arr, zval *index1, zval *index2, zval *index3, zval **value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_string_zval_zval_multi_3(zval **arr, zval *index1, zval *index2, char *index3, uint index3_length, zval **value, int flags) PHALCON_ATTR_NONNULL;
static void phalcon_array_update_zval_string_string_multi_3(zval **arr, zval *index1, char *index2, uint index2_length, char *index3, uint index3_length, zval **value, int flags) PHALCON_ATTR_NONNULL;
static int phalcon_array_fetch(zval **return_value, zval *arr, zval *index, int silent) PHALCON_ATTR_NONNULL;
static int phalcon_array_fetch_long(zval **return_value, zval *arr, ulong index, int silent) PHALCON_ATTR_NONNULL;
static int phalcon_array_fetch_quick_string(zval **return_value, zval *arr, const char *index, uint index_length, ulong key, int silent) PHALCON_ATTR_NONNULL;
PHALCON_ATTR_NONNULL static inline int phalcon_array_fetch_string(zval **return_value, zval *arr, const char *index, uint index_length, int silent)
{
#ifdef __GNUC__
if (__builtin_constant_p(index) && __builtin_constant_p(index_length)) {
return phalcon_array_fetch_quick_string(return_value, arr, index, index_length + 1, zend_inline_hash_func(index, index_length + 1), silent);
}
#endif
return phalcon_array_fetch_quick_string(return_value, arr, index, index_length + 1, zend_hash_func(index, index_length + 1), silent);
}
static void phalcon_merge_append(zval *left, zval *values) PHALCON_ATTR_NONNULL;
static void phalcon_array_get_current(zval *return_value, zval *array) PHALCON_ATTR_NONNULL;
static int phalcon_fast_in_array(zval *needle, zval *haystack TSRMLS_DC) PHALCON_ATTR_NONNULL;
static void phalcon_fast_array_merge(zval *return_value, zval **array1, zval **array2 TSRMLS_DC) PHALCON_ATTR_NONNULL;
static void phalcon_array_merge_recursive_n(zval **a1, zval *a2) PHALCON_ATTR_NONNULL;
static void phalcon_array_unshift(zval *arr, zval *arg) PHALCON_ATTR_NONNULL;
static void phalcon_array_keys(zval *return_value, zval *arr) PHALCON_ATTR_NONNULL;
static void phalcon_array_values(zval *return_value, zval *arr) PHALCON_ATTR_NONNULL;
static int phalcon_array_key_exists(zval *arr, zval *key TSRMLS_DC) PHALCON_ATTR_NONNULL;
#endif /* PHALCON_KERNEL_ARRAY_H */
#ifndef PHALCON_KERNEL_HASH_H
#define PHALCON_KERNEL_HASH_H
#include <Zend/zend.h>
static int phalcon_hash_exists(const HashTable *ht, const char *arKey, uint nKeyLength);
static int phalcon_hash_quick_exists(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h);
static int phalcon_hash_find(const HashTable *ht, const char *arKey, uint nKeyLength, void **pData);
static int phalcon_hash_quick_find(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h, void **pData);
static void phalcon_get_current_key(zval **key, const HashTable *hash_table, HashPosition *hash_position TSRMLS_DC);
zval phalcon_get_current_key_w(const HashTable *hash_table, HashPosition *hash_position);
static int phalcon_has_numeric_keys(const zval *data);
static void phalcon_hash_update_or_insert(HashTable *ht, zval *offset, zval *value);
zval** phalcon_hash_get(HashTable *ht, zval *key, int type);
static int phalcon_hash_unset(HashTable *ht, zval *offset);
#endif /* PHALCON_KERNEL_HASH_H */
/** Class Retrieving/Checking */
static int phalcon_class_exists(const zval *class_name, int autoload TSRMLS_DC);
static int phalcon_class_exists_ex(zend_class_entry **zce, const zval *class_name, int autoload TSRMLS_DC);
static void phalcon_get_class(zval *result, zval *object, int lower TSRMLS_DC);
static void phalcon_get_class_ns(zval *result, zval *object, int lower TSRMLS_DC);
static void phalcon_get_ns_class(zval *result, zval *object, int lower TSRMLS_DC);
static void phalcon_get_called_class(zval *return_value TSRMLS_DC);
zend_class_entry *phalcon_fetch_class(const zval *class_name TSRMLS_DC);
zend_class_entry* phalcon_fetch_self_class(TSRMLS_D);
zend_class_entry* phalcon_fetch_parent_class(TSRMLS_D);
zend_class_entry* phalcon_fetch_static_class(TSRMLS_D);
#define PHALCON_GET_CLASS_CONSTANT(return_value, ce, const_name) \
do { \
if (FAILURE == phalcon_get_class_constant(return_value, ce, const_name, strlen(const_name)+1 TSRMLS_CC)) { \
PHALCON_MM_RESTORE(); \
return; \
} \
} while (0)
/** Class constants */
static int phalcon_get_class_constant(zval *return_value, zend_class_entry *ce, char *constant_name, unsigned int constant_length TSRMLS_DC);
/** Cloning/Instance of*/
static int phalcon_clone(zval *destiny, zval *obj TSRMLS_DC);
static int phalcon_instance_of(zval *result, const zval *object, const zend_class_entry *ce TSRMLS_DC);
static int phalcon_is_instance_of(zval *object, const char *class_name, unsigned int class_length TSRMLS_DC);
/** Method exists */
static int phalcon_method_exists(const zval *object, const zval *method_name TSRMLS_DC);
static int phalcon_method_exists_ex(const zval *object, const char *method_name, unsigned int method_len TSRMLS_DC);
static int phalcon_method_quick_exists_ex(const zval *object, const char *method_name, unsigned int method_len, unsigned long hash TSRMLS_DC);
/** Isset properties */
static int phalcon_isset_property(zval *object, const char *property_name, unsigned int property_length TSRMLS_DC);
static int phalcon_isset_property_quick(zval *object, const char *property_name, unsigned int property_length, unsigned long hash TSRMLS_DC);
static int phalcon_isset_property_zval(zval *object, const zval *property TSRMLS_DC);
/** Reading properties */
static int phalcon_read_property_this(zval **result, zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC);
static int phalcon_read_property_this_quick(zval **result, zval *object, char *property_name, unsigned int property_length, unsigned long key, int silent TSRMLS_DC);
zval* phalcon_fetch_nproperty_this(zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC);
zval* phalcon_fetch_nproperty_this_quick(zval *object, char *property_name, unsigned int property_length, unsigned long key, int silent TSRMLS_DC);
zval* phalcon_fetch_property_this(zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC);
zval* phalcon_fetch_property_this_quick(zval *object, char *property_name, unsigned int property_length, unsigned long key, int silent TSRMLS_DC);
static int phalcon_read_property(zval **result, zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC);
static int phalcon_read_property_zval(zval **result, zval *object, zval *property, int silent TSRMLS_DC);
static int phalcon_return_property(zval *return_value, zval **return_value_ptr, zval *object, char *property_name, unsigned int property_length TSRMLS_DC);
static int phalcon_return_property_quick(zval *return_value, zval **return_value_ptr, zval *object, char *property_name, unsigned int property_length, unsigned long key TSRMLS_DC);
/** Updating properties */
static int phalcon_update_property_this(zval *object, char *property_name, unsigned int property_length, zval *value TSRMLS_DC);
static int phalcon_update_property_long(zval *obj, char *property_name, unsigned int property_length, long value TSRMLS_DC);
static int phalcon_update_property_string(zval *object, char *property_name, unsigned int property_length, char *str, unsigned int str_length TSRMLS_DC);
static int phalcon_update_property_bool(zval *obj, char *property_name, unsigned int property_length, int value TSRMLS_DC);
static int phalcon_update_property_null(zval *obj, char *property_name, unsigned int property_length TSRMLS_DC);
static int phalcon_update_property_zval(zval *obj, char *property_name, unsigned int property_length, zval *value TSRMLS_DC);
static int phalcon_update_property_zval_zval(zval *obj, zval *property, zval *value TSRMLS_DC);
static int phalcon_update_property_empty_array(zend_class_entry *ce, zval *object, char *property, unsigned int property_length TSRMLS_DC);
/** Updating array properties */
static int phalcon_update_property_array(zval *object, char *property, unsigned int property_length, zval *index, zval *value TSRMLS_DC);
static int phalcon_update_property_array_string(zval *object, char *property, unsigned int property_length, char *index, unsigned int index_length, zval *value TSRMLS_DC);
static int phalcon_update_property_array_append(zval *object, char *property, unsigned int property_length, zval *value TSRMLS_DC);
/** Increment/Decrement properties */
static int phalcon_property_incr(zval *object, char *property_name, unsigned int property_length TSRMLS_DC);
static int phalcon_property_decr(zval *object, char *property_name, unsigned int property_length TSRMLS_DC);
/** Unset Array properties */
static int phalcon_unset_property_array(zval *object, char *property, unsigned int property_length, zval *index TSRMLS_DC);
/** Static properties */
static int phalcon_read_static_property(zval **result, const char *class_name, unsigned int class_length, char *property_name, unsigned int property_length TSRMLS_DC);
static int phalcon_update_static_property_ce(zend_class_entry *ce, char *name, int len, zval *value TSRMLS_DC);
static int phalcon_update_static_property(const char *class_name, unsigned int class_length, char *name, unsigned int name_length, zval *value TSRMLS_DC);
static int phalcon_read_static_property_ce(zval **result, zend_class_entry *ce, char *property, int len TSRMLS_DC);
static int phalcon_read_class_property(zval **result, int type, char *property, int len TSRMLS_DC);
zval* phalcon_fetch_static_property_ce(zend_class_entry *ce, char *property, int len TSRMLS_DC);
/** Create instances */
static int phalcon_create_instance_params_ce(zval *return_value, zend_class_entry *ce, zval *params TSRMLS_DC);
static int phalcon_create_instance(zval *return_value, const zval *class_name TSRMLS_DC);
static int phalcon_create_instance_params(zval *return_value, const zval *class_name, zval *params TSRMLS_DC);
#ifndef PHALCON_KERNEL_STRING_H
#define PHALCON_KERNEL_STRING_H
#include <Zend/zend.h>
#define PHALCON_TRIM_LEFT 1
#define PHALCON_TRIM_RIGHT 2
#define PHALCON_TRIM_BOTH 3
/** Fast char position */
static int phalcon_memnstr(const zval *haystack, const zval *needle);
static int phalcon_memnstr_str(const zval *haystack, char *needle, unsigned int needle_length);
/** Function replacement */
static void phalcon_fast_strlen(zval *return_value, zval *str);
static void phalcon_fast_strtolower(zval *return_value, zval *str);
static void phalcon_strtolower_inplace(zval *s);
static void phalcon_fast_join(zval *result, zval *glue, zval *pieces TSRMLS_DC);
static void phalcon_fast_join_str(zval *result, char *glue, unsigned int glue_length, zval *pieces TSRMLS_DC);
static void phalcon_fast_explode(zval *result, zval *delimiter, zval *str);
static void phalcon_fast_explode_str(zval *result, const char *delimiter, int delimiter_length, zval *str);
static void phalcon_fast_strpos(zval *return_value, const zval *haystack, const zval *needle);
static void phalcon_fast_strpos_str(zval *return_value, const zval *haystack, char *needle, unsigned int needle_length);
static void phalcon_fast_stripos_str(zval *return_value, zval *haystack, char *needle, unsigned int needle_length);
static void phalcon_fast_str_replace(zval *return_value, zval *search, zval *replace, zval *subject);
static void phalcon_fast_trim(zval *return_value, zval *str, int where TSRMLS_DC);
static void phalcon_fast_strip_tags(zval *return_value, zval *str);
static void phalcon_fast_strtoupper(zval *return_value, zval *str);
/** Camelize/Uncamelize */
static void phalcon_camelize(zval *return_value, const zval *str);
static void phalcon_uncamelize(zval *return_value, const zval *str);
/** Starts/Ends with */
static int phalcon_start_with(const zval *str, const zval *compared, zval *case_sensitive);
static int phalcon_start_with_str(const zval *str, char *compared, unsigned int compared_length);
static int phalcon_start_with_str_str(char *str, unsigned int str_length, char *compared, unsigned int compared_length);
static int phalcon_end_with(const zval *str, const zval *compared, zval *case_sensitive);
static int phalcon_end_with_str(const zval *str, char *compared, unsigned int compared_length);
/** Random string */
static void phalcon_random_string(zval *return_value, const zval *type, const zval *length TSRMLS_DC);
/* Strips extra slashes */
static void phalcon_remove_extra_slashes(zval *return_value, const zval *str);
/** Generates a unique key for an array/object */
static void phalcon_unique_key(zval *return_value, zval *prefix, zval *value TSRMLS_DC);
/** spprintf */
static int phalcon_spprintf(char **message, int max_len, char *format, ...);
/* Substr */
static void phalcon_substr(zval *return_value, zval *str, unsigned long from, unsigned long length);
/** EOL */
zval *phalcon_eol(int eol TSRMLS_DC);
/** Preg-Match */
static void phalcon_preg_match(zval *return_value, zval **return_value_ptr, zval *regex, zval *subject, zval *matches TSRMLS_DC);
/** Base64 */
static void phalcon_base64_encode(zval *return_value, zval *data);
static void phalcon_base64_decode(zval *return_value, zval *data);
/** Hash */
static void phalcon_md5(zval *return_value, zval *str);
/** JSON */
static void phalcon_json_encode(zval *return_value, zval **return_value_ptr, zval *v, int opts TSRMLS_DC);
static void phalcon_json_decode(zval *return_value, zval **return_value_ptr, zval *v, zend_bool assoc TSRMLS_DC);
/***/
static void phalcon_lcfirst(zval *return_value, zval *s);
static void phalcon_ucfirst(zval *return_value, zval *s);
static int phalcon_http_build_query(zval *return_value, zval *params, char *sep TSRMLS_DC);
static void phalcon_htmlspecialchars(zval *return_value, zval *string, zval *quoting, zval *charset TSRMLS_DC);
static void phalcon_htmlentities(zval *return_value, zval *string, zval *quoting, zval *charset TSRMLS_DC);
static void phalcon_strval(zval *return_value, zval *v);
static void phalcon_date(zval *return_value, zval *format, zval *timestamp TSRMLS_DC);
static void phalcon_addslashes(zval *return_value, zval *str TSRMLS_DC);
static void phalcon_add_trailing_slash(zval** v);
#if PHP_VERSION_ID < 50400
const char* zend_new_interned_string(const char *arKey, int nKeyLength, int free_src TSRMLS_DC);
#define PHALCON_ZVAL_MAYBE_INTERNED_STRING(pz, string) ZVAL_STRING(pz, string, 1);
#else
#define PHALCON_ZVAL_MAYBE_INTERNED_STRING(pz, string) \
do { \
if (IS_INTERNED(string)) { \
ZVAL_STRINGL(pz, string, INTERNED_LEN(string)-1, 0); \
} \
else { \
ZVAL_STRING(pz, string, 1); \
} \
} while (0)
#endif /* PHP_VERSION_ID < 50400 */
#endif /* PHALCON_KERNEL_STRING_H */
/** Low level filters */
static void phalcon_filter_alphanum(zval *return_value, zval *param);
static void phalcon_filter_identifier(zval *return_value, zval *param);
/** Encoding */
static void phalcon_is_basic_charset(zval *return_value, const zval *param);
/** Escaping */
static void phalcon_escape_css(zval *return_value, zval *param);
static void phalcon_escape_js(zval *return_value, zval *param);
static void phalcon_escape_htmlattr(zval *return_value, zval *param);
static void phalcon_escape_html(zval *return_value, zval *str, zval *quote_style, zval *charset TSRMLS_DC);
#ifndef PHALCON_KERNEL_FILE_H
#define PHALCON_KERNEL_FILE_H
static int phalcon_file_exists(zval *filename TSRMLS_DC);
static int phalcon_compare_mtime(zval *filename1, zval *filename2 TSRMLS_DC);
static void phalcon_fix_path(zval **return_value, zval *path, zval *directory_separator TSRMLS_DC);
static void phalcon_prepare_virtual_path(zval *return_value, zval *path, zval *virtual_separator TSRMLS_DC);
static void phalcon_unique_path_key(zval *return_value, zval *path TSRMLS_DC);
static void phalcon_realpath(zval *return_value, zval *filename TSRMLS_DC);
static void phalcon_file_get_contents(zval *return_value, zval *filename TSRMLS_DC);
static void phalcon_file_put_contents(zval *return_value, zval *filename, zval *data TSRMLS_DC);
static void phalcon_possible_autoload_filepath(zval *return_value, zval *prefix, zval *class_name, zval *virtual_separator, zval *separator TSRMLS_DC);
static void phalcon_is_dir(zval *return_value, zval *path TSRMLS_DC);
static void phalcon_unlink(zval *return_value, zval *path TSRMLS_DC);
static void phalcon_filemtime(zval *return_value, zval *path TSRMLS_DC);
static void phalcon_basename(zval *return_value, zval *path TSRMLS_DC);
#ifdef TSRM_WIN32
#define PHALCON_DIRECTORY_SEPARATOR "\\"
#else
#define PHALCON_DIRECTORY_SEPARATOR "/"
#endif
#endif /* PHALCON_KERNEL_FILE_H */
static void phalcon_ob_start(TSRMLS_D);
static void phalcon_ob_get_contents(zval *result TSRMLS_DC);
static int phalcon_ob_end_flush(TSRMLS_D);
static int phalcon_ob_end_clean(TSRMLS_D);
static int phalcon_ob_flush(TSRMLS_D);
static int phalcon_ob_clean(TSRMLS_D);
static int phalcon_ob_get_level(TSRMLS_D);
/** Strict comparing */
#define PHALCON_IS_LONG(op1, op2) phalcon_compare_strict_long(op1, op2 TSRMLS_CC)
#define PHALCON_IS_STRING(op1, op2) phalcon_compare_strict_string(op1, op2, strlen(op2))
/** strict boolean comparison */
#define PHALCON_IS_FALSE(var) (Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var))
#define PHALCON_IS_TRUE(var) (Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var))
#define PHALCON_IS_NOT_FALSE(var) (Z_TYPE_P(var) != IS_BOOL || (Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var)))
#define PHALCON_IS_NOT_TRUE(var) (Z_TYPE_P(var) != IS_BOOL || (Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var)))
/** SQL null empty **/
#define PHALCON_IS_EMPTY(var) (Z_TYPE_P(var) == IS_NULL || (Z_TYPE_P(var) == IS_STRING && !Z_STRLEN_P(var)))
#define PHALCON_IS_NOT_EMPTY(var) (!(Z_TYPE_P(var) == IS_NULL || (Z_TYPE_P(var) == IS_STRING && !Z_STRLEN_P(var))))
/** Is scalar */
#define PHALCON_IS_SCALAR(var) (!(Z_TYPE_P(var) == IS_NULL || Z_TYPE_P(var) == IS_ARRAY || Z_TYPE_P(var) == IS_OBJECT || Z_TYPE_P(var) == IS_RESOURCE))
#define PHALCON_IS_NOT_SCALAR(var) (Z_TYPE_P(var) == IS_NULL || Z_TYPE_P(var) == IS_ARRAY || Z_TYPE_P(var) == IS_OBJECT || Z_TYPE_P(var) == IS_RESOURCE)
/** Equals/Identical */
#define PHALCON_IS_EQUAL(op1, op2) phalcon_is_equal(op1, op2 TSRMLS_CC)
#define PHALCON_IS_IDENTICAL(op1, op2) phalcon_is_identical(op1, op2 TSRMLS_CC)
/** Greater/Smaller equals */
#define PHALCON_LE(op1, op2) phalcon_less_equal(op1, op2 TSRMLS_CC)
#define PHALCON_LE_LONG(op1, op2) phalcon_less_equal_long(op1, op2 TSRMLS_CC)
#define PHALCON_GE(op1, op2) phalcon_greater_equal(op1, op2 TSRMLS_CC)
#define PHALCON_GE_LONG(op1, op2) phalcon_greater_equal_long(op1, op2 TSRMLS_CC)
#define PHALCON_LT(op1, op2) phalcon_less(op1, op2 TSRMLS_CC)
#define PHALCON_LT_LONG(op1, op2) phalcon_less_long(op1, op2 TSRMLS_CC)
#define PHALCON_GT(op1, op2) phalcon_greater(op1, op2 TSRMLS_CC)
#define PHALCON_GT_LONG(op1, op2) phalcon_greater_long(op1, op2 TSRMLS_CC)
#if PHP_VERSION_ID < 50400
#define phalcon_increment(var) increment_function(var)
#else
#define phalcon_increment(var) fast_increment_function(var)
#endif
#if PHP_VERSION_ID < 50400
#define phalcon_decrement(var) decrement_function(var)
#else
#define phalcon_decrement(var) fast_decrement_function(var)
#endif
/** Operator functions */
static int phalcon_add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
static int phalcon_and_function(zval *result, zval *left, zval *right);
static void phalcon_concat_self(zval **left, zval *right TSRMLS_DC);
static void phalcon_concat_self_str(zval **left, const char *right, int right_length TSRMLS_DC);
/** Strict comparing */
static int phalcon_compare_strict_string(zval *op1, const char *op2, int op2_length);
static int phalcon_compare_strict_long(zval *op1, long op2 TSRMLS_DC);
static void phalcon_cast(zval *result, zval *var, zend_uint type);
long phalcon_get_intval(const zval *op);
static int phalcon_is_numeric(const zval *op);
static int phalcon_is_equal(zval *op1, zval *op2 TSRMLS_DC);
static int phalcon_is_identical(zval *op1, zval *op2 TSRMLS_DC);
static int phalcon_less(zval *op1, zval *op2 TSRMLS_DC);
static int phalcon_less_long(zval *op1, long op2 TSRMLS_DC);
static int phalcon_greater(zval *op1, zval *op2 TSRMLS_DC);
static int phalcon_greater_long(zval *op1, long op2 TSRMLS_DC);
static int phalcon_less_equal(zval *op1, zval *op2 TSRMLS_DC);
static int phalcon_less_equal_long(zval *op1, long op2 TSRMLS_DC);
static int phalcon_greater_equal(zval *op1, zval *op2 TSRMLS_DC);
static int phalcon_greater_equal_long(zval *op1, long op2 TSRMLS_DC);
#ifndef PHALCON_KERNEL_CONCAT_H
#define PHALCON_KERNEL_CONCAT_H
#define PHALCON_CONCAT_SV(result, op1, op2) \
phalcon_concat_sv(&result, op1, sizeof(op1)-1, op2, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SV(result, op1, op2) \
phalcon_concat_sv(&result, op1, sizeof(op1)-1, op2, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVS(result, op1, op2, op3) \
phalcon_concat_svs(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVS(result, op1, op2, op3) \
phalcon_concat_svs(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVSV(result, op1, op2, op3, op4) \
phalcon_concat_svsv(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVSV(result, op1, op2, op3, op4) \
phalcon_concat_svsv(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVSVS(result, op1, op2, op3, op4, op5) \
phalcon_concat_svsvs(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, sizeof(op5)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVSVS(result, op1, op2, op3, op4, op5) \
phalcon_concat_svsvs(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, sizeof(op5)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVSVSV(result, op1, op2, op3, op4, op5, op6) \
phalcon_concat_svsvsv(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, sizeof(op5)-1, op6, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVSVSV(result, op1, op2, op3, op4, op5, op6) \
phalcon_concat_svsvsv(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, sizeof(op5)-1, op6, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVSVSVS(result, op1, op2, op3, op4, op5, op6, op7) \
phalcon_concat_svsvsvs(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, sizeof(op5)-1, op6, op7, sizeof(op7)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVSVSVS(result, op1, op2, op3, op4, op5, op6, op7) \
phalcon_concat_svsvsvs(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, sizeof(op5)-1, op6, op7, sizeof(op7)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVSVV(result, op1, op2, op3, op4, op5) \
phalcon_concat_svsvv(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVSVV(result, op1, op2, op3, op4, op5) \
phalcon_concat_svsvv(&result, op1, sizeof(op1)-1, op2, op3, sizeof(op3)-1, op4, op5, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVV(result, op1, op2, op3) \
phalcon_concat_svv(&result, op1, sizeof(op1)-1, op2, op3, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVV(result, op1, op2, op3) \
phalcon_concat_svv(&result, op1, sizeof(op1)-1, op2, op3, 1 TSRMLS_CC);
#define PHALCON_CONCAT_SVVS(result, op1, op2, op3, op4) \
phalcon_concat_svvs(&result, op1, sizeof(op1)-1, op2, op3, op4, sizeof(op4)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_SVVS(result, op1, op2, op3, op4) \
phalcon_concat_svvs(&result, op1, sizeof(op1)-1, op2, op3, op4, sizeof(op4)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VS(result, op1, op2) \
phalcon_concat_vs(&result, op1, op2, sizeof(op2)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VS(result, op1, op2) \
phalcon_concat_vs(&result, op1, op2, sizeof(op2)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VSV(result, op1, op2, op3) \
phalcon_concat_vsv(&result, op1, op2, sizeof(op2)-1, op3, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VSV(result, op1, op2, op3) \
phalcon_concat_vsv(&result, op1, op2, sizeof(op2)-1, op3, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VSVS(result, op1, op2, op3, op4) \
phalcon_concat_vsvs(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VSVS(result, op1, op2, op3, op4) \
phalcon_concat_vsvs(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VSVSV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vsvsv(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VSVSV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vsvsv(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VSVSVS(result, op1, op2, op3, op4, op5, op6) \
phalcon_concat_vsvsvs(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, op6, sizeof(op6)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VSVSVS(result, op1, op2, op3, op4, op5, op6) \
phalcon_concat_vsvsvs(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, op6, sizeof(op6)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VSVSVSV(result, op1, op2, op3, op4, op5, op6, op7) \
phalcon_concat_vsvsvsv(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, op6, sizeof(op6)-1, op7, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VSVSVSV(result, op1, op2, op3, op4, op5, op6, op7) \
phalcon_concat_vsvsvsv(&result, op1, op2, sizeof(op2)-1, op3, op4, sizeof(op4)-1, op5, op6, sizeof(op6)-1, op7, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VSVV(result, op1, op2, op3, op4) \
phalcon_concat_vsvv(&result, op1, op2, sizeof(op2)-1, op3, op4, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VSVV(result, op1, op2, op3, op4) \
phalcon_concat_vsvv(&result, op1, op2, sizeof(op2)-1, op3, op4, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VSVVV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vsvvv(&result, op1, op2, sizeof(op2)-1, op3, op4, op5, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VSVVV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vsvvv(&result, op1, op2, sizeof(op2)-1, op3, op4, op5, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VV(result, op1, op2) \
phalcon_concat_vv(&result, op1, op2, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VV(result, op1, op2) \
phalcon_concat_vv(&result, op1, op2, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VVS(result, op1, op2, op3) \
phalcon_concat_vvs(&result, op1, op2, op3, sizeof(op3)-1, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VVS(result, op1, op2, op3) \
phalcon_concat_vvs(&result, op1, op2, op3, sizeof(op3)-1, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VVSV(result, op1, op2, op3, op4) \
phalcon_concat_vvsv(&result, op1, op2, op3, sizeof(op3)-1, op4, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VVSV(result, op1, op2, op3, op4) \
phalcon_concat_vvsv(&result, op1, op2, op3, sizeof(op3)-1, op4, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VVV(result, op1, op2, op3) \
phalcon_concat_vvv(&result, op1, op2, op3, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VVV(result, op1, op2, op3) \
phalcon_concat_vvv(&result, op1, op2, op3, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VVVSV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vvvsv(&result, op1, op2, op3, op4, sizeof(op4)-1, op5, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VVVSV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vvvsv(&result, op1, op2, op3, op4, sizeof(op4)-1, op5, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VVVV(result, op1, op2, op3, op4) \
phalcon_concat_vvvv(&result, op1, op2, op3, op4, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VVVV(result, op1, op2, op3, op4) \
phalcon_concat_vvvv(&result, op1, op2, op3, op4, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VVVVSVV(result, op1, op2, op3, op4, op5, op6, op7) \
phalcon_concat_vvvvsvv(&result, op1, op2, op3, op4, op5, sizeof(op5)-1, op6, op7, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VVVVSVV(result, op1, op2, op3, op4, op5, op6, op7) \
phalcon_concat_vvvvsvv(&result, op1, op2, op3, op4, op5, sizeof(op5)-1, op6, op7, 1 TSRMLS_CC);
#define PHALCON_CONCAT_VVVVV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vvvvv(&result, op1, op2, op3, op4, op5, 0 TSRMLS_CC);
#define PHALCON_SCONCAT_VVVVV(result, op1, op2, op3, op4, op5) \
phalcon_concat_vvvvv(&result, op1, op2, op3, op4, op5, 1 TSRMLS_CC);
static void phalcon_concat_sv(zval **result, const char *op1, zend_uint op1_len, zval *op2, int self_var TSRMLS_DC);
static void phalcon_concat_svs(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, int self_var TSRMLS_DC);
static void phalcon_concat_svsv(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, int self_var TSRMLS_DC);
static void phalcon_concat_svsvs(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, const char *op5, zend_uint op5_len, int self_var TSRMLS_DC);
static void phalcon_concat_svsvsv(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, const char *op5, zend_uint op5_len, zval *op6, int self_var TSRMLS_DC);
static void phalcon_concat_svsvsvs(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, const char *op5, zend_uint op5_len, zval *op6, const char *op7, zend_uint op7_len, int self_var TSRMLS_DC);
static void phalcon_concat_svsvv(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, zval *op5, int self_var TSRMLS_DC);
static void phalcon_concat_svv(zval **result, const char *op1, zend_uint op1_len, zval *op2, zval *op3, int self_var TSRMLS_DC);
static void phalcon_concat_svvs(zval **result, const char *op1, zend_uint op1_len, zval *op2, zval *op3, const char *op4, zend_uint op4_len, int self_var TSRMLS_DC);
static void phalcon_concat_vs(zval **result, zval *op1, const char *op2, zend_uint op2_len, int self_var TSRMLS_DC);
static void phalcon_concat_vsv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, int self_var TSRMLS_DC);
static void phalcon_concat_vsvs(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, int self_var TSRMLS_DC);
static void phalcon_concat_vsvsv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, zval *op5, int self_var TSRMLS_DC);
static void phalcon_concat_vsvsvs(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, zval *op5, const char *op6, zend_uint op6_len, int self_var TSRMLS_DC);
static void phalcon_concat_vsvsvsv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, zval *op5, const char *op6, zend_uint op6_len, zval *op7, int self_var TSRMLS_DC);
static void phalcon_concat_vsvv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, zval *op4, int self_var TSRMLS_DC);
static void phalcon_concat_vsvvv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, zval *op4, zval *op5, int self_var TSRMLS_DC);
static void phalcon_concat_vv(zval **result, zval *op1, zval *op2, int self_var TSRMLS_DC);
static void phalcon_concat_vvs(zval **result, zval *op1, zval *op2, const char *op3, zend_uint op3_len, int self_var TSRMLS_DC);
static void phalcon_concat_vvsv(zval **result, zval *op1, zval *op2, const char *op3, zend_uint op3_len, zval *op4, int self_var TSRMLS_DC);
static void phalcon_concat_vvv(zval **result, zval *op1, zval *op2, zval *op3, int self_var TSRMLS_DC);
static void phalcon_concat_vvvsv(zval **result, zval *op1, zval *op2, zval *op3, const char *op4, zend_uint op4_len, zval *op5, int self_var TSRMLS_DC);
static void phalcon_concat_vvvv(zval **result, zval *op1, zval *op2, zval *op3, zval *op4, int self_var TSRMLS_DC);
static void phalcon_concat_vvvvsvv(zval **result, zval *op1, zval *op2, zval *op3, zval *op4, const char *op5, zend_uint op5_len, zval *op6, zval *op7, int self_var TSRMLS_DC);
static void phalcon_concat_vvvvv(zval **result, zval *op1, zval *op2, zval *op3, zval *op4, zval *op5, int self_var TSRMLS_DC);
#endif /* PHALCON_KERNEL_CONCAT_H */
#ifndef PHALCON_KERNEL_EXCEPTION_H
#define PHALCON_KERNEL_EXCEPTION_H
/** Exceptions */
#define PHALCON_THROW_EXCEPTION_STR(class_entry, message) \
do { \
phalcon_throw_exception_string(class_entry, message TSRMLS_CC); \
PHALCON_MM_RESTORE(); \
} while (0)
#define PHALCON_THROW_EXCEPTION_ZVAL(class_entry, message) \
do { \
phalcon_throw_exception_zval(class_entry, message TSRMLS_CC); \
PHALCON_MM_RESTORE(); \
} while (0)
#define PHALCON_THROW_EXCEPTION_STRW(class_entry, message) phalcon_throw_exception_string(class_entry, message TSRMLS_CC)
#define PHALCON_THROW_EXCEPTION_ZVALW(class_entry, message) phalcon_throw_exception_zval(class_entry, message TSRMLS_CC)
/** Throw Exceptions */
static void phalcon_throw_exception(zval *object TSRMLS_DC);
static void phalcon_throw_exception_string(zend_class_entry *ce, const char *message TSRMLS_DC);
static void phalcon_throw_exception_zval(zend_class_entry *ce, zval *message TSRMLS_DC);
static void phalcon_throw_exception_internal(zval *exception TSRMLS_DC);
#endif /* PHALCON_KERNEL_EXCEPTION_H */
int ZEND_FASTCALL phalcon_require(const zval *require_path TSRMLS_DC);
int ZEND_FASTCALL phalcon_require_ret(zval *return_value, const zval *require_path TSRMLS_DC);
#ifndef PHALCON_KERNEL_VARIABLES_H
#define PHALCON_KERNEL_VARIABLES_H
#include <Zend/zend.h>
static void phalcon_serialize(zval *return_value, zval **var TSRMLS_DC);
static void phalcon_unserialize(zval *return_value, zval *var TSRMLS_DC);
#endif /* PHALCON_KERNEL_VARIABLES_H */
#ifndef PHALCON_KERNEL_SESSION_H
#define PHALCON_KERNEL_SESSION_H
static void phalcon_session_start(TSRMLS_D);
static void phalcon_session_destroy(TSRMLS_D);
static void phalcon_get_session_id(zval *return_value, zval **return_value_ptr TSRMLS_DC);
static void phalcon_set_session_id(zval *sid TSRMLS_DC);
static void phalcon_session_write_close(TSRMLS_D);
#endif /* PHALCON_KERNEL_SESSION_H */
/* Executor Pointers */
#ifdef ZTS
# define PHALCON_EG(v) TSRMG(executor_globals_id, zend_executor_globals *, v)
# define PHALCON_VEG ((zend_executor_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(executor_globals_id)])
#else
# define PHALCON_EG(v) (executor_globals.v)
# define PHALCON_VEG (&executor_globals)
#endif
static int phalcon_alt_call_user_method(zend_class_entry *ce, zval **object_pp, char *method_name, unsigned int method_len, zval *retval_ptr, zval **retval_ptr_ptr, zend_uint param_count, zval *params[], unsigned long method_key TSRMLS_DC);
static int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned long hash_key, char *method_name, unsigned int method_len, unsigned long method_key TSRMLS_DC);
static void phalcon_orm_destroy_cache(TSRMLS_D);
static void phalcon_orm_get_prepared_ast(zval **return_value, zval *unique_id TSRMLS_DC);
static void phalcon_orm_set_prepared_ast(zval *unique_id, zval *prepared_ast TSRMLS_DC);
static void phalcon_orm_singlequotes(zval *return_value, zval *str TSRMLS_DC);
/** Extract named parameters */
static void phalcon_extract_named_params(zval *return_value, zval *str, zval *matches);
static void phalcon_replace_paths(zval *return_value, zval *pattern, zval *paths, zval *uri TSRMLS_DC);
/** Get the possible URI based on a script path */
static void phalcon_get_uri(zval *return_value, zval *path);
static void phalcon_raw_url_encode(zval *return_value, zval *url);
#include <ext/spl/spl_exceptions.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
void php_phalcon_init_globals(zend_phalcon_globals *phalcon_globals TSRMLS_DC) {
/* Memory options */
phalcon_globals->active_memory = NULL;
/* Virtual Symbol Tables */
phalcon_globals->active_symbol_table = NULL;
/* Cache options */
phalcon_globals->function_cache = NULL;
/* Recursive Lock */
phalcon_globals->recursive_lock = 0;
/* ORM options*/
phalcon_globals->orm.events = 1;
phalcon_globals->orm.virtual_foreign_keys = 1;
phalcon_globals->orm.column_renaming = 1;
phalcon_globals->orm.not_null_validations = 1;
phalcon_globals->orm.exception_on_failed_save = 0;
phalcon_globals->orm.enable_literals = 1;
phalcon_globals->orm.cache_level = 3;
phalcon_globals->orm.unique_cache_id = 0;
phalcon_globals->orm.parser_cache = NULL;
phalcon_globals->orm.ast_cache = NULL;
/* DB options */
phalcon_globals->db.escape_identifiers = 1;
}
zend_class_entry *phalcon_register_internal_interface_ex(zend_class_entry *orig_ce, zend_class_entry *parent_ce TSRMLS_DC) {
zend_class_entry *ce;
ce = zend_register_internal_interface(orig_ce TSRMLS_CC);
if (parent_ce) {
zend_do_inheritance(ce, parent_ce TSRMLS_CC);
}
return ce;
}
static int phalcon_init_global(char *global, unsigned int global_length TSRMLS_DC) {
#if PHP_VERSION_ID < 50400
zend_bool jit_initialization = (PG(auto_globals_jit) && !PG(register_globals) && !PG(register_long_arrays));
if (jit_initialization) {
return zend_is_auto_global(global, global_length - 1 TSRMLS_CC);
}
#else
if (PG(auto_globals_jit)) {
return zend_is_auto_global(global, global_length - 1 TSRMLS_CC);
}
#endif
return SUCCESS;
}
static int phalcon_get_global(zval **arr, const char *global, unsigned int global_length TSRMLS_DC) {
zval **gv;
zend_bool jit_initialization = PG(auto_globals_jit);
if (jit_initialization) {
zend_is_auto_global(global, global_length - 1 TSRMLS_CC);
}
if (&EG(symbol_table)) {
if (zend_hash_find(&EG(symbol_table), global, global_length, (void **) &gv) == SUCCESS) {
if (Z_TYPE_PP(gv) == IS_ARRAY) {
*arr = *gv;
if (!*arr) {
PHALCON_INIT_VAR(*arr);
array_init(*arr);
}
} else {
PHALCON_INIT_VAR(*arr);
array_init(*arr);
}
return SUCCESS;
}
}
PHALCON_INIT_VAR(*arr);
array_init(*arr);
return SUCCESS;
}
long int phalcon_fast_count_int(zval *value TSRMLS_DC) {
if (Z_TYPE_P(value) == IS_ARRAY) {
return zend_hash_num_elements(Z_ARRVAL_P(value));
}
if (Z_TYPE_P(value) == IS_OBJECT) {
if (Z_OBJ_HT_P(value)->count_elements) {
long int result;
if (SUCCESS == Z_OBJ_HT(*value)->count_elements(value, &result TSRMLS_CC)) {
return result;
}
}
if (Z_OBJ_HT_P(value)->get_class_entry && instanceof_function_ex(Z_OBJCE_P(value), spl_ce_Countable, 1 TSRMLS_CC)) {
zval *retval = NULL;
long int result = 0;
zend_call_method_with_0_params(&value, Z_OBJCE_P(value), NULL, "count", &retval);
if (retval) {
convert_to_long_ex(&retval);
result = Z_LVAL_P(retval);
zval_ptr_dtor(&retval);
}
return result;
}
return 0;
}
if (Z_TYPE_P(value) == IS_NULL) {
return 0;
}
return 1;
}
static void phalcon_fast_count(zval *result, zval *value TSRMLS_DC) {
if (Z_TYPE_P(value) == IS_ARRAY) {
ZVAL_LONG(result, zend_hash_num_elements(Z_ARRVAL_P(value)));
return;
}
if (Z_TYPE_P(value) == IS_OBJECT) {
#ifdef HAVE_SPL
zval *retval = NULL;
#endif
if (Z_OBJ_HT_P(value)->count_elements) {
ZVAL_LONG(result, 1);
if (SUCCESS == Z_OBJ_HT(*value)->count_elements(value, &Z_LVAL_P(result) TSRMLS_CC)) {
return;
}
}
#ifdef HAVE_SPL
if (Z_OBJ_HT_P(value)->get_class_entry && instanceof_function(Z_OBJCE_P(value), spl_ce_Countable TSRMLS_CC)) {
zend_call_method_with_0_params(&value, NULL, NULL, "count", &retval);
if (retval) {
convert_to_long_ex(&retval);
ZVAL_LONG(result, Z_LVAL_P(retval));
zval_ptr_dtor(&retval);
}
return;
}
#endif
ZVAL_LONG(result, 0);
return;
}
if (Z_TYPE_P(value) == IS_NULL) {
ZVAL_LONG(result, 0);
return;
}
ZVAL_LONG(result, 1);
}
static int phalcon_fast_count_ev(zval *value TSRMLS_DC) {
long count = 0;
if (Z_TYPE_P(value) == IS_ARRAY) {
return (int) zend_hash_num_elements(Z_ARRVAL_P(value)) > 0;
}
if (Z_TYPE_P(value) == IS_OBJECT) {
#ifdef HAVE_SPL
zval *retval = NULL;
#endif
if (Z_OBJ_HT_P(value)->count_elements) {
Z_OBJ_HT(*value)->count_elements(value, &count TSRMLS_CC);
return (int) count > 0;
}
#ifdef HAVE_SPL
if (Z_OBJ_HT_P(value)->get_class_entry && instanceof_function(Z_OBJCE_P(value), spl_ce_Countable TSRMLS_CC)) {
zend_call_method_with_0_params(&value, NULL, NULL, "count", &retval);
if (retval) {
convert_to_long_ex(&retval);
count = Z_LVAL_P(retval);
zval_ptr_dtor(&retval);
return (int) count > 0;
}
return 0;
}
#endif
return 0;
}
if (Z_TYPE_P(value) == IS_NULL) {
return 0;
}
return 1;
}
static int phalcon_function_exists(const zval *function_name TSRMLS_DC) {
return phalcon_function_quick_exists_ex(
Z_STRVAL_P(function_name),
Z_STRLEN_P(function_name) + 1,
zend_inline_hash_func(Z_STRVAL_P(function_name), Z_STRLEN_P(function_name) + 1) TSRMLS_CC
);
}
static int phalcon_function_exists_ex(const char *function_name, unsigned int function_len TSRMLS_DC) {
return phalcon_function_quick_exists_ex(function_name, function_len, zend_inline_hash_func(function_name, function_len) TSRMLS_CC);
}
static int phalcon_function_quick_exists_ex(const char *method_name, unsigned int method_len, unsigned long key TSRMLS_DC) {
if (zend_hash_quick_exists(CG(function_table), method_name, method_len, key)) {
return SUCCESS;
}
return FAILURE;
}
static int phalcon_is_callable(zval *var TSRMLS_DC) {
char *error = NULL;
zend_bool retval;
retval = zend_is_callable_ex(var, NULL, 0, NULL, NULL, NULL, &error TSRMLS_CC);
if (error) {
efree(error);
}
return (int) retval;
}
static int phalcon_is_iterable_ex(zval *arr, HashTable **arr_hash, HashPosition *hash_position, int duplicate, int reverse) {
if (unlikely(Z_TYPE_P(arr) != IS_ARRAY)) {
return 0;
}
if (duplicate) {
ALLOC_HASHTABLE(*arr_hash);
zend_hash_init(*arr_hash, 0, NULL, NULL, 0);
zend_hash_copy(*arr_hash, Z_ARRVAL_P(arr), NULL, NULL, sizeof(zval*));
} else {
*arr_hash = Z_ARRVAL_P(arr);
}
if (reverse) {
zend_hash_internal_pointer_end_ex(*arr_hash, hash_position);
} else {
zend_hash_internal_pointer_reset_ex(*arr_hash, hash_position);
}
return 1;
}
static void phalcon_safe_zval_ptr_dtor(zval *pzval)
{
if (pzval) {
zval_ptr_dtor(&pzval);
}
}
static int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, int optional_args, ...)
{
va_list va;
int arg_count = (int) (zend_uintptr_t) *(zend_vm_stack_top(TSRMLS_C) - 1);
zval **arg, **p;
int i;
if (num_args < required_args || (num_args > (required_args + optional_args))) {
phalcon_throw_exception_string(spl_ce_BadMethodCallException, "Wrong number of parameters" TSRMLS_CC);
return FAILURE;
}
if (num_args > arg_count) {
phalcon_throw_exception_string(spl_ce_BadMethodCallException, "Could not obtain parameters for parsing" TSRMLS_CC);
return FAILURE;
}
if (!num_args) {
return SUCCESS;
}
va_start(va, optional_args);
i = 0;
while (num_args-- > 0) {
arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count - i));
p = va_arg(va, zval **);
*p = *arg;
i++;
}
va_end(va);
return SUCCESS;
}
static int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...)
{
void **p;
int arg_count, param_count;
va_list ptr;
p = zend_vm_stack_top(TSRMLS_C) - 1;
arg_count = (int)(zend_uintptr_t)*p;
param_count = n_req + n_opt;
if (param_count < arg_count || n_req > arg_count) {
return FAILURE;
}
va_start(ptr, n_opt);
while (arg_count > 0) {
zval ***param = va_arg(ptr, zval ***);
*param = (zval**)p - arg_count;
--arg_count;
}
va_end(ptr);
return SUCCESS;
}
#include <Zend/zend_alloc.h>
static phalcon_memory_entry* phalcon_memory_grow_stack_common(zend_phalcon_globals *phalcon_globals_ptr)
{
assert(phalcon_globals_ptr->start_memory != NULL);
if (!phalcon_globals_ptr->active_memory) {
phalcon_globals_ptr->active_memory = phalcon_globals_ptr->start_memory;
return phalcon_globals_ptr->start_memory;
}
{
phalcon_memory_entry *entry = (phalcon_memory_entry *) ecalloc(1, sizeof(phalcon_memory_entry));
/* ecalloc() will take care of these members
entry->pointer = 0;
entry->capacity = 0;
entry->addresses = NULL;
entry->hash_pointer = 0;
entry->hash_capacity = 0;
entry->hash_addresses = NULL;
entry->next = NULL;
*/
entry->prev = phalcon_globals_ptr->active_memory;
entry->prev->next = entry;
phalcon_globals_ptr->active_memory = entry;
return entry;
}
}
static void phalcon_memory_restore_stack_common(zend_phalcon_globals *phalcon_globals_ptr TSRMLS_DC) {
size_t i;
phalcon_memory_entry *prev, *active_memory;
phalcon_symbol_table *active_symbol_table;
active_memory = phalcon_globals_ptr->active_memory;
assert(active_memory != NULL);
if (likely(!CG(unclean_shutdown))) {
/* Clean active symbol table */
if (phalcon_globals_ptr->active_symbol_table) {
active_symbol_table = phalcon_globals_ptr->active_symbol_table;
if (active_symbol_table->scope == active_memory) {
zend_hash_destroy(EG(active_symbol_table));
FREE_HASHTABLE(EG(active_symbol_table));
EG(active_symbol_table) = active_symbol_table->symbol_table;
phalcon_globals_ptr->active_symbol_table = active_symbol_table->prev;
efree(active_symbol_table);
}
}
for (i = 0; i < active_memory->hash_pointer; ++i) {
assert(active_memory->hash_addresses[i] != NULL && *(active_memory->hash_addresses[i]) != NULL);
if (Z_REFCOUNT_PP(active_memory->hash_addresses[i]) <= 1) {
ZVAL_NULL(*active_memory->hash_addresses[i]);
} else {
zval_copy_ctor(*active_memory->hash_addresses[i]);
}
}
#ifndef PHALCON_RELEASE
for (i = 0; i < active_memory->pointer; ++i) {
if (likely(active_memory->addresses[i] != NULL && *(active_memory->addresses[i]) != NULL)) {
zval **var = active_memory->addresses[i];
#if PHP_VERSION_ID < 50400
if (Z_TYPE_PP(var) > IS_CONSTANT_ARRAY) {
fprintf(stderr, "%s: observed variable #%d (%p) has invalid type %u\n", __func__, (int)i, *var, Z_TYPE_PP(var));
}
#else
if (Z_TYPE_PP(var) > IS_CALLABLE) {
fprintf(stderr, "%s: observed variable #%d (%p) has invalid type %u\n", __func__, (int)i, *var, Z_TYPE_PP(var));
}
#endif
if (Z_REFCOUNT_PP(var) == 0) {
fprintf(stderr, "%s: observed variable #%d (%p) has 0 references\n", __func__, (int)i, *var);
}
else if (Z_REFCOUNT_PP(var) >= 1000000) {
fprintf(stderr, "%s: observed variable #%d (%p) has too many references (%u)\n", __func__, (int)i, *var, Z_REFCOUNT_PP(var));
}
else if (Z_REFCOUNT_PP(var) == 1 && Z_ISREF_PP(var)) {
fprintf(stderr, "%s: observed variable #%d (%p) is a reference with reference count = 1\n", __func__, (int)i, *var);
}
}
}
#endif
for (i = 0; i < active_memory->pointer; ++i) {
if (likely(active_memory->addresses[i] != NULL && *(active_memory->addresses[i]) != NULL)) {
if (Z_REFCOUNT_PP(active_memory->addresses[i]) == 1) {
zval_ptr_dtor(active_memory->addresses[i]);
} else {
Z_DELREF_PP(active_memory->addresses[i]);
}
}
}
}
prev = active_memory->prev;
if (prev != NULL) {
if (active_memory->hash_addresses != NULL) {
efree(active_memory->hash_addresses);
}
if (likely(active_memory->addresses != NULL)) {
efree(active_memory->addresses);
}
efree(phalcon_globals_ptr->active_memory);
phalcon_globals_ptr->active_memory = prev;
prev->next = NULL;
} else {
assert(phalcon_globals_ptr->start_memory == active_memory);
assert(active_memory->next == NULL);
active_memory->pointer = 0;
active_memory->hash_pointer = 0;
phalcon_globals_ptr->active_memory = NULL;
}
}
#ifndef PHALCON_RELEASE
static void phalcon_dump_current_frame(TSRMLS_D)
{
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
phalcon_memory_entry *active_memory;
int i;
if (unlikely(phalcon_globals_ptr->active_memory == NULL)) {
fprintf(stderr, "WARNING: calling phalcon_dump_current_frame() without an active memory frame!\n");
phalcon_print_backtrace();
return;
}
active_memory = phalcon_globals_ptr->active_memory;
assert(active_memory != NULL);
fprintf(stderr, "Dump of the memory frame %p\n", active_memory);
if (active_memory->hash_pointer) {
for (i = 0; i < active_memory->hash_pointer; ++i) {
assert(active_memory->hash_addresses[i] != NULL && *(active_memory->hash_addresses[i]) != NULL);
fprintf(stderr, "Hash ptr %d (%p => %p), type=%u, refcnt=%u\n", i, active_memory->hash_addresses[i], *active_memory->hash_addresses[i], Z_TYPE_PP(active_memory->hash_addresses[i]), Z_REFCOUNT_PP(active_memory->hash_addresses[i]));
}
}
for (i = 0; i < active_memory->pointer; ++i) {
if (likely(active_memory->addresses[i] != NULL && *(active_memory->addresses[i]) != NULL)) {
zval **var = active_memory->addresses[i];
fprintf(stderr, "Obs var %d (%p => %p), type=%u, refcnt=%u; ", i, var, *var, Z_TYPE_PP(var), Z_REFCOUNT_PP(var));
switch (Z_TYPE_PP(var)) {
case IS_NULL: fprintf(stderr, "value=NULL\n"); break;
case IS_LONG: fprintf(stderr, "value=%ld\n", Z_LVAL_PP(var)); break;
case IS_DOUBLE: fprintf(stderr, "value=%E\n", Z_DVAL_PP(var)); break;
case IS_BOOL: fprintf(stderr, "value=(bool)%d\n", Z_BVAL_PP(var)); break;
case IS_ARRAY: fprintf(stderr, "value=array(%p), %d elements\n", Z_ARRVAL_PP(var), zend_hash_num_elements(Z_ARRVAL_PP(var))); break;
case IS_OBJECT: fprintf(stderr, "value=object(%u), %s\n", Z_OBJ_HANDLE_PP(var), Z_OBJCE_PP(var)->name); break;
case IS_STRING: fprintf(stderr, "value=%*s (%p)\n", Z_STRLEN_PP(var), Z_STRVAL_PP(var), Z_STRVAL_PP(var)); break;
case IS_RESOURCE: fprintf(stderr, "value=(resource)%ld\n", Z_LVAL_PP(var)); break;
default: fprintf(stderr, "\n"); break;
}
}
}
fprintf(stderr, "End of the dump of the memory frame %p\n", active_memory);
}
int ZEND_FASTCALL phalcon_memory_restore_stack(const char *func TSRMLS_DC)
{
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
if (unlikely(phalcon_globals_ptr->active_memory == NULL)) {
fprintf(stderr, "WARNING: calling phalcon_memory_restore_stack() without an active memory frame!\n");
phalcon_print_backtrace();
return FAILURE;
}
if (unlikely(phalcon_globals_ptr->active_memory->func != func)) {
fprintf(stderr, "Trying to free someone else's memory frame!\n");
fprintf(stderr, "The frame was created by %s\n", phalcon_globals_ptr->active_memory->func);
fprintf(stderr, "Calling function: %s\n", func);
phalcon_print_backtrace();
}
phalcon_globals_ptr->active_memory->func = NULL;
phalcon_memory_restore_stack_common(phalcon_globals_ptr TSRMLS_CC);
return SUCCESS;
}
void ZEND_FASTCALL phalcon_memory_grow_stack(const char *func TSRMLS_DC) {
phalcon_memory_entry *entry = phalcon_memory_grow_stack_common(PHALCON_VGLOBAL);
entry->func = func;
}
#else
void ZEND_FASTCALL phalcon_memory_grow_stack(TSRMLS_D) {
phalcon_memory_grow_stack_common(PHALCON_VGLOBAL);
}
int ZEND_FASTCALL phalcon_memory_restore_stack(TSRMLS_D) {
phalcon_memory_restore_stack_common(PHALCON_VGLOBAL TSRMLS_CC);
return SUCCESS;
}
#endif
static void phalcon_reallocate_memory(phalcon_memory_entry *frame)
{
void *buf = perealloc(frame->addresses, sizeof(zval **) * (frame->capacity + 16), unlikely(frame->prev == NULL));
if (likely(buf != NULL)) {
frame->capacity += 16;
frame->addresses = buf;
}
else {
zend_error(E_CORE_ERROR, "Memory allocation failed");
}
}
static void phalcon_reallocate_hmemory(phalcon_memory_entry *frame)
{
void *buf = perealloc(frame->hash_addresses, sizeof(zval **) * (frame->hash_capacity + 4), unlikely(frame->prev == NULL));
if (likely(buf != NULL)) {
frame->hash_capacity += 4;
frame->hash_addresses = buf;
}
else {
zend_error(E_CORE_ERROR, "Memory allocation failed");
}
}
static inline void phalcon_do_memory_observe(zval **var, phalcon_memory_entry *frame)
{
#ifndef PHALCON_RELEASE
if (unlikely(frame == NULL)) {
TSRMLS_FETCH();
fprintf(stderr, "PHALCON_MM_GROW() must be called before using any of MM functions or macros!");
phalcon_memory_grow_stack("N/A" TSRMLS_CC);
frame = PHALCON_GLOBAL(active_memory);
ASSUME(frame != NULL);
}
#endif
if (unlikely(frame->pointer == frame->capacity)) {
phalcon_reallocate_memory(frame);
}
frame->addresses[frame->pointer] = var;
++frame->pointer;
}
void ZEND_FASTCALL phalcon_memory_observe(zval **var TSRMLS_DC) {
phalcon_do_memory_observe(var, PHALCON_GLOBAL(active_memory));
*var = NULL; /* In case an exception or error happens BEFORE the observed variable gets initialized */
}
void ZEND_FASTCALL phalcon_memory_alloc(zval **var TSRMLS_DC) {
phalcon_do_memory_observe(var, PHALCON_GLOBAL(active_memory));
ALLOC_INIT_ZVAL(*var);
}
void ZEND_FASTCALL phalcon_memory_alloc_pnull(zval **var TSRMLS_DC) {
phalcon_memory_entry *active_memory = PHALCON_GLOBAL(active_memory);
#ifndef PHALCON_RELEASE
if (unlikely(active_memory == NULL)) {
TSRMLS_FETCH();
fprintf(stderr, "PHALCON_MM_GROW() must be called before using any of MM functions or macros!");
phalcon_memory_grow_stack("N/A" TSRMLS_CC);
active_memory = PHALCON_GLOBAL(active_memory);
ASSUME(active_memory != NULL);
}
#endif
phalcon_do_memory_observe(var, active_memory);
ALLOC_INIT_ZVAL(*var);
if (active_memory->hash_pointer == active_memory->hash_capacity) {
phalcon_reallocate_hmemory(active_memory);
}
active_memory->hash_addresses[active_memory->hash_pointer] = var;
++active_memory->hash_pointer;
}
void ZEND_FASTCALL phalcon_memory_remove(zval **var TSRMLS_DC) {
zval_ptr_dtor(var);
*var = NULL;
}
int ZEND_FASTCALL phalcon_clean_restore_stack(TSRMLS_D) {
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
while (phalcon_globals_ptr->active_memory != NULL) {
phalcon_memory_restore_stack_common(phalcon_globals_ptr TSRMLS_CC);
}
return SUCCESS;
}
void ZEND_FASTCALL phalcon_copy_ctor(zval *destination, zval *origin) {
if (Z_REFCOUNT_P(origin) > 1) {
zval_copy_ctor(destination);
} else {
ZVAL_NULL(origin);
}
}
static void phalcon_create_symbol_table(TSRMLS_D) {
phalcon_symbol_table *entry;
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
HashTable *symbol_table;
#ifndef PHALCON_RELEASE
if (!phalcon_globals_ptr->active_memory) {
fprintf(stderr, "ERROR: Trying to create a virtual symbol table without a memory frame");
phalcon_print_backtrace();
return;
}
#endif
entry = (phalcon_symbol_table *) emalloc(sizeof(phalcon_symbol_table));
entry->scope = phalcon_globals_ptr->active_memory;
entry->symbol_table = EG(active_symbol_table);
entry->prev = phalcon_globals_ptr->active_symbol_table;
phalcon_globals_ptr->active_symbol_table = entry;
ALLOC_HASHTABLE(symbol_table);
zend_hash_init(symbol_table, 0, NULL, ZVAL_PTR_DTOR, 0);
EG(active_symbol_table) = symbol_table;
}
static void phalcon_clean_symbol_tables(TSRMLS_D) {
/*unsigned int i;
if (PHALCON_GLOBAL(symbol_tables)) {
for (i = PHALCON_GLOBAL(number_symbol_tables); i > 0; i--) {
EG(active_symbol_table) = PHALCON_GLOBAL(symbol_tables)[i - 1];
}
efree(PHALCON_GLOBAL(symbol_tables));
PHALCON_GLOBAL(symbol_tables) = NULL;
}*/
}
static int phalcon_set_symbol(zval *key_name, zval *value TSRMLS_DC) {
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
}
if (EG(active_symbol_table)) {
if (Z_TYPE_P(key_name) == IS_STRING) {
Z_ADDREF_P(value);
zend_hash_update(EG(active_symbol_table), Z_STRVAL_P(key_name), Z_STRLEN_P(key_name) + 1, &value, sizeof(zval *), NULL);
if (EG(exception)) {
return FAILURE;
}
}
}
return SUCCESS;
}
static int phalcon_set_symbol_str(char *key_name, unsigned int key_length, zval *value TSRMLS_DC) {
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
}
if (&EG(symbol_table)) {
Z_ADDREF_P(value);
zend_hash_update(&EG(symbol_table), key_name, key_length, &value, sizeof(zval *), NULL);
if (EG(exception)) {
return FAILURE;
}
}
return SUCCESS;
}
#ifndef PHALCON_RELEASE
#if defined(linux)
#include <execinfo.h>
#include <Zend/zend.h>
#include <ext/standard/php_smart_str.h>
void *backtrace_buf[4096];
static void phalcon_print_backtrace(void)
{
int i;
int stack_size = backtrace(backtrace_buf, sizeof(backtrace_buf) / sizeof(void*));
char **stack_symbols = backtrace_symbols(backtrace_buf, stack_size);
char buf[50];
smart_str s;
s.c = NULL;
for (i = 0; i < stack_size; ++i) {
snprintf(buf, sizeof(buf), "#%d %p [", i, backtrace_buf[i]);
smart_str_appends(&s, buf);
smart_str_appends(&s, stack_symbols[i]);
smart_str_appends(&s, "]\n");
}
smart_str_0(&s);
fprintf(stderr, "%s\n", s.c);
smart_str_free(&s);
}
#else
static void phalcon_print_backtrace(void)
{
}
#endif /* defined(linux) */
#else
/* Release mode */
static void phalcon_print_backtrace(void)
{
}
#endif /* PHALCON_RELEASE */
#include <Zend/zend_API.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_execute.h>
static int phalcon_has_constructor_ce(zend_class_entry *ce) {
while (ce) {
if (ce->constructor) {
return 1;
}
ce = ce->parent;
}
return 0;
}
static int phalcon_has_constructor(const zval *object TSRMLS_DC){
return phalcon_has_constructor_ce(Z_OBJCE_P(object));
}
static int phalcon_call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zval **retval_ptr_ptr, zend_uint param_count, zval *params[] TSRMLS_DC) {
zval ***params_array = NULL;
zval **static_params_array[10];
zval ***params_ptr;
zval *local_retval_ptr = NULL;
zend_uint i;
int ex_retval;
zend_fcall_info fci;
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
if (retval_ptr_ptr && *retval_ptr_ptr) {
zval_ptr_dtor(retval_ptr_ptr);
*retval_ptr_ptr = NULL;
}
assert(retval_ptr != NULL);
phalcon_globals_ptr->recursive_lock++;
if (unlikely(phalcon_globals_ptr->recursive_lock > 2048)) {
ex_retval = FAILURE;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Maximum recursion depth exceeded");
} else {
if (param_count) {
if (unlikely(param_count > 10)) {
params_array = (zval ***) emalloc(param_count * sizeof(zval**));
params_ptr = params_array;
for (i = 0; i < param_count; i++) {
params_array[i] = &params[i];
}
} else {
params_ptr = static_params_array;
for (i = 0; i < param_count; i++) {
static_params_array[i] = &params[i];
}
}
}
else {
params_ptr = NULL;
}
fci.size = sizeof(fci);
fci.function_table = function_table;
fci.object_ptr = object_pp ? *object_pp : NULL;
fci.function_name = function_name;
fci.retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &local_retval_ptr;
fci.param_count = param_count;
fci.params = params_ptr;
fci.no_separation = 1;
fci.symbol_table = NULL;
ex_retval = PHALCON_ZEND_CALL_FUNCTION_WRAPPER(&fci, NULL TSRMLS_CC);
if (local_retval_ptr) {
COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
}
else if (!retval_ptr_ptr) {
INIT_ZVAL(*retval_ptr);
}
if (unlikely(params_array != NULL)) {
efree(params_array);
}
}
phalcon_globals_ptr->recursive_lock--;
return ex_retval;
}
static void phalcon_check_return_value(zval *return_value) {
#ifndef PHALCON_RELEASE
int valid_return_value = 1;
assert(return_value != NULL);
if (Z_REFCOUNT_P(return_value) > 1) {
valid_return_value = 0;
fprintf(stderr, "return_value has %u references, expect crashes!\n", Z_REFCOUNT_P(return_value));
} else if (Z_TYPE_P(return_value) > IS_BOOL) {
valid_return_value = 0;
fprintf(stderr, "return_value is of complex type (%d), expect memory leaks (refcnt=%u)!\n", Z_TYPE_P(return_value), Z_REFCOUNT_P(return_value));
}
if (!valid_return_value) {
phalcon_print_backtrace();
abort();
}
#endif
}
static int phalcon_call_func_vparams(zval *return_value, zval **return_value_ptr, zval *func TSRMLS_DC, int param_count, va_list ap)
{
zval **params_ptr, **params = NULL;
zval *static_params[10];
int free_params = 0, i, status, caller_wants_result = 1;
if (!return_value) {
ALLOC_INIT_ZVAL(return_value);
caller_wants_result = 0;
}
else {
phalcon_check_return_value(return_value);
}
if (param_count < 0) {
params = va_arg(ap, zval**);
param_count = -param_count;
params_ptr = params;
}
else if (param_count > 0 && param_count <= 10) {
params_ptr = static_params;
for (i=0; i<param_count; ++i) {
static_params[i] = va_arg(ap, zval*);
}
}
else if (unlikely(param_count > 10)) {
free_params = 1;
params = (zval**)emalloc(param_count * sizeof(zval*));
params_ptr = params;
for (i=0; i<param_count; ++i) {
params[i] = va_arg(ap, zval*);
}
}
else {
params_ptr = NULL;
}
status = phalcon_call_user_function(EG(function_table), NULL, func, return_value, return_value_ptr, param_count, params_ptr TSRMLS_CC);
if (unlikely(free_params)) {
efree(params);
}
if (status == FAILURE && !EG(exception)) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s()", Z_STRVAL_P(func));
}
else if (EG(exception)) {
status = FAILURE;
}
if (!caller_wants_result) {
zval_ptr_dtor(&return_value);
}
return status;
}
static int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, va_list ap) {
int i, status, free_params = -0, caller_wants_result = 1;
zend_class_entry *ce, *active_scope = NULL;
zval **params_ptr, **params = NULL;
zval *static_params[10];
if (unlikely(Z_TYPE_P(object) != IS_OBJECT)) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to method %s() on a non object", method_name);
return FAILURE;
}
if (!return_value) {
ALLOC_INIT_ZVAL(return_value);
caller_wants_result = 0;
}
else {
phalcon_check_return_value(return_value);
}
if (param_count < 0) {
params = va_arg(ap, zval**);
param_count = -param_count;
params_ptr = params;
}
else if (param_count > 0 && param_count <= 10) {
params_ptr = static_params;
for (i=0; i<param_count; ++i) {
static_params[i] = va_arg(ap, zval*);
}
}
else if (unlikely(param_count > 10)) {
free_params = 1;
params = (zval**)emalloc(param_count * sizeof(zval*));
params_ptr = params;
for (i=0; i<param_count; ++i) {
params[i] = va_arg(ap, zval*);
}
}
else {
params_ptr = NULL;
}
ce = Z_OBJCE_P(object);
active_scope = EG(scope);
EG(scope) = ce;
status = phalcon_alt_call_user_method(ce, &object, (char*)method_name, method_len, return_value, return_value_ptr, param_count, params_ptr, method_key TSRMLS_CC);
EG(scope) = active_scope;
if (unlikely(free_params)) {
efree(params);
}
if (status == FAILURE && !EG(exception)) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined method %s::%s()", ce->name, method_name);
}
else if (EG(exception)) {
status = FAILURE;
}
if (!caller_wants_result) {
zval_ptr_dtor(&return_value);
}
return status;
}
static int phalcon_call_static_zval_str_func_vparams(zval *return_value, zval **return_value_ptr, zval *mixed_name, const char *method_name, int method_len TSRMLS_DC, int param_count, va_list ap) {
zval **params_ptr, **params = NULL, *fn;
zval *static_params[10];
int free_params = 0, i, status, caller_wants_result = 1;
if (!return_value) {
ALLOC_INIT_ZVAL(return_value);
caller_wants_result = 0;
}
else {
phalcon_check_return_value(return_value);
}
Z_ADDREF_P(mixed_name);
MAKE_STD_ZVAL(fn);
array_init_size(fn, 2);
add_next_index_zval(fn, mixed_name);
add_next_index_stringl(fn, method_name, method_len, 1);
if (param_count < 0) {
params = va_arg(ap, zval**);
param_count = -param_count;
params_ptr = params;
}
else if (param_count > 0 && param_count <= 10) {
params_ptr = static_params;
for (i=0; i<param_count; ++i) {
static_params[i] = va_arg(ap, zval*);
}
}
else if (unlikely(param_count > 10)) {
free_params = 1;
params = (zval**)emalloc(param_count * sizeof(zval*));
params_ptr = params;
for (i=0; i<param_count; ++i) {
params[i] = va_arg(ap, zval*);
}
}
else {
params_ptr = NULL;
}
status = phalcon_call_user_function(EG(function_table), NULL, fn, return_value, return_value_ptr, param_count, params_ptr TSRMLS_CC);
if (unlikely(free_params)) {
efree(params);
}
if (status == FAILURE && !EG(exception)) {
if (Z_TYPE_P(mixed_name) == IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s::%s()", Z_STRVAL_P(mixed_name), method_name);
} else {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function not-callable::%s()", method_name);
}
}
else if (EG(exception)) {
status = FAILURE;
}
zval_ptr_dtor(&fn);
if (!caller_wants_result) {
zval_ptr_dtor(&return_value);
}
return status;
}
static int phalcon_call_func_params(zval *return_value, zval **return_value_ptr, const char *func_name, int func_length TSRMLS_DC, int param_count, ...) {
zval fn;
int status;
va_list ap;
INIT_ZVAL(fn);
ZVAL_STRINGL(&fn, func_name, func_length, 0);
va_start(ap, param_count);
status = phalcon_call_func_vparams(return_value, return_value_ptr, &fn TSRMLS_CC, param_count, ap);
va_end(ap);
return status;
}
static int phalcon_call_method_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, ...) {
int status;
va_list ap;
va_start(ap, param_count);
status = phalcon_call_method_vparams(return_value, return_value_ptr, object, method_name, method_len, method_key TSRMLS_CC, param_count, ap);
va_end(ap);
return status;
}
static int phalcon_call_method_zval_params(zval *return_value, zval **return_value_ptr, zval *object, zval *method TSRMLS_DC, int param_count, ...)
{
if (likely(Z_TYPE_P(method) == IS_STRING)) {
va_list ap;
int status;
char *m = Z_STRVAL_P(method);
va_start(ap, param_count);
status = phalcon_call_method_vparams(return_value, return_value_ptr, object, m, Z_STRLEN_P(method), (IS_INTERNED(m) ? INTERNED_HASH(m) : 0) TSRMLS_CC, param_count, ap);
va_end(ap);
return status;
}
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Method name must be string");
return FAILURE;
}
static int phalcon_call_static_func_params(zval *return_value, zval **return_value_ptr, const char *class_name, int class_length, const char *method_name, int method_length TSRMLS_DC, int param_count, ...) {
zval cls;
va_list ap;
int status;
INIT_ZVAL(cls);
ZVAL_STRINGL(&cls, class_name, class_length, 0);
va_start(ap, param_count);
status = phalcon_call_static_zval_str_func_vparams(return_value, return_value_ptr, &cls, method_name, method_length TSRMLS_CC, param_count, ap);
va_end(ap);
assert(!Z_ISREF_P(&cls));
assert(Z_REFCOUNT_P(&cls) == 1);
return status;
}
static int phalcon_call_parent_func_params(zval *return_value, zval **return_value_ptr, zval *object, zend_class_entry *active_class_ce, const char *method_name, int method_len TSRMLS_DC, int param_count, ...) {
zval cls;
int status;
zend_class_entry *active_scope;
va_list ap;
if (object) {
active_scope = EG(scope);
EG(scope) = active_class_ce;
}
INIT_ZVAL(cls);
ZVAL_STRING(&cls, "parent", 0);
va_start(ap, param_count);
status = phalcon_call_static_zval_str_func_vparams(return_value, return_value_ptr, &cls, method_name, method_len TSRMLS_CC, param_count, ap);
va_end(ap);
if (object) {
EG(scope) = active_scope;
}
return status;
}
static int phalcon_call_self_func_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len TSRMLS_DC, int param_count, ...) {
int status;
zend_class_entry *active_scope;
va_list ap;
zval cls;
if (object) {
active_scope = EG(scope);
EG(scope) = Z_OBJCE_P(object);
}
INIT_ZVAL(cls);
ZVAL_STRING(&cls, "self", 0);
va_start(ap, param_count);
status = phalcon_call_static_zval_str_func_vparams(return_value, return_value_ptr, &cls, method_name, method_len TSRMLS_CC, param_count, ap);
va_end(ap);
if (object) {
EG(scope) = active_scope;
}
return status;
}
static int phalcon_call_static_zval_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, zval *method TSRMLS_DC, int param_count, ...) {
if (likely(Z_TYPE_P(method) == IS_STRING)) {
int status;
va_list ap;
va_start(ap, param_count);
status = phalcon_call_static_zval_str_func_vparams(return_value, return_value_ptr, mixed_name, Z_STRVAL_P(method), Z_STRLEN_P(method) TSRMLS_CC, param_count, ap);
va_end(ap);
return status;
}
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function not-callable::not-callable()");
return FAILURE;
}
static int phalcon_call_static_zval_str_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, const char *method_name, int method_len TSRMLS_DC, int param_count, ...) {
int status;
va_list ap;
va_start(ap, param_count);
status = phalcon_call_static_zval_str_func_vparams(return_value, return_value_ptr, mixed_name, method_name, method_len TSRMLS_CC, param_count, ap);
va_end(ap);
return status;
}
static int phalcon_call_user_func_array(zval *return_value, zval *handler, zval *params TSRMLS_DC){
int status = phalcon_call_user_func_array_noex(return_value, handler, params TSRMLS_CC);
if (EG(exception)) {
status = FAILURE;
}
return status;
}
static int phalcon_call_user_func_array_noex(zval *return_value, zval *handler, zval *params TSRMLS_DC){
zval *retval_ptr = NULL;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
char *is_callable_error = NULL;
int status = FAILURE;
if (params && Z_TYPE_P(params) != IS_ARRAY) {
ZVAL_NULL(return_value);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for phalcon_call_user_func_array_noex()");
return FAILURE;
}
if (zend_fcall_info_init(handler, 0, &fci, &fci_cache, NULL, &is_callable_error TSRMLS_CC) == SUCCESS) {
if (is_callable_error) {
zend_error(E_STRICT, "%s", is_callable_error);
efree(is_callable_error);
}
status = SUCCESS;
} else {
if (is_callable_error) {
zend_error(E_WARNING, "%s", is_callable_error);
efree(is_callable_error);
} else {
status = SUCCESS;
}
}
if (status == SUCCESS) {
zend_fcall_info_args(&fci, params TSRMLS_CC);
fci.retval_ptr_ptr = &retval_ptr;
if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && fci.retval_ptr_ptr && *fci.retval_ptr_ptr) {
COPY_PZVAL_TO_ZVAL(*return_value, *fci.retval_ptr_ptr);
}
if (fci.params) {
efree(fci.params);
}
}
if (EG(exception)) {
status = SUCCESS;
}
return status;
}
#if PHP_VERSION_ID <= 50309
static int phalcon_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC) {
zend_uint i;
zval **original_return_value;
HashTable *calling_symbol_table;
zend_op_array *original_op_array;
zend_op **original_opline_ptr;
zend_class_entry *current_scope;
zend_class_entry *current_called_scope;
zend_class_entry *calling_scope = NULL;
zend_class_entry *called_scope = NULL;
zval *current_this;
zend_execute_data execute_data;
*fci->retval_ptr_ptr = NULL;
if (!EG(active)) {
return FAILURE; /* executor is already inactive */
}
if (EG(exception)) {
return FAILURE; /* we would result in an instable executor otherwise */
}
switch (fci->size) {
case sizeof(zend_fcall_info):
break; /* nothing to do currently */
default:
zend_error(E_ERROR, "Corrupted fcall_info provided to phalcon_call_function()");
break;
}
/* Initialize execute_data */
if (EG(current_execute_data)) {
execute_data = *EG(current_execute_data);
EX(op_array) = NULL;
EX(opline) = NULL;
EX(object) = NULL;
} else {
/* This only happens when we're called outside any execute()'s
* It shouldn't be strictly necessary to NULL execute_data out,
* but it may make bugs easier to spot
*/
memset(&execute_data, 0, sizeof(zend_execute_data));
}
if (!fci_cache || !fci_cache->initialized) {
zend_fcall_info_cache fci_cache_local;
char *callable_name;
char *error = NULL;
if (!fci_cache) {
fci_cache = &fci_cache_local;
}
if (!zend_is_callable_ex(fci->function_name, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC)) {
if (error) {
zend_error(E_WARNING, "Invalid callback %s, %s", callable_name, error);
efree(error);
}
if (callable_name) {
efree(callable_name);
}
return FAILURE;
} else {
if (error) {
/* Capitalize the first latter of the error message */
if (error[0] >= 'a' && error[0] <= 'z') {
error[0] += ('A' - 'a');
}
zend_error(E_STRICT, "%s", error);
efree(error);
}
}
efree(callable_name);
}
EX(function_state).function = fci_cache->function_handler;
calling_scope = fci_cache->calling_scope;
called_scope = fci_cache->called_scope;
fci->object_ptr = fci_cache->object_ptr;
EX(object) = fci->object_ptr;
if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
(!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
return FAILURE;
}
if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", EX(function_state).function->common.scope->name, EX(function_state).function->common.function_name);
return FAILURE;
}
ZEND_VM_STACK_GROW_IF_NEEDED(fci->param_count + 1);
for (i = 0; i < fci->param_count; i++) {
zval *param;
if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION
&& (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0
&& !ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)
&& PZVAL_IS_REF(*fci->params[i])) {
ALLOC_ZVAL(param);
*param = **(fci->params[i]);
INIT_PZVAL(param);
zval_copy_ctor(param);
} else if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)
&& !PZVAL_IS_REF(*fci->params[i])) {
if (Z_REFCOUNT_PP(fci->params[i]) > 1) {
zval *new_zval;
if (fci->no_separation &&
!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == EG(argument_stack)->top)) {
/* hack to clean up the stack */
zend_vm_stack_push_nocheck((void *) (zend_uintptr_t)i TSRMLS_CC);
#if PHP_VERSION_ID <= 50500
zend_vm_stack_clear_multiple(TSRMLS_C);
#else
zend_vm_stack_clear_multiple(0 TSRMLS_C);
#endif
}
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
i+1,
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
EX(function_state).function->common.scope ? "::" : "",
EX(function_state).function->common.function_name);
return FAILURE;
}
ALLOC_ZVAL(new_zval);
*new_zval = **fci->params[i];
zval_copy_ctor(new_zval);
Z_SET_REFCOUNT_P(new_zval, 1);
Z_DELREF_PP(fci->params[i]);
*fci->params[i] = new_zval;
}
Z_ADDREF_PP(fci->params[i]);
Z_SET_ISREF_PP(fci->params[i]);
param = *fci->params[i];
} else if (*fci->params[i] != &EG(uninitialized_zval)) {
Z_ADDREF_PP(fci->params[i]);
param = *fci->params[i];
} else {
ALLOC_ZVAL(param);
*param = **(fci->params[i]);
INIT_PZVAL(param);
}
zend_vm_stack_push_nocheck(param TSRMLS_CC);
}
EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C);
zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
current_scope = EG(scope);
EG(scope) = calling_scope;
current_this = EG(This);
current_called_scope = EG(called_scope);
if (called_scope) {
EG(called_scope) = called_scope;
} else {
if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
EG(called_scope) = NULL;
}
}
if (fci->object_ptr) {
if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
EG(This) = NULL;
} else {
EG(This) = fci->object_ptr;
if (!PZVAL_IS_REF(EG(This))) {
Z_ADDREF_P(EG(This)); /* For $this pointer */
} else {
zval *this_ptr;
ALLOC_ZVAL(this_ptr);
*this_ptr = *EG(This);
INIT_PZVAL(this_ptr);
zval_copy_ctor(this_ptr);
EG(This) = this_ptr;
}
}
} else {
EG(This) = NULL;
}
EX(prev_execute_data) = EG(current_execute_data);
EG(current_execute_data) = &execute_data;
if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
calling_symbol_table = EG(active_symbol_table);
EG(scope) = EX(function_state).function->common.scope;
if (fci->symbol_table) {
EG(active_symbol_table) = fci->symbol_table;
} else {
EG(active_symbol_table) = NULL;
}
original_return_value = EG(return_value_ptr_ptr);
original_op_array = EG(active_op_array);
EG(return_value_ptr_ptr) = fci->retval_ptr_ptr;
EG(active_op_array) = (zend_op_array *) EX(function_state).function;
original_opline_ptr = EG(opline_ptr);
zend_execute(EG(active_op_array) TSRMLS_CC);
if (!fci->symbol_table && EG(active_symbol_table)) {
if (EG(symtable_cache_ptr)>=EG(symtable_cache_limit)) {
zend_hash_destroy(EG(active_symbol_table));
FREE_HASHTABLE(EG(active_symbol_table));
} else {
/* clean before putting into the cache, since clean
could call dtors, which could use cached hash */
zend_hash_clean(EG(active_symbol_table));
*(++EG(symtable_cache_ptr)) = EG(active_symbol_table);
}
}
EG(active_symbol_table) = calling_symbol_table;
EG(active_op_array) = original_op_array;
EG(return_value_ptr_ptr)=original_return_value;
EG(opline_ptr) = original_opline_ptr;
} else if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
if (EX(function_state).function->common.scope) {
EG(scope) = EX(function_state).function->common.scope;
}
((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
/* We shouldn't fix bad extensions here,
because it can break proper ones (Bug #34045)
if (!EX(function_state).function->common.return_reference)
{
INIT_PZVAL(*fci->retval_ptr_ptr);
}*/
if (EG(exception) && fci->retval_ptr_ptr) {
zval_ptr_dtor(fci->retval_ptr_ptr);
*fci->retval_ptr_ptr = NULL;
}
if (call_via_handler) {
/* We must re-initialize function again */
fci_cache->initialized = 0;
}
} else {
ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
if (fci->object_ptr) {
Z_OBJ_HT_P(fci->object_ptr)->call_method(EX(function_state).function->common.function_name, fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
} else {
zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
return FAILURE;
}
if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
efree(EX(function_state).function->common.function_name);
}
efree(EX(function_state).function);
if (EG(exception) && fci->retval_ptr_ptr) {
zval_ptr_dtor(fci->retval_ptr_ptr);
*fci->retval_ptr_ptr = NULL;
}
}
#if PHP_VERSION_ID <= 50500
zend_vm_stack_clear_multiple(TSRMLS_C);
#else
zend_vm_stack_clear_multiple(0 TSRMLS_C);
#endif
if (EG(This)) {
zval_ptr_dtor(&EG(This));
}
EG(called_scope) = current_called_scope;
EG(scope) = current_scope;
EG(This) = current_this;
EG(current_execute_data) = EX(prev_execute_data);
if (EG(exception)) {
phalcon_throw_exception_internal(NULL TSRMLS_CC);
}
return SUCCESS;
}
#endif
#include <ext/standard/php_array.h>
static int phalcon_array_isset_fetch(zval **fetched, const zval *arr, zval *index) {
HashTable *h;
zval **val;
int result;
if (Z_TYPE_P(arr) != IS_ARRAY) {
return 0;
}
h = Z_ARRVAL_P(arr);
switch (Z_TYPE_P(index)) {
case IS_NULL:
result = phalcon_hash_find(h, ZEND_STRS(""), (void**)&val);
break;
case IS_DOUBLE:
result = zend_hash_index_find(h, (ulong)Z_DVAL_P(index), (void**)&val);
break;
case IS_LONG:
case IS_BOOL:
case IS_RESOURCE:
result = zend_hash_index_find(h, Z_LVAL_P(index), (void**)&val);
break;
case IS_STRING:
result = zend_symtable_find(h, (Z_STRLEN_P(index) ? Z_STRVAL_P(index) : ""), Z_STRLEN_P(index)+1, (void**)&val);
break;
default:
zend_error(E_WARNING, "Illegal offset type");
return 0;
}
if (result == SUCCESS) {
*fetched = *val;
return 1;
}
return 0;
}
static int phalcon_array_isset_quick_string_fetch(zval **fetched, zval *arr, const char *index, uint index_length, ulong key) {
zval **zv;
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
if (phalcon_hash_quick_find(Z_ARRVAL_P(arr), index, index_length, key, (void**) &zv) == SUCCESS) {
*fetched = *zv;
return 1;
}
}
return 0;
}
static int phalcon_array_isset_long_fetch(zval **fetched, zval *arr, ulong index) {
zval **zv;
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
if (zend_hash_index_find(Z_ARRVAL_P(arr), index, (void**)&zv) == SUCCESS) {
*fetched = *zv;
return 1;
}
}
return 0;
}
static int phalcon_array_isset(const zval *arr, zval *index) {
HashTable *h;
if (Z_TYPE_P(arr) != IS_ARRAY) {
return 0;
}
h = Z_ARRVAL_P(arr);
switch (Z_TYPE_P(index)) {
case IS_NULL:
return phalcon_hash_exists(h, ZEND_STRS(""));
case IS_DOUBLE:
return zend_hash_index_exists(h, (ulong)Z_DVAL_P(index));
case IS_BOOL:
case IS_LONG:
case IS_RESOURCE:
return zend_hash_index_exists(h, Z_LVAL_P(index));
case IS_STRING:
return zend_symtable_exists(h, Z_STRVAL_P(index), Z_STRLEN_P(index)+1);
default:
zend_error(E_WARNING, "Illegal offset type");
return 0;
}
}
static int phalcon_array_isset_quick_string(const zval *arr, const char *index, uint index_length, ulong key) {
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
return zend_hash_quick_exists(Z_ARRVAL_P(arr), index, index_length, key);
}
return 0;
}
static int phalcon_array_isset_long(const zval *arr, ulong index) {
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
return zend_hash_index_exists(Z_ARRVAL_P(arr), index);
}
return 0;
}
static int phalcon_array_unset(zval **arr, zval *index, int flags) {
HashTable *ht;
if (Z_TYPE_PP(arr) != IS_ARRAY) {
return FAILURE;
}
if ((flags & PH_SEPARATE) == PH_SEPARATE) {
SEPARATE_ZVAL(arr);
}
ht = Z_ARRVAL_PP(arr);
switch (Z_TYPE_P(index)) {
case IS_NULL:
return (zend_hash_del(ht, "", 1) == SUCCESS);
case IS_DOUBLE:
return (zend_hash_index_del(ht, (ulong)Z_DVAL_P(index)) == SUCCESS);
case IS_LONG:
case IS_BOOL:
case IS_RESOURCE:
return (zend_hash_index_del(ht, Z_LVAL_P(index)) == SUCCESS);
case IS_STRING:
return (zend_symtable_del(ht, Z_STRVAL_P(index), Z_STRLEN_P(index)+1) == SUCCESS);
default:
zend_error(E_WARNING, "Illegal offset type");
return 0;
}
}
static int phalcon_array_unset_string(zval **arr, const char *index, uint index_length, int flags) {
if (Z_TYPE_PP(arr) != IS_ARRAY) {
return FAILURE;
}
if ((flags & PH_SEPARATE) == PH_SEPARATE) {
SEPARATE_ZVAL(arr);
}
return zend_hash_del(Z_ARRVAL_PP(arr), index, index_length);
}
static int phalcon_array_unset_long(zval **arr, ulong index, int flags) {
if (Z_TYPE_PP(arr) != IS_ARRAY) {
return FAILURE;
}
if ((flags & PH_SEPARATE) == PH_SEPARATE) {
SEPARATE_ZVAL(arr);
}
return zend_hash_index_del(Z_ARRVAL_PP(arr), index);
}
static int phalcon_array_append(zval **arr, zval *value, int flags) {
if (Z_TYPE_PP(arr) != IS_ARRAY) {
zend_error(E_WARNING, "Cannot use a scalar value as an array");
return FAILURE;
}
if ((flags & PH_SEPARATE) == PH_SEPARATE) {
SEPARATE_ZVAL(arr);
}
Z_ADDREF_P(value);
return add_next_index_zval(*arr, value);
}
static int phalcon_array_update_zval(zval **arr, zval *index, zval **value, int flags) {
HashTable *ht;
if (Z_TYPE_PP(arr) != IS_ARRAY) {
zend_error(E_WARNING, "Cannot use a scalar value as an array");
return FAILURE;
}
if ((flags & PH_CTOR) == PH_CTOR) {
zval *new_zv;
Z_DELREF_PP(value);
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, *value);
*value = new_zv;
zval_copy_ctor(new_zv);
}
if ((flags & PH_SEPARATE) == PH_SEPARATE) {
SEPARATE_ZVAL(arr);
}
if ((flags & PH_COPY) == PH_COPY) {
Z_ADDREF_PP(value);
}
ht = Z_ARRVAL_PP(arr);
switch (Z_TYPE_P(index)) {
case IS_NULL:
return zend_symtable_update(ht, "", 1, value, sizeof(zval*), NULL);
case IS_DOUBLE:
return zend_hash_index_update(ht, (ulong)Z_DVAL_P(index), value, sizeof(zval*), NULL);
case IS_LONG:
case IS_BOOL:
case IS_RESOURCE:
return zend_hash_index_update(ht, Z_LVAL_P(index), value, sizeof(zval*), NULL);
case IS_STRING:
return zend_symtable_update(ht, Z_STRVAL_P(index), Z_STRLEN_P(index)+1, value, sizeof(zval*), NULL);
default:
zend_error(E_WARNING, "Illegal offset type");
return FAILURE;
}
}
static int phalcon_array_update_quick_string(zval **arr, const char *index, uint index_length, ulong key, zval **value, int flags){
if (Z_TYPE_PP(arr) != IS_ARRAY) {
zend_error(E_WARNING, "Cannot use a scalar value as an array");
return FAILURE;
}
if ((flags & PH_CTOR) == PH_CTOR) {
zval *new_zv;
Z_DELREF_PP(value);
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, *value);
*value = new_zv;
zval_copy_ctor(new_zv);
}
if ((flags & PH_SEPARATE) == PH_SEPARATE) {
SEPARATE_ZVAL(arr);
}
if ((flags & PH_COPY) == PH_COPY) {
Z_ADDREF_PP(value);
}
return zend_hash_quick_update(Z_ARRVAL_PP(arr), index, index_length, key, value, sizeof(zval *), NULL);
}
static int phalcon_array_update_long(zval **arr, ulong index, zval **value, int flags){
if (Z_TYPE_PP(arr) != IS_ARRAY) {
zend_error(E_WARNING, "Cannot use a scalar value as an array");
return FAILURE;
}
if ((flags & PH_CTOR) == PH_CTOR) {
zval *new_zv;
Z_DELREF_PP(value);
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, *value);
*value = new_zv;
zval_copy_ctor(new_zv);
}
if ((flags & PH_SEPARATE) == PH_SEPARATE) {
SEPARATE_ZVAL(arr);
}
if ((flags & PH_COPY) == PH_COPY) {
Z_ADDREF_PP(value);
}
return zend_hash_index_update(Z_ARRVAL_PP(arr), index, value, sizeof(zval *), NULL);
}
static int phalcon_array_fetch(zval **return_value, zval *arr, zval *index, int silent){
zval **zv;
HashTable *ht;
int result;
ulong uidx = 0;
char *sidx = NULL;
if (Z_TYPE_P(arr) == IS_ARRAY) {
ht = Z_ARRVAL_P(arr);
switch (Z_TYPE_P(index)) {
case IS_NULL:
result = phalcon_hash_find(ht, ZEND_STRS(""), (void**) &zv);
sidx = "";
break;
case IS_DOUBLE:
uidx = (ulong)Z_DVAL_P(index);
result = zend_hash_index_find(ht, uidx, (void**) &zv);
break;
case IS_LONG:
case IS_BOOL:
case IS_RESOURCE:
uidx = Z_LVAL_P(index);
result = zend_hash_index_find(ht, uidx, (void**) &zv);
break;
case IS_STRING:
sidx = Z_STRLEN_P(index) ? Z_STRVAL_P(index) : "";
result = zend_symtable_find(ht, Z_STRVAL_P(index), Z_STRLEN_P(index)+1, (void**) &zv);
break;
default:
if (silent == PH_NOISY) {
zend_error(E_WARNING, "Illegal offset type");
}
result = FAILURE;
break;
}
if (result != FAILURE) {
*return_value = *zv;
Z_ADDREF_PP(return_value);
return SUCCESS;
}
if (silent == PH_NOISY) {
if (sidx == NULL) {
zend_error(E_NOTICE, "Undefined index: %ld", uidx);
} else {
zend_error(E_NOTICE, "Undefined index: %s", sidx);
}
}
}
ALLOC_INIT_ZVAL(*return_value);
return FAILURE;
}
static int phalcon_array_fetch_quick_string(zval **return_value, zval *arr, const char *index, uint index_length, ulong key, int silent){
zval **zv;
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
if (phalcon_hash_quick_find(Z_ARRVAL_P(arr), index, index_length, key, (void**) &zv) == SUCCESS) {
*return_value = *zv;
Z_ADDREF_PP(return_value);
return SUCCESS;
}
if (silent == PH_NOISY) {
zend_error(E_NOTICE, "Undefined index: %s", index);
}
}
else {
if (silent == PH_NOISY) {
zend_error(E_NOTICE, "Cannot use a scalar value as an array");
}
}
ALLOC_INIT_ZVAL(*return_value);
return FAILURE;
}
static int phalcon_array_fetch_long(zval **return_value, zval *arr, ulong index, int silent){
zval **zv;
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
if (zend_hash_index_find(Z_ARRVAL_P(arr), index, (void**)&zv) == SUCCESS) {
*return_value = *zv;
Z_ADDREF_PP(return_value);
return SUCCESS;
}
if (silent == PH_NOISY) {
zend_error(E_NOTICE, "Undefined index: %lu", index);
}
}
else {
if (silent == PH_NOISY) {
zend_error(E_NOTICE, "Cannot use a scalar value as an array");
}
}
ALLOC_INIT_ZVAL(*return_value);
return FAILURE;
}
static void phalcon_array_append_multi_2(zval **arr, zval *index, zval *value, int flags){
zval *temp;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp, *arr, index, PH_SILENT);
if (Z_REFCOUNT_P(temp) > 1) {
phalcon_array_update_zval(arr, index, &temp, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp) != IS_ARRAY) {
convert_to_array(temp);
phalcon_array_update_zval(arr, index, &temp, PH_COPY);
}
phalcon_array_append(&temp, value, flags);
zval_ptr_dtor(&temp);
}
}
static void phalcon_array_update_multi_2(zval **arr, zval *index1, zval *index2, zval **value, int flags){
zval *temp;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp) > 1) {
phalcon_array_update_zval(arr, index1, &temp, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp) != IS_ARRAY) {
convert_to_array(temp);
phalcon_array_update_zval(arr, index1, &temp, PH_COPY);
}
phalcon_array_update_zval(&temp, index2, value, flags | PH_COPY);
zval_ptr_dtor(&temp);
}
}
static void phalcon_array_update_string_multi_2(zval **arr, zval *index1, char *index2, uint index2_length, zval **value, int flags){
zval *temp;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp) > 1) {
phalcon_array_update_zval(arr, index1, &temp, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp) != IS_ARRAY) {
convert_to_array(temp);
phalcon_array_update_zval(arr, index1, &temp, PH_COPY);
}
phalcon_array_update_string(&temp, index2, index2_length, value, flags | PH_COPY);
zval_ptr_dtor(&temp);
}
}
static void phalcon_array_update_long_long_multi_2(zval **arr, long index1, long index2, zval **value, int flags){
zval *temp = NULL;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch_long(&temp, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp) > 1) {
phalcon_array_update_long(arr, index1, &temp, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp) != IS_ARRAY) {
convert_to_array(temp);
phalcon_array_update_long(arr, index1, &temp, PH_COPY);
}
phalcon_array_update_long(&temp, index2, value, flags | PH_COPY);
zval_ptr_dtor(&temp);
}
}
static void phalcon_array_update_long_string_multi_2(zval **arr, long index1, char *index2, uint index2_length, zval **value, int flags){
zval *temp;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch_long(&temp, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp) > 1) {
phalcon_array_update_long(arr, index1, &temp, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp) != IS_ARRAY) {
convert_to_array(temp);
phalcon_array_update_long(arr, index1, &temp, PH_COPY);
}
phalcon_array_update_string(&temp, index2, index2_length, value, flags | PH_COPY);
zval_ptr_dtor(&temp);
}
}
static void phalcon_array_update_append_multi_2(zval **arr, zval *index1, zval *value, int flags){
zval *temp;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp) > 1) {
phalcon_array_update_zval(arr, index1, &temp, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp) != IS_ARRAY) {
convert_to_array(temp);
phalcon_array_update_zval(arr, index1, &temp, PH_COPY);
}
phalcon_array_append(&temp, value, flags);
zval_ptr_dtor(&temp);
}
}
static void phalcon_array_update_zval_string_append_multi_3(zval **arr, zval *index1, char *index2, uint index2_length, zval **value, int flags){
zval *temp1 = NULL, *temp2 = NULL;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp1, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp1) > 1) {
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp1) != IS_ARRAY) {
convert_to_array(temp1);
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY);
}
phalcon_array_fetch_string(&temp2, temp1, index2, index2_length, PH_SILENT);
if (Z_REFCOUNT_P(temp2) > 1) {
phalcon_array_update_string(&temp1, index2, index2_length, &temp2, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp2) != IS_ARRAY) {
convert_to_array(temp2);
phalcon_array_update_string(&temp1, index2, index2_length, &temp2, PH_COPY);
}
phalcon_array_append(&temp2, *value, flags);
}
if (temp1 != NULL) {
zval_ptr_dtor(&temp1);
}
if (temp2 != NULL) {
zval_ptr_dtor(&temp2);
}
}
static void phalcon_array_update_zval_zval_zval_multi_3(zval **arr, zval *index1, zval *index2, zval *index3, zval **value, int flags){
zval *temp1 = NULL, *temp2 = NULL;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp1, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp1) > 1) {
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp1) != IS_ARRAY) {
convert_to_array(temp1);
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY);
}
phalcon_array_fetch(&temp2, temp1, index2, PH_SILENT);
if (Z_REFCOUNT_P(temp2) > 1) {
phalcon_array_update_zval(&temp1, index2, &temp2, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp2) != IS_ARRAY) {
convert_to_array(temp2);
phalcon_array_update_zval(&temp1, index2, &temp2, PH_COPY);
}
phalcon_array_update_zval(&temp2, index3, value, PH_COPY);
}
if (temp1 != NULL) {
zval_ptr_dtor(&temp1);
}
if (temp2 != NULL) {
zval_ptr_dtor(&temp2);
}
}
static void phalcon_array_update_string_zval_zval_multi_3(zval **arr, zval *index1, zval *index2, char *index3, uint index3_length, zval **value, int flags){
zval *temp1 = NULL, *temp2 = NULL;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp1, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp1) > 1) {
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp1) != IS_ARRAY) {
convert_to_array(temp1);
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY);
}
phalcon_array_fetch(&temp2, temp1, index2, PH_SILENT);
if (Z_REFCOUNT_P(temp2) > 1) {
phalcon_array_update_zval(&temp1, index2, &temp2, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp2) != IS_ARRAY) {
convert_to_array(temp2);
phalcon_array_update_zval(&temp1, index2, &temp2, PH_COPY);
}
phalcon_array_update_string(&temp2, index3, index3_length, value, PH_COPY);
}
if (temp1 != NULL) {
zval_ptr_dtor(&temp1);
}
if (temp2 != NULL) {
zval_ptr_dtor(&temp2);
}
}
static void phalcon_array_update_zval_string_string_multi_3(zval **arr, zval *index1, char *index2, uint index2_length, char *index3, uint index3_length, zval **value, int flags){
zval *temp1 = NULL, *temp2 = NULL;
if (Z_TYPE_PP(arr) == IS_ARRAY) {
phalcon_array_fetch(&temp1, *arr, index1, PH_SILENT);
if (Z_REFCOUNT_P(temp1) > 1) {
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp1) != IS_ARRAY) {
convert_to_array(temp1);
phalcon_array_update_zval(arr, index1, &temp1, PH_COPY);
}
phalcon_array_fetch_string(&temp2, temp1, index2, index2_length, PH_SILENT);
if (Z_REFCOUNT_P(temp2) > 1) {
phalcon_array_update_string(&temp1, index2, index2_length, &temp2, PH_COPY | PH_CTOR);
}
if (Z_TYPE_P(temp2) != IS_ARRAY) {
convert_to_array(temp2);
phalcon_array_update_string(&temp1, index2, index2_length, &temp2, PH_COPY);
}
phalcon_array_update_string(&temp2, index3, index3_length, value, PH_COPY);
}
if (temp1 != NULL) {
zval_ptr_dtor(&temp1);
}
if (temp2 != NULL) {
zval_ptr_dtor(&temp2);
}
}
static void phalcon_merge_append(zval *left, zval *values){
if (Z_TYPE_P(left) != IS_ARRAY) {
zend_error(E_NOTICE, "The first parameter of phalcon_merge_append must be an array");
return;
}
if (Z_TYPE_P(values) == IS_ARRAY) {
HashPosition pos;
zval **tmp;
HashTable *arr_values = Z_ARRVAL_P(values);
for (
zend_hash_internal_pointer_reset_ex(arr_values, &pos);
zend_hash_get_current_data_ex(arr_values, (void**)&tmp, &pos) == SUCCESS;
zend_hash_move_forward_ex(arr_values, &pos)
) {
Z_ADDREF_PP(tmp);
add_next_index_zval(left, *tmp);
}
} else {
Z_ADDREF_P(values);
add_next_index_zval(left, values);
}
}
static void phalcon_array_get_current(zval *return_value, zval *array){
zval **entry;
if (Z_TYPE_P(array) == IS_ARRAY) {
if (zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) &entry) == FAILURE) {
RETURN_FALSE;
}
RETURN_ZVAL(*entry, 1, 0);
}
RETURN_FALSE;
}
static int phalcon_fast_in_array(zval *needle, zval *haystack TSRMLS_DC) {
zval **tmp;
HashTable *arr;
HashPosition pos;
unsigned int numelems;
if (Z_TYPE_P(haystack) != IS_ARRAY) {
return 0;
}
arr = Z_ARRVAL_P(haystack);
numelems = zend_hash_num_elements(arr);
if (numelems == 0) {
return 0;
}
zend_hash_internal_pointer_reset_ex(arr, &pos);
while (zend_hash_get_current_data_ex(arr, (void **) &tmp, &pos) == SUCCESS) {
if (phalcon_is_equal(needle, *tmp TSRMLS_CC)) {
return 1;
}
zend_hash_move_forward_ex(arr, &pos);
}
return 0;
}
static void phalcon_fast_array_merge(zval *return_value, zval **array1, zval **array2 TSRMLS_DC) {
int init_size, num;
if (Z_TYPE_PP(array1) != IS_ARRAY) {
zend_error(E_WARNING, "First argument is not an array");
RETURN_NULL();
}
if (Z_TYPE_PP(array2) != IS_ARRAY) {
zend_error(E_WARNING, "Second argument is not an array");
RETURN_NULL();
}
init_size = zend_hash_num_elements(Z_ARRVAL_PP(array1));
num = zend_hash_num_elements(Z_ARRVAL_PP(array2));
if (num > init_size) {
init_size = num;
}
array_init_size(return_value, init_size);
php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(array1), 0 TSRMLS_CC);
php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(array2), 0 TSRMLS_CC);
}
static void phalcon_array_merge_recursive_n(zval **a1, zval *a2)
{
HashPosition hp;
zval **value, key, *tmp1, *tmp2;
assert(Z_TYPE_PP(a1) == IS_ARRAY);
assert(Z_TYPE_P(a2) == IS_ARRAY);
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(a2), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(a2), (void**) &value, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(a2), &hp)
) {
key = phalcon_get_current_key_w(Z_ARRVAL_P(a2), &hp);
if (!phalcon_array_isset(*a1, &key) || Z_TYPE_PP(value) != IS_ARRAY) {
phalcon_array_update_zval(a1, &key, value, PH_COPY | PH_SEPARATE);
} else {
phalcon_array_fetch(&tmp1, *a1, &key, PH_NOISY);
phalcon_array_fetch(&tmp2, a2, &key, PH_NOISY);
phalcon_array_merge_recursive_n(&tmp1, tmp2);
zval_ptr_dtor(&tmp1);
zval_ptr_dtor(&tmp2);
}
}
}
static void phalcon_array_unshift(zval *arr, zval *arg)
{
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
zval** args[1] = { &arg };
HashTable *newhash = php_splice(Z_ARRVAL_P(arr), 0, 0, args, 1, NULL);
HashTable oldhash = *Z_ARRVAL_P(arr);
*Z_ARRVAL_P(arr) = *newhash;
FREE_HASHTABLE(newhash);
zend_hash_destroy(&oldhash);
}
}
static void phalcon_array_keys(zval *return_value, zval *arr) {
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
HashPosition pos;
zval **entry, *new_val;
char *skey;
uint skey_len;
ulong nkey;
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(arr)));
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void**)&entry, &pos) == SUCCESS) {
MAKE_STD_ZVAL(new_val);
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &skey, &skey_len, &nkey, 1, &pos)) {
case HASH_KEY_IS_STRING:
ZVAL_STRINGL(new_val, skey, skey_len - 1, 0);
zend_hash_next_index_insert(Z_ARRVAL_P(arr), &new_val, sizeof(zval*), NULL);
break;
case HASH_KEY_IS_LONG:
ZVAL_LONG(new_val, nkey);
zend_hash_next_index_insert(Z_ARRVAL_P(arr), &new_val, sizeof(zval*), NULL);
break;
}
zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
}
}
}
static void phalcon_array_values(zval *return_value, zval *arr)
{
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
zval **entry;
HashPosition pos;
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(arr)));
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &pos) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos)
) {
Z_ADDREF_PP(entry);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry, sizeof(zval*), NULL);
}
}
}
static int phalcon_array_key_exists(zval *arr, zval *key TSRMLS_DC)
{
HashTable *h = HASH_OF(arr);
if (h) {
switch (Z_TYPE_P(key)) {
case IS_STRING:
return zend_symtable_exists(h, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1);
case IS_LONG:
return zend_hash_index_exists(h, Z_LVAL_P(key));
case IS_NULL:
return zend_hash_exists(h, "", 1);
default:
zend_error(E_WARNING, "The key should be either a string or an integer");
return 0;
}
}
return 0;
}
static int phalcon_hash_exists(const HashTable *ht, const char *arKey, uint nKeyLength)
{
ulong h;
uint nIndex;
Bucket *p;
h = zend_inline_hash_func(arKey, nKeyLength);
nIndex = h & ht->nTableMask;
p = ht->arBuckets[nIndex];
while (p != NULL) {
if (p->arKey == arKey || ((p->h == h) && (p->nKeyLength == nKeyLength))) {
if (!memcmp(p->arKey, arKey, nKeyLength)) {
return 1;
}
}
p = p->pNext;
}
return 0;
}
static int phalcon_hash_quick_exists(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h)
{
uint nIndex;
Bucket *p;
if (nKeyLength == 0) {
return zend_hash_index_exists(ht, h);
}
nIndex = h & ht->nTableMask;
p = ht->arBuckets[nIndex];
while (p != NULL) {
if (p->arKey == arKey || ((p->h == h) && (p->nKeyLength == nKeyLength))) {
if (!memcmp(p->arKey, arKey, nKeyLength)) {
return 1;
}
}
p = p->pNext;
}
return 0;
}
static int phalcon_hash_find(const HashTable *ht, const char *arKey, uint nKeyLength, void **pData)
{
ulong h;
uint nIndex;
Bucket *p;
h = zend_inline_hash_func(arKey, nKeyLength);
nIndex = h & ht->nTableMask;
p = ht->arBuckets[nIndex];
while (p != NULL) {
if (p->arKey == arKey || ((p->h == h) && (p->nKeyLength == nKeyLength))) {
if (!memcmp(p->arKey, arKey, nKeyLength)) {
*pData = p->pData;
return SUCCESS;
}
}
p = p->pNext;
}
return FAILURE;
}
static int phalcon_hash_quick_find(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h, void **pData)
{
uint nIndex;
Bucket *p;
if (nKeyLength == 0) {
return zend_hash_index_find(ht, h, pData);
}
nIndex = h & ht->nTableMask;
p = ht->arBuckets[nIndex];
while (p != NULL) {
if (p->arKey == arKey || ((p->h == h) && (p->nKeyLength == nKeyLength))) {
if (!memcmp(p->arKey, arKey, nKeyLength)) {
*pData = p->pData;
return SUCCESS;
}
}
p = p->pNext;
}
return FAILURE;
}
static void phalcon_get_current_key(zval **key, const HashTable *hash_table, HashPosition *hash_position TSRMLS_DC)
{
Bucket *p;
PHALCON_INIT_NVAR_PNULL(*key);
p = hash_position ? (*hash_position) : hash_table->pInternalPointer;
if (p) {
if (p->nKeyLength) {
ZVAL_STRINGL(*key, (char *) p->arKey, p->nKeyLength - 1, 0);
} else {
ZVAL_LONG(*key, p->h);
}
}
}
zval phalcon_get_current_key_w(const HashTable *hash_table, HashPosition *hash_position)
{
Bucket *p;
zval result;
INIT_ZVAL(result);
p = hash_position ? (*hash_position) : hash_table->pInternalPointer;
if (p) {
if (p->nKeyLength) {
ZVAL_STRINGL(&result, (char *) p->arKey, p->nKeyLength - 1, 0);
} else {
ZVAL_LONG(&result, p->h);
}
}
return result;
}
static int phalcon_has_numeric_keys(const zval *data)
{
HashTable *ht;
if (Z_TYPE_P(data) == IS_ARRAY) {
ht = Z_ARRVAL_P(data);
ht->pInternalPointer = ht->pListHead;
while (ht->pInternalPointer) {
if (!ht->pInternalPointer->nKeyLength) {
return 1;
}
ht->pInternalPointer = ht->pInternalPointer->pListNext;
}
}
return 0;
}
static void phalcon_hash_update_or_insert(HashTable *ht, zval *key, zval *value)
{
if (!key || Z_TYPE_P(key) == IS_NULL) {
zend_hash_next_index_insert(ht, (void**)&value, sizeof(zval*), NULL);
return;
}
switch (Z_TYPE_P(key)) {
case IS_STRING:
zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)+1, (void**)&value, sizeof(zval*), NULL);
return;
case IS_RESOURCE:
case IS_DOUBLE:
case IS_BOOL:
case IS_LONG:
zend_hash_index_update(ht, ((Z_TYPE_P(key) == IS_DOUBLE) ? (ulong)Z_DVAL_P(key) : Z_LVAL_P(key)), (void*)&value, sizeof(zval*), NULL);
return;
default:
zend_error(E_WARNING, "Illegal offset type");
return;
}
}
zval** phalcon_hash_get(HashTable *ht, zval *key, int type)
{
zval **ret = NULL;
switch (Z_TYPE_P(key)) {
case IS_RESOURCE:
zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(key), Z_LVAL_P(key));
/* no break */
case IS_LONG:
case IS_DOUBLE:
case IS_BOOL: {
ulong index = (Z_TYPE_P(key) == IS_DOUBLE) ? ((long int)Z_DVAL_P(key)) : Z_LVAL_P(key);
if (FAILURE == zend_hash_index_find(ht, index, (void**)&ret)) {
switch (type) {
case BP_VAR_R:
zend_error(E_NOTICE, "Undefined offset: %ld", index);
/* no break */
case BP_VAR_UNSET:
case BP_VAR_IS: {
TSRMLS_FETCH();
ret = &EG(uninitialized_zval_ptr);
break;
}
case BP_VAR_RW:
zend_error(E_NOTICE, "Undefined offset: %ld", index);
/* no break */
case BP_VAR_W: {
zval *value;
ALLOC_INIT_ZVAL(value);
zend_hash_index_update(ht, index, (void**)&value, sizeof(void*), NULL);
break;
}
}
}
return ret;
}
case IS_STRING:
if (FAILURE == zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)+1, (void**)&ret)) {
switch (type) {
case BP_VAR_R:
zend_error(E_NOTICE, "Undefined offset: %s", Z_STRVAL_P(key));
/* no break */
case BP_VAR_UNSET:
case BP_VAR_IS: {
TSRMLS_FETCH();
ret = &EG(uninitialized_zval_ptr);
break;
}
case BP_VAR_RW:
zend_error(E_NOTICE, "Undefined offset: %s", Z_STRVAL_P(key));
/* no break */
case BP_VAR_W: {
zval *value;
ALLOC_INIT_ZVAL(value);
zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)+1, (void**)&value, sizeof(void*), NULL);
break;
}
}
}
return ret;
default: {
TSRMLS_FETCH();
zend_error(E_WARNING, "Illegal offset type");
return (type == BP_VAR_W || type == BP_VAR_RW) ? &EG(error_zval_ptr) : &EG(uninitialized_zval_ptr);
}
}
}
static int phalcon_hash_unset(HashTable *ht, zval *key)
{
switch (Z_TYPE_P(key)) {
case IS_LONG:
case IS_DOUBLE:
case IS_BOOL:
case IS_RESOURCE:
return (zend_hash_index_del(ht, (Z_TYPE_P(key) == IS_DOUBLE) ? ((long int)Z_DVAL_P(key)) : Z_LVAL_P(key)) == SUCCESS);
case IS_STRING:
return (zend_symtable_del(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)+1) == SUCCESS);
default:
zend_error(E_WARNING, "Illegal offset type");
return 0;
}
}
#ifdef PHP_WIN32
#include <ext/standard/php_string.h>
#endif
static int phalcon_get_class_constant(zval *return_value, zend_class_entry *ce, char *constant_name, unsigned int constant_length TSRMLS_DC) {
zval **result_ptr;
if (phalcon_hash_find(&ce->constants_table, constant_name, constant_length, (void **) &result_ptr) != SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Undefined class constant '%s::%s'", ce->name, constant_name);
return FAILURE;
}
ZVAL_ZVAL(return_value, *result_ptr, 1, 0);
return SUCCESS;
}
static int phalcon_instance_of(zval *result, const zval *object, const zend_class_entry *ce TSRMLS_DC) {
if (Z_TYPE_P(object) != IS_OBJECT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "instanceof expects an object instance");
ZVAL_FALSE(result);
return FAILURE;
}
ZVAL_BOOL(result, instanceof_function(Z_OBJCE_P(object), ce TSRMLS_CC));
return SUCCESS;
}
static int phalcon_is_instance_of(zval *object, const char *class_name, unsigned int class_length TSRMLS_DC) {
zend_class_entry *ce;
if (Z_TYPE_P(object) == IS_OBJECT) {
ce = Z_OBJCE_P(object);
if (ce->name_length == class_length) {
return !zend_binary_strcasecmp(ce->name, ce->name_length, class_name, class_length);
}
}
return 0;
}
static void phalcon_get_class(zval *result, zval *object, int lower TSRMLS_DC) {
zend_class_entry *ce;
if (Z_TYPE_P(object) == IS_OBJECT) {
ce = Z_OBJCE_P(object);
Z_STRLEN_P(result) = ce->name_length;
Z_STRVAL_P(result) = (char *) emalloc(ce->name_length + 1);
memcpy(Z_STRVAL_P(result), ce->name, ce->name_length);
Z_STRVAL_P(result)[Z_STRLEN_P(result)] = 0;
Z_TYPE_P(result) = IS_STRING;
if (lower) {
zend_str_tolower(Z_STRVAL_P(result), Z_STRLEN_P(result));
}
} else {
ZVAL_NULL(result);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "phalcon_get_class expects an object");
}
}
static void phalcon_get_class_ns(zval *result, zval *object, int lower TSRMLS_DC) {
int found = 0;
zend_class_entry *ce;
unsigned int i, class_length;
const char *cursor, *class_name;
if (Z_TYPE_P(object) != IS_OBJECT) {
if (Z_TYPE_P(object) != IS_STRING) {
ZVAL_NULL(result);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "phalcon_get_class_ns expects an object");
return;
}
}
if (Z_TYPE_P(object) == IS_OBJECT) {
ce = Z_OBJCE_P(object);
class_name = ce->name;
class_length = ce->name_length;
} else {
class_name = Z_STRVAL_P(object);
class_length = Z_STRLEN_P(object);
}
if (!class_length) {
ZVAL_NULL(result);
return;
}
i = class_length;
cursor = (char *) (class_name + class_length - 1);
while (i > 0) {
if ((*cursor) == '\\') {
found = 1;
break;
}
cursor--;
i--;
}
if (found) {
Z_STRLEN_P(result) = class_length - i;
Z_STRVAL_P(result) = (char *) emalloc(class_length - i + 1);
memcpy(Z_STRVAL_P(result), class_name + i, class_length - i);
Z_STRVAL_P(result)[Z_STRLEN_P(result)] = 0;
Z_TYPE_P(result) = IS_STRING;
} else {
ZVAL_STRINGL(result, class_name, class_length, 1);
}
if (lower) {
zend_str_tolower(Z_STRVAL_P(result), Z_STRLEN_P(result));
}
}
static void phalcon_get_ns_class(zval *result, zval *object, int lower TSRMLS_DC) {
zend_class_entry *ce;
int found = 0;
unsigned int i, j, class_length;
const char *cursor, *class_name;
if (Z_TYPE_P(object) != IS_OBJECT) {
if (Z_TYPE_P(object) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "phalcon_get_ns_class expects an object");
ZVAL_NULL(result);
return;
}
}
if (Z_TYPE_P(object) == IS_OBJECT) {
ce = Z_OBJCE_P(object);
class_name = ce->name;
class_length = ce->name_length;
} else {
class_name = Z_STRVAL_P(object);
class_length = Z_STRLEN_P(object);
}
if (!class_length) {
ZVAL_NULL(result);
return;
}
j = 0;
i = class_length;
cursor = (char *) (class_name + class_length - 1);
while (i > 0) {
if ((*cursor) == '\\') {
found = 1;
break;
}
cursor--;
i--;
j++;
}
if (j > 0) {
if (found) {
Z_STRLEN_P(result) = class_length - j - 1;
Z_STRVAL_P(result) = (char *) emalloc(class_length - j);
memcpy(Z_STRVAL_P(result), class_name, class_length - j - 1);
Z_STRVAL_P(result)[Z_STRLEN_P(result)] = 0;
Z_TYPE_P(result) = IS_STRING;
} else {
ZVAL_EMPTY_STRING(result);
}
if (lower) {
zend_str_tolower(Z_STRVAL_P(result), Z_STRLEN_P(result));
}
} else {
ZVAL_NULL(result);
}
}
static void phalcon_get_called_class(zval *return_value TSRMLS_DC) {
if (EG(called_scope)) {
RETURN_STRINGL(EG(called_scope)->name, EG(called_scope)->name_length, 1);
}
if (!EG(scope)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "phalcon_get_called_class() called from outside a class");
}
}
zend_class_entry *phalcon_fetch_class(const zval *class_name TSRMLS_DC) {
if (Z_TYPE_P(class_name) == IS_STRING) {
return zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "class name must be a string");
return zend_fetch_class("stdclass", strlen("stdclass"), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);
}
zend_class_entry* phalcon_fetch_self_class(TSRMLS_D) {
return zend_fetch_class(NULL, 0, ZEND_FETCH_CLASS_SELF TSRMLS_CC);
}
zend_class_entry* phalcon_fetch_parent_class(TSRMLS_D) {
return zend_fetch_class(NULL, 0, ZEND_FETCH_CLASS_PARENT TSRMLS_CC);
}
zend_class_entry* phalcon_fetch_static_class(TSRMLS_D) {
return zend_fetch_class(NULL, 0, ZEND_FETCH_CLASS_STATIC TSRMLS_CC);
}
static int phalcon_class_exists(const zval *class_name, int autoload TSRMLS_DC) {
zend_class_entry **ce;
if (Z_TYPE_P(class_name) == IS_STRING) {
if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &ce TSRMLS_CC) == SUCCESS) {
#if PHP_VERSION_ID < 50400
return (((*ce)->ce_flags & ZEND_ACC_INTERFACE) == 0);
#else
return ((*ce)->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0;
#endif
}
return 0;
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "class name must be a string");
return 0;
}
static int phalcon_class_exists_ex(zend_class_entry **zce, const zval *class_name, int autoload TSRMLS_DC) {
zend_class_entry **ce;
if (Z_TYPE_P(class_name) == IS_STRING) {
if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &ce TSRMLS_CC) == SUCCESS) {
*zce = *ce;
#if PHP_VERSION_ID < 50400
return (((*ce)->ce_flags & ZEND_ACC_INTERFACE) == 0);
#else
return ((*ce)->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0;
#endif
}
return 0;
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "class name must be a string");
return 0;
}
static int phalcon_clone(zval *destination, zval *obj TSRMLS_DC) {
int status = SUCCESS;
zend_class_entry *ce;
zend_object_clone_obj_t clone_call;
if (Z_TYPE_P(obj) != IS_OBJECT) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "__clone method called on non-object");
status = FAILURE;
} else {
ce = Z_OBJCE_P(obj);
clone_call = Z_OBJ_HT_P(obj)->clone_obj;
if (!clone_call) {
if (ce) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Trying to clone an uncloneable object of class %s", ce->name);
} else {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Trying to clone an uncloneable object");
}
status = FAILURE;
} else {
if (!EG(exception)) {
Z_OBJVAL_P(destination) = clone_call(obj TSRMLS_CC);
Z_TYPE_P(destination) = IS_OBJECT;
Z_SET_REFCOUNT_P(destination, 1);
Z_UNSET_ISREF_P(destination);
if (EG(exception)) {
zval_dtor(destination);
ZVAL_NULL(destination);
}
}
}
}
return status;
}
static int phalcon_isset_property_quick(zval *object, const char *property_name, unsigned int property_length, unsigned long hash TSRMLS_DC) {
if (Z_TYPE_P(object) == IS_OBJECT) {
if (likely(phalcon_hash_quick_exists(&Z_OBJCE_P(object)->properties_info, property_name, property_length, hash))) {
return 1;
} else {
return phalcon_hash_quick_exists(Z_OBJ_HT_P(object)->get_properties(object TSRMLS_CC), property_name, property_length, hash);
}
}
return 0;
}
static int phalcon_isset_property(zval *object, const char *property_name, unsigned int property_length TSRMLS_DC) {
return phalcon_isset_property_quick(object, property_name, property_length, zend_inline_hash_func(property_name, property_length) TSRMLS_CC);
}
static int phalcon_isset_property_zval(zval *object, const zval *property TSRMLS_DC) {
unsigned long hash;
if (Z_TYPE_P(object) == IS_OBJECT) {
if (Z_TYPE_P(property) == IS_STRING) {
hash = zend_inline_hash_func(Z_STRVAL_P(property), Z_STRLEN_P(property) + 1);
if (likely(phalcon_hash_quick_exists(&Z_OBJCE_P(object)->properties_info, Z_STRVAL_P(property), Z_STRLEN_P(property) + 1, hash))) {
return 1;
} else {
return phalcon_hash_quick_exists(Z_OBJ_HT_P(object)->get_properties(object TSRMLS_CC), Z_STRVAL_P(property), Z_STRLEN_P(property) + 1, hash);
}
}
}
return 0;
}
static inline zend_class_entry *phalcon_lookup_class_ce_quick(zend_class_entry *ce, char *property_name, unsigned int property_length, unsigned long hash TSRMLS_DC) {
zend_class_entry *original_ce;
original_ce = ce;
while (ce) {
if (phalcon_hash_quick_exists(&ce->properties_info, property_name, property_length + 1, hash)) {
return ce;
}
ce = ce->parent;
}
return original_ce;
}
static inline zend_class_entry *phalcon_lookup_class_ce(zend_class_entry *ce, char *property_name, unsigned int property_length TSRMLS_DC) {
return phalcon_lookup_class_ce_quick(ce, property_name, property_length, zend_inline_hash_func(property_name, property_length + 1) TSRMLS_CC);
}
static int phalcon_read_property(zval **result, zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC) {
zval *property;
zend_class_entry *ce, *old_scope;
if (Z_TYPE_P(object) != IS_OBJECT) {
if (silent == PH_NOISY) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Trying to get property of non-object");
}
ALLOC_INIT_ZVAL(*result);
return FAILURE;
}
ce = Z_OBJCE_P(object);
if (ce->parent) {
ce = phalcon_lookup_class_ce(ce, property_name, property_length TSRMLS_CC);
}
old_scope = EG(scope);
EG(scope) = ce;
if (!Z_OBJ_HT_P(object)->read_property) {
#if PHP_VERSION_ID < 50400
char *class_name;
#else
const char *class_name;
#endif
zend_uint class_name_len;
zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
zend_error(E_CORE_ERROR, "Property %s of class %s cannot be read", property_name, class_name);
}
MAKE_STD_ZVAL(property);
ZVAL_STRINGL(property, property_name, property_length, 0);
#if PHP_VERSION_ID < 50400
*result = Z_OBJ_HT_P(object)->read_property(object, property, silent ? BP_VAR_IS : BP_VAR_R TSRMLS_CC);
#else
*result = Z_OBJ_HT_P(object)->read_property(object, property, silent ? BP_VAR_IS : BP_VAR_R, 0 TSRMLS_CC);
#endif
Z_ADDREF_PP(result);
if (Z_REFCOUNT_P(property) > 1) {
ZVAL_STRINGL(property, property_name, property_length, 1);
} else {
ZVAL_NULL(property);
}
zval_ptr_dtor(&property);
EG(scope) = old_scope;
return SUCCESS;
}
static int phalcon_read_property_this(zval **result, zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC) {
return phalcon_read_property_this_quick(result, object, property_name, property_length, zend_inline_hash_func(property_name, property_length + 1), silent TSRMLS_CC);
}
static int phalcon_read_property_this_quick(zval **result, zval *object, char *property_name, unsigned int property_length, unsigned long key, int silent TSRMLS_DC) {
zval *tmp = phalcon_fetch_property_this_quick(object, property_name, property_length, key, silent TSRMLS_CC);
if (likely(tmp != NULL)) {
*result = tmp;
Z_ADDREF_PP(result);
return SUCCESS;
}
ALLOC_INIT_ZVAL(*result);
return FAILURE;
}
zval* phalcon_fetch_nproperty_this(zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC) {
return phalcon_fetch_nproperty_this_quick(object, property_name, property_length, zend_inline_hash_func(property_name, property_length + 1), silent TSRMLS_CC);
}
zval* phalcon_fetch_nproperty_this_quick(zval *object, char *property_name, unsigned int property_length, unsigned long key, int silent TSRMLS_DC) {
zval *result = phalcon_fetch_property_this_quick(object, property_name, property_length, zend_inline_hash_func(property_name, property_length + 1), silent TSRMLS_CC);
return result ? result : EG(uninitialized_zval_ptr);
}
zval* phalcon_fetch_property_this(zval *object, char *property_name, unsigned int property_length, int silent TSRMLS_DC) {
return phalcon_fetch_property_this_quick(object, property_name, property_length, zend_inline_hash_func(property_name, property_length + 1), silent TSRMLS_CC);
}
zval* phalcon_fetch_property_this_quick(zval *object, char *property_name, unsigned int property_length, unsigned long key, int silent TSRMLS_DC) {
zval **zv = NULL;
zend_object *zobj;
zend_property_info *property_info;
zend_class_entry *ce, *old_scope;
if (likely(Z_TYPE_P(object) == IS_OBJECT)) {
ce = Z_OBJCE_P(object);
if (ce->parent) {
ce = phalcon_lookup_class_ce_quick(ce, property_name, property_length, key TSRMLS_CC);
}
old_scope = EG(scope);
EG(scope) = ce;
zobj = zend_objects_get_address(object TSRMLS_CC);
if (phalcon_hash_quick_find(&ce->properties_info, property_name, property_length + 1, key, (void **) &property_info) == SUCCESS) {
#if PHP_VERSION_ID < 50400
if (phalcon_hash_quick_find(zobj->properties, property_info->name, property_info->name_length + 1, property_info->h, (void **) &zv) == SUCCESS) {
EG(scope) = old_scope;
return *zv;
}
#else
int flag;
if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) && property_info->offset >= 0) {
if (zobj->properties) {
zv = (zval**) zobj->properties_table[property_info->offset];
flag = (zv == NULL) ? 1 : 0;
} else {
zv = &zobj->properties_table[property_info->offset];
flag = (*zv == NULL) ? 1 : 0;
}
} else if (UNEXPECTED(!zobj->properties)) {
flag = 1;
} else if (UNEXPECTED(phalcon_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &zv) == FAILURE)) {
flag = 2;
} else {
flag = 0;
}
if (unlikely(flag) && zobj->properties) {
if (
(flag == 2 || phalcon_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &zv) == FAILURE)
&& zv && *zv
) {
flag = 0;
}
}
if (likely(!flag)) {
EG(scope) = old_scope;
return *zv;
}
#endif
}
EG(scope) = old_scope;
} else {
if (silent == PH_NOISY) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Trying to get property of non-object");
}
}
return NULL;
}
static int phalcon_return_property_quick(zval *return_value, zval **return_value_ptr, zval *object, char *property_name, unsigned int property_length, unsigned long key TSRMLS_DC) {
zval **zv;
zend_object *zobj;
zend_property_info *property_info;
zend_class_entry *ce, *old_scope;
if (likely(Z_TYPE_P(object) == IS_OBJECT)) {
ce = Z_OBJCE_P(object);
if (ce->parent) {
ce = phalcon_lookup_class_ce_quick(ce, property_name, property_length, key TSRMLS_CC);
}
old_scope = EG(scope);
EG(scope) = ce;
zobj = zend_objects_get_address(object TSRMLS_CC);
if (phalcon_hash_quick_find(&ce->properties_info, property_name, property_length + 1, key, (void **) &property_info) == SUCCESS) {
#if PHP_VERSION_ID < 50400
if (phalcon_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &zv) == SUCCESS) {
EG(scope) = old_scope;
if (return_value_ptr) {
zval_ptr_dtor(return_value_ptr);
Z_ADDREF_PP(zv);
*return_value_ptr = *zv;
}
else {
ZVAL_ZVAL(return_value, *zv, 1, 0);
}
return SUCCESS;
}
#else
int flag;
if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) && property_info->offset >= 0) {
if (zobj->properties) {
zv = (zval**) zobj->properties_table[property_info->offset];
flag = (zv == NULL) ? 1 : 0;
} else {
zv = &zobj->properties_table[property_info->offset];
flag = (*zv == NULL) ? 1 : 0;
}
} else if (UNEXPECTED(!zobj->properties)) {
flag = 1;
} else if (UNEXPECTED(phalcon_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &zv) == FAILURE)) {
flag = 2;
} else {
flag = 0;
}
if (unlikely(flag) && zobj->properties) {
if (
(flag == 2 || phalcon_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &zv) == FAILURE)
&& zv && *zv
) {
flag = 0;
}
}
if (likely(!flag)) {
EG(scope) = old_scope;
if (return_value_ptr) {
zval_ptr_dtor(return_value_ptr);
Z_ADDREF_PP(zv);
*return_value_ptr = *zv;
}
else {
ZVAL_ZVAL(return_value, *zv, 1, 0);
}
return SUCCESS;
}
#endif
}
EG(scope) = old_scope;
} else {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Trying to get property of non-object");
}
ZVAL_NULL(return_value);
return FAILURE;
}
static int phalcon_return_property(zval *return_value, zval **return_value_ptr, zval *object, char *property_name, unsigned int property_length TSRMLS_DC) {
return phalcon_return_property_quick(return_value, return_value_ptr, object, property_name, property_length, zend_inline_hash_func(property_name, property_length + 1) TSRMLS_CC);
}
static int phalcon_read_property_zval(zval **result, zval *object, zval *property, int silent TSRMLS_DC) {
if (unlikely(Z_TYPE_P(property) != IS_STRING)) {
if (silent == PH_NOISY) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot access empty property %d", Z_TYPE_P(property));
}
ALLOC_INIT_ZVAL(*result);
return FAILURE;
}
return phalcon_read_property(result, object, Z_STRVAL_P(property), Z_STRLEN_P(property), silent TSRMLS_CC);
}
static int phalcon_update_property_long(zval *object, char *property_name, unsigned int property_length, long value TSRMLS_DC) {
zval *v;
ALLOC_ZVAL(v);
Z_UNSET_ISREF_P(v);
Z_SET_REFCOUNT_P(v, 0);
ZVAL_LONG(v, value);
return phalcon_update_property_zval(object, property_name, property_length, v TSRMLS_CC);
}
static int phalcon_update_property_string(zval *object, char *property_name, unsigned int property_length, char *str, unsigned int str_length TSRMLS_DC) {
zval *value;
int res;
ALLOC_ZVAL(value);
Z_UNSET_ISREF_P(value);
Z_SET_REFCOUNT_P(value, 0);
ZVAL_STRINGL(value, str, str_length, 1);
res = phalcon_update_property_zval(object, property_name, property_length, value TSRMLS_CC);
if (res == SUCCESS) {
return SUCCESS;
}
return FAILURE;
}
static int phalcon_update_property_bool(zval *object, char *property_name, unsigned int property_length, int value TSRMLS_DC) {
zval *v = value ? PHALCON_GLOBAL(z_true) : PHALCON_GLOBAL(z_false);
return phalcon_update_property_zval(object, property_name, property_length, v TSRMLS_CC);
}
static int phalcon_update_property_null(zval *object, char *property_name, unsigned int property_length TSRMLS_DC) {
zval *v = PHALCON_GLOBAL(z_null);
return phalcon_update_property_zval(object, property_name, property_length, v TSRMLS_CC);
}
static int phalcon_update_property_zval(zval *object, char *property_name, unsigned int property_length, zval *value TSRMLS_DC){
zend_class_entry *ce, *old_scope;
zval *property;
old_scope = EG(scope);
if (Z_TYPE_P(object) != IS_OBJECT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to assign property of non-object");
return FAILURE;
}
ce = Z_OBJCE_P(object);
if (ce->parent) {
ce = phalcon_lookup_class_ce(ce, property_name, property_length TSRMLS_CC);
}
EG(scope) = ce;
if (!Z_OBJ_HT_P(object)->write_property) {
#if PHP_VERSION_ID < 50400
char *class_name;
#else
const char *class_name;
#endif
zend_uint class_name_len;
zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
zend_error(E_CORE_ERROR, "Property %s of class %s cannot be updated", property_name, class_name);
}
MAKE_STD_ZVAL(property);
ZVAL_STRINGL(property, property_name, property_length, 0);
#if PHP_VERSION_ID < 50400
Z_OBJ_HT_P(object)->write_property(object, property, value TSRMLS_CC);
#else
Z_OBJ_HT_P(object)->write_property(object, property, value, 0 TSRMLS_CC);
#endif
if (Z_REFCOUNT_P(property) > 1) {
ZVAL_STRINGL(property, property_name, property_length, 1);
} else {
ZVAL_NULL(property);
}
zval_ptr_dtor(&property);
EG(scope) = old_scope;
return SUCCESS;
}
static int phalcon_update_property_this_quick(zval *object, char *property_name, unsigned int property_length, zval *value, unsigned long key TSRMLS_DC){
zend_class_entry *ce, *old_scope;
if (unlikely(Z_TYPE_P(object) != IS_OBJECT)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to assign property of non-object");
return FAILURE;
}
ce = Z_OBJCE_P(object);
if (ce->parent) {
ce = phalcon_lookup_class_ce_quick(ce, property_name, property_length, key TSRMLS_CC);
}
old_scope = EG(scope);
EG(scope) = ce;
#if PHP_VERSION_ID < 50400
{
zval *property;
if (!Z_OBJ_HT_P(object)->write_property) {
EG(scope) = old_scope;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Property %s of class %s cannot be updated", property_name, ce->name);
return FAILURE;
}
MAKE_STD_ZVAL(property);
ZVAL_STRINGL(property, property_name, property_length, 0);
Z_OBJ_HT_P(object)->write_property(object, property, value TSRMLS_CC);
if (Z_REFCOUNT_P(property) > 1) {
ZVAL_STRINGL(property, property_name, property_length, 1);
} else {
ZVAL_NULL(property);
}
zval_ptr_dtor(&property);
}
#else
{
zend_object *zobj;
zval **variable_ptr;
zend_property_info *property_info;
zobj = zend_objects_get_address(object TSRMLS_CC);
if (phalcon_hash_quick_find(&ce->properties_info, property_name, property_length + 1, key, (void **) &property_info) == SUCCESS) {
assert(property_info != NULL);
/** This is as zend_std_write_property, but we're not interesed in validate properties visibility */
if (property_info->offset >= 0 ? (zobj->properties ? ((variable_ptr = (zval**) zobj->properties_table[property_info->offset]) != NULL) : (*(variable_ptr = &zobj->properties_table[property_info->offset]) != NULL)) : (EXPECTED(zobj->properties != NULL) && EXPECTED(phalcon_hash_quick_find(zobj->properties, property_info->name, property_info->name_length + 1, property_info->h, (void **) &variable_ptr) == SUCCESS))) {
if (EXPECTED(*variable_ptr != value)) {
/* if we are assigning reference, we shouldn't move it, but instead assign variable to the same pointer */
if (PZVAL_IS_REF(*variable_ptr)) {
zval garbage = **variable_ptr; /* old value should be destroyed */
/* To check: can't *variable_ptr be some system variable like error_zval here? */
Z_TYPE_PP(variable_ptr) = Z_TYPE_P(value);
(*variable_ptr)->value = value->value;
if (Z_REFCOUNT_P(value) > 0) {
zval_copy_ctor(*variable_ptr);
} else {
efree(value);
}
zval_dtor(&garbage);
} else {
zval *garbage = *variable_ptr;
/* if we assign referenced variable, we should separate it */
Z_ADDREF_P(value);
if (PZVAL_IS_REF(value)) {
SEPARATE_ZVAL(&value);
}
*variable_ptr = value;
zval_ptr_dtor(&garbage);
}
}
}
}
}
#endif
EG(scope) = old_scope;
return SUCCESS;
}
static int phalcon_update_property_this(zval *object, char *property_name, unsigned int property_length, zval *value TSRMLS_DC){
return phalcon_update_property_this_quick(object, property_name, property_length, value, zend_inline_hash_func(property_name, property_length + 1) TSRMLS_CC);
}
static int phalcon_update_property_zval_zval(zval *object, zval *property, zval *value TSRMLS_DC){
if (Z_TYPE_P(property) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Property should be string");
return FAILURE;
}
return phalcon_update_property_zval(object, Z_STRVAL_P(property), Z_STRLEN_P(property), value TSRMLS_CC);
}
static int phalcon_update_property_array(zval *object, char *property, unsigned int property_length, zval *index, zval *value TSRMLS_DC) {
zval *tmp;
int separated = 0;
if (Z_TYPE_P(object) == IS_OBJECT) {
phalcon_read_property(&tmp, object, property, property_length, PH_NOISY_CC);
Z_DELREF_P(tmp);
/** Separation only when refcount > 1 */
if (Z_REFCOUNT_P(tmp) > 1) {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
separated = 1;
}
/** Convert the value to array if not is an array */
if (Z_TYPE_P(tmp) != IS_ARRAY) {
if (separated) {
convert_to_array(tmp);
} else {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
array_init(tmp);
separated = 1;
}
}
Z_ADDREF_P(value);
if (Z_TYPE_P(index) == IS_STRING) {
zend_symtable_update(Z_ARRVAL_P(tmp), Z_STRVAL_P(index), Z_STRLEN_P(index) + 1, &value, sizeof(zval*), NULL);
} else {
if (Z_TYPE_P(index) == IS_LONG) {
zend_hash_index_update(Z_ARRVAL_P(tmp), Z_LVAL_P(index), &value, sizeof(zval *), NULL);
}
}
if (separated) {
phalcon_update_property_zval(object, property, property_length, tmp TSRMLS_CC);
}
}
return SUCCESS;
}
static int phalcon_update_property_array_string(zval *object, char *property, unsigned int property_length, char *index, unsigned int index_length, zval *value TSRMLS_DC) {
zval *tmp;
int separated = 0;
if (likely(Z_TYPE_P(object) == IS_OBJECT)) {
phalcon_read_property(&tmp, object, property, property_length, PH_NOISY_CC);
Z_DELREF_P(tmp);
/** Separation only when refcount > 1 */
if (Z_REFCOUNT_P(tmp) > 1) {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
separated = 1;
}
/** Convert the value to array if not is an array */
if (Z_TYPE_P(tmp) != IS_ARRAY) {
if (separated) {
convert_to_array(tmp);
} else {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
array_init(tmp);
separated = 1;
}
}
Z_ADDREF_P(value);
zend_hash_update(Z_ARRVAL_P(tmp), index, index_length, &value, sizeof(zval *), NULL);
if (separated) {
phalcon_update_property_zval(object, property, property_length, tmp TSRMLS_CC);
}
}
return SUCCESS;
}
static int phalcon_update_property_array_append(zval *object, char *property, unsigned int property_length, zval *value TSRMLS_DC) {
zval *tmp;
int separated = 0;
if (Z_TYPE_P(object) != IS_OBJECT) {
return SUCCESS;
}
phalcon_read_property(&tmp, object, property, property_length, PH_NOISY_CC);
Z_DELREF_P(tmp);
/** Separation only when refcount > 1 */
if (Z_REFCOUNT_P(tmp) > 1) {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
separated = 1;
}
/** Convert the value to array if not is an array */
if (Z_TYPE_P(tmp) != IS_ARRAY) {
if (separated) {
convert_to_array(tmp);
} else {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
array_init(tmp);
separated = 1;
}
}
Z_ADDREF_P(value);
add_next_index_zval(tmp, value);
if (separated) {
phalcon_update_property_zval(object, property, property_length, tmp TSRMLS_CC);
}
return SUCCESS;
}
static int phalcon_update_property_empty_array(zend_class_entry *ce, zval *object, char *property_name, unsigned int property_length TSRMLS_DC) {
zval *empty_array;
int res;
MAKE_STD_ZVAL(empty_array);
array_init(empty_array);
res = phalcon_update_property_zval(object, property_name, property_length, empty_array TSRMLS_CC);
zval_ptr_dtor(&empty_array);
return res;
}
static int phalcon_unset_property_array(zval *object, char *property, unsigned int property_length, zval *index TSRMLS_DC) {
zval *tmp;
int separated = 0;
if (Z_TYPE_P(object) == IS_OBJECT) {
phalcon_read_property(&tmp, object, property, property_length, PH_NOISY_CC);
Z_DELREF_P(tmp);
/** Separation only when refcount > 1 */
if (Z_REFCOUNT_P(tmp) > 1) {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
separated = 1;
}
phalcon_array_unset(&tmp, index, 0);
if (separated) {
phalcon_update_property_zval(object, property, property_length, tmp TSRMLS_CC);
}
}
return SUCCESS;
}
static int phalcon_method_exists(const zval *object, const zval *method_name TSRMLS_DC){
char *lcname = zend_str_tolower_dup(Z_STRVAL_P(method_name), Z_STRLEN_P(method_name));
int res = phalcon_method_exists_ex(object, lcname, Z_STRLEN_P(method_name)+1 TSRMLS_CC);
efree(lcname);
return res;
}
static int phalcon_method_exists_ex(const zval *object, const char *method_name, unsigned int method_len TSRMLS_DC){
return phalcon_method_quick_exists_ex(object, method_name, method_len, zend_inline_hash_func(method_name, method_len) TSRMLS_CC);
}
static int phalcon_method_quick_exists_ex(const zval *object, const char *method_name, unsigned int method_len, unsigned long hash TSRMLS_DC){
zend_class_entry *ce;
if (likely(Z_TYPE_P(object) == IS_OBJECT)) {
ce = Z_OBJCE_P(object);
} else {
if (Z_TYPE_P(object) == IS_STRING) {
ce = zend_fetch_class(Z_STRVAL_P(object), Z_STRLEN_P(object), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);
} else {
return FAILURE;
}
}
while (ce) {
if (phalcon_hash_quick_exists(&ce->function_table, method_name, method_len, hash)) {
return SUCCESS;
}
ce = ce->parent;
}
return FAILURE;
}
zval* phalcon_fetch_static_property_ce(zend_class_entry *ce, char *property, int len TSRMLS_DC) {
assert(ce != NULL);
return zend_read_static_property(ce, property, len, (zend_bool)ZEND_FETCH_CLASS_SILENT TSRMLS_CC);
}
static int phalcon_read_static_property_ce(zval **result, zend_class_entry *ce, char *property, int len TSRMLS_DC) {
assert(ce != NULL);
*result = phalcon_fetch_static_property_ce(ce, property, len TSRMLS_CC);
if (*result) {
Z_ADDREF_PP(result);
return SUCCESS;
}
return FAILURE;
}
static int phalcon_read_static_property(zval **result, const char *class_name, unsigned int class_length, char *property_name, unsigned int property_length TSRMLS_DC){
zend_class_entry **ce;
if (zend_lookup_class(class_name, class_length, &ce TSRMLS_CC) == SUCCESS) {
return phalcon_read_static_property_ce(result, *ce, property_name, property_length TSRMLS_CC);
}
return FAILURE;
}
static int phalcon_update_static_property_ce(zend_class_entry *ce, char *name, int len, zval *value TSRMLS_DC) {
assert(ce != NULL);
return zend_update_static_property(ce, name, len, value TSRMLS_CC);
}
static int phalcon_update_static_property(const char *class_name, unsigned int class_length, char *name, unsigned int name_length, zval *value TSRMLS_DC){
zend_class_entry **ce;
if (zend_lookup_class(class_name, class_length, &ce TSRMLS_CC) == SUCCESS) {
return phalcon_update_static_property_ce(*ce, name, name_length, value TSRMLS_CC);
}
return FAILURE;
}
static int phalcon_read_class_property(zval **result, int type, char *property, int len TSRMLS_DC) {
zend_class_entry *ce;
type |= (ZEND_FETCH_CLASS_SILENT | ZEND_FETCH_CLASS_NO_AUTOLOAD);
type &= ZEND_FETCH_CLASS_MASK;
ce = zend_fetch_class(NULL, 0, type TSRMLS_CC);
if (likely(ce != NULL)) {
return phalcon_read_static_property_ce(result, ce, property, len TSRMLS_CC);
}
return FAILURE;
}
static int phalcon_create_instance_params_ce(zval *return_value, zend_class_entry *ce, zval *params TSRMLS_DC)
{
int outcome = SUCCESS;
object_init_ex(return_value, ce);
if (phalcon_has_constructor_ce(ce)) {
int param_count = (Z_TYPE_P(params) == IS_ARRAY) ? zend_hash_num_elements(Z_ARRVAL_P(params)) : 0;
zval *static_params[10];
zval **params_ptr, **params_arr = NULL;
if (param_count > 0) {
HashPosition pos;
zval **item;
int i = 0;
if (likely(param_count) <= 10) {
params_ptr = static_params;
}
else {
params_arr = emalloc(param_count * sizeof(zval*));
params_ptr = &params;
}
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(params), &pos);
zend_hash_get_current_data_ex(Z_ARRVAL_P(params), (void**)&item, &pos) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(params), &pos), ++i
) {
params_ptr[i] = *item;
}
}
else {
params_ptr = NULL;
}
outcome = phalcon_call_method_params(NULL, NULL, return_value, SL("__construct"), 1107214344UL TSRMLS_CC, -param_count, params_ptr);
if (unlikely(params_arr != NULL)) {
efree(params_arr);
}
}
return outcome;
}
static int phalcon_create_instance(zval *return_value, const zval *class_name TSRMLS_DC){
zend_class_entry *ce;
if (unlikely(Z_TYPE_P(class_name) != IS_STRING)) {
phalcon_throw_exception_string(phalcon_exception_ce, "Invalid class name" TSRMLS_CC);
return FAILURE;
}
ce = zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);
if (!ce) {
return FAILURE;
}
return phalcon_create_instance_params_ce(return_value, ce, PHALCON_GLOBAL(z_null) TSRMLS_CC);
}
static int phalcon_create_instance_params(zval *return_value, const zval *class_name, zval *params TSRMLS_DC){
zend_class_entry *ce;
if (unlikely(Z_TYPE_P(class_name) != IS_STRING)) {
phalcon_throw_exception_string(phalcon_exception_ce, "Invalid class name" TSRMLS_CC);
return FAILURE;
}
ce = zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);
if (!ce) {
return FAILURE;
}
return phalcon_create_instance_params_ce(return_value, ce, params TSRMLS_CC);
}
static int phalcon_property_incr(zval *object, char *property_name, unsigned int property_length TSRMLS_DC){
zval *tmp = NULL;
int separated = 0;
if (unlikely(Z_TYPE_P(object) != IS_OBJECT)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to assign property of non-object");
return FAILURE;
}
phalcon_read_property(&tmp, object, property_name, property_length, 0 TSRMLS_CC);
if (tmp) {
Z_DELREF_P(tmp);
/** Separation only when refcount > 1 */
if (Z_REFCOUNT_P(tmp) > 1) {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
separated = 1;
}
phalcon_increment(tmp);
if (separated) {
phalcon_update_property_zval(object, property_name, property_length, tmp TSRMLS_CC);
}
}
return SUCCESS;
}
static int phalcon_property_decr(zval *object, char *property_name, unsigned int property_length TSRMLS_DC){
zval *tmp = NULL;
int separated = 0;
if (unlikely(Z_TYPE_P(object) != IS_OBJECT)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to assign property of non-object");
return FAILURE;
}
phalcon_read_property(&tmp, object, property_name, property_length, 0 TSRMLS_CC);
if (tmp) {
Z_DELREF_P(tmp);
/** Separation only when refcount > 1 */
if (Z_REFCOUNT_P(tmp) > 1) {
zval *new_zv;
ALLOC_ZVAL(new_zv);
INIT_PZVAL_COPY(new_zv, tmp);
tmp = new_zv;
zval_copy_ctor(new_zv);
Z_SET_REFCOUNT_P(tmp, 0);
separated = 1;
}
phalcon_decrement(tmp);
if (separated) {
phalcon_update_property_zval(object, property_name, property_length, tmp TSRMLS_CC);
}
}
return SUCCESS;
}
#include <ctype.h>
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_string.h>
#include <ext/standard/php_rand.h>
#include <ext/standard/php_lcg.h>
#include <ext/standard/php_http.h>
#include <ext/standard/base64.h>
#include <ext/standard/md5.h>
#include <ext/standard/url.h>
#include <ext/standard/html.h>
#include <ext/date/php_date.h>
#ifdef PHALCON_USE_PHP_PCRE
#include <ext/pcre/php_pcre.h>
#endif
#ifdef PHALCON_USE_PHP_JSON
#include <ext/json/php_json.h>
#endif
#define PH_RANDOM_ALNUM 0
#define PH_RANDOM_ALPHA 1
#define PH_RANDOM_HEXDEC 2
#define PH_RANDOM_NUMERIC 3
#define PH_RANDOM_NOZERO 4
static void phalcon_fast_strlen(zval *return_value, zval *str){
zval copy;
int use_copy = 0;
if (Z_TYPE_P(str) != IS_STRING) {
zend_make_printable_zval(str, &copy, &use_copy);
if (use_copy) {
str = &copy;
}
}
ZVAL_LONG(return_value, Z_STRLEN_P(str));
if (use_copy) {
zval_dtor(str);
}
}
static void phalcon_fast_strtolower(zval *return_value, zval *str){
zval copy;
int use_copy = 0;
char *lower_str;
unsigned int length;
if (Z_TYPE_P(str) != IS_STRING) {
zend_make_printable_zval(str, &copy, &use_copy);
if (use_copy) {
str = &copy;
}
}
length = Z_STRLEN_P(str);
lower_str = estrndup(Z_STRVAL_P(str), length);
php_strtolower(lower_str, length);
if (use_copy) {
zval_dtor(str);
}
ZVAL_STRINGL(return_value, lower_str, length, 0);
}
static void phalcon_strtolower_inplace(zval *s) {
if (likely(Z_TYPE_P(s) == IS_STRING)) {
php_strtolower(Z_STRVAL_P(s), Z_STRLEN_P(s));
}
}
static void phalcon_fast_join(zval *result, zval *glue, zval *pieces TSRMLS_DC){
if (Z_TYPE_P(glue) != IS_STRING || Z_TYPE_P(pieces) != IS_ARRAY) {
ZVAL_NULL(result);
zend_error(E_WARNING, "Invalid arguments supplied for join()");
return;
}
php_implode(glue, pieces, result TSRMLS_CC);
}
static void phalcon_append_printable_zval(smart_str *implstr, zval **tmp TSRMLS_DC) {
zval tmp_val;
unsigned int str_len;
switch (Z_TYPE_PP(tmp)) {
case IS_STRING:
smart_str_appendl(implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
break;
case IS_LONG:
smart_str_append_long(implstr, Z_LVAL_PP(tmp));
break;
case IS_BOOL:
if (Z_LVAL_PP(tmp) == 1) {
smart_str_appendl(implstr, "1", sizeof("1") - 1);
}
break;
case IS_NULL:
break;
case IS_DOUBLE: {
char *stmp;
str_len = spprintf(&stmp, 0, "%.*G", (int) EG(precision), Z_DVAL_PP(tmp));
smart_str_appendl(implstr, stmp, str_len);
efree(stmp);
}
break;
case IS_OBJECT: {
int copy;
zval expr;
zend_make_printable_zval(*tmp, &expr, &copy);
smart_str_appendl(implstr, Z_STRVAL(expr), Z_STRLEN(expr));
if (copy) {
zval_dtor(&expr);
}
}
break;
default:
tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
convert_to_string(&tmp_val);
smart_str_appendl(implstr, Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
zval_dtor(&tmp_val);
break;
}
}
static void phalcon_fast_join_str(zval *return_value, char *glue, unsigned int glue_length, zval *pieces TSRMLS_DC){
zval **tmp;
HashTable *arr;
HashPosition pos;
smart_str implstr = {0};
unsigned int numelems, i = 0;
if (Z_TYPE_P(pieces) != IS_ARRAY) {
ZVAL_NULL(return_value);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for fast_join()");
return;
}
arr = Z_ARRVAL_P(pieces);
numelems = zend_hash_num_elements(arr);
if (numelems == 0) {
RETURN_EMPTY_STRING();
}
zend_hash_internal_pointer_reset_ex(arr, &pos);
while (zend_hash_get_current_data_ex(arr, (void **) &tmp, &pos) == SUCCESS) {
phalcon_append_printable_zval(&implstr, tmp TSRMLS_CC);
if (++i != numelems) {
smart_str_appendl(&implstr, glue, glue_length);
}
zend_hash_move_forward_ex(arr, &pos);
}
smart_str_0(&implstr);
if (implstr.len) {
RETURN_STRINGL(implstr.c, implstr.len, 0);
} else {
smart_str_free(&implstr);
RETURN_EMPTY_STRING();
}
}
static void phalcon_camelize(zval *return_value, const zval *str){
int i, len;
smart_str camelize_str = {0};
char *marker, ch;
if (unlikely(Z_TYPE_P(str) != IS_STRING)) {
zend_error(E_WARNING, "Invalid arguments supplied for camelize()");
RETURN_EMPTY_STRING();
return;
}
marker = Z_STRVAL_P(str);
len = Z_STRLEN_P(str);
for (i = 0; i < len; i++) {
ch = *marker;
if (i == 0 || ch == '-' || ch == '_') {
if (ch == '-' || ch == '_') {
i++;
marker++;
}
smart_str_appendc(&camelize_str, toupper(*marker));
}
else {
smart_str_appendc(&camelize_str, tolower(*marker));
}
marker++;
}
if (likely(i == len - 1)) {
smart_str_appendc(&camelize_str, *marker);
}
smart_str_0(&camelize_str);
if (camelize_str.c) {
RETURN_STRINGL(camelize_str.c, camelize_str.len, 0);
} else {
RETURN_EMPTY_STRING();
}
}
static void phalcon_uncamelize(zval *return_value, const zval *str){
unsigned int i;
smart_str uncamelize_str = {0};
char *marker, ch;
if (Z_TYPE_P(str) != IS_STRING) {
zend_error(E_WARNING, "Invalid arguments supplied for camelize()");
return;
}
marker = Z_STRVAL_P(str);
for (i = 0; i < Z_STRLEN_P(str); i++) {
ch = *marker;
if (ch == '\0') {
break;
}
if (ch >= 'A' && ch <= 'Z') {
if (i > 0) {
smart_str_appendc(&uncamelize_str, '_');
}
smart_str_appendc(&uncamelize_str, (*marker) + 32);
} else {
smart_str_appendc(&uncamelize_str, (*marker));
}
marker++;
}
smart_str_0(&uncamelize_str);
if (uncamelize_str.c) {
RETURN_STRINGL(uncamelize_str.c, uncamelize_str.len, 0);
} else {
RETURN_EMPTY_STRING();
}
}
static void phalcon_fast_explode(zval *result, zval *delimiter, zval *str){
if (unlikely(Z_TYPE_P(str) != IS_STRING || Z_TYPE_P(delimiter) != IS_STRING)) {
ZVAL_NULL(result);
zend_error(E_WARNING, "Invalid arguments supplied for explode()");
return;
}
array_init(result);
php_explode(delimiter, str, result, LONG_MAX);
}
static void phalcon_fast_explode_str(zval *result, const char *delimiter, int delimiter_length, zval *str){
zval delimiter_zval;
if (unlikely(Z_TYPE_P(str) != IS_STRING)) {
ZVAL_NULL(result);
zend_error(E_WARNING, "Invalid arguments supplied for explode()");
return;
}
ZVAL_STRINGL(&delimiter_zval, delimiter, delimiter_length, 0);
array_init(result);
php_explode(&delimiter_zval, str, result, LONG_MAX);
}
static int phalcon_memnstr(const zval *haystack, const zval *needle) {
if (Z_TYPE_P(haystack) != IS_STRING || Z_TYPE_P(needle) != IS_STRING) {
zend_error(E_WARNING, "Invalid arguments supplied for memnstr()");
return 0;
}
if (Z_STRLEN_P(haystack) >= Z_STRLEN_P(needle)) {
return php_memnstr(Z_STRVAL_P(haystack), Z_STRVAL_P(needle), Z_STRLEN_P(needle), Z_STRVAL_P(haystack) + Z_STRLEN_P(haystack)) ? 1 : 0;
}
return 0;
}
static int phalcon_memnstr_str(const zval *haystack, char *needle, unsigned int needle_length) {
if (Z_TYPE_P(haystack) != IS_STRING) {
zend_error(E_WARNING, "Invalid arguments supplied for memnstr()");
return 0;
}
if (Z_STRLEN_P(haystack) >= needle_length) {
return php_memnstr(Z_STRVAL_P(haystack), needle, needle_length, Z_STRVAL_P(haystack) + Z_STRLEN_P(haystack)) ? 1 : 0;
}
return 0;
}
static void phalcon_fast_strpos(zval *return_value, const zval *haystack, const zval *needle) {
#if PHP_VERSION_ID >= 50600
const
#endif
char *found = NULL;
if (unlikely(Z_TYPE_P(haystack) != IS_STRING || Z_TYPE_P(needle) != IS_STRING)) {
ZVAL_NULL(return_value);
zend_error(E_WARNING, "Invalid arguments supplied for strpos()");
return;
}
if (!Z_STRLEN_P(needle)) {
ZVAL_NULL(return_value);
zend_error(E_WARNING, "Empty delimiter");
return;
}
found = php_memnstr(Z_STRVAL_P(haystack), Z_STRVAL_P(needle), Z_STRLEN_P(needle), Z_STRVAL_P(haystack) + Z_STRLEN_P(haystack));
if (found) {
ZVAL_LONG(return_value, found-Z_STRVAL_P(haystack));
} else {
ZVAL_FALSE(return_value);
}
}
static void phalcon_fast_strpos_str(zval *return_value, const zval *haystack, char *needle, unsigned int needle_length) {
#if PHP_VERSION_ID >= 50600
const
#endif
char *found = NULL;
if (unlikely(Z_TYPE_P(haystack) != IS_STRING)) {
ZVAL_NULL(return_value);
zend_error(E_WARNING, "Invalid arguments supplied for strpos()");
return;
}
found = php_memnstr(Z_STRVAL_P(haystack), needle, needle_length, Z_STRVAL_P(haystack) + Z_STRLEN_P(haystack));
if (found) {
ZVAL_LONG(return_value, found-Z_STRVAL_P(haystack));
} else {
ZVAL_FALSE(return_value);
}
}
static void phalcon_fast_stripos_str(zval *return_value, zval *haystack, char *needle, unsigned int needle_length) {
#if PHP_VERSION_ID >= 50600
const
#endif
char *found = NULL;
char *needle_dup, *haystack_dup;
if (unlikely(Z_TYPE_P(haystack) != IS_STRING)) {
ZVAL_NULL(return_value);
zend_error(E_WARNING, "Invalid arguments supplied for stripos()");
return;
}
haystack_dup = estrndup(Z_STRVAL_P(haystack), Z_STRLEN_P(haystack));
php_strtolower(haystack_dup, Z_STRLEN_P(haystack));
needle_dup = estrndup(needle, needle_length);
php_strtolower(needle_dup, needle_length);
found = php_memnstr(haystack_dup, needle, needle_length, haystack_dup + Z_STRLEN_P(haystack));
efree(haystack_dup);
efree(needle_dup);
if (found) {
ZVAL_LONG(return_value, found-Z_STRVAL_P(haystack));
} else {
ZVAL_FALSE(return_value);
}
}
static void phalcon_fast_str_replace(zval *return_value, zval *search, zval *replace, zval *subject) {
zval replace_copy, search_copy;
int copy_replace = 0, copy_search = 0;
if (Z_TYPE_P(subject) != IS_STRING) {
ZVAL_NULL(return_value);
zend_error(E_WARNING, "Invalid arguments supplied for str_replace()");
return;
}
if (Z_TYPE_P(replace) != IS_STRING) {
zend_make_printable_zval(replace, &replace_copy, &copy_replace);
if (copy_replace) {
replace = &replace_copy;
}
}
if (Z_TYPE_P(search) != IS_STRING) {
zend_make_printable_zval(search, &search_copy, &copy_search);
if (copy_search) {
search = &search_copy;
}
}
Z_TYPE_P(return_value) = IS_STRING;
if (Z_STRLEN_P(subject) == 0) {
ZVAL_STRINGL(return_value, "", 0, 1);
return;
}
if (Z_STRLEN_P(search) == 1) {
php_char_to_str_ex(Z_STRVAL_P(subject),
Z_STRLEN_P(subject),
Z_STRVAL_P(search)[0],
Z_STRVAL_P(replace),
Z_STRLEN_P(replace),
return_value,
1,
NULL);
} else {
if (Z_STRLEN_P(search) > 1) {
Z_STRVAL_P(return_value) = php_str_to_str_ex(Z_STRVAL_P(subject), Z_STRLEN_P(subject),
Z_STRVAL_P(search), Z_STRLEN_P(search),
Z_STRVAL_P(replace), Z_STRLEN_P(replace), &Z_STRLEN_P(return_value), 1, NULL);
} else {
MAKE_COPY_ZVAL(&subject, return_value);
}
}
if (copy_replace) {
zval_dtor(replace);
}
if (copy_search) {
zval_dtor(search);
}
}
static void phalcon_fast_trim(zval *return_value, zval *str, int where TSRMLS_DC) {
zval copy;
int use_copy = 0;
if (Z_TYPE_P(str) != IS_STRING) {
zend_make_printable_zval(str, &copy, &use_copy);
if (use_copy) {
str = &copy;
}
}
php_trim(Z_STRVAL_P(str), Z_STRLEN_P(str), NULL, 0, return_value, where TSRMLS_CC);
if (use_copy) {
zval_dtor(&copy);
}
}
static void phalcon_fast_strip_tags(zval *return_value, zval *str) {
zval copy;
int use_copy = 0;
char *stripped;
size_t len;
if (Z_TYPE_P(str) != IS_STRING) {
zend_make_printable_zval(str, &copy, &use_copy);
if (use_copy) {
str = &copy;
}
}
stripped = estrndup(Z_STRVAL_P(str), Z_STRLEN_P(str));
len = php_strip_tags(stripped, Z_STRLEN_P(str), NULL, NULL, 0);
if (use_copy) {
zval_dtor(&copy);
}
ZVAL_STRINGL(return_value, stripped, len, 0);
}
static void phalcon_fast_strtoupper(zval *return_value, zval *str) {
zval copy;
int use_copy = 0;
char *lower_str;
unsigned int length;
if (Z_TYPE_P(str) != IS_STRING) {
zend_make_printable_zval(str, &copy, &use_copy);
if (use_copy) {
str = &copy;
}
}
length = Z_STRLEN_P(str);
lower_str = estrndup(Z_STRVAL_P(str), length);
php_strtoupper(lower_str, length);
if (use_copy) {
zval_dtor(str);
}
ZVAL_STRINGL(return_value, lower_str, length, 0);
}
static int phalcon_start_with(const zval *str, const zval *compared, zval *case_sensitive){
int sensitive = 0;
int i;
char *op1_cursor, *op2_cursor;
if (Z_TYPE_P(str) != IS_STRING || Z_TYPE_P(compared) != IS_STRING) {
return 0;
}
if (!Z_STRLEN_P(compared) || !Z_STRLEN_P(str) || Z_STRLEN_P(compared) > Z_STRLEN_P(str)) {
return 0;
}
if (case_sensitive) {
sensitive = zend_is_true(case_sensitive);
}
if (!sensitive) {
return !memcmp(Z_STRVAL_P(str), Z_STRVAL_P(compared), Z_STRLEN_P(compared));
}
op1_cursor = Z_STRVAL_P(str);
op2_cursor = Z_STRVAL_P(compared);
for (i = 0; i < Z_STRLEN_P(compared); i++) {
if (tolower(*op1_cursor) != tolower(*op2_cursor)) {
return 0;
}
op1_cursor++;
op2_cursor++;
}
return 1;
}
static int phalcon_start_with_str(const zval *str, char *compared, unsigned int compared_length){
if (Z_TYPE_P(str) != IS_STRING || compared_length > Z_STRLEN_P(str)) {
return 0;
}
return !memcmp(Z_STRVAL_P(str), compared, compared_length);
}
static int phalcon_start_with_str_str(char *str, unsigned int str_length, char *compared, unsigned int compared_length){
if (compared_length > str_length) {
return 0;
}
return !memcmp(str, compared, compared_length);
}
static int phalcon_end_with(const zval *str, const zval *compared, zval *case_sensitive){
int sensitive = 0;
int i;
char *op1_cursor, *op2_cursor;
if (Z_TYPE_P(str) != IS_STRING || Z_TYPE_P(compared) != IS_STRING) {
return 0;
}
if (!Z_STRLEN_P(compared) || !Z_STRLEN_P(str) || Z_STRLEN_P(compared) > Z_STRLEN_P(str)) {
return 0;
}
if (case_sensitive) {
sensitive = zend_is_true(case_sensitive);
}
if (!sensitive) {
return !memcmp(Z_STRVAL_P(str) + Z_STRLEN_P(str) - Z_STRLEN_P(compared), Z_STRVAL_P(compared), Z_STRLEN_P(compared));
}
op1_cursor = Z_STRVAL_P(str) + Z_STRLEN_P(str) - Z_STRLEN_P(compared);
op2_cursor = Z_STRVAL_P(compared);
for (i = 0; i < Z_STRLEN_P(compared); ++i) {
if (tolower(*op1_cursor) != tolower(*op2_cursor)) {
return 0;
}
++op1_cursor;
++op2_cursor;
}
return 1;
}
static int phalcon_end_with_str(const zval *str, char *compared, unsigned int compared_length){
if (Z_TYPE_P(str) != IS_STRING) {
return 0;
}
if (!compared_length || !Z_STRLEN_P(str) || compared_length > Z_STRLEN_P(str)) {
return 0;
}
return !memcmp(Z_STRVAL_P(str) + Z_STRLEN_P(str) - compared_length, compared, compared_length);
}
static void phalcon_random_string(zval *return_value, const zval *type, const zval *length TSRMLS_DC) {
long i, rand_type, ch;
smart_str random_str = {0};
if (Z_TYPE_P(type) != IS_LONG) {
return;
}
if (Z_LVAL_P(type) > PH_RANDOM_NOZERO) {
return;
}
if (Z_TYPE_P(length) != IS_LONG) {
return;
}
/** Generate seed */
if (!BG(mt_rand_is_seeded)) {
php_mt_srand(GENERATE_SEED() TSRMLS_CC);
}
for (i = 0; i < Z_LVAL_P(length); i++) {
switch (Z_LVAL_P(type)) {
case PH_RANDOM_ALNUM:
rand_type = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(rand_type, 0, 3, PHP_MT_RAND_MAX);
break;
case PH_RANDOM_ALPHA:
rand_type = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(rand_type, 1, 2, PHP_MT_RAND_MAX);
break;
case PH_RANDOM_HEXDEC:
rand_type = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(rand_type, 0, 1, PHP_MT_RAND_MAX);
break;
case PH_RANDOM_NUMERIC:
rand_type = 0;
break;
case PH_RANDOM_NOZERO:
rand_type = 5;
break;
default:
continue;
}
switch (rand_type) {
case 0:
ch = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(ch, '0', '9', PHP_MT_RAND_MAX);
break;
case 1:
ch = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(ch, 'a', 'f', PHP_MT_RAND_MAX);
break;
case 2:
ch = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(ch, 'a', 'z', PHP_MT_RAND_MAX);
break;
case 3:
ch = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(ch, 'A', 'Z', PHP_MT_RAND_MAX);
break;
case 5:
ch = (long) (php_mt_rand(TSRMLS_C) >> 1);
RAND_RANGE(ch, '1', '9', PHP_MT_RAND_MAX);
break;
default:
continue;
}
smart_str_appendc(&random_str, (unsigned int) ch);
}
smart_str_0(&random_str);
if (random_str.len) {
RETURN_STRINGL(random_str.c, random_str.len, 0);
} else {
smart_str_free(&random_str);
RETURN_EMPTY_STRING();
}
}
static void phalcon_remove_extra_slashes(zval *return_value, const zval *str) {
char *cursor, *removed_str;
unsigned int i;
if (Z_TYPE_P(str) != IS_STRING) {
RETURN_EMPTY_STRING();
}
if (Z_STRLEN_P(str) > 1) {
cursor = Z_STRVAL_P(str);
cursor += (Z_STRLEN_P(str) - 1);
for (i = Z_STRLEN_P(str); i > 0; i--) {
if ((*cursor) == '/') {
cursor--;
continue;
}
break;
}
} else {
i = Z_STRLEN_P(str);
}
removed_str = emalloc(i + 1);
memcpy(removed_str, Z_STRVAL_P(str), i);
removed_str[i] = '\0';
RETURN_STRINGL(removed_str, i, 0);
}
static int phalcon_spprintf(char **message, int max_len, char *format, ...)
{
va_list arg;
int len;
va_start(arg, format);
len = vspprintf(message, max_len, format, arg);
va_end(arg);
return len;
}
static void phalcon_substr(zval *return_value, zval *str, unsigned long from, unsigned long length) {
if (Z_TYPE_P(str) != IS_STRING) {
if (Z_TYPE_P(str) == IS_NULL || Z_TYPE_P(str) == IS_BOOL) {
RETURN_FALSE;
}
if (Z_TYPE_P(str) == IS_LONG) {
RETURN_EMPTY_STRING();
}
zend_error(E_WARNING, "Invalid arguments supplied for phalcon_substr()");
RETURN_FALSE;
}
if (Z_STRLEN_P(str) < from){
RETURN_FALSE;
}
if (!length || (Z_STRLEN_P(str) < (length + from))) {
length = Z_STRLEN_P(str) - from;
}
if (length <= 0){
RETURN_EMPTY_STRING();
}
RETURN_STRINGL(Z_STRVAL_P(str) + from, length, 1);
}
static void phalcon_append_printable_array(smart_str *implstr, zval *value TSRMLS_DC) {
zval **tmp;
HashTable *arr;
HashPosition pos;
unsigned int numelems, i = 0, str_len;
arr = Z_ARRVAL_P(value);
numelems = zend_hash_num_elements(arr);
smart_str_appendc(implstr, '[');
if (numelems > 0) {
zend_hash_internal_pointer_reset_ex(arr, &pos);
while (zend_hash_get_current_data_ex(arr, (void **) &tmp, &pos) == SUCCESS) {
if (Z_TYPE_PP(tmp) == IS_OBJECT) {
smart_str_appendc(implstr, 'O');
{
char stmp[MAX_LENGTH_OF_LONG + 1];
str_len = slprintf(stmp, sizeof(stmp), "%ld", Z_OBJVAL_PP(tmp).handle);
smart_str_appendl(implstr, stmp, str_len);
}
} else {
if (Z_TYPE_PP(tmp) == IS_ARRAY) {
phalcon_append_printable_array(implstr, *tmp TSRMLS_CC);
} else {
phalcon_append_printable_zval(implstr, tmp TSRMLS_CC);
}
}
if (++i != numelems) {
smart_str_appendc(implstr, ',');
}
zend_hash_move_forward_ex(arr, &pos);
}
}
smart_str_appendc(implstr, ']');
}
static void phalcon_unique_key(zval *return_value, zval *prefix, zval *value TSRMLS_DC) {
smart_str implstr = {0};
if (Z_TYPE_P(prefix) == IS_STRING) {
smart_str_appendl(&implstr, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix));
}
if (Z_TYPE_P(value) == IS_ARRAY) {
phalcon_append_printable_array(&implstr, value TSRMLS_CC);
} else {
phalcon_append_printable_zval(&implstr, &value TSRMLS_CC);
}
smart_str_0(&implstr);
if (implstr.len) {
RETURN_STRINGL(implstr.c, implstr.len, 0);
} else {
smart_str_free(&implstr);
RETURN_NULL();
}
}
zval *phalcon_eol(int eol TSRMLS_DC) {
zval *local_eol;
PHALCON_INIT_VAR(local_eol);
if (eol) {
ZVAL_STRING(local_eol, PHP_EOL, 1);
} else {
ZVAL_EMPTY_STRING(local_eol);
}
return local_eol;
}
static void phalcon_base64_encode(zval *return_value, zval *data) {
zval copy;
char *encoded;
int use_copy = 0, length;
if (Z_TYPE_P(data) != IS_STRING) {
zend_make_printable_zval(data, &copy, &use_copy);
if (use_copy) {
data = &copy;
}
}
encoded = (char *) php_base64_encode((unsigned char *)(Z_STRVAL_P(data)), Z_STRLEN_P(data), &length);
if (use_copy) {
zval_dtor(data);
}
if (encoded) {
RETURN_STRINGL(encoded, length, 0);
} else {
RETURN_NULL();
}
}
static void phalcon_base64_decode(zval *return_value, zval *data) {
zval copy;
char *decoded;
int use_copy = 0, length;
if (Z_TYPE_P(data) != IS_STRING) {
zend_make_printable_zval(data, &copy, &use_copy);
if (use_copy) {
data = &copy;
}
}
decoded = (char *) php_base64_decode((unsigned char *)(Z_STRVAL_P(data)), Z_STRLEN_P(data), &length);
if (use_copy) {
zval_dtor(data);
}
if (decoded) {
RETURN_STRINGL(decoded, length, 0);
} else {
RETURN_NULL();
}
}
static void phalcon_md5(zval *return_value, zval *str) {
PHP_MD5_CTX ctx;
unsigned char digest[16];
char hexdigest[33];
zval copy;
int use_copy = 0;
if (Z_TYPE_P(str) != IS_STRING) {
zend_make_printable_zval(str, &copy, &use_copy);
if (use_copy) {
str = &copy;
}
}
PHP_MD5Init(&ctx);
PHP_MD5Update(&ctx, Z_STRVAL_P(str), Z_STRLEN_P(str));
PHP_MD5Final(digest, &ctx);
make_digest(hexdigest, digest);
ZVAL_STRINGL(return_value, hexdigest, 32, 1);
}
#if PHALCON_USE_PHP_PCRE
static void phalcon_preg_match(zval *return_value, zval **return_value_ptr, zval *regex, zval *subject, zval *matches TSRMLS_DC)
{
zval copy;
int use_copy = 0;
pcre_cache_entry *pce;
if (Z_TYPE_P(regex) != IS_STRING) {
zend_error(E_WARNING, "Invalid arguments supplied for phalcon_preg_match()");
RETURN_FALSE;
}
if (Z_TYPE_P(subject) != IS_STRING) {
zend_make_printable_zval(subject, &copy, &use_copy);
if (use_copy) {
subject = &copy;
}
}
/* Compile regex or get it from cache. */
if ((pce = pcre_get_compiled_regex_cache(Z_STRVAL_P(regex), Z_STRLEN_P(regex) TSRMLS_CC)) == NULL) {
if (use_copy) {
zval_dtor(subject);
}
RETURN_FALSE;
}
php_pcre_match_impl(pce, Z_STRVAL_P(subject), Z_STRLEN_P(subject), return_value, matches, 0, 0, 0, 0 TSRMLS_CC);
if (use_copy) {
zval_dtor(&copy);
}
}
#else
static void phalcon_preg_match(zval *return_value, zval **return_value_ptr, zval *regex, zval *subject, zval *matches TSRMLS_DC)
{
if (matches) {
Z_SET_ISREF_P(matches);
}
phalcon_call_func_params(return_value, return_value_ptr, SL("preg_match") TSRMLS_CC, (matches ? 3 : 2), regex, subject, matches);
if (matches) {
Z_UNSET_ISREF_P(matches);
}
}
#endif /* PHALCON_USE_PHP_PCRE */
#ifdef PHALCON_USE_PHP_JSON
static void phalcon_json_encode(zval *return_value, zval **return_value_ptr, zval *v, int opts TSRMLS_DC)
{
smart_str buf = { NULL, 0, 0 };
php_json_encode(&buf, v, opts TSRMLS_CC);
smart_str_0(&buf);
ZVAL_STRINGL(return_value, buf.c, buf.len, 0);
}
static void phalcon_json_decode(zval *return_value, zval **return_value_ptr, zval *v, zend_bool assoc TSRMLS_DC)
{
zval copy;
int use_copy = 0;
if (unlikely(Z_TYPE_P(v) != IS_STRING)) {
zend_make_printable_zval(v, &copy, &use_copy);
if (use_copy) {
v = &copy;
}
}
php_json_decode(return_value, Z_STRVAL_P(v), Z_STRLEN_P(v), assoc, 512 /* JSON_PARSER_DEFAULT_DEPTH */ TSRMLS_CC);
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
}
#else
static void phalcon_json_encode(zval *return_value, zval **return_value_ptr, zval *v, int opts TSRMLS_DC)
{
zval *zopts;
MAKE_STD_ZVAL(zopts);
ZVAL_LONG(zopts, opts);
if (FAILURE == phalcon_call_func_params(return_value, return_value_ptr, ZEND_STRL("json_encode") TSRMLS_CC, 2, v, zopts)) {
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
zval_ptr_dtor(&zopts);
}
static void phalcon_json_decode(zval *return_value, zval **return_value_ptr, zval *v, zend_bool assoc TSRMLS_DC)
{
zval *zassoc = assoc ? PHALCON_GLOBAL(z_true) : PHALCON_GLOBAL(z_false);
if (FAILURE == phalcon_call_func_params(return_value, return_value_ptr, ZEND_STRL("json_decode") TSRMLS_CC, 2, v, zassoc)) {
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
}
#endif /* PHALCON_USE_PHP_JSON */
static void phalcon_lcfirst(zval *return_value, zval *s)
{
zval copy;
char *c;
int use_copy = 0;
if (unlikely(Z_TYPE_P(s) != IS_STRING)) {
zend_make_printable_zval(s, &copy, &use_copy);
if (use_copy) {
s = &copy;
}
}
if (!Z_STRLEN_P(s)) {
ZVAL_EMPTY_STRING(return_value);
}
else {
ZVAL_STRINGL(return_value, Z_STRVAL_P(s), Z_STRLEN_P(s), 1);
c = Z_STRVAL_P(return_value);
*c = tolower((unsigned char)*c);
}
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
}
static void phalcon_ucfirst(zval *return_value, zval *s)
{
zval copy;
char *c;
int use_copy = 0;
if (unlikely(Z_TYPE_P(s) != IS_STRING)) {
zend_make_printable_zval(s, &copy, &use_copy);
if (use_copy) {
s = &copy;
}
}
if (!Z_STRLEN_P(s)) {
ZVAL_EMPTY_STRING(return_value);
}
else {
ZVAL_STRINGL(return_value, Z_STRVAL_P(s), Z_STRLEN_P(s), 1);
c = Z_STRVAL_P(return_value);
*c = toupper((unsigned char)*c);
}
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
}
static int phalcon_http_build_query(zval *return_value, zval *params, char *sep TSRMLS_DC)
{
if (Z_TYPE_P(params) == IS_ARRAY || Z_TYPE_P(params) == IS_OBJECT) {
smart_str formstr = { NULL, 0, 0 };
int res;
#if PHP_VERSION_ID < 50400
res = php_url_encode_hash_ex(HASH_OF(params), &formstr, NULL, 0, NULL, 0, NULL, 0, (Z_TYPE_P(params) == IS_OBJECT ? params : NULL), sep TSRMLS_CC);
#else
res = php_url_encode_hash_ex(HASH_OF(params), &formstr, NULL, 0, NULL, 0, NULL, 0, (Z_TYPE_P(params) == IS_OBJECT ? params : NULL), sep, PHP_QUERY_RFC1738 TSRMLS_CC);
#endif
if (res == SUCCESS) {
if (!formstr.c) {
ZVAL_EMPTY_STRING(return_value);
}
else {
smart_str_0(&formstr);
ZVAL_STRINGL(return_value, formstr.c, formstr.len, 0);
}
return SUCCESS;
}
smart_str_free(&formstr);
ZVAL_FALSE(return_value);
}
else {
ZVAL_NULL(return_value);
}
return FAILURE;
}
static void phalcon_htmlspecialchars(zval *return_value, zval *string, zval *quoting, zval *charset TSRMLS_DC)
{
zval copy;
char *escaped, *cs;
int qs, use_copy = 0;
#if PHP_VERSION_ID < 50400
int escaped_len;
#else
size_t escaped_len;
#endif
if (unlikely(Z_TYPE_P(string) != IS_STRING)) {
zend_make_printable_zval(string, &copy, &use_copy);
if (use_copy) {
string = &copy;
}
}
cs = (charset && Z_TYPE_P(charset) == IS_STRING) ? Z_STRVAL_P(charset) : NULL;
qs = (quoting && Z_TYPE_P(quoting) == IS_LONG) ? Z_LVAL_P(quoting) : ENT_COMPAT;
escaped = php_escape_html_entities_ex((unsigned char *)(Z_STRVAL_P(string)), Z_STRLEN_P(string), &escaped_len, 0, qs, cs, 1 TSRMLS_CC);
ZVAL_STRINGL(return_value, escaped, escaped_len, 0);
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
}
static void phalcon_htmlentities(zval *return_value, zval *string, zval *quoting, zval *charset TSRMLS_DC)
{
zval copy;
char *escaped, *cs;
int qs, use_copy = 0;
#if PHP_VERSION_ID < 50400
int escaped_len;
#else
size_t escaped_len;
#endif
if (unlikely(Z_TYPE_P(string) != IS_STRING)) {
zend_make_printable_zval(string, &copy, &use_copy);
if (use_copy) {
string = &copy;
}
}
cs = (charset && Z_TYPE_P(charset) == IS_STRING) ? Z_STRVAL_P(charset) : NULL;
qs = (quoting && Z_TYPE_P(quoting) == IS_LONG) ? Z_LVAL_P(quoting) : ENT_COMPAT;
escaped = php_escape_html_entities_ex((unsigned char *)(Z_STRVAL_P(string)), Z_STRLEN_P(string), &escaped_len, 1, qs, cs, 1 TSRMLS_CC);
ZVAL_STRINGL(return_value, escaped, escaped_len, 0);
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
}
static void phalcon_strval(zval *return_value, zval *v)
{
zval copy;
int use_copy = 0;
zend_make_printable_zval(v, &copy, &use_copy);
if (use_copy) {
zval *tmp = &copy;
ZVAL_ZVAL(return_value, tmp, 0, 0);
}
else {
ZVAL_ZVAL(return_value, v, 1, 0);
}
}
static void phalcon_date(zval *return_value, zval *format, zval *timestamp TSRMLS_DC)
{
long int ts;
zval copy;
int use_copy = 0;
char *formatted;
if (unlikely(Z_TYPE_P(format) != IS_STRING)) {
zend_make_printable_zval(format, &copy, &use_copy);
if (use_copy) {
format = &copy;
}
}
ts = (timestamp) ? phalcon_get_intval(timestamp) : time(NULL);
formatted = php_format_date(Z_STRVAL_P(format), Z_STRLEN_P(format), ts, 1 TSRMLS_CC);
ZVAL_STRING(return_value, formatted, 0);
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
}
static void phalcon_addslashes(zval *return_value, zval *str TSRMLS_DC)
{
zval copy;
int use_copy = 0;
if (unlikely(Z_TYPE_P(str) != IS_STRING)) {
zend_make_printable_zval(str, &copy, &use_copy);
if (use_copy) {
str = &copy;
}
}
ZVAL_STRING(return_value, php_addslashes(Z_STRVAL_P(str), Z_STRLEN_P(str), &Z_STRLEN_P(return_value), 0 TSRMLS_CC), 0);
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
}
#if PHP_VERSION_ID < 50400
const char* zend_new_interned_string(const char *arKey, int nKeyLength, int free_src TSRMLS_DC)
{
return arKey;
}
#endif
static void phalcon_add_trailing_slash(zval** v)
{
PHALCON_ENSURE_IS_STRING(v);
if (Z_STRLEN_PP(v)) {
int len = Z_STRLEN_PP(v);
char *c = Z_STRVAL_PP(v);
#ifdef PHP_WIN32
if (c[len-1] != '/' && c[len-1] != '\\')
#else
if (c[len-1] != PHP_DIR_SEPARATOR)
#endif
{
SEPARATE_ZVAL(v);
c = Z_STRVAL_PP(v);
if (!IS_INTERNED(c)) {
c = erealloc(c, len+2);
}
else {
c = emalloc(len+2);
if (c != NULL) {
memcpy(c, Z_STRVAL_PP(v), Z_STRLEN_PP(v));
}
}
if (c != NULL) {
c[len] = PHP_DIR_SEPARATOR;
c[len+1] = 0;
ZVAL_STRINGL(*v, c, len+1, 0);
}
}
}
}
#include <ctype.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_math.h>
#include <ext/standard/html.h>
static void phalcon_filter_alphanum(zval *return_value, zval *param){
unsigned int i;
unsigned char ch;
smart_str filtered_str = {0};
zval copy;
int use_copy = 0;
if (Z_TYPE_P(param) != IS_STRING) {
zend_make_printable_zval(param, &copy, &use_copy);
if (use_copy) {
param = &copy;
}
}
for (i = 0; i < Z_STRLEN_P(param); i++) {
ch = Z_STRVAL_P(param)[i];
if (ch == '\0') {
break;
}
if (isalnum(ch)) {
smart_str_appendc(&filtered_str, ch);
}
}
if (use_copy) {
zval_dtor(param);
}
smart_str_0(&filtered_str);
if (filtered_str.c) {
RETURN_STRINGL(filtered_str.c, filtered_str.len, 0);
} else {
RETURN_EMPTY_STRING();
}
}
static void phalcon_filter_identifier(zval *return_value, zval *param){
unsigned int i;
unsigned char ch;
zval copy;
smart_str filtered_str = {0};
int use_copy = 0;
if (Z_TYPE_P(param) != IS_STRING) {
zend_make_printable_zval(param, &copy, &use_copy);
if (use_copy) {
param = &copy;
}
}
for (i = 0; i < Z_STRLEN_P(param); i++) {
ch = Z_STRVAL_P(param)[i];
if (ch == '\0') {
break;
}
if (isalnum(ch) || ch == '_') {
smart_str_appendc(&filtered_str, ch);
}
}
if (use_copy) {
zval_dtor(param);
}
smart_str_0(&filtered_str);
if (filtered_str.c) {
RETURN_STRINGL(filtered_str.c, filtered_str.len, 0);
} else {
RETURN_EMPTY_STRING();
}
}
static void phalcon_is_basic_charset(zval *return_value, const zval *param){
unsigned int i;
unsigned int ch;
int iso88591 = 0;
for (i = 0; i < Z_STRLEN_P(param); i++) {
ch = Z_STRVAL_P(param)[i];
if (ch != '\0') {
if (ch == 172 || (ch >= 128 && ch <= 159)) {
continue;
}
if (ch >= 160 && ch <= 255) {
iso88591 = 1;
continue;
}
}
RETURN_FALSE;
}
if (!iso88591) {
RETURN_STRING("ASCII", 1);
}
RETURN_STRING("ISO-8859-1", 1);
}
static long phalcon_unpack(char *data, int size, int issigned, int *map)
{
long result;
char *cresult = (char *) &result;
int i;
result = issigned ? -1 : 0;
for (i = 0; i < size; i++) {
cresult[map[i]] = *data++;
}
return result;
}
static inline char *phalcon_longtohex(unsigned long value) {
static char digits[] = "0123456789abcdef";
char buf[(sizeof(unsigned long) << 3) + 1];
char *ptr, *end;
end = ptr = buf + sizeof(buf) - 1;
*ptr = '\0';
do {
*--ptr = digits[value & 0x0F];
value >>= 4;
} while (ptr > buf && value);
return estrndup(ptr, end - ptr);
}
static void phalcon_escape_multi(zval *return_value, zval *param, const char *escape_char, unsigned int escape_length, char escape_extra, int use_whitelist) {
unsigned int i;
zval copy;
smart_str escaped_str = {0};
char machine_little_endian, *hex;
int big_endian_long_map[4];
int use_copy = 0, machine_endian_check = 1;
int issigned = 0;
long value;
if (Z_TYPE_P(param) != IS_STRING) {
zend_make_printable_zval(param, &copy, &use_copy);
if (use_copy) {
param = &copy;
}
}
if (Z_STRLEN_P(param) <= 0) {
RETURN_FALSE;
}
machine_little_endian = ((char *) &machine_endian_check)[0];
if (machine_little_endian) {
big_endian_long_map[0] = 3;
big_endian_long_map[1] = 2;
big_endian_long_map[2] = 1;
big_endian_long_map[3] = 0;
} else {
int size = sizeof(Z_LVAL_P(param));
big_endian_long_map[0] = size - 4;
big_endian_long_map[1] = size - 3;
big_endian_long_map[2] = size - 2;
big_endian_long_map[3] = size - 1;
}
if ((Z_STRLEN_P(param) % 4) != 0) {
RETURN_FALSE;
}
for (i = 0; i < Z_STRLEN_P(param); i += 4) {
issigned = Z_STRVAL_P(param)[i] & 0x80;
value = 0;
if (sizeof(long) > 4 && issigned) {
value = ~INT_MAX;
}
value |= phalcon_unpack(&Z_STRVAL_P(param)[i], 4, issigned, big_endian_long_map);
if (sizeof(long) > 4) {
value = (unsigned int) value;
}
if (value == '\0') {
RETURN_FALSE;
}
if (value < 256 && isalnum(value)) {
smart_str_appendc(&escaped_str, (unsigned char) value);
continue;
}
if (use_whitelist) {
switch (value) {
case ' ':
case '/':
case '*':
case '+':
case '-':
case '\t':
case '\n':
case '^':
case '$':
case '!':
case '?':
case '\\':
case '#':
case '}':
case '{':
case ')':
case '(':
case ']':
case '[':
case '.':
case ',':
case ':':
case ';':
case '_':
case '|':
smart_str_appendc(&escaped_str, (unsigned char) value);
continue;
}
}
hex = phalcon_longtohex(value);
smart_str_appendl(&escaped_str, escape_char, escape_length);
smart_str_appendl(&escaped_str, hex, strlen(hex));
if (escape_extra != '\0') {
smart_str_appendc(&escaped_str, escape_extra);
}
efree(hex);
}
if (use_copy) {
zval_dtor(param);
}
smart_str_0(&escaped_str);
if (escaped_str.c) {
RETURN_STRINGL(escaped_str.c, escaped_str.len, 0);
} else {
RETURN_EMPTY_STRING();
}
}
static void phalcon_escape_css(zval *return_value, zval *param) {
phalcon_escape_multi(return_value, param, "\\", sizeof("\\")-1, ' ', 0);
}
static void phalcon_escape_js(zval *return_value, zval *param) {
phalcon_escape_multi(return_value, param, "\\x", sizeof("\\x")-1, '\0', 1);
}
static void phalcon_escape_htmlattr(zval *return_value, zval *param) {
phalcon_escape_multi(return_value, param, "&#x", sizeof("&#x")-1, ';', 1);
}
static void phalcon_escape_html(zval *return_value, zval *str, zval *quote_style, zval *charset TSRMLS_DC) {
#if PHP_VERSION_ID < 50400
int length;
#else
size_t length;
#endif
char *escaped;
if (Z_TYPE_P(str) != IS_STRING) {
/* Nothing to escape */
RETURN_ZVAL(str, 1, 0);
}
if (Z_TYPE_P(quote_style) != IS_LONG) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid quote_style supplied for phalcon_escape_html()");
RETURN_ZVAL(str, 1, 0);
}
if (Z_TYPE_P(charset) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid charset supplied for phalcon_escape_html()");
RETURN_ZVAL(str, 1, 0);
}
escaped = php_escape_html_entities((unsigned char*) Z_STRVAL_P(str), Z_STRLEN_P(str), &length, 0, Z_LVAL_P(quote_style), Z_STRVAL_P(charset) TSRMLS_CC);
RETURN_STRINGL(escaped, length, 0);
}
#include <ext/standard/php_string.h>
#include <Zend/zend_operators.h>
static void phalcon_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy){
zend_make_printable_zval(expr, expr_copy, use_copy);
if (use_copy) {
Z_SET_REFCOUNT_P(expr_copy, 1);
Z_UNSET_ISREF_P(expr_copy);
}
}
static int phalcon_and_function(zval *result, zval *left, zval *right){
int istrue = zend_is_true(left) && zend_is_true(right);
ZVAL_BOOL(result, istrue);
return SUCCESS;
}
static void phalcon_concat_self(zval **left, zval *right TSRMLS_DC){
zval left_copy, right_copy;
uint length;
int use_copy_left = 0, use_copy_right = 0;
if (Z_TYPE_P(right) != IS_STRING) {
phalcon_make_printable_zval(right, &right_copy, &use_copy_right);
if (use_copy_right) {
right = &right_copy;
}
}
if (Z_TYPE_PP(left) == IS_NULL) {
Z_STRVAL_PP(left) = emalloc(Z_STRLEN_P(right) + 1);
memcpy(Z_STRVAL_PP(left), Z_STRVAL_P(right), Z_STRLEN_P(right));
Z_STRVAL_PP(left)[Z_STRLEN_P(right)] = 0;
Z_STRLEN_PP(left) = Z_STRLEN_P(right);
Z_TYPE_PP(left) = IS_STRING;
if (use_copy_right) {
zval_dtor(&right_copy);
}
return;
}
if (Z_TYPE_PP(left) != IS_STRING) {
phalcon_make_printable_zval(*left, &left_copy, &use_copy_left);
if (use_copy_left) {
PHALCON_CPY_WRT_CTOR(*left, (&left_copy));
}
}
length = Z_STRLEN_PP(left) + Z_STRLEN_P(right);
Z_STRVAL_PP(left) = erealloc(Z_STRVAL_PP(left), length + 1);
memcpy(Z_STRVAL_PP(left) + Z_STRLEN_PP(left), Z_STRVAL_P(right), Z_STRLEN_P(right));
Z_STRVAL_PP(left)[length] = 0;
Z_STRLEN_PP(left) = length;
Z_TYPE_PP(left) = IS_STRING;
if (use_copy_left) {
zval_dtor(&left_copy);
}
if (use_copy_right) {
zval_dtor(&right_copy);
}
}
static void phalcon_concat_self_str(zval **left, const char *right, int right_length TSRMLS_DC){
zval left_copy;
uint length;
int use_copy = 0;
if (Z_TYPE_PP(left) == IS_NULL) {
Z_STRVAL_PP(left) = emalloc(right_length + 1);
memcpy(Z_STRVAL_PP(left), right, right_length);
Z_STRVAL_PP(left)[right_length] = 0;
Z_STRLEN_PP(left) = right_length;
Z_TYPE_PP(left) = IS_STRING;
return;
}
if (Z_TYPE_PP(left) != IS_STRING) {
phalcon_make_printable_zval(*left, &left_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*left, (&left_copy));
}
}
length = Z_STRLEN_PP(left) + right_length;
Z_STRVAL_PP(left) = erealloc(Z_STRVAL_PP(left), length + 1);
memcpy(Z_STRVAL_PP(left) + Z_STRLEN_PP(left), right, right_length);
Z_STRVAL_PP(left)[length] = 0;
Z_STRLEN_PP(left) = length;
Z_TYPE_PP(left) = IS_STRING;
if (use_copy) {
zval_dtor(&left_copy);
}
}
static int phalcon_compare_strict_string(zval *op1, const char *op2, int op2_length){
switch (Z_TYPE_P(op1)) {
case IS_STRING:
if (!Z_STRLEN_P(op1) && !op2_length) {
return 1;
}
if (Z_STRLEN_P(op1) != op2_length) {
return 0;
}
return !zend_binary_strcmp(Z_STRVAL_P(op1), Z_STRLEN_P(op1), op2, op2_length);
case IS_NULL:
return !zend_binary_strcmp("", 0, op2, op2_length);
case IS_BOOL:
if (!Z_BVAL_P(op1)) {
return !zend_binary_strcmp("0", strlen("0"), op2, op2_length);
} else {
return !zend_binary_strcmp("1", strlen("1"), op2, op2_length);
}
}
return 0;
}
static int phalcon_compare_strict_long(zval *op1, long op2 TSRMLS_DC){
int bool_result;
switch (Z_TYPE_P(op1)) {
case IS_LONG:
return Z_LVAL_P(op1) == op2;
case IS_DOUBLE:
return Z_LVAL_P(op1) == (double) op2;
case IS_NULL:
return 0 == op2;
case IS_BOOL:
if (Z_BVAL_P(op1)) {
return 0 == op2;
} else {
return 1 == op2;
}
default:
{
zval result, op2_tmp;
ZVAL_LONG(&op2_tmp, op2);
is_equal_function(&result, op1, &op2_tmp TSRMLS_CC);
bool_result = Z_BVAL(result);
return bool_result;
}
}
return 0;
}
static int phalcon_add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC){
int status;
int ref_count = Z_REFCOUNT_P(result);
int is_ref = Z_ISREF_P(result);
status = add_function(result, op1, op2 TSRMLS_CC);
Z_SET_REFCOUNT_P(result, ref_count);
Z_SET_ISREF_TO_P(result, is_ref);
return status;
}
static void phalcon_cast(zval *result, zval *var, zend_uint type){
ZVAL_ZVAL(result, var, 1, 0);
switch (type) {
case IS_STRING:
convert_to_string(result);
break;
case IS_LONG:
convert_to_long(result);
break;
case IS_DOUBLE:
convert_to_double(result);
break;
/*case IS_BOOL:
convert_to_bool(result);
break;*/
case IS_ARRAY:
if (Z_TYPE_P(result) != IS_ARRAY) {
convert_to_array(result);
}
break;
}
}
long phalcon_get_intval(const zval *op) {
switch (Z_TYPE_P(op)) {
case IS_LONG:
return Z_LVAL_P(op);
case IS_BOOL:
return Z_BVAL_P(op);
case IS_DOUBLE:
return (long) Z_DVAL_P(op);
case IS_STRING: {
long long_value;
double double_value;
zend_uchar type;
ASSUME(Z_STRVAL_P(op) != NULL);
type = is_numeric_string(Z_STRVAL_P(op), Z_STRLEN_P(op), &long_value, &double_value, 0);
if (type == IS_LONG) {
return long_value;
}
if (type == IS_DOUBLE) {
return (long)double_value;
}
return 0;
}
}
return 0;
}
static int phalcon_is_numeric(const zval *op) {
int type;
switch (Z_TYPE_P(op)) {
case IS_LONG:
return 1;
case IS_BOOL:
return 0;
case IS_DOUBLE:
return 1;
case IS_STRING:
if ((type = is_numeric_string(Z_STRVAL_P(op), Z_STRLEN_P(op), NULL, NULL, 0))) {
if (type == IS_LONG || type == IS_DOUBLE) {
return 1;
}
}
}
return 0;
}
static int phalcon_is_equal(zval *op1, zval *op2 TSRMLS_DC) {
zval result;
is_equal_function(&result, op1, op2 TSRMLS_CC);
return Z_BVAL(result);
}
static int phalcon_less(zval *op1, zval *op2 TSRMLS_DC) {
zval result;
is_smaller_function(&result, op1, op2 TSRMLS_CC);
return Z_BVAL(result);
}
static int phalcon_less_equal(zval *op1, zval *op2 TSRMLS_DC) {
zval result;
is_smaller_or_equal_function(&result, op1, op2 TSRMLS_CC);
return Z_BVAL(result);
}
static int phalcon_less_long(zval *op1, long op2 TSRMLS_DC) {
zval result, op2_zval;
ZVAL_LONG(&op2_zval, op2);
is_smaller_function(&result, op1, &op2_zval TSRMLS_CC);
return Z_BVAL(result);
}
static int phalcon_less_equal_long(zval *op1, long op2 TSRMLS_DC) {
zval result, op2_zval;
ZVAL_LONG(&op2_zval, op2);
is_smaller_or_equal_function(&result, op1, &op2_zval TSRMLS_CC);
return Z_BVAL(result);
}
static int phalcon_greater(zval *op1, zval *op2 TSRMLS_DC) {
zval result;
is_smaller_or_equal_function(&result, op1, op2 TSRMLS_CC);
return !Z_BVAL(result);
}
static int phalcon_greater_long(zval *op1, long op2 TSRMLS_DC) {
zval result, op2_zval;
ZVAL_LONG(&op2_zval, op2);
is_smaller_or_equal_function(&result, op1, &op2_zval TSRMLS_CC);
return !Z_BVAL(result);
}
static int phalcon_greater_equal(zval *op1, zval *op2 TSRMLS_DC) {
zval result;
is_smaller_function(&result, op1, op2 TSRMLS_CC);
return !Z_BVAL(result);
}
static int phalcon_greater_equal_long(zval *op1, long op2 TSRMLS_DC) {
zval result, op2_zval;
ZVAL_LONG(&op2_zval, op2);
is_smaller_function(&result, op1, &op2_zval TSRMLS_CC);
return !Z_BVAL(result);
}
static int phalcon_is_identical(zval *op1, zval *op2 TSRMLS_DC) {
zval result;
is_identical_function(&result, op1, op2 TSRMLS_CC);
return Z_BVAL(result);
}
#include <ext/standard/php_string.h>
static void phalcon_concat_sv(zval **result, const char *op1, zend_uint op1_len, zval *op2, int self_var TSRMLS_DC){
zval result_copy, op2_copy;
int use_copy = 0, use_copy2 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
length = op1_len + Z_STRLEN_P(op2);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svs(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, int self_var TSRMLS_DC){
zval result_copy, op2_copy;
int use_copy = 0, use_copy2 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + op3_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), op3, op3_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svsv(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, int self_var TSRMLS_DC){
zval result_copy, op2_copy, op4_copy;
int use_copy = 0, use_copy2 = 0, use_copy4 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), op3, op3_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len, Z_STRVAL_P(op4), Z_STRLEN_P(op4));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svsvs(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, const char *op5, zend_uint op5_len, int self_var TSRMLS_DC){
zval result_copy, op2_copy, op4_copy;
int use_copy = 0, use_copy2 = 0, use_copy4 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4) + op5_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), op3, op3_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len, Z_STRVAL_P(op4), Z_STRLEN_P(op4));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4), op5, op5_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svsvsv(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, const char *op5, zend_uint op5_len, zval *op6, int self_var TSRMLS_DC){
zval result_copy, op2_copy, op4_copy, op6_copy;
int use_copy = 0, use_copy2 = 0, use_copy4 = 0, use_copy6 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
if (Z_TYPE_P(op6) != IS_STRING) {
zend_make_printable_zval(op6, &op6_copy, &use_copy6);
if (use_copy6) {
op6 = &op6_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4) + op5_len + Z_STRLEN_P(op6);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), op3, op3_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len, Z_STRVAL_P(op4), Z_STRLEN_P(op4));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4), op5, op5_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4) + op5_len, Z_STRVAL_P(op6), Z_STRLEN_P(op6));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy6) {
zval_dtor(op6);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svsvsvs(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, const char *op5, zend_uint op5_len, zval *op6, const char *op7, zend_uint op7_len, int self_var TSRMLS_DC){
zval result_copy, op2_copy, op4_copy, op6_copy;
int use_copy = 0, use_copy2 = 0, use_copy4 = 0, use_copy6 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
if (Z_TYPE_P(op6) != IS_STRING) {
zend_make_printable_zval(op6, &op6_copy, &use_copy6);
if (use_copy6) {
op6 = &op6_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4) + op5_len + Z_STRLEN_P(op6) + op7_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), op3, op3_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len, Z_STRVAL_P(op4), Z_STRLEN_P(op4));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4), op5, op5_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4) + op5_len, Z_STRVAL_P(op6), Z_STRLEN_P(op6));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4) + op5_len + Z_STRLEN_P(op6), op7, op7_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy6) {
zval_dtor(op6);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svsvv(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, zval *op4, zval *op5, int self_var TSRMLS_DC){
zval result_copy, op2_copy, op4_copy, op5_copy;
int use_copy = 0, use_copy2 = 0, use_copy4 = 0, use_copy5 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
if (Z_TYPE_P(op5) != IS_STRING) {
zend_make_printable_zval(op5, &op5_copy, &use_copy5);
if (use_copy5) {
op5 = &op5_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4) + Z_STRLEN_P(op5);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), op3, op3_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len, Z_STRVAL_P(op4), Z_STRLEN_P(op4));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4), Z_STRVAL_P(op5), Z_STRLEN_P(op5));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy5) {
zval_dtor(op5);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svv(zval **result, const char *op1, zend_uint op1_len, zval *op2, zval *op3, int self_var TSRMLS_DC){
zval result_copy, op2_copy, op3_copy;
int use_copy = 0, use_copy2 = 0, use_copy3 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + Z_STRLEN_P(op3);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), Z_STRVAL_P(op3), Z_STRLEN_P(op3));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_svvs(zval **result, const char *op1, zend_uint op1_len, zval *op2, zval *op3, const char *op4, zend_uint op4_len, int self_var TSRMLS_DC){
zval result_copy, op2_copy, op3_copy;
int use_copy = 0, use_copy2 = 0, use_copy3 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
length = op1_len + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + op4_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2), Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + op1_len + Z_STRLEN_P(op2) + Z_STRLEN_P(op3), op4, op4_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vs(zval **result, zval *op1, const char *op2, zend_uint op2_len, int self_var TSRMLS_DC){
zval result_copy, op1_copy;
int use_copy = 0, use_copy1 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vsv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op3_copy;
int use_copy = 0, use_copy1 = 0, use_copy3 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vsvs(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op3_copy;
int use_copy = 0, use_copy1 = 0, use_copy3 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3), op4, op4_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vsvsv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, zval *op5, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op3_copy, op5_copy;
int use_copy = 0, use_copy1 = 0, use_copy3 = 0, use_copy5 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op5) != IS_STRING) {
zend_make_printable_zval(op5, &op5_copy, &use_copy5);
if (use_copy5) {
op5 = &op5_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3), op4, op4_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len, Z_STRVAL_P(op5), Z_STRLEN_P(op5));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy5) {
zval_dtor(op5);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vsvsvs(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, zval *op5, const char *op6, zend_uint op6_len, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op3_copy, op5_copy;
int use_copy = 0, use_copy1 = 0, use_copy3 = 0, use_copy5 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op5) != IS_STRING) {
zend_make_printable_zval(op5, &op5_copy, &use_copy5);
if (use_copy5) {
op5 = &op5_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5) + op6_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3), op4, op4_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len, Z_STRVAL_P(op5), Z_STRLEN_P(op5));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5), op6, op6_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy5) {
zval_dtor(op5);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vsvsvsv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, const char *op4, zend_uint op4_len, zval *op5, const char *op6, zend_uint op6_len, zval *op7, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op3_copy, op5_copy, op7_copy;
int use_copy = 0, use_copy1 = 0, use_copy3 = 0, use_copy5 = 0, use_copy7 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op5) != IS_STRING) {
zend_make_printable_zval(op5, &op5_copy, &use_copy5);
if (use_copy5) {
op5 = &op5_copy;
}
}
if (Z_TYPE_P(op7) != IS_STRING) {
zend_make_printable_zval(op7, &op7_copy, &use_copy7);
if (use_copy7) {
op7 = &op7_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5) + op6_len + Z_STRLEN_P(op7);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3), op4, op4_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len, Z_STRVAL_P(op5), Z_STRLEN_P(op5));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5), op6, op6_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5) + op6_len, Z_STRVAL_P(op7), Z_STRLEN_P(op7));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy5) {
zval_dtor(op5);
}
if (use_copy7) {
zval_dtor(op7);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vsvv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, zval *op4, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op3_copy, op4_copy;
int use_copy = 0, use_copy1 = 0, use_copy3 = 0, use_copy4 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + Z_STRLEN_P(op4);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3), Z_STRVAL_P(op4), Z_STRLEN_P(op4));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vsvvv(zval **result, zval *op1, const char *op2, zend_uint op2_len, zval *op3, zval *op4, zval *op5, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op3_copy, op4_copy, op5_copy;
int use_copy = 0, use_copy1 = 0, use_copy3 = 0, use_copy4 = 0, use_copy5 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
if (Z_TYPE_P(op5) != IS_STRING) {
zend_make_printable_zval(op5, &op5_copy, &use_copy5);
if (use_copy5) {
op5 = &op5_copy;
}
}
length = Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + Z_STRLEN_P(op4) + Z_STRLEN_P(op5);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3), Z_STRVAL_P(op4), Z_STRLEN_P(op4));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + op2_len + Z_STRLEN_P(op3) + Z_STRLEN_P(op4), Z_STRVAL_P(op5), Z_STRLEN_P(op5));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy5) {
zval_dtor(op5);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vv(zval **result, zval *op1, zval *op2, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vvs(zval **result, zval *op1, zval *op2, const char *op3, zend_uint op3_len, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + op3_len;
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), op3, op3_len);
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vvsv(zval **result, zval *op1, zval *op2, const char *op3, zend_uint op3_len, zval *op4, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy, op4_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0, use_copy4 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + op3_len + Z_STRLEN_P(op4);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), op3, op3_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + op3_len, Z_STRVAL_P(op4), Z_STRLEN_P(op4));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vvv(zval **result, zval *op1, zval *op2, zval *op3, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy, op3_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0, use_copy3 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), Z_STRVAL_P(op3), Z_STRLEN_P(op3));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vvvsv(zval **result, zval *op1, zval *op2, zval *op3, const char *op4, zend_uint op4_len, zval *op5, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy, op3_copy, op5_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0, use_copy3 = 0, use_copy5 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op5) != IS_STRING) {
zend_make_printable_zval(op5, &op5_copy, &use_copy5);
if (use_copy5) {
op5 = &op5_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + op4_len + Z_STRLEN_P(op5);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3), op4, op4_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + op4_len, Z_STRVAL_P(op5), Z_STRLEN_P(op5));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy5) {
zval_dtor(op5);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vvvv(zval **result, zval *op1, zval *op2, zval *op3, zval *op4, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy, op3_copy, op4_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0, use_copy3 = 0, use_copy4 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + Z_STRLEN_P(op4);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3), Z_STRVAL_P(op4), Z_STRLEN_P(op4));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vvvvsvv(zval **result, zval *op1, zval *op2, zval *op3, zval *op4, const char *op5, zend_uint op5_len, zval *op6, zval *op7, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy, op3_copy, op4_copy, op6_copy, op7_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0, use_copy3 = 0, use_copy4 = 0, use_copy6 = 0, use_copy7 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
if (Z_TYPE_P(op6) != IS_STRING) {
zend_make_printable_zval(op6, &op6_copy, &use_copy6);
if (use_copy6) {
op6 = &op6_copy;
}
}
if (Z_TYPE_P(op7) != IS_STRING) {
zend_make_printable_zval(op7, &op7_copy, &use_copy7);
if (use_copy7) {
op7 = &op7_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + Z_STRLEN_P(op4) + op5_len + Z_STRLEN_P(op6) + Z_STRLEN_P(op7);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3), Z_STRVAL_P(op4), Z_STRLEN_P(op4));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + Z_STRLEN_P(op4), op5, op5_len);
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + Z_STRLEN_P(op4) + op5_len, Z_STRVAL_P(op6), Z_STRLEN_P(op6));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + Z_STRLEN_P(op4) + op5_len + Z_STRLEN_P(op6), Z_STRVAL_P(op7), Z_STRLEN_P(op7));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy6) {
zval_dtor(op6);
}
if (use_copy7) {
zval_dtor(op7);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
static void phalcon_concat_vvvvv(zval **result, zval *op1, zval *op2, zval *op3, zval *op4, zval *op5, int self_var TSRMLS_DC){
zval result_copy, op1_copy, op2_copy, op3_copy, op4_copy, op5_copy;
int use_copy = 0, use_copy1 = 0, use_copy2 = 0, use_copy3 = 0, use_copy4 = 0, use_copy5 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
if (use_copy1) {
op1 = &op1_copy;
}
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
if (use_copy2) {
op2 = &op2_copy;
}
}
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
if (Z_TYPE_P(op4) != IS_STRING) {
zend_make_printable_zval(op4, &op4_copy, &use_copy4);
if (use_copy4) {
op4 = &op4_copy;
}
}
if (Z_TYPE_P(op5) != IS_STRING) {
zend_make_printable_zval(op5, &op5_copy, &use_copy5);
if (use_copy5) {
op5 = &op5_copy;
}
}
length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + Z_STRLEN_P(op4) + Z_STRLEN_P(op5);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
PHALCON_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), Z_STRVAL_P(op3), Z_STRLEN_P(op3));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3), Z_STRVAL_P(op4), Z_STRLEN_P(op4));
memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + Z_STRLEN_P(op3) + Z_STRLEN_P(op4), Z_STRVAL_P(op5), Z_STRLEN_P(op5));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy4) {
zval_dtor(op4);
}
if (use_copy5) {
zval_dtor(op5);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
#include <main/php_streams.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
#include <ext/standard/file.h>
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_filestat.h>
#include <ext/standard/php_string.h>
static int phalcon_file_exists(zval *filename TSRMLS_DC){
zval return_value;
if (Z_TYPE_P(filename) != IS_STRING) {
return FAILURE;
}
php_stat(Z_STRVAL_P(filename), (php_stat_len) Z_STRLEN_P(filename), FS_EXISTS, &return_value TSRMLS_CC);
if (PHALCON_IS_FALSE((&return_value))) {
return FAILURE;
}
if (PHALCON_IS_EMPTY((&return_value))) {
return FAILURE;
}
return SUCCESS;
}
static int phalcon_compare_mtime(zval *filename1, zval *filename2 TSRMLS_DC){
php_stream_statbuf statbuffer1, statbuffer2;
if (Z_TYPE_P(filename1) != IS_STRING || Z_TYPE_P(filename2) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for compare_mtime()");
return 0;
}
if (php_stream_stat_path_ex(Z_STRVAL_P(filename1), 0, &statbuffer1, NULL)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "mstat failed for %s", Z_STRVAL_P(filename1));
return 0;
}
if (php_stream_stat_path_ex(Z_STRVAL_P(filename2), 0, &statbuffer2, NULL)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "mstat failed for %s", Z_STRVAL_P(filename2));
return 0;
}
return (int) (statbuffer1.sb.st_mtime >= statbuffer2.sb.st_mtime);
}
static void phalcon_fast_filemtime(zval *return_value, zval *filename TSRMLS_DC){
if (Z_TYPE_P(filename) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for fast_filemtime()");
return;
}
php_stat(Z_STRVAL_P(filename), (php_stat_len) Z_STRLEN_P(filename), FS_MTIME, return_value TSRMLS_CC);
}
static void phalcon_fix_path(zval **return_value, zval *path, zval *directory_separator TSRMLS_DC) {
if (Z_TYPE_P(path) != IS_STRING || Z_TYPE_P(directory_separator) != IS_STRING) {
return;
}
if (Z_STRLEN_P(path) > 0 && Z_STRLEN_P(directory_separator) > 0) {
if (Z_STRVAL_P(path)[Z_STRLEN_P(path) - 1] != '\\' && Z_STRVAL_P(path)[Z_STRLEN_P(path) - 1] != '/') {
PHALCON_CONCAT_VV(*return_value, path, directory_separator);
return;
}
}
zval_ptr_dtor(return_value);
*return_value = path;
Z_ADDREF_P(path);
}
static void phalcon_prepare_virtual_path(zval *return_value, zval *path, zval *virtual_separator TSRMLS_DC) {
unsigned int i;
unsigned char ch;
smart_str virtual_str = {0};
if (Z_TYPE_P(path) != IS_STRING || Z_TYPE_P(virtual_separator) != IS_STRING) {
if (Z_TYPE_P(path) == IS_STRING) {
RETURN_STRINGL(Z_STRVAL_P(path), Z_STRLEN_P(path), 1);
} else {
RETURN_EMPTY_STRING();
}
return;
}
for (i = 0; i < Z_STRLEN_P(path); i++) {
ch = Z_STRVAL_P(path)[i];
if (ch == '\0') {
break;
}
if (ch == '/' || ch == '\\' || ch == ':') {
smart_str_appendl(&virtual_str, Z_STRVAL_P(virtual_separator), Z_STRLEN_P(virtual_separator));
}
else {
smart_str_appendc(&virtual_str, tolower(ch));
}
}
smart_str_0(&virtual_str);
if (virtual_str.c) {
RETURN_STRINGL(virtual_str.c, virtual_str.len, 0);
} else {
RETURN_EMPTY_STRING();
}
}
static void phalcon_unique_path_key(zval *return_value, zval *path TSRMLS_DC) {
unsigned long h;
char *strKey;
if (Z_TYPE_P(path) != IS_STRING) {
return;
}
h = zend_hash_func(Z_STRVAL_P(path), Z_STRLEN_P(path) + 1);
strKey = emalloc(24);
sprintf(strKey, "v%lu", h);
RETURN_STRING(strKey, 0);
}
static void phalcon_realpath(zval *return_value, zval *filename TSRMLS_DC) {
char resolved_path_buff[MAXPATHLEN];
if (Z_TYPE_P(filename) != IS_STRING) {
RETURN_FALSE;
}
if (strlen(Z_STRVAL_P(filename)) != Z_STRLEN_P(filename)) {
RETURN_FALSE;
}
if (VCWD_REALPATH(Z_STRVAL_P(filename), resolved_path_buff)) {
RETURN_STRING(resolved_path_buff, 1);
}
RETURN_FALSE;
}
static void phalcon_possible_autoload_filepath(zval *return_value, zval *prefix, zval *class_name, zval *virtual_separator, zval *separator TSRMLS_DC) {
unsigned int i, length;
unsigned char ch;
smart_str virtual_str = {0};
if (Z_TYPE_P(prefix) != IS_STRING || Z_TYPE_P(class_name) != IS_STRING || Z_TYPE_P(virtual_separator) != IS_STRING) {
RETURN_FALSE;
}
length = Z_STRLEN_P(prefix);
if (!length) {
RETURN_FALSE;
}
if (length > Z_STRLEN_P(class_name)) {
RETURN_FALSE;
}
if (separator) {
if (Z_STRVAL_P(prefix)[Z_STRLEN_P(prefix) - 1] == Z_STRVAL_P(separator)[0]) {
length--;
}
}
for (i = length + 1; i < Z_STRLEN_P(class_name); i++) {
ch = Z_STRVAL_P(class_name)[i];
if (ch == '\0') {
break;
}
if (ch == '\\') {
smart_str_appendl(&virtual_str, Z_STRVAL_P(virtual_separator), Z_STRLEN_P(virtual_separator));
continue;
}
if (separator) {
if (ch == Z_STRVAL_P(separator)[0]) {
smart_str_appendl(&virtual_str, Z_STRVAL_P(virtual_separator), Z_STRLEN_P(virtual_separator));
continue;
}
}
if ((ch == '_') || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
smart_str_appendc(&virtual_str, ch);
continue;
}
if (ch > 127) {
smart_str_appendc(&virtual_str, ch);
continue;
}
}
smart_str_0(&virtual_str);
if (virtual_str.len) {
RETURN_STRINGL(virtual_str.c, virtual_str.len, 0);
} else {
smart_str_free(&virtual_str);
RETURN_FALSE;
}
}
static void phalcon_file_get_contents(zval *return_value, zval *filename TSRMLS_DC)
{
char *contents;
php_stream *stream;
int len;
long maxlen = PHP_STREAM_COPY_ALL;
zval *zcontext = NULL;
php_stream_context *context = NULL;
if (Z_TYPE_P(filename) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for phalcon_file_get_contents()");
RETVAL_FALSE;
return;
}
context = php_stream_context_from_zval(zcontext, 0);
stream = php_stream_open_wrapper_ex(Z_STRVAL_P(filename), "rb", 0 | REPORT_ERRORS, NULL, context);
if (!stream) {
RETURN_FALSE;
}
if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
RETVAL_STRINGL(contents, len, 0);
} else {
if (len == 0) {
RETVAL_EMPTY_STRING();
} else {
RETVAL_FALSE;
}
}
php_stream_close(stream);
}
static void phalcon_file_put_contents(zval *return_value, zval *filename, zval *data TSRMLS_DC)
{
php_stream *stream;
int numbytes = 0, use_copy = 0;
zval *zcontext = NULL;
zval copy;
php_stream_context *context = NULL;
if (Z_TYPE_P(filename) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for phalcon_file_put_contents()");
if (return_value) {
RETVAL_FALSE;
}
return;
}
context = php_stream_context_from_zval(zcontext, 0 & PHP_FILE_NO_DEFAULT_CONTEXT);
stream = php_stream_open_wrapper_ex(Z_STRVAL_P(filename), "wb", ((0 & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | REPORT_ERRORS, NULL, context);
if (stream == NULL) {
if (return_value) {
RETURN_FALSE;
}
return;
}
switch (Z_TYPE_P(data)) {
case IS_NULL:
case IS_LONG:
case IS_DOUBLE:
case IS_BOOL:
case IS_CONSTANT:
zend_make_printable_zval(data, &copy, &use_copy);
if (use_copy) {
data = &copy;
}
/* no break */
case IS_STRING:
if (Z_STRLEN_P(data)) {
numbytes = php_stream_write(stream, Z_STRVAL_P(data), Z_STRLEN_P(data));
if (numbytes != Z_STRLEN_P(data)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, Z_STRLEN_P(data));
numbytes = -1;
}
}
break;
default:
numbytes = -1;
break;
}
php_stream_close(stream);
if (use_copy) {
zval_dtor(data);
}
if (numbytes < 0) {
if (return_value) {
RETURN_FALSE;
} else {
return;
}
}
if (return_value) {
RETURN_LONG(numbytes);
}
return;
}
static void phalcon_is_dir(zval *return_value, zval *path TSRMLS_DC)
{
if (likely(Z_TYPE_P(path) == IS_STRING)) {
php_stat(Z_STRVAL_P(path), (php_stat_len)(Z_STRLEN_P(path)), FS_IS_DIR, return_value TSRMLS_CC);
}
else {
ZVAL_FALSE(return_value);
}
}
static void phalcon_unlink(zval *return_value, zval *path TSRMLS_DC)
{
if (likely(Z_TYPE_P(path) == IS_STRING)) {
php_stream_context *context;
php_stream_wrapper *wrapper;
zval *zctx = NULL;
if (unlikely(strlen(Z_STRVAL_P(path)) != Z_STRLEN_P(path))) {
ZVAL_FALSE(return_value);
return;
}
context = php_stream_context_from_zval(zctx, 0);
wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(path), NULL, 0 TSRMLS_CC);
if (!wrapper || !wrapper->wops || !wrapper->wops->unlink) {
ZVAL_FALSE(return_value);
return;
}
ZVAL_BOOL(return_value, wrapper->wops->unlink(wrapper, Z_STRVAL_P(path), REPORT_ERRORS, context TSRMLS_CC));
return;
}
ZVAL_FALSE(return_value);
return;
}
static void phalcon_filemtime(zval *return_value, zval *path TSRMLS_DC)
{
if (likely(Z_TYPE_P(path) == IS_STRING)) {
php_stat(Z_STRVAL_P(path), (php_stat_len)(Z_STRLEN_P(path)), FS_MTIME, return_value TSRMLS_CC);
}
else {
ZVAL_FALSE(return_value);
}
}
static void phalcon_basename(zval *return_value, zval *path TSRMLS_DC)
{
if (likely(Z_TYPE_P(path) == IS_STRING)) {
char *ret;
size_t ret_len;
php_basename(Z_STRVAL_P(path), Z_STRLEN_P(path), NULL, 0, &ret, &ret_len TSRMLS_CC);
ZVAL_STRINGL(return_value, ret, (int)ret_len, 0);
}
else {
ZVAL_FALSE(return_value);
}
}
#include <Zend/zend_API.h>
#include <main/php_output.h>
static void phalcon_ob_start(TSRMLS_D)
{
#if PHP_VERSION_ID < 50400
php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
#else
php_output_start_default(TSRMLS_C);
#endif
}
static void phalcon_ob_get_contents(zval *result TSRMLS_DC)
{
#if PHP_VERSION_ID < 50400
php_ob_get_buffer(result TSRMLS_CC);
#else
php_output_get_contents(result TSRMLS_CC);
#endif
}
static int phalcon_ob_end_flush(TSRMLS_D)
{
if (phalcon_ob_get_level(TSRMLS_C) < 1) {
php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to flush");
return FAILURE;
}
#if PHP_VERSION_ID < 50400
php_end_ob_buffer(1, 0 TSRMLS_CC);
return SUCCESS;
#else
return php_output_end(TSRMLS_C);
#endif
}
static int phalcon_ob_end_clean(TSRMLS_D)
{
if (phalcon_ob_get_level(TSRMLS_C) < 1) {
php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete");
return FAILURE;
}
#if PHP_VERSION_ID < 50400
php_end_ob_buffer(0, 0 TSRMLS_CC);
return SUCCESS;
#else
return php_output_discard(TSRMLS_C);
#endif
}
static int phalcon_ob_flush(TSRMLS_D)
{
if (phalcon_ob_get_level(TSRMLS_C) < 1) {
php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush");
return FAILURE;
}
#if PHP_VERSION_ID < 50400
php_end_ob_buffer(1, 1 TSRMLS_CC);
return SUCCESS;
#else
return php_output_flush(TSRMLS_C);
#endif
}
static int phalcon_ob_clean(TSRMLS_D)
{
if (phalcon_ob_get_level(TSRMLS_C) < 1) {
php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete");
return FAILURE;
}
#if PHP_VERSION_ID < 50400
php_end_ob_buffer(0, 1 TSRMLS_CC);
return SUCCESS;
#else
return php_output_clean(TSRMLS_C);
#endif
}
static int phalcon_ob_get_level(TSRMLS_D)
{
#if PHP_VERSION_ID < 50400
return OG(ob_nesting_level);
#else
return php_output_get_level(TSRMLS_C);
#endif
}
#include <Zend/zend_exceptions.h>
static void phalcon_throw_exception(zval *object TSRMLS_DC){
Z_ADDREF_P(object);
zend_throw_exception_object(object TSRMLS_CC);
}
static void phalcon_throw_exception_string(zend_class_entry *ce, const char *message TSRMLS_DC){
zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s", message);
}
static void phalcon_throw_exception_zval(zend_class_entry *ce, zval *message TSRMLS_DC){
zval *object;
MAKE_STD_ZVAL(object);
object_init_ex(object, ce);
if (SUCCESS == phalcon_call_method_params(NULL, NULL, object, SL("__construct"), 1107214344UL TSRMLS_CC, 1, message)) {
zend_throw_exception_object(object TSRMLS_CC);
}
}
static void phalcon_throw_exception_internal(zval *exception TSRMLS_DC) {
if (exception != NULL) {
zval *previous = EG(exception);
zend_exception_set_previous(exception, EG(exception) TSRMLS_CC);
EG(exception) = exception;
if (previous) {
return;
}
}
if (!EG(current_execute_data)) {
if (EG(exception)) {
zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
}
zend_error(E_ERROR, "Exception thrown without a stack frame");
}
if (zend_throw_exception_hook) {
zend_throw_exception_hook(exception TSRMLS_CC);
}
if (EG(current_execute_data)->opline == NULL ||
(EG(current_execute_data)->opline + 1)->opcode == ZEND_HANDLE_EXCEPTION) {
/* no need to rethrow the exception */
return;
}
EG(opline_before_exception) = EG(current_execute_data)->opline;
EG(current_execute_data)->opline = EG(exception_op);
}
#include <main/php_main.h>
#include <Zend/zend_exceptions.h>
int ZEND_FASTCALL phalcon_internal_require(zval *return_value, const zval *require_path TSRMLS_DC){
int ret;
char *file_path;
unsigned int file_path_length;
zend_file_handle file_handle;
zval *result = NULL;
int status = SUCCESS;
int dummy = 0;
zval **original_return_value = EG(return_value_ptr_ptr);
zend_op **original_opline_ptr = EG(opline_ptr);
zend_op_array *original_active_op_array = EG(active_op_array);
zend_op_array *new_op_array = NULL;
if (unlikely(Z_TYPE_P(require_path) != IS_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid require path value");
status = FAILURE;
} else {
file_path = Z_STRVAL_P(require_path);
#if PHP_VERSION_ID < 50400
ret = php_stream_open_for_zend_ex(file_path, &file_handle, ENFORCE_SAFE_MODE|USE_PATH|STREAM_OPEN_FOR_INCLUDE|IGNORE_URL TSRMLS_CC);
#else
ret = php_stream_open_for_zend_ex(file_path, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE|IGNORE_URL TSRMLS_CC);
#endif
if (likely(ret == SUCCESS)) {
if (!file_handle.opened_path) {
file_path_length = Z_STRLEN_P(require_path);
file_handle.opened_path = estrndup(file_path, file_path_length);
}
EG(exit_status) = 0;
PG(during_request_startup) = 0;
if (file_handle.filename) {
if ((file_handle.filename[0] != '-' || file_handle.filename[1] != 0) && file_handle.opened_path == NULL && file_handle.type != ZEND_HANDLE_FILENAME) {
char realfile[MAXPATHLEN];
int realfile_len;
dummy = 1;
if (expand_filepath(file_handle.filename, realfile TSRMLS_CC)) {
realfile_len = strlen(realfile);
zend_hash_add(&EG(included_files), realfile, realfile_len + 1, (void *)&dummy, sizeof(int), NULL);
file_handle.opened_path = estrndup(realfile, realfile_len);
}
}
}
if (!dummy) {
if (file_handle.opened_path) {
file_path_length = strlen(file_handle.opened_path);
zend_hash_add(&EG(included_files), file_handle.opened_path, file_path_length + 1, (void *)&dummy, sizeof(int), NULL);
}
}
new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC);
zend_destroy_file_handle(&file_handle TSRMLS_CC);
if (likely(new_op_array != NULL)) {
EG(return_value_ptr_ptr) = &result;
EG(active_op_array) = new_op_array;
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
}
/** This provides compatibility with AOP extension */
new_op_array->type = ZEND_EVAL_CODE;
zend_execute(new_op_array TSRMLS_CC);
zend_exception_restore(TSRMLS_C);
destroy_op_array(new_op_array TSRMLS_CC);
efree(new_op_array);
if (!EG(exception)) {
if (EG(return_value_ptr_ptr)) {
ASSUME(result != NULL);
if (return_value) {
COPY_PZVAL_TO_ZVAL(*return_value, result);
} else {
zval_ptr_dtor(EG(return_value_ptr_ptr));
}
}
}
}
EG(return_value_ptr_ptr) = original_return_value;
EG(opline_ptr) = original_opline_ptr;
EG(active_op_array) = original_active_op_array;
if (EG(exception) || EG(exit_status) == 255) {
status = FAILURE;
}
} else {
zend_destroy_file_handle(&file_handle TSRMLS_CC);
status = FAILURE;
}
}
return status;
}
int ZEND_FASTCALL phalcon_require(const zval *require_path TSRMLS_DC){
return phalcon_internal_require(NULL, require_path TSRMLS_CC);
}
int ZEND_FASTCALL phalcon_require_ret(zval *return_value, const zval *require_path TSRMLS_DC){
return phalcon_internal_require(return_value, require_path TSRMLS_CC);
}
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_var.h>
static void phalcon_serialize(zval *return_value, zval **var TSRMLS_DC) {
php_serialize_data_t var_hash;
smart_str buf = {0};
PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, var, &var_hash TSRMLS_CC);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
if (EG(exception)) {
smart_str_free(&buf);
RETURN_FALSE;
}
if (buf.c) {
RETURN_STRINGL(buf.c, buf.len, 0);
} else {
RETURN_NULL();
}
}
static void phalcon_unserialize(zval *return_value, zval *var TSRMLS_DC) {
const unsigned char *p;
php_unserialize_data_t var_hash;
if (Z_TYPE_P(var) != IS_STRING) {
RETURN_FALSE;
}
if (Z_STRLEN_P(var) == 0) {
RETURN_FALSE;
}
p = (const unsigned char*) Z_STRVAL_P(var);
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&return_value, &p, p + Z_STRLEN_P(var), &var_hash TSRMLS_CC)) {
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
zval_dtor(return_value);
ZVAL_NULL(return_value);
if (!EG(exception)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %ld of %d bytes", (long)((char*)p - Z_STRVAL_P(var)), Z_STRLEN_P(var));
}
RETURN_FALSE;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
}
#ifdef PHALCON_USE_PHP_SESSION
#include <ext/session/php_session.h>
#endif
static void phalcon_session_start(TSRMLS_D)
{
#ifdef PHALCON_USE_PHP_SESSION
php_session_start(TSRMLS_C);
#else
phalcon_call_func_params(NULL, NULL, SL("session_start") TSRMLS_CC, 0);
#endif
}
static void phalcon_session_destroy(TSRMLS_D)
{
phalcon_call_func_params(NULL, NULL, SL("session_destroy") TSRMLS_CC, 0);
}
static void phalcon_get_session_id(zval *return_value, zval **return_value_ptr TSRMLS_DC)
{
#ifdef PHALCON_USE_PHP_SESSION
if (PS(id)) {
RETURN_STRING(PS(id), 1);
}
RETURN_EMPTY_STRING();
#else
if (FAILURE == phalcon_call_func_params(return_value, return_value_ptr, SL("session_id") TSRMLS_CC, 0)) {
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
#endif
}
static void phalcon_set_session_id(zval *sid TSRMLS_DC)
{
#ifdef PHALCON_USE_PHP_SESSION
zval copy;
int use_copy = 0;
if (unlikely(Z_TYPE_P(sid) != IS_STRING)) {
zend_make_printable_zval(sid, &copy, &use_copy);
if (use_copy) {
sid = &copy;
}
}
if (PS(id)) {
efree(PS(id));
}
PS(id) = estrndup(Z_STRVAL_P(sid), Z_STRLEN_P(sid));
if (unlikely(use_copy)) {
zval_dtor(&copy);
}
#else
phalcon_call_func_params(NULL, NULL, SL("session_id") TSRMLS_CC, 1, sid);
#endif
}
static void phalcon_session_write_close(TSRMLS_D)
{
phalcon_call_func_params(NULL, NULL, SL("session_write_close") TSRMLS_CC, 0);
}
#include <ext/standard/php_smart_str.h>
#include <Zend/zend_API.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_execute.h>
static int phalcon_alt_is_callable_check_method(zend_class_entry *ce, int check_flags, char *method_name, unsigned int method_len, zend_fcall_info_cache *fcc, char **error, unsigned long method_key TSRMLS_DC)
{
int retval = 0;
#ifndef PHALCON_RELEASE
int call_via_handler = 0;
#endif
if (error) {
*error = NULL;
}
if (!method_key) {
method_key = zend_inline_hash_func(method_name, method_len + 1);
}
/* Try to fetch find static method of given class. */
if (likely(phalcon_hash_quick_find(&ce->function_table, method_name, method_len + 1, method_key, (void**) &fcc->function_handler) == SUCCESS)) {
retval = 1;
if ((fcc->function_handler->op_array.fn_flags & ZEND_ACC_CHANGED) && PHALCON_EG(scope) && instanceof_function(fcc->function_handler->common.scope, EG(scope) TSRMLS_CC)) {
zend_function *priv_fbc;
if (phalcon_hash_quick_find(&PHALCON_EG(scope)->function_table, method_name, method_len + 1, method_key, (void **) &priv_fbc)==SUCCESS && (priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE) && priv_fbc->common.scope == EG(scope)) {
fcc->function_handler = priv_fbc;
}
}
#ifndef PHALCON_RELEASE
if ((check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0 && (fcc->calling_scope && (fcc->calling_scope->__call || fcc->calling_scope->__callstatic))) {
if (fcc->function_handler->op_array.fn_flags & ZEND_ACC_PRIVATE) {
if (!zend_check_private(fcc->function_handler, ce, method_name, method_len TSRMLS_CC)) {
retval = 0;
fcc->function_handler = NULL;
goto get_function_via_handler;
}
} else {
if (fcc->function_handler->common.fn_flags & ZEND_ACC_PROTECTED) {
if (!zend_check_protected(fcc->function_handler->common.scope, PHALCON_EG(scope))) {
retval = 0;
fcc->function_handler = NULL;
goto get_function_via_handler;
}
}
}
}
#endif
} else {
#ifndef PHALCON_RELEASE
get_function_via_handler:
if (Z_OBJ_HT_P(fcc->object_ptr)->get_method) {
#if PHP_VERSION_ID < 50400
fcc->function_handler = Z_OBJ_HT_P(fcc->object_ptr)->get_method(&fcc->object_ptr, method_name, method_len TSRMLS_CC);
#else
fcc->function_handler = Z_OBJ_HT_P(fcc->object_ptr)->get_method(&fcc->object_ptr, method_name, method_len, NULL TSRMLS_CC);
#endif
if (fcc->function_handler) {
retval = 1;
call_via_handler = (fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
}
}
#endif
}
if (retval) {
#ifndef PHALCON_RELEASE
if (fcc->calling_scope && !call_via_handler) {
if (!fcc->object_ptr && (fcc->function_handler->common.fn_flags & ZEND_ACC_ABSTRACT)) {
if (error) {
phalcon_spprintf(error, 0, "cannot call abstract method %s::%s()", fcc->calling_scope->name, fcc->function_handler->common.function_name);
retval = 0;
} else {
zend_error(E_ERROR, "Cannot call abstract method %s::%s()", fcc->calling_scope->name, fcc->function_handler->common.function_name);
}
}
if (retval && (check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0) {
if (fcc->function_handler->op_array.fn_flags & ZEND_ACC_PRIVATE) {
if (!zend_check_private(fcc->function_handler, ce, method_name, method_len TSRMLS_CC)) {
if (error) {
if (*error) {
efree(*error);
}
phalcon_spprintf(error, 0, "cannot access private method %s::%s()", fcc->calling_scope->name, fcc->function_handler->common.function_name);
}
retval = 0;
}
} else {
if ((fcc->function_handler->common.fn_flags & ZEND_ACC_PROTECTED)) {
if (!zend_check_protected(fcc->function_handler->common.scope, EG(scope))) {
if (error) {
if (*error) {
efree(*error);
}
phalcon_spprintf(error, 0, "cannot access protected method %s::%s()", fcc->calling_scope->name, fcc->function_handler->common.function_name);
}
retval = 0;
}
}
}
}
}
#endif
} else {
if (error && !(check_flags & IS_CALLABLE_CHECK_SILENT)) {
if (fcc->calling_scope) {
if (error) {
phalcon_spprintf(error, 0, "class '%s' does not have a method '%s'", fcc->calling_scope->name, method_name);
}
} else {
if (error) {
phalcon_spprintf(error, 0, "function '%s' does not exist", method_name);
}
}
}
}
if (retval) {
fcc->initialized = 1;
}
return retval;
}
static inline zend_bool phalcon_alt_is_callable_method_ex(zend_class_entry *ce, char *method_name, unsigned int method_len, zval *object_ptr, uint check_flags, zend_fcall_info_cache *fcc, char **error, int exists, unsigned long method_key TSRMLS_DC) {
if (error) {
*error = NULL;
}
fcc->called_scope = ce;
fcc->object_ptr = object_ptr;
fcc->calling_scope = ce;
if (!exists) {
fcc->initialized = 0;
fcc->function_handler = NULL;
return phalcon_alt_is_callable_check_method(ce, check_flags, method_name, method_len, fcc, error, method_key TSRMLS_CC);
} else {
fcc->initialized = 1;
}
return 1;
}
#if PHP_VERSION_ID < 50400
static int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned long hash_key, char *method_name, unsigned int method_len, unsigned long method_key TSRMLS_DC)
{
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
zend_uint i, exists = 0, is_phalcon_function = 0;
zend_class_entry *current_scope;
zend_class_entry *current_called_scope;
zend_class_entry *calling_scope = NULL;
zend_class_entry *called_scope = NULL;
zval **original_return_value;
HashTable *calling_symbol_table;
zend_op_array *original_op_array;
zend_op **original_opline_ptr;
zval *current_this;
zend_execute_data execute_data;
zend_fcall_info_cache *fci_cache, fci_local;
zend_function **function_handler;
fci_cache = &fci_local;
*fci->retval_ptr_ptr = NULL;
/* Initialize execute_data */
execute_data = *EG(current_execute_data);
EX(op_array) = NULL;
EX(opline) = NULL;
EX(object) = NULL;
/* Check if a fci_cache is already loaded for this method */
if (hash_key > 0 && phalcon_globals_ptr->function_cache) {
if (zend_hash_index_find(phalcon_globals_ptr->function_cache, hash_key, (void**) &function_handler) == SUCCESS) {
fci_cache->function_handler = *function_handler;
exists = 1;
is_phalcon_function = 1;
}
}
/** Check if it's a Phalcon function */
if (!is_phalcon_function) {
is_phalcon_function = ce->type == ZEND_INTERNAL_CLASS && ce->name_length > 10 && !memcmp(ce->name, SL("Phalcon\\"));
}
/* The fci_cache doesn't exist, so we check it */
if (!exists) {
char *callable_name;
char *error = NULL;
if (is_phalcon_function) {
/** Use the Phalcon optimized version */
if (!phalcon_alt_is_callable_method_ex(ce, method_name, method_len, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, fci_cache, &error, exists, method_key TSRMLS_CC)) {
if (error) {
zend_error(E_WARNING, "Invalid callback %s, %s", method_name, error);
efree(error);
}
return FAILURE;
}
} else {
MAKE_STD_ZVAL(fci->function_name);
ZVAL_STRINGL(fci->function_name, method_name, method_len, 0);
/** Use the slow function instead */
if (unlikely(!zend_is_callable_ex(fci->function_name, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC))) {
if (error) {
zend_error(E_WARNING, "Invalid callback %s, %s", callable_name, error);
efree(error);
}
if (callable_name) {
efree(callable_name);
}
return FAILURE;
} else {
if (error) {
zend_error(E_STRICT, "%s", error);
efree(error);
}
}
efree(callable_name);
}
/* Store the function in the cache only if it is a zend internal function */
if (is_phalcon_function) {
if (fci_cache->function_handler->type == ZEND_INTERNAL_FUNCTION) {
if (!phalcon_globals_ptr->function_cache) {
ALLOC_HASHTABLE(phalcon_globals_ptr->function_cache);
zend_hash_init(phalcon_globals_ptr->function_cache, 0, NULL, NULL, 0);
}
zend_hash_index_update(
phalcon_globals_ptr->function_cache,
hash_key,
&fci_cache->function_handler,
sizeof(zend_function *),
NULL
);
}
}
} else {
fci_cache->called_scope = ce;
fci_cache->object_ptr = fci->object_ptr;
fci_cache->calling_scope = ce;
fci_cache->initialized = 1;
}
EX(function_state).function = fci_cache->function_handler;
calling_scope = ce;
called_scope = ce;
fci->object_ptr = fci_cache->object_ptr;
EX(object) = fci->object_ptr;
if (!is_phalcon_function) {
if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT && (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
return FAILURE;
}
if (EX(function_state).function->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", EX(function_state).function->common.scope->name, EX(function_state).function->common.function_name);
}
if (EX(function_state).function->common.fn_flags & ZEND_ACC_DEPRECATED) {
zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
EX(function_state).function->common.scope ? "::" : "",
EX(function_state).function->common.function_name);
}
}
}
ZEND_VM_STACK_GROW_IF_NEEDED(fci->param_count + 1);
for (i = 0; i < fci->param_count; i++) {
zval *param;
if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION
&& (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0
&& !ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)
&& PZVAL_IS_REF(*fci->params[i])) {
ALLOC_ZVAL(param);
*param = **(fci->params[i]);
INIT_PZVAL(param);
zval_copy_ctor(param);
} else {
if (!is_phalcon_function && ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1) && !PZVAL_IS_REF(*fci->params[i])) {
if (Z_REFCOUNT_PP(fci->params[i]) > 1) {
zval *new_zval;
if (fci->no_separation &&
!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == EG(argument_stack)->top)) {
#if PHP_VERSION_ID < 50500
zend_vm_stack_push_nocheck((void *) (zend_uintptr_t)i TSRMLS_CC);
zend_vm_stack_clear_multiple(TSRMLS_C);
#else
zend_vm_stack_push((void *) (zend_uintptr_t)i TSRMLS_CC);
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
#endif
}
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
i + 1,
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
EX(function_state).function->common.scope ? "::" : "",
EX(function_state).function->common.function_name);
return FAILURE;
}
ALLOC_ZVAL(new_zval);
*new_zval = **fci->params[i];
zval_copy_ctor(new_zval);
Z_SET_REFCOUNT_P(new_zval, 1);
Z_DELREF_PP(fci->params[i]);
*fci->params[i] = new_zval;
}
Z_ADDREF_PP(fci->params[i]);
Z_SET_ISREF_PP(fci->params[i]);
param = *fci->params[i];
} else {
if (*fci->params[i] != &EG(uninitialized_zval)) {
Z_ADDREF_PP(fci->params[i]);
param = *fci->params[i];
} else {
ALLOC_ZVAL(param);
*param = **(fci->params[i]);
INIT_PZVAL(param);
}
}
}
#if PHP_VERSION_ID < 50500
zend_vm_stack_push_nocheck(param TSRMLS_CC);
#else
zend_vm_stack_push(param TSRMLS_CC);
#endif
}
EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C);
#if PHP_VERSION_ID < 50500
zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
#else
zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
#endif
current_scope = EG(scope);
EG(scope) = calling_scope;
current_this = EG(This);
current_called_scope = EG(called_scope);
if (called_scope) {
EG(called_scope) = called_scope;
} else {
if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
EG(called_scope) = NULL;
}
}
if (fci->object_ptr) {
if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
EG(This) = NULL;
} else {
EG(This) = fci->object_ptr;
if (!PZVAL_IS_REF(EG(This))) {
Z_ADDREF_P(EG(This));
} else {
zval *this_ptr;
ALLOC_ZVAL(this_ptr);
*this_ptr = *EG(This);
INIT_PZVAL(this_ptr);
zval_copy_ctor(this_ptr);
EG(This) = this_ptr;
}
}
} else {
EG(This) = NULL;
}
EX(prev_execute_data) = EG(current_execute_data);
EG(current_execute_data) = &execute_data;
if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
calling_symbol_table = EG(active_symbol_table);
EG(scope) = EX(function_state).function->common.scope;
if (fci->symbol_table) {
EG(active_symbol_table) = fci->symbol_table;
} else {
EG(active_symbol_table) = NULL;
}
original_return_value = EG(return_value_ptr_ptr);
original_op_array = EG(active_op_array);
EG(return_value_ptr_ptr) = fci->retval_ptr_ptr;
EG(active_op_array) = (zend_op_array *) EX(function_state).function;
original_opline_ptr = EG(opline_ptr);
zend_execute(EG(active_op_array) TSRMLS_CC);
if (!fci->symbol_table && EG(active_symbol_table)) {
if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) {
zend_hash_destroy(EG(active_symbol_table));
FREE_HASHTABLE(EG(active_symbol_table));
} else {
zend_hash_clean(EG(active_symbol_table));
*(++EG(symtable_cache_ptr)) = EG(active_symbol_table);
}
}
EG(active_symbol_table) = calling_symbol_table;
EG(active_op_array) = original_op_array;
EG(return_value_ptr_ptr)=original_return_value;
EG(opline_ptr) = original_opline_ptr;
} else {
if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
if (EX(function_state).function->common.scope) {
EG(scope) = EX(function_state).function->common.scope;
}
((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
if (EG(exception) && fci->retval_ptr_ptr) {
zval_ptr_dtor(fci->retval_ptr_ptr);
*fci->retval_ptr_ptr = NULL;
}
if (call_via_handler) {
fci_cache->initialized = 0;
}
} else {
ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
if (fci->object_ptr) {
Z_OBJ_HT_P(fci->object_ptr)->call_method(EX(function_state).function->common.function_name, fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
} else {
zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
}
if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
efree(EX(function_state).function->common.function_name);
}
efree(EX(function_state).function);
if (EG(exception) && fci->retval_ptr_ptr) {
zval_ptr_dtor(fci->retval_ptr_ptr);
*fci->retval_ptr_ptr = NULL;
}
}
}
#if PHP_VERSION_ID < 50500
zend_vm_stack_clear_multiple(TSRMLS_C);
#else
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
#endif
if (EG(This)) {
zval_ptr_dtor(&EG(This));
}
EG(called_scope) = current_called_scope;
EG(scope) = current_scope;
EG(This) = current_this;
EG(current_execute_data) = EX(prev_execute_data);
if (EG(exception)) {
phalcon_throw_exception_internal(NULL TSRMLS_CC);
}
return SUCCESS;
}
#else
static int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned long hash_key, char *method_name, unsigned int method_len, unsigned long method_key TSRMLS_DC)
{
zend_uint i;
zend_executor_globals *executor_globals_ptr = PHALCON_VEG;
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
zval **original_return_value;
HashTable *calling_symbol_table;
zend_op_array *original_op_array;
zend_op **original_opline_ptr;
zend_class_entry *current_scope;
zend_class_entry *current_called_scope;
zend_class_entry *calling_scope = NULL;
zend_class_entry *called_scope = NULL;
zval *current_this;
zend_execute_data execute_data;
zend_fcall_info_cache *fci_cache, fci_local;
zend_function **function_handler;
int exists = 0, is_phalcon_function = 0;
fci_cache = &fci_local;
assert(*fci->retval_ptr_ptr == NULL);
*fci->retval_ptr_ptr = NULL;
/* Initialize execute_data */
execute_data = *executor_globals_ptr->current_execute_data;
EX(op_array) = NULL;
EX(opline) = NULL;
EX(object) = NULL;
/* Check if a fci_cache is already loaded for this method */
if (hash_key > 0 && phalcon_globals_ptr->function_cache) {
if (zend_hash_index_find(phalcon_globals_ptr->function_cache, hash_key, (void**) &function_handler) == SUCCESS) {
fci_cache->function_handler = *function_handler;
exists = 1;
is_phalcon_function = 1;
}
}
/** Check if it's a Phalcon function */
if (!is_phalcon_function) {
if (ce->type == ZEND_INTERNAL_CLASS) {
if (ce->name_length > 10) {
is_phalcon_function = !memcmp(ce->name, SL("Phalcon\\"));
}
}
}
/* The fci_cache doesn't exist, so we check it */
if (!exists) {
char *callable_name;
char *error = NULL;
if (is_phalcon_function) {
/** Use the Phalcon optimized version */
if (unlikely(!phalcon_alt_is_callable_method_ex(ce, method_name, method_len, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, fci_cache, &error, exists, method_key TSRMLS_CC))) {
if (error) {
zend_error(E_WARNING, "Invalid callback %s, %s", method_name, error);
efree(error);
}
return FAILURE;
} else {
if (error) {
zend_error(E_STRICT, "%s", error);
efree(error);
}
}
} else {
MAKE_STD_ZVAL(fci->function_name);
ZVAL_STRINGL(fci->function_name, method_name, method_len, 0);
/** Use the slow function instead */
if (unlikely(!zend_is_callable_ex(fci->function_name, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC))) {
if (error) {
zend_error(E_WARNING, "Invalid callback %s, %s", callable_name, error);
efree(error);
}
if (callable_name) {
efree(callable_name);
}
return FAILURE;
} else {
if (error) {
zend_error(E_STRICT, "%s", error);
efree(error);
}
}
efree(callable_name);
}
/* Store the function in the cache only if it is a zend internal function */
if (is_phalcon_function) {
if (likely(fci_cache->function_handler->type == ZEND_INTERNAL_FUNCTION)) {
if (!phalcon_globals_ptr->function_cache) {
ALLOC_HASHTABLE(phalcon_globals_ptr->function_cache);
zend_hash_init(phalcon_globals_ptr->function_cache, 0, NULL, NULL, 0);
}
zend_hash_index_update(
phalcon_globals_ptr->function_cache,
hash_key,
&fci_cache->function_handler,
sizeof(zend_function *),
NULL
);
}
}
} else {
fci_cache->called_scope = ce;
fci_cache->object_ptr = fci->object_ptr;
fci_cache->calling_scope = ce;
fci_cache->initialized = 1;
}
EX(function_state).function = fci_cache->function_handler;
calling_scope = fci_cache->calling_scope;
called_scope = fci_cache->called_scope;
fci->object_ptr = fci_cache->object_ptr;
EX(object) = fci->object_ptr;
if (!is_phalcon_function) {
if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
(!executor_globals_ptr->objects_store.object_buckets || !executor_globals_ptr->objects_store.object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
return FAILURE;
}
if (EX(function_state).function->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", EX(function_state).function->common.scope->name, EX(function_state).function->common.function_name);
}
if (EX(function_state).function->common.fn_flags & ZEND_ACC_DEPRECATED) {
zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
EX(function_state).function->common.scope ? "::" : "",
EX(function_state).function->common.function_name);
}
}
}
ZEND_VM_STACK_GROW_IF_NEEDED(fci->param_count + 1);
for (i = 0; i < fci->param_count; i++) {
zval *param;
if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
if (!PZVAL_IS_REF(*fci->params[i]) && Z_REFCOUNT_PP(fci->params[i]) > 1) {
zval *new_zval;
if (fci->no_separation &&
!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(executor_globals_ptr->argument_stack) == executor_globals_ptr->argument_stack->top)) {
/* hack to clean up the stack */
#if PHP_VERSION_ID < 50500
zend_vm_stack_push_nocheck((void *) (zend_uintptr_t)i TSRMLS_CC);
zend_vm_stack_clear_multiple(TSRMLS_C);
#else
zend_vm_stack_push((void *) (zend_uintptr_t)i TSRMLS_CC);
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
#endif
}
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
i+1,
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
EX(function_state).function->common.scope ? "::" : "",
EX(function_state).function->common.function_name);
return FAILURE;
}
ALLOC_ZVAL(new_zval);
*new_zval = **fci->params[i];
zval_copy_ctor(new_zval);
Z_SET_REFCOUNT_P(new_zval, 1);
Z_DELREF_PP(fci->params[i]);
*fci->params[i] = new_zval;
}
Z_ADDREF_PP(fci->params[i]);
Z_SET_ISREF_PP(fci->params[i]);
param = *fci->params[i];
} else if (PZVAL_IS_REF(*fci->params[i]) &&
/* don't separate references for __call */
(EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 ) {
ALLOC_ZVAL(param);
*param = **(fci->params[i]);
INIT_PZVAL(param);
zval_copy_ctor(param);
} else {
if (*fci->params[i] != &executor_globals_ptr->uninitialized_zval) {
Z_ADDREF_PP(fci->params[i]);
param = *fci->params[i];
} else {
ALLOC_ZVAL(param);
*param = **(fci->params[i]);
INIT_PZVAL(param);
}
}
#if PHP_VERSION_ID < 50500
zend_vm_stack_push_nocheck(param TSRMLS_CC);
#else
zend_vm_stack_push(param TSRMLS_CC);
#endif
}
EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C);
#if PHP_VERSION_ID < 50500
zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
#else
zend_vm_stack_push((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
#endif
current_scope = executor_globals_ptr->scope;
executor_globals_ptr->scope = calling_scope;
current_this = executor_globals_ptr->This;
current_called_scope = executor_globals_ptr->called_scope;
if (called_scope) {
executor_globals_ptr->called_scope = called_scope;
} else {
if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
executor_globals_ptr->called_scope = NULL;
}
}
if (fci->object_ptr) {
if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
executor_globals_ptr->This = NULL;
} else {
executor_globals_ptr->This = fci->object_ptr;
if (!PZVAL_IS_REF(executor_globals_ptr->This)) {
Z_ADDREF_P(executor_globals_ptr->This); /* For $this pointer */
} else {
zval *this_ptr;
ALLOC_ZVAL(this_ptr);
*this_ptr = *executor_globals_ptr->This;
INIT_PZVAL(this_ptr);
zval_copy_ctor(this_ptr);
executor_globals_ptr->This = this_ptr;
}
}
} else {
executor_globals_ptr->This = NULL;
}
EX(prev_execute_data) = executor_globals_ptr->current_execute_data;
executor_globals_ptr->current_execute_data = &execute_data;
if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
calling_symbol_table = executor_globals_ptr->active_symbol_table;
executor_globals_ptr->scope = EX(function_state).function->common.scope;
if (fci->symbol_table) {
executor_globals_ptr->active_symbol_table = fci->symbol_table;
} else {
executor_globals_ptr->active_symbol_table = NULL;
}
original_return_value = executor_globals_ptr->return_value_ptr_ptr;
original_op_array = executor_globals_ptr->active_op_array;
executor_globals_ptr->return_value_ptr_ptr = fci->retval_ptr_ptr;
executor_globals_ptr->active_op_array = (zend_op_array *) EX(function_state).function;
original_opline_ptr = executor_globals_ptr->opline_ptr;
zend_execute(executor_globals_ptr->active_op_array TSRMLS_CC);
if (!fci->symbol_table && executor_globals_ptr->active_symbol_table) {
if (executor_globals_ptr->symtable_cache_ptr >= executor_globals_ptr->symtable_cache_limit) {
zend_hash_destroy(executor_globals_ptr->active_symbol_table);
FREE_HASHTABLE(executor_globals_ptr->active_symbol_table);
} else {
/* clean before putting into the cache, since clean
could call dtors, which could use cached hash */
zend_hash_clean(executor_globals_ptr->active_symbol_table);
*(++executor_globals_ptr->symtable_cache_ptr) = executor_globals_ptr->active_symbol_table;
}
}
executor_globals_ptr->active_symbol_table = calling_symbol_table;
executor_globals_ptr->active_op_array = original_op_array;
executor_globals_ptr->return_value_ptr_ptr = original_return_value;
executor_globals_ptr->opline_ptr = original_opline_ptr;
} else {
if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
if (EX(function_state).function->common.scope) {
executor_globals_ptr->scope = EX(function_state).function->common.scope;
}
((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
/* We shouldn't fix bad extensions here,
because it can break proper ones (Bug #34045)
if (!EX(function_state).function->common.return_reference)
{
INIT_PZVAL(*fci->retval_ptr_ptr);
}*/
if (executor_globals_ptr->exception && fci->retval_ptr_ptr && *fci->retval_ptr_ptr) {
zval_ptr_dtor(fci->retval_ptr_ptr);
*fci->retval_ptr_ptr = NULL;
}
if (call_via_handler) {
/* We must re-initialize function again */
fci_cache->initialized = 0;
}
} else { /* ZEND_OVERLOADED_FUNCTION */
ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
/* Not sure what should be done here if it's a static method */
if (fci->object_ptr) {
Z_OBJ_HT_P(fci->object_ptr)->call_method(EX(function_state).function->common.function_name, fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
} else {
zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
}
if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
efree((char*)EX(function_state).function->common.function_name);
}
efree(EX(function_state).function);
if (executor_globals_ptr->exception && fci->retval_ptr_ptr && *fci->retval_ptr_ptr) {
zval_ptr_dtor(fci->retval_ptr_ptr);
*fci->retval_ptr_ptr = NULL;
}
}
}
#if PHP_VERSION_ID < 50500
zend_vm_stack_clear_multiple(TSRMLS_C);
#else
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
#endif
if (executor_globals_ptr->This) {
zval_ptr_dtor(&executor_globals_ptr->This);
}
executor_globals_ptr->called_scope = current_called_scope;
executor_globals_ptr->scope = current_scope;
executor_globals_ptr->This = current_this;
executor_globals_ptr->current_execute_data = EX(prev_execute_data);
if (executor_globals_ptr->exception) {
phalcon_throw_exception_internal(NULL TSRMLS_CC);
}
return SUCCESS;
}
#endif
static int phalcon_alt_call_user_method(zend_class_entry *ce, zval **object_pp, char *method_name, unsigned int method_len, zval *retval_ptr, zval **retval_ptr_ptr, zend_uint param_count, zval *params[], unsigned long method_key TSRMLS_DC)
{
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
zval ***params_array = NULL;
zval **static_params_array[5];
zend_uint i;
int ex_retval;
zval *local_retval_ptr = NULL;
zend_fcall_info fci;
unsigned long hash_key = 0;
phalcon_globals_ptr->recursive_lock++;
if (unlikely(phalcon_globals_ptr->recursive_lock > 2048)) {
ex_retval = FAILURE;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Maximum recursion depth exceeded");
} else {
if (param_count) {
if (param_count > 5) {
params_array = (zval ***) emalloc(sizeof(zval **)*param_count);
for (i = 0; i < param_count; i++) {
params_array[i] = &params[i];
}
} else {
for (i = 0; i < param_count; i++) {
static_params_array[i] = &params[i];
}
}
}
/** Create a unique key */
if (ce->name_length >= 8 && ce->name[7] == '\\') {
for (i = 7; i < ce->name_length; i++) {
hash_key = ce->name[i] + (hash_key << 6) + (hash_key << 16) - hash_key;
}
hash_key = '$' + (hash_key << 6) + (hash_key << 16) - hash_key;
for (i = 0; i < method_len; i++) {
hash_key = method_name[i] + (hash_key << 6) + (hash_key << 16) - hash_key;
}
}
if (retval_ptr_ptr && *retval_ptr_ptr) {
zval_ptr_dtor(retval_ptr_ptr);
*retval_ptr_ptr = NULL;
}
fci.size = sizeof(fci);
fci.no_separation = 1;
fci.symbol_table = NULL;
fci.function_table = &ce->function_table;
fci.object_ptr = *object_pp;
fci.function_name = NULL;
fci.retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &local_retval_ptr;
fci.param_count = param_count;
if (param_count > 5) {
fci.params = params_array;
} else{
fci.params = static_params_array;
}
ex_retval = phalcon_alt_call_method(&fci, ce, hash_key, method_name, method_len, method_key TSRMLS_CC);
if (fci.function_name) {
ZVAL_NULL(fci.function_name);
zval_ptr_dtor(&fci.function_name);
}
}
phalcon_globals_ptr->recursive_lock--;
if (local_retval_ptr) {
COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
} else if (!retval_ptr_ptr) {
INIT_ZVAL(*retval_ptr);
}
if (params_array) {
efree(params_array);
}
return ex_retval;
}
#include <ext/standard/php_smart_str.h>
static void phalcon_orm_destroy_cache(TSRMLS_D) {
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
if (phalcon_globals_ptr->orm.parser_cache != NULL) {
zend_hash_destroy(phalcon_globals_ptr->orm.parser_cache);
FREE_HASHTABLE(phalcon_globals_ptr->orm.parser_cache);
phalcon_globals_ptr->orm.parser_cache = NULL;
}
if (phalcon_globals_ptr->orm.ast_cache != NULL) {
zend_hash_destroy(phalcon_globals_ptr->orm.ast_cache);
FREE_HASHTABLE(phalcon_globals_ptr->orm.ast_cache);
phalcon_globals_ptr->orm.ast_cache = NULL;
}
}
static void phalcon_orm_get_prepared_ast(zval **return_value, zval *unique_id TSRMLS_DC) {
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
zval **temp_ast;
if (Z_TYPE_P(unique_id) == IS_LONG) {
if (phalcon_globals_ptr->orm.cache_level >= 1) {
if (phalcon_globals_ptr->orm.ast_cache != NULL) {
if (zend_hash_index_find(phalcon_globals_ptr->orm.ast_cache, Z_LVAL_P(unique_id), (void**) &temp_ast) == SUCCESS) {
ZVAL_ZVAL(*return_value, *temp_ast, 1, 0);
Z_SET_REFCOUNT_P(*return_value, 1);
return;
}
}
}
}
}
static void phalcon_orm_set_prepared_ast(zval *unique_id, zval *prepared_ast TSRMLS_DC) {
zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL;
if (Z_TYPE_P(unique_id) == IS_LONG) {
if (phalcon_globals_ptr->orm.cache_level >= 1) {
if (!phalcon_globals_ptr->orm.ast_cache) {
ALLOC_HASHTABLE(phalcon_globals_ptr->orm.ast_cache);
zend_hash_init(phalcon_globals_ptr->orm.ast_cache, 0, NULL, ZVAL_PTR_DTOR, 0);
}
Z_ADDREF_P(prepared_ast);
zend_hash_index_update(
phalcon_globals_ptr->orm.ast_cache,
Z_LVAL_P(unique_id),
prepared_ast,
sizeof(zval *),
NULL
);
}
}
}
static void phalcon_orm_singlequotes(zval *return_value, zval *str TSRMLS_DC) {
int i;
smart_str escaped_str = {0};
char *marker;
if (Z_TYPE_P(str) != IS_STRING) {
RETURN_ZVAL(str, 1, 0);
}
marker = Z_STRVAL_P(str);
for (i = 0; i < Z_STRLEN_P(str); i++) {
if ((*marker) == '\0') {
break;
}
if ((*marker) == '\'') {
if (i > 0) {
if (*(marker - 1) != '\\') {
smart_str_appendc(&escaped_str, '\'');
}
} else {
smart_str_appendc(&escaped_str, '\'');
}
}
smart_str_appendc(&escaped_str, (*marker));
marker++;
}
smart_str_0(&escaped_str);
if (escaped_str.len) {
RETURN_STRINGL(escaped_str.c, escaped_str.len, 0);
} else {
smart_str_free(&escaped_str);
RETURN_EMPTY_STRING();
}
}
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_string.h>
zval *phalcon_replace_marker(int named, zval *paths, zval *replacements, unsigned long *position, char *cursor, char *marker){
zval **zv, **tmp;
int result = FAILURE;
unsigned int length = 0, variable_length, ch;
char *item = NULL, *cursor_var, *variable = NULL;
int not_valid = 0, j;
if (named) {
length = cursor - marker - 1;
item = estrndup(marker + 1, length);
cursor_var = item;
marker = item;
for (j = 0; j < length; j++) {
ch = *cursor_var;
if (ch == '\0') {
not_valid = 1;
break;
}
if (j == 0 && !((ch >= 'a' && ch <='z') || (ch >= 'A' && ch <= 'Z'))){
not_valid = 1;
break;
}
if ((ch >= 'a' && ch <='z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '-' || ch == '_' || ch == ':') {
if (ch == ':') {
variable_length = cursor_var - marker;
variable = estrndup(marker, variable_length);
break;
}
} else {
not_valid = 1;
break;
}
cursor_var++;
}
}
if (!not_valid) {
if (zend_hash_index_exists(Z_ARRVAL_P(paths), *position)) {
if (named) {
if (variable) {
efree(item);
item = variable;
length = variable_length;
}
if (zend_hash_exists(Z_ARRVAL_P(replacements), item, length + 1)) {
if ((result = zend_hash_find(Z_ARRVAL_P(replacements), item, length + 1, (void**) &zv)) == SUCCESS) {
efree(item);
(*position)++;
return *zv;
}
}
} else {
if ((result = zend_hash_index_find(Z_ARRVAL_P(paths), *position, (void**) &zv)) == SUCCESS) {
if (Z_TYPE_PP(zv) == IS_STRING) {
if (zend_hash_exists(Z_ARRVAL_P(replacements), Z_STRVAL_PP(zv), Z_STRLEN_PP(zv) + 1)) {
if ((result = zend_hash_find(Z_ARRVAL_P(replacements), Z_STRVAL_PP(zv), Z_STRLEN_PP(zv) + 1, (void**) &tmp)) == SUCCESS) {
(*position)++;
return *tmp;
}
}
}
}
}
}
(*position)++;
}
if (item) {
efree(item);
}
return NULL;
}
static void phalcon_replace_paths(zval *return_value, zval *pattern, zval *paths, zval *replacements TSRMLS_DC){
char *cursor, *marker = NULL;
unsigned int i, bracket_count = 0, parentheses_count = 0, intermediate = 0;
unsigned char ch;
smart_str route_str = {0};
unsigned long position = 1;
zval *replace, replace_copy;
int use_copy, looking_placeholder = 0;
if (Z_TYPE_P(pattern) != IS_STRING || Z_TYPE_P(replacements) != IS_ARRAY || Z_TYPE_P(paths) != IS_ARRAY) {
ZVAL_NULL(return_value);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for phalcon_replace_paths()");
return;
}
if (Z_STRLEN_P(pattern) <= 0) {
ZVAL_FALSE(return_value);
return;
}
if (!zend_hash_num_elements(Z_ARRVAL_P(paths))) {
ZVAL_STRINGL(return_value, Z_STRVAL_P(pattern), Z_STRLEN_P(pattern), 1);
return;
}
cursor = Z_STRVAL_P(pattern);
cursor++;
for (i = 1; i < Z_STRLEN_P(pattern); i++) {
ch = *cursor;
if (ch == '\0') {
break;
}
if (parentheses_count == 0 && !looking_placeholder) {
if (ch == '{') {
if (bracket_count == 0) {
marker = cursor;
intermediate = 0;
}
bracket_count++;
} else {
if (ch == '}') {
bracket_count--;
if (intermediate > 0) {
if (bracket_count == 0) {
replace = phalcon_replace_marker(1, paths, replacements, &position, cursor, marker);
if (replace) {
use_copy = 0;
if (Z_TYPE_P(replace) != IS_STRING) {
zend_make_printable_zval(replace, &replace_copy, &use_copy);
if (use_copy) {
replace = &replace_copy;
}
}
smart_str_appendl(&route_str, Z_STRVAL_P(replace), Z_STRLEN_P(replace));
if (use_copy) {
zval_dtor(&replace_copy);
}
}
cursor++;
continue;
}
}
}
}
}
if (bracket_count == 0 && !looking_placeholder) {
if (ch == '(') {
if (parentheses_count == 0) {
marker = cursor;
intermediate = 0;
}
parentheses_count++;
} else {
if (ch == ')') {
parentheses_count--;
if (intermediate > 0) {
if (parentheses_count == 0) {
replace = phalcon_replace_marker(0, paths, replacements, &position, cursor, marker);
if (replace) {
use_copy = 0;
if (Z_TYPE_P(replace) != IS_STRING) {
zend_make_printable_zval(replace, &replace_copy, &use_copy);
if (use_copy) {
replace = &replace_copy;
}
}
smart_str_appendl(&route_str, Z_STRVAL_P(replace), Z_STRLEN_P(replace));
if (use_copy) {
zval_dtor(&replace_copy);
}
}
cursor++;
continue;
}
}
}
}
}
if (bracket_count == 0 && parentheses_count == 0) {
if (looking_placeholder) {
if (intermediate > 0) {
if (ch < 'a' || ch > 'z' || i == (Z_STRLEN_P(pattern) - 1)) {
replace = phalcon_replace_marker(0, paths, replacements, &position, cursor, marker);
if (replace) {
use_copy = 0;
if (Z_TYPE_P(replace) != IS_STRING) {
zend_make_printable_zval(replace, &replace_copy, &use_copy);
if (use_copy) {
replace = &replace_copy;
}
}
smart_str_appendl(&route_str, Z_STRVAL_P(replace), Z_STRLEN_P(replace));
if (use_copy) {
zval_dtor(&replace_copy);
}
}
looking_placeholder = 0;
continue;
}
}
} else {
if (ch == ':') {
looking_placeholder = 1;
marker = cursor;
intermediate = 0;
}
}
}
if (bracket_count > 0 || parentheses_count > 0 || looking_placeholder) {
intermediate++;
} else {
smart_str_appendc(&route_str, ch);
}
cursor++;
}
smart_str_0(&route_str);
if (route_str.len) {
RETURN_STRINGL(route_str.c, route_str.len, 0);
} else {
smart_str_free(&route_str);
RETURN_EMPTY_STRING();
}
}
static void phalcon_extract_named_params(zval *return_value, zval *str, zval *matches){
unsigned int i, j, k, bracket_count = 0, parentheses_count = 0, ch;
unsigned int intermediate = 0, length, number_matches = 0, found_pattern;
int variable_length, regexp_length = 0, not_valid = 0;
char *cursor, *cursor_var, *marker = NULL;
char *item, *variable = NULL, *regexp = NULL;
smart_str route_str = {0};
if (Z_TYPE_P(str) != IS_STRING || Z_STRLEN_P(str) <= 0 || Z_TYPE_P(matches) != IS_ARRAY) {
ZVAL_FALSE(return_value);
return;
}
cursor = Z_STRVAL_P(str);
for (i = 0; i < Z_STRLEN_P(str); i++) {
ch = *cursor;
if (ch == '\0') {
break;
}
if (parentheses_count == 0) {
if (ch == '{') {
if (bracket_count == 0) {
marker = cursor;
intermediate = 0;
not_valid = 0;
}
bracket_count++;
} else {
if (ch == '}') {
bracket_count--;
if (intermediate > 0) {
if (bracket_count == 0) {
number_matches++;
variable = NULL;
length = cursor - marker - 1;
item = estrndup(marker + 1, length);
cursor_var = item;
marker = item;
for (j = 0; j < length; j++) {
ch = *cursor_var;
if (ch == '\0') {
break;
}
if (j == 0 && !((ch >= 'a' && ch <='z') || (ch >= 'A' && ch <='Z'))){
not_valid = 1;
break;
}
if ((ch >= 'a' && ch <='z') || (ch >= 'A' && ch <='Z') || (ch >= '0' && ch <='9') || ch == '-' || ch == '_' || ch == ':') {
if (ch == ':') {
regexp_length = length - j - 1;
variable_length = cursor_var - marker;
variable = estrndup(marker, variable_length);
regexp = estrndup(cursor_var + 1, regexp_length);
break;
}
} else {
not_valid = 1;
break;
}
cursor_var++;
}
if (!not_valid) {
{
zval *tmp;
MAKE_STD_ZVAL(tmp);
ZVAL_LONG(tmp, number_matches);
if (variable) {
if (regexp_length > 0) {
ASSUME(regexp != NULL);
found_pattern = 0;
for (k = 0; k < regexp_length; k++) {
if (regexp[k] == '\0') {
break;
}
if (!found_pattern) {
if (regexp[k] == '(') {
found_pattern = 1;
}
} else {
if (regexp[k] == ')') {
found_pattern = 2;
break;
}
}
}
if (found_pattern != 2) {
smart_str_appendc(&route_str, '(');
smart_str_appendl(&route_str, regexp, regexp_length);
smart_str_appendc(&route_str, ')');
} else {
smart_str_appendl(&route_str, regexp, regexp_length);
}
zend_hash_update(Z_ARRVAL_P(matches), variable, variable_length + 1, &tmp, sizeof(zval *), NULL);
}
efree(regexp);
efree(variable);
} else {
smart_str_appendl(&route_str, "([^/]*)", strlen("([^/]*)"));
zend_hash_update(Z_ARRVAL_P(matches), item, length + 1, &tmp, sizeof(zval *), NULL);
}
}
} else {
smart_str_appendc(&route_str, '{');
smart_str_appendl(&route_str, item, length);
smart_str_appendc(&route_str, '}');
}
efree(item);
cursor++;
continue;
}
}
}
}
}
if (bracket_count == 0) {
if (ch == '(') {
parentheses_count++;
} else {
if (ch == ')') {
parentheses_count--;
if (parentheses_count == 0) {
number_matches++;
}
}
}
}
if (bracket_count > 0) {
intermediate++;
} else {
smart_str_appendc(&route_str, ch);
}
cursor++;
}
smart_str_0(&route_str);
if (route_str.len) {
RETURN_STRINGL(route_str.c, route_str.len, 0);
} else {
smart_str_free(&route_str);
RETURN_EMPTY_STRING();
}
}
#include <ext/standard/url.h>
static void phalcon_get_uri(zval *return_value, zval *path) {
int i, found = 0, mark = 0;
char *cursor, *str, ch;
if (Z_TYPE_P(path) != IS_STRING) {
RETURN_EMPTY_STRING();
}
if (Z_STRLEN_P(path) > 0) {
cursor = Z_STRVAL_P(path) + Z_STRLEN_P(path) - 1;
for (i = Z_STRLEN_P(path); i > 0; i--) {
ch = *cursor;
if (ch == '/' || ch == '\\') {
found++;
if (found == 1) {
mark = i - 1;
} else {
str = emalloc(mark - i + 1);
memcpy(str, Z_STRVAL_P(path) + i, mark - i);
str[mark - i] = '\0';
ZVAL_STRINGL(return_value, str, mark - i, 0);
return;
}
}
cursor--;
}
}
RETURN_EMPTY_STRING();
}
static void phalcon_raw_url_encode(zval *return_value, zval *url) {
zval copy;
char *escaped;
int use_copy = 0, length;
if (Z_TYPE_P(url) == IS_STRING) {
zend_make_printable_zval(url, &copy, &use_copy);
if (use_copy) {
url = &copy;
}
}
escaped = php_raw_url_encode(Z_STRVAL_P(url), Z_STRLEN_P(url), &length);
if (use_copy) {
zval_dtor(url);
}
if (escaped) {
RETURN_STRINGL(escaped, length, 0);
} else {
RETURN_NULL();
}
}
#ifndef PHALCON_INTERNED_STRINGS_H
#define PHALCON_INTERNED_STRINGS_H
#include <TSRM/TSRM.h>
const char *phalcon_interned_DELETE;
const char *phalcon_interned_GET;
const char *phalcon_interned_HEAD;
const char *phalcon_interned_OPTIONS;
const char *phalcon_interned_PATCH;
const char *phalcon_interned_POST;
const char *phalcon_interned_PUT;
const char *phalcon_interned_alias;
const char *phalcon_interned_all;
const char *phalcon_interned_arguments;
const char *phalcon_interned_balias;
const char *phalcon_interned_binary_op;
const char *phalcon_interned_column;
const char *phalcon_interned_columns;
const char *phalcon_interned_conditions;
const char *phalcon_interned_delete;
const char *phalcon_interned_distinct;
const char *phalcon_interned_domain;
const char *phalcon_interned_escaper;
const char *phalcon_interned_expr;
const char *phalcon_interned_fields;
const char *phalcon_interned_file;
const char *phalcon_interned_filter;
const char *phalcon_interned_functionCall;
const char *phalcon_interned_group;
const char *phalcon_interned_groupBy;
const char *phalcon_interned_having;
const char *phalcon_interned_items;
const char *phalcon_interned_joins;
const char *phalcon_interned_left;
const char *phalcon_interned_limit;
const char *phalcon_interned_line;
const char *phalcon_interned_model;
const char *phalcon_interned_models;
const char *phalcon_interned_modelsCache;
const char *phalcon_interned_modelsManager;
const char *phalcon_interned_modelsMetadata;
const char *phalcon_interned_name;
const char *phalcon_interned_ns_alias;
const char *phalcon_interned_number;
const char *phalcon_interned_offset;
const char *phalcon_interned_op;
const char *phalcon_interned_order;
const char *phalcon_interned_orderBy;
const char *phalcon_interned_qualified;
const char *phalcon_interned_qualifiedName;
const char *phalcon_interned_right;
const char *phalcon_interned_select;
const char *phalcon_interned_sort;
const char *phalcon_interned_source;
const char *phalcon_interned_sqlAlias;
const char *phalcon_interned_table;
const char *phalcon_interned_tables;
const char *phalcon_interned_type;
const char *phalcon_interned_update;
const char *phalcon_interned_url;
const char *phalcon_interned_value;
const char *phalcon_interned_values;
const char *phalcon_interned_where;
static void phalcon_init_interned_strings(TSRMLS_D);
#endif /* PHALCON_INTERNED_STRINGS_H */
#ifndef PHALCON_FORMS_ELEMENT_HELPERS_H
#define PHALCON_FORMS_ELEMENT_HELPERS_H
static inline void phalcon_forms_element_render_helper(const char *method, int use_checked, INTERNAL_FUNCTION_PARAMETERS)
{
zval **attributes = NULL, *widget_attributes = NULL, *uc;
phalcon_fetch_params_ex(0, 1, &attributes);
if (!attributes) {
attributes = &PHALCON_GLOBAL(z_null);
}
uc = use_checked ? PHALCON_GLOBAL(z_true) : PHALCON_GLOBAL(z_false);
phalcon_call_method_params(
widget_attributes, &widget_attributes,
getThis(), SL("prepareattributes"),
597834619UL TSRMLS_CC,
2, *attributes, uc
);
if (!EG(exception)) {
phalcon_call_static_func_params(return_value, return_value_ptr, SL("phalcon\\tag"), method, strlen(method) TSRMLS_CC, 1, widget_attributes);
if (EG(exception) && return_value_ptr) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
zval_ptr_dtor(&widget_attributes);
}
}
#endif /* PHALCON_FORMS_ELEMENT_HELPERS_H */
#ifndef PHALCON_MVC_VIEW_ENGINE_HELPERS_H
#define PHALCON_MVC_VIEW_ENGINE_HELPERS_H
PHALCON_STATIC zend_bool phalcon_mvc_view_engine_php_symtable_merger(HashTable *ht, void *pData, zend_hash_key *hash_key, void *pParam);
#endif /* PHALCON_MBC_VIEW_ENGINE_HELPERS_H */
zend_class_entry *phalcon_acl_ce;
PHALCON_INIT_CLASS(Phalcon_Acl){
PHALCON_REGISTER_CLASS(Phalcon, Acl, acl, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_class_constant_long(phalcon_acl_ce, SL("ALLOW"), PHALCON_ACL_ALLOW TSRMLS_CC);
zend_declare_class_constant_long(phalcon_acl_ce, SL("DENY"), PHALCON_ACL_DENY TSRMLS_CC);
return SUCCESS;
}
zend_class_entry *phalcon_config_ce;
static PHP_METHOD(Phalcon_Config, __construct);
static PHP_METHOD(Phalcon_Config, offsetExists);
static PHP_METHOD(Phalcon_Config, get);
static PHP_METHOD(Phalcon_Config, offsetGet);
static PHP_METHOD(Phalcon_Config, offsetSet);
static PHP_METHOD(Phalcon_Config, offsetUnset);
static PHP_METHOD(Phalcon_Config, merge);
static PHP_METHOD(Phalcon_Config, toArray);
static PHP_METHOD(Phalcon_Config, count);
static PHP_METHOD(Phalcon_Config, __wakeup);
static PHP_METHOD(Phalcon_Config, __set_state);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config___construct, 0, 0, 0)
ZEND_ARG_INFO(0, arrayConfig)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_offsetexists, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_get, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, defaultValue)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_offsetget, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_offsetset, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_offsetunset, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_merge, 0, 0, 1)
ZEND_ARG_INFO(0, config)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_toarray, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_count, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config___wakeup, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config___set_state, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_config_method_entry[] = {
PHP_ME(Phalcon_Config, __construct, arginfo_phalcon_config___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Config, offsetExists, arginfo_phalcon_config_offsetexists, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, get, arginfo_phalcon_config_get, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, offsetGet, arginfo_phalcon_config_offsetget, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, offsetSet, arginfo_phalcon_config_offsetset, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, offsetUnset, arginfo_phalcon_config_offsetunset, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, merge, arginfo_phalcon_config_merge, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, toArray, arginfo_phalcon_config_toarray, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, count, arginfo_phalcon_config_count, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, __wakeup, arginfo_phalcon_config___wakeup, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Config, __set_state, arginfo_phalcon_config___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(Phalcon_Config, __get, offsetGet, arginfo_phalcon_config_offsetget, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_Config, __set, offsetSet, arginfo_phalcon_config_offsetset, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_Config, __isset, offsetExists, arginfo_phalcon_config_offsetexists, ZEND_ACC_PUBLIC)
PHP_FE_END
};
static zend_object_handlers phalcon_config_object_handlers;
typedef struct _phalcon_config_object {
zend_object obj; /**< Zend object data */
HashTable* props; /**< Properties */
} phalcon_config_object;
static inline phalcon_config_object* fetchPhalconConfigObject(zval* zobj TSRMLS_DC)
{
return (phalcon_config_object*)zend_objects_get_address(zobj TSRMLS_CC);
}
static int phalcon_config_count_elements(zval *object, long int *count TSRMLS_DC)
{
phalcon_config_object* obj = fetchPhalconConfigObject(object TSRMLS_CC);
*count = zend_hash_num_elements(obj->props);
return SUCCESS;
}
static zval* phalcon_config_read_internal(phalcon_config_object *object, zval *key, int type TSRMLS_DC)
{
zval **retval;
if (UNEXPECTED(!key)) {
return EG(uninitialized_zval_ptr);
}
retval = phalcon_hash_get(object->props, key, type);
return retval ? *retval : NULL;
}
static zval* phalcon_config_read_property(zval *object, zval *offset, int type ZLK_DC TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
if (BP_VAR_IS == type && !zend_get_std_object_handlers()->has_property(object, offset, 0 ZLK_CC TSRMLS_CC)) {
return EG(uninitialized_zval_ptr);
}
return zend_get_std_object_handlers()->read_property(object, offset, type ZLK_CC TSRMLS_CC);
}
return phalcon_config_read_internal(obj, offset, type TSRMLS_CC);
}
static zval* phalcon_config_read_dimension(zval *object, zval *offset, int type TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
if (BP_VAR_IS == type && !zend_get_std_object_handlers()->has_dimension(object, offset, 0 TSRMLS_CC)) {
return EG(uninitialized_zval_ptr);
}
return zend_get_std_object_handlers()->read_dimension(object, offset, type TSRMLS_CC);
}
return phalcon_config_read_internal(obj, offset, type TSRMLS_CC);
}
static void phalcon_config_write_internal(phalcon_config_object *object, zval *offset, zval *value TSRMLS_DC)
{
if (Z_TYPE_P(value) == IS_ARRAY) {
zval *instance;
HashTable *h = Z_ARRVAL_P(value);
if (!h->nApplyCount) {
++h->nApplyCount;
MAKE_STD_ZVAL(instance);
object_init_ex(instance, phalcon_config_ce);
phalcon_config_construct_internal(instance, value TSRMLS_CC);
phalcon_hash_update_or_insert(object->props, offset, instance);
--h->nApplyCount;
}
else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Recursion detected");
}
}
else {
Z_ADDREF_P(value);
phalcon_hash_update_or_insert(object->props, offset, value);
}
}
static void phalcon_config_write_property(zval *object, zval *offset, zval *value ZLK_DC TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
zend_get_std_object_handlers()->write_property(object, offset, value ZLK_CC TSRMLS_CC);
return;
}
phalcon_config_write_internal(obj, offset, value TSRMLS_CC);
}
static void phalcon_config_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
zend_get_std_object_handlers()->write_dimension(object, offset, value TSRMLS_CC);
return;
}
phalcon_config_write_internal(obj, offset, value TSRMLS_CC);
}
static int phalcon_config_has_internal(phalcon_config_object *object, zval *key, int check_empty TSRMLS_DC)
{
zval **tmp = phalcon_hash_get(object->props, key, BP_VAR_NA);
if (!tmp) {
return 0;
}
if (0 == check_empty) {
return Z_TYPE_PP(tmp) != IS_NULL;
}
if (1 == check_empty) {
return zend_is_true(*tmp);
}
return 1;
}
static int phalcon_config_has_property(zval *object, zval *offset, int has_set_exists ZLK_DC TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
return zend_get_std_object_handlers()->has_property(object, offset, has_set_exists ZLK_CC TSRMLS_CC);
}
return phalcon_config_has_internal(obj, offset, 0 TSRMLS_CC);
}
static int phalcon_config_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
return zend_get_std_object_handlers()->has_dimension(object, offset, check_empty TSRMLS_CC);
}
return phalcon_config_has_internal(obj, offset, check_empty TSRMLS_CC);
}
static void phalcon_config_unset_internal(phalcon_config_object *obj, zval *key TSRMLS_DC)
{
phalcon_hash_unset(obj->props, key);
}
static void phalcon_config_unset_property(zval *object, zval *member ZLK_DC TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
zend_get_std_object_handlers()->unset_property(object, member ZLK_CC TSRMLS_CC);
return;
}
phalcon_config_unset_internal(obj, member TSRMLS_CC);
}
static void phalcon_config_unset_dimension(zval *object, zval *offset TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
zend_get_std_object_handlers()->unset_dimension(object, offset TSRMLS_CC);
return;
}
phalcon_config_unset_internal(obj, offset TSRMLS_CC);
}
static HashTable* phalcon_config_get_properties(zval* object TSRMLS_DC)
{
HashTable* props = zend_std_get_properties(object TSRMLS_CC);
if (!GC_G(gc_active)) {
phalcon_config_object* obj = fetchPhalconConfigObject(object TSRMLS_CC);
zend_hash_copy(props, obj->props, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
}
return props;
}
static int phalcon_config_compare_objects(zval *object1, zval *object2 TSRMLS_DC)
{
phalcon_config_object *zobj1, *zobj2;
zval result;
zobj1 = fetchPhalconConfigObject(object1 TSRMLS_CC);
zobj2 = fetchPhalconConfigObject(object2 TSRMLS_CC);
if (zobj1->obj.ce != zobj2->obj.ce) {
return 1;
}
if (zobj1->props == zobj2->props) {
return 0;
}
zend_compare_symbol_tables(&result, zobj1->props, zobj2->props TSRMLS_CC);
assert(Z_TYPE_P(&result) == IS_LONG);
return Z_LVAL_P(&result);
}
static void phalcon_config_object_dtor(void* v TSRMLS_DC)
{
phalcon_config_object* obj = v;
zend_hash_destroy(obj->props);
FREE_HASHTABLE(obj->props);
zend_object_std_dtor(&(obj->obj) TSRMLS_CC);
efree(obj);
}
static zend_object_value phalcon_config_object_ctor(zend_class_entry* ce TSRMLS_DC)
{
phalcon_config_object *obj = ecalloc(1, sizeof(phalcon_config_object));
zend_object_value retval;
zend_object_std_init(&obj->obj, ce TSRMLS_CC);
#if PHP_VERSION_ID >= 50400
object_properties_init(&obj->obj, ce);
#endif
ALLOC_HASHTABLE(obj->props);
zend_hash_init(obj->props, 0, NULL, ZVAL_PTR_DTOR, 0);
retval.handle = zend_objects_store_put(
obj,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
phalcon_config_object_dtor,
NULL
TSRMLS_CC
);
retval.handlers = &phalcon_config_object_handlers;
return retval;
}
static zend_object_value phalcon_config_clone_obj(zval *object TSRMLS_DC)
{
phalcon_config_object *orig = fetchPhalconConfigObject(object TSRMLS_CC);
zend_object_value result = phalcon_config_object_ctor(Z_OBJCE_P(object) TSRMLS_CC);
phalcon_config_object *clone = zend_object_store_get_object_by_handle(result.handle TSRMLS_CC);
zend_objects_clone_members(&clone->obj, result, &orig->obj, Z_OBJ_HANDLE_P(object) TSRMLS_CC);
zend_hash_copy(clone->props, orig->props, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
return result;
}
PHALCON_INIT_CLASS(Phalcon_Config){
PHALCON_REGISTER_CLASS(Phalcon, Config, config, phalcon_config_method_entry, 0);
phalcon_config_ce->create_object = phalcon_config_object_ctor;
phalcon_config_object_handlers = *zend_get_std_object_handlers();
phalcon_config_object_handlers.count_elements = phalcon_config_count_elements;
phalcon_config_object_handlers.read_property = phalcon_config_read_property;
phalcon_config_object_handlers.write_property = phalcon_config_write_property;
phalcon_config_object_handlers.unset_property = phalcon_config_unset_property;
phalcon_config_object_handlers.has_property = phalcon_config_has_property;
phalcon_config_object_handlers.read_dimension = phalcon_config_read_dimension;
phalcon_config_object_handlers.write_dimension = phalcon_config_write_dimension;
phalcon_config_object_handlers.unset_dimension = phalcon_config_unset_dimension;
phalcon_config_object_handlers.has_dimension = phalcon_config_has_dimension;
phalcon_config_object_handlers.get_properties = phalcon_config_get_properties;
phalcon_config_object_handlers.compare_objects = phalcon_config_compare_objects;
phalcon_config_object_handlers.clone_obj = phalcon_config_clone_obj;
zend_class_implements(phalcon_config_ce TSRMLS_CC, 2, zend_ce_arrayaccess, spl_ce_Countable);
return SUCCESS;
}
static void phalcon_config_construct_internal(zval* this_ptr, zval *array_config TSRMLS_DC)
{
HashTable *ah0;
HashPosition hp0;
zval **hd;
phalcon_config_object* obj;
if (!array_config || Z_TYPE_P(array_config) == IS_NULL) {
return;
}
phalcon_is_iterable(array_config, &ah0, &hp0, 0, 0);
obj = fetchPhalconConfigObject(getThis() TSRMLS_CC);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
zval key = phalcon_get_current_key_w(ah0, &hp0);
phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC);
zend_hash_move_forward_ex(ah0, &hp0);
}
}
static void phalcon_config_toarray_internal(zval **return_value_ptr, zval *this_ptr TSRMLS_DC)
{
phalcon_config_object *obj = fetchPhalconConfigObject(this_ptr TSRMLS_CC);
assert(!EG(exception));
if (likely(obj->obj.ce == phalcon_config_ce)) {
zval *tmp;
array_init_size(*return_value_ptr, zend_hash_num_elements(obj->props));
zend_hash_copy(Z_ARRVAL_PP(return_value_ptr), obj->props, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*));
}
else if (phalcon_method_quick_exists_ex(this_ptr, SS("toarray"), 3566966151UL TSRMLS_CC) == SUCCESS) {
phalcon_call_method_params(*return_value_ptr, return_value_ptr, this_ptr, SL("toarray"), 3566966151UL TSRMLS_CC, 0);
}
else {
phalcon_call_func_params(*return_value_ptr, return_value_ptr, SL("get_object_vars") TSRMLS_CC, 1, this_ptr);
}
if (EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
static PHP_METHOD(Phalcon_Config, __construct){
zval *array_config = NULL;
phalcon_fetch_params(0, 0, 1, &array_config);
if (array_config && Z_TYPE_P(array_config) != IS_ARRAY && Z_TYPE_P(array_config) != IS_NULL) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_config_exception_ce, "The configuration must be an Array");
return;
}
phalcon_config_construct_internal(getThis(), array_config TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Config, offsetExists){
zval *index;
phalcon_fetch_params(0, 1, 0, &index);
RETURN_BOOL(phalcon_config_has_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, 0 TSRMLS_CC));
}
static PHP_METHOD(Phalcon_Config, get){
zval *index, *default_value = NULL, *value;
phalcon_fetch_params(0, 1, 1, &index, &default_value);
value = phalcon_config_read_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, BP_VAR_NA TSRMLS_CC);
if (!value || Z_TYPE_P(value) == IS_NULL) {
if (default_value) {
RETURN_ZVAL(default_value, 1, 0);
}
RETURN_NULL();
}
RETURN_ZVAL(value, 1, 0);
}
static PHP_METHOD(Phalcon_Config, offsetGet){
zval *index;
zval* retval;
phalcon_fetch_params(0, 1, 0, &index);
retval = phalcon_config_read_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, BP_VAR_R TSRMLS_CC);
RETURN_ZVAL(retval, 1, 0);
}
static PHP_METHOD(Phalcon_Config, offsetSet){
zval *index, *value;
phalcon_fetch_params(0, 2, 0, &index, &value);
phalcon_config_write_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, value TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Config, offsetUnset){
zval *index;
phalcon_fetch_params(0, 1, 0, &index);
phalcon_config_unset_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Config, merge){
zval *config, *array_config, key, *active_value = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
phalcon_config_object *obj;
phalcon_fetch_params(0, 1, 0, &config);
if (Z_TYPE_P(config) != IS_OBJECT && Z_TYPE_P(config) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_config_exception_ce, "Configuration must be an object or array");
return;
}
if (Z_TYPE_P(config) == IS_OBJECT) {
ALLOC_INIT_ZVAL(array_config);
phalcon_config_toarray_internal(&array_config, config TSRMLS_CC);
}
else {
array_config = config;
Z_ADDREF_P(array_config);
}
phalcon_is_iterable(array_config, &ah0, &hp0, 0, 0);
obj = fetchPhalconConfigObject(getThis() TSRMLS_CC);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
key = phalcon_get_current_key_w(ah0, &hp0);
active_value = phalcon_config_read_internal(obj, &key, BP_VAR_NA TSRMLS_CC);
if (active_value) {
if ((Z_TYPE_PP(hd) == IS_OBJECT || Z_TYPE_PP(hd) == IS_ARRAY) && Z_TYPE_P(active_value) == IS_OBJECT) {
if (phalcon_method_quick_exists_ex(active_value, SS("merge"), 226837141UL TSRMLS_CC) == SUCCESS) { /* Path AAA in the test */
phalcon_call_method_params(NULL, NULL, active_value, SL("merge"), 226837141UL TSRMLS_CC, 1, *hd);
}
else { /* Path AAB in the test */
phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC);
}
}
else { /* Path AE in the test */
phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC);
}
}
else { /* Path B in the test */
phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
zval_ptr_dtor(&array_config);
}
static PHP_METHOD(Phalcon_Config, toArray){
zval key, *array_value, *recursive = NULL, *tmp;
HashPosition hp;
zval **value;
phalcon_config_object *obj;
phalcon_fetch_params(0, 0, 1, &recursive);
obj = fetchPhalconConfigObject(getThis() TSRMLS_CC);
array_init_size(return_value, zend_hash_num_elements(obj->props));
zend_hash_copy(Z_ARRVAL_P(return_value), obj->props, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*));
if (!recursive || zend_is_true(recursive)) {
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(return_value), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(return_value), (void**)&value, &hp) == SUCCESS && !EG(exception);
zend_hash_move_forward_ex(Z_ARRVAL_P(return_value), &hp)
) {
key = phalcon_get_current_key_w(Z_ARRVAL_P(return_value), &hp);
if (Z_TYPE_PP(value) == IS_OBJECT && phalcon_method_exists_ex(*value, SS("toarray") TSRMLS_CC) == SUCCESS) {
array_value = NULL;
if (SUCCESS == phalcon_call_method_params(array_value, &array_value, *value, SL("toarray"), 3566966151UL TSRMLS_CC, 0)) {
phalcon_array_update_zval(&return_value, &key, &array_value, 0);
}
}
}
}
}
static PHP_METHOD(Phalcon_Config, count)
{
long int cnt;
phalcon_config_count_elements(getThis(), &cnt TSRMLS_CC);
RETURN_LONG(cnt);
}
static PHP_METHOD(Phalcon_Config, __wakeup)
{
HashTable *props;
phalcon_config_object *obj;
obj = fetchPhalconConfigObject(getThis() TSRMLS_CC);
props = zend_std_get_properties(getThis() TSRMLS_CC);
zend_hash_copy(obj->props, props, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
}
static PHP_METHOD(Phalcon_Config, __set_state){
zval *data;
phalcon_fetch_params(0, 1, 0, &data);
object_init_ex(return_value, phalcon_config_ce);
phalcon_config_construct_internal(return_value, data TSRMLS_CC);
}
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_string.h>
zend_class_entry *phalcon_crypt_ce;
static PHP_METHOD(Phalcon_Crypt, setCipher);
static PHP_METHOD(Phalcon_Crypt, getCipher);
static PHP_METHOD(Phalcon_Crypt, setMode);
static PHP_METHOD(Phalcon_Crypt, getMode);
static PHP_METHOD(Phalcon_Crypt, setKey);
static PHP_METHOD(Phalcon_Crypt, getKey);
static PHP_METHOD(Phalcon_Crypt, setPadding);
static PHP_METHOD(Phalcon_Crypt, getPadding);
static PHP_METHOD(Phalcon_Crypt, encrypt);
static PHP_METHOD(Phalcon_Crypt, decrypt);
static PHP_METHOD(Phalcon_Crypt, encryptBase64);
static PHP_METHOD(Phalcon_Crypt, decryptBase64);
static PHP_METHOD(Phalcon_Crypt, getAvailableCiphers);
static PHP_METHOD(Phalcon_Crypt, getAvailableModes);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_crypt_getpadding, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_crypt_setpadding, 0, 0, 1)
ZEND_ARG_INFO(0, scheme)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_crypt_method_entry[] = {
PHP_ME(Phalcon_Crypt, setCipher, arginfo_phalcon_cryptinterface_setcipher, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, getCipher, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, setMode, arginfo_phalcon_cryptinterface_setmode, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, getMode, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, setKey, arginfo_phalcon_cryptinterface_setkey, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, getKey, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, setPadding, arginfo_phalcon_crypt_setpadding, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, getPadding, arginfo_phalcon_crypt_getpadding, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, encrypt, arginfo_phalcon_cryptinterface_encrypt, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, decrypt, arginfo_phalcon_cryptinterface_decrypt, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, encryptBase64, arginfo_phalcon_cryptinterface_encryptbase64, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, decryptBase64, arginfo_phalcon_cryptinterface_decryptbase64, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, getAvailableCiphers, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Crypt, getAvailableModes, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Crypt){
PHALCON_REGISTER_CLASS(Phalcon, Crypt, crypt, phalcon_crypt_method_entry, 0);
zend_declare_property_null(phalcon_crypt_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_crypt_ce, SL("_mode"), "cbc", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_crypt_ce, SL("_cipher"), "rijndael-256", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(phalcon_crypt_ce, SL("_padding"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_crypt_ce TSRMLS_CC, 1, phalcon_cryptinterface_ce);
zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_DEFAULT"), PHALCON_CRYPT_PADDING_DEFAULT TSRMLS_CC);
zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ANSI_X_923"), PHALCON_CRYPT_PADDING_ANSI_X_923 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_PKCS7"), PHALCON_CRYPT_PADDING_PKCS7 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ISO_10126"), PHALCON_CRYPT_PADDING_ISO_10126 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ISO_IEC_7816_4"), PHALCON_CRYPT_PADDING_ISO_IEC_7816_4 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ZERO"), PHALCON_CRYPT_PADDING_ZERO TSRMLS_CC);
zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_SPACE"), PHALCON_CRYPT_PADDING_SPACE TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Crypt, setCipher){
zval *cipher;
phalcon_fetch_params(0, 1, 0, &cipher);
phalcon_update_property_this_quick(this_ptr, SL("_cipher"), cipher, 3925470815UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Crypt, getCipher){
RETURN_MEMBER_QUICK(this_ptr, "_cipher", 3925470815UL);
}
static PHP_METHOD(Phalcon_Crypt, setMode){
zval **mode;
phalcon_fetch_params_ex(1, 0, &mode);
PHALCON_ENSURE_IS_STRING(mode);
phalcon_update_property_this(this_ptr, SL("_mode"), *mode TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Crypt, getMode){
RETURN_MEMBER_QUICK(this_ptr, "_mode", 3983285225UL);
}
static PHP_METHOD(Phalcon_Crypt, setKey){
zval **key;
phalcon_fetch_params_ex(1, 0, &key);
PHALCON_ENSURE_IS_STRING(key);
phalcon_update_property_this(this_ptr, SL("_key"), *key TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Crypt, getKey){
RETURN_MEMBER_QUICK(this_ptr, "_key", 250773965UL);
}
static PHP_METHOD(Phalcon_Crypt, setPadding) {
zval **scheme;
phalcon_fetch_params_ex(1, 0, &scheme);
PHALCON_ENSURE_IS_LONG(scheme);
phalcon_update_property_this(this_ptr, SL("_padding"), *scheme TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Crypt, getPadding) {
RETURN_MEMBER_QUICK(this_ptr, "_padding", 2759428059UL);
}
static void phalcon_crypt_pad_text(zval *return_value, zval *text, zval *mode, uint block_size, int padding_type TSRMLS_DC)
{
uint padding_size, i;
char padding[256];
char *str_mode;
assert(Z_TYPE_P(text) == IS_STRING);
assert(Z_TYPE_P(mode) == IS_STRING);
padding_size = 0;
str_mode = Z_STRVAL_P(mode);
if (!strcmp(str_mode, "ecb") || !strcmp(str_mode, "cbc")) {
padding_size = block_size - (Z_STRLEN_P(text) % block_size);
switch (padding_type) {
case PHALCON_CRYPT_PADDING_ANSI_X_923:
memset(padding, 0, padding_size - 1);
padding[padding_size-1] = (unsigned char)padding_size;
break;
case PHALCON_CRYPT_PADDING_PKCS7:
memset(padding, padding_size, padding_size);
break;
case PHALCON_CRYPT_PADDING_ISO_10126:
for (i=0; i<padding_size-1; ++i) {
padding[i] = (unsigned char)rand();
}
padding[padding_size-1] = (unsigned char)padding_size;
break;
case PHALCON_CRYPT_PADDING_ISO_IEC_7816_4:
padding[0] = 0x80;
memset(padding + 1, 0, padding_size - 1);
break;
case PHALCON_CRYPT_PADDING_ZERO:
memset(padding, 0, padding_size);
break;
case PHALCON_CRYPT_PADDING_SPACE:
memset(padding, 0x20, padding_size);
break;
default:
padding_size = 0;
break;
}
}
if (!padding_size) {
ZVAL_ZVAL(return_value, text, 1, 0);
}
else {
assert(padding_size <= block_size);
phalcon_concat_vs(&return_value, text, padding, padding_size, 0 TSRMLS_CC);
}
}
static void phalcon_crypt_unpad_text(zval *return_value, zval *text, zval *mode, uint block_size, int padding_type TSRMLS_DC)
{
uint padding_size;
char padding[256];
int i;
char *str_mode;
char *str_text;
int text_len;
assert(Z_TYPE_P(text) == IS_STRING);
assert(Z_TYPE_P(mode) == IS_STRING);
padding_size = 0;
str_mode = Z_STRVAL_P(mode);
str_text = Z_STRVAL_P(text);
text_len = Z_STRLEN_P(text);
if (text_len && (text_len % block_size == 0) && (!strcmp(str_mode, "ecb") || !strcmp(str_mode, "cbc"))) {
switch (padding_type) {
case PHALCON_CRYPT_PADDING_ANSI_X_923:
if (str_text[text_len-1] <= block_size) {
padding_size = str_text[text_len-1];
memset(padding, 0, padding_size - 1);
padding[padding_size-1] = (unsigned char)padding_size;
if (memcmp(padding, str_text + text_len - padding_size, padding_size)) {
padding_size = 0;
}
}
break;
case PHALCON_CRYPT_PADDING_PKCS7:
if (str_text[text_len-1] <= block_size) {
padding_size = str_text[text_len-1];
memset(padding, padding_size, padding_size);
if (memcmp(padding, str_text + text_len - padding_size, padding_size)) {
padding_size = 0;
}
}
break;
case PHALCON_CRYPT_PADDING_ISO_10126:
padding_size = str_text[text_len-1];
break;
case PHALCON_CRYPT_PADDING_ISO_IEC_7816_4:
i = text_len - 1;
while (i > 0 && str_text[i] == 0x00 && padding_size < block_size) {
++padding_size;
--i;
}
padding_size = ((unsigned char)str_text[i] == 0x80) ? (padding_size + 1) : 0;
break;
case PHALCON_CRYPT_PADDING_ZERO:
i = text_len - 1;
while (i >= 0 && str_text[i] == 0x00 && padding_size <= block_size) {
++padding_size;
--i;
}
break;
case PHALCON_CRYPT_PADDING_SPACE:
i = text_len - 1;
while (i >= 0 && str_text[i] == 0x20 && padding_size <= block_size) {
++padding_size;
--i;
}
break;
default:
break;
}
if (padding_size && padding_size <= block_size) {
assert(padding_size <= text_len);
if (padding_size < text_len) {
phalcon_substr(return_value, text, 0, text_len - padding_size);
}
else {
ZVAL_EMPTY_STRING(return_value);
}
}
else {
padding_size = 0;
}
}
if (!padding_size) {
ZVAL_ZVAL(return_value, text, 1, 0);
}
}
static PHP_METHOD(Phalcon_Crypt, encrypt){
zval *source, *text, *key = NULL, *encrypt_key = NULL, *cipher, *mode, *padding_type, *iv_size;
zval *rand, *iv, *encrypt, *block_size, *padded;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &source, &key);
/* Do not use make_printable_zval() here: we need the conversion with type juggling */
if (Z_TYPE_P(source) != IS_STRING) {
PHALCON_INIT_VAR(text);
phalcon_cast(text, source, IS_STRING);
}
else {
text = source;
}
if (phalcon_function_quick_exists_ex(SS("mcrypt_get_iv_size"), 547857179UL TSRMLS_CC) == FAILURE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "mcrypt extension is required");
return;
}
if (!key || Z_TYPE_P(key) == IS_NULL) {
encrypt_key = phalcon_fetch_nproperty_this(this_ptr, SL("_key"), PH_NOISY_CC);
} else {
PHALCON_CPY_WRT_CTOR(encrypt_key, key);
if (Z_TYPE_P(encrypt_key) != IS_STRING) {
convert_to_string(encrypt_key);
}
}
if (PHALCON_IS_EMPTY(encrypt_key)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Encryption key cannot be empty");
return;
}
cipher = phalcon_fetch_nproperty_this(this_ptr, SL("_cipher"), PH_NOISY_CC);
mode = phalcon_fetch_nproperty_this(this_ptr, SL("_mode"), PH_NOISY_CC);
PHALCON_OBS_VAR(iv_size);
phalcon_call_func_p2_ex(iv_size, &iv_size, "mcrypt_get_iv_size", cipher, mode);
if (unlikely(Z_TYPE_P(iv_size) != IS_LONG)) {
convert_to_long(iv_size);
}
if (Z_STRLEN_P(encrypt_key) > Z_LVAL_P(iv_size)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm");
return;
}
PHALCON_INIT_VAR(rand);
ZVAL_LONG(rand, 2);
PHALCON_OBS_VAR(iv);
phalcon_call_func_p2_ex(iv, &iv, "mcrypt_create_iv", iv_size, rand);
if (unlikely(Z_TYPE_P(iv) != IS_STRING)) {
convert_to_string(iv);
}
PHALCON_OBS_VAR(block_size);
phalcon_call_func_p2_ex(block_size, &block_size, "mcrypt_get_block_size", cipher, mode);
if (unlikely(Z_TYPE_P(block_size) != IS_LONG)) {
convert_to_long(block_size);
}
padding_type = phalcon_fetch_nproperty_this(this_ptr, SL("_padding"), PH_NOISY_CC);
assert(Z_TYPE_P(padding_type) == IS_LONG);
assert(Z_TYPE_P(block_size) == IS_LONG);
assert(Z_TYPE_P(mode) == IS_STRING);
assert(Z_TYPE_P(text) == IS_STRING);
PHALCON_INIT_VAR(padded);
phalcon_crypt_pad_text(padded, text, mode, Z_LVAL_P(block_size), Z_LVAL_P(padding_type) TSRMLS_CC);
assert(Z_TYPE_P(padded) == IS_STRING);
PHALCON_OBS_VAR(encrypt);
phalcon_call_func_p5_ex(encrypt, &encrypt, "mcrypt_encrypt", cipher, encrypt_key, padded, mode, iv);
PHALCON_CONCAT_VV(return_value, iv, encrypt);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Crypt, decrypt){
zval *text, *key = NULL, *decrypt_key = NULL, *cipher, *mode, *iv_size;
zval *key_size, *text_size, *iv, *text_to_decipher, *decrypted;
zval *padding_type, *block_size;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &text, &key);
if (phalcon_function_quick_exists_ex(SS("mcrypt_get_iv_size"), 547857179UL TSRMLS_CC) == FAILURE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "mcrypt extension is required");
return;
}
if (!key || Z_TYPE_P(key) == IS_NULL) {
decrypt_key = phalcon_fetch_nproperty_this(this_ptr, SL("_key"), PH_NOISY_CC);
} else {
decrypt_key = key;
}
if (PHALCON_IS_EMPTY(decrypt_key)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Decryption key cannot be empty");
return;
}
cipher = phalcon_fetch_nproperty_this(this_ptr, SL("_cipher"), PH_NOISY_CC);
mode = phalcon_fetch_nproperty_this(this_ptr, SL("_mode"), PH_NOISY_CC);
PHALCON_OBS_VAR(iv_size);
phalcon_call_func_p2_ex(iv_size, &iv_size, "mcrypt_get_iv_size", cipher, mode);
if (unlikely(Z_TYPE_P(iv_size) != IS_LONG)) {
convert_to_long(iv_size);
}
PHALCON_INIT_VAR(key_size);
phalcon_fast_strlen(key_size, decrypt_key);
if (PHALCON_GT(key_size, iv_size)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm");
return;
}
PHALCON_INIT_VAR(text_size);
phalcon_fast_strlen(text_size, text);
if (PHALCON_GT(key_size, text_size)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Size of IV is larger than text to decrypt");
return;
}
PHALCON_INIT_VAR(iv);
phalcon_substr(iv, text, 0, Z_LVAL_P(iv_size));
PHALCON_INIT_VAR(text_to_decipher);
phalcon_substr(text_to_decipher, text, Z_LVAL_P(iv_size), 0);
PHALCON_OBS_VAR(decrypted);
phalcon_call_func_p5_ex(decrypted, &decrypted, "mcrypt_decrypt", cipher, decrypt_key, text_to_decipher, mode, iv);
if (unlikely(Z_TYPE_P(decrypted) != IS_STRING)) {
convert_to_string(decrypted);
}
PHALCON_OBS_VAR(block_size);
phalcon_call_func_p2_ex(block_size, &block_size, "mcrypt_get_block_size", cipher, mode);
if (unlikely(Z_TYPE_P(block_size) != IS_LONG)) {
convert_to_long(block_size);
}
padding_type = phalcon_fetch_nproperty_this(this_ptr, SL("_padding"), PH_NOISY_CC);
assert(Z_TYPE_P(padding_type) == IS_LONG);
assert(Z_TYPE_P(block_size) == IS_LONG);
assert(Z_TYPE_P(mode) == IS_STRING);
assert(Z_TYPE_P(decrypted) == IS_STRING);
phalcon_crypt_unpad_text(return_value, decrypted, mode, Z_LVAL_P(block_size), Z_LVAL_P(padding_type) TSRMLS_CC);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Crypt, encryptBase64){
zval *text, *key = NULL, *safe = NULL, *encrypted, *from, *to;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 2, &text, &key, &safe);
if (!key) {
key = PHALCON_GLOBAL(z_null);
}
if (!safe) {
safe = PHALCON_GLOBAL(z_false);
}
PHALCON_OBS_VAR(encrypted);
phalcon_call_method_p2_ex(encrypted, &encrypted, this_ptr, "encrypt", text, key);
phalcon_base64_encode(return_value, encrypted);
if (zend_is_true(safe)) {
PHALCON_INIT_VAR(from);
ZVAL_STRING(from, "+/", 1);
PHALCON_INIT_VAR(to);
ZVAL_STRING(to, "-_", 1);
php_strtr(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), Z_STRVAL_P(from), Z_STRVAL_P(to), MIN(Z_STRLEN_P(from), Z_STRLEN_P(to)));
}
RETURN_MM();
}
static PHP_METHOD(Phalcon_Crypt, decryptBase64){
zval *text, *key = NULL, *safe = NULL, *decrypt_text, *from, *to;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 2, &text, &key, &safe);
if (!key) {
key = PHALCON_GLOBAL(z_null);
}
if (!safe) {
safe = PHALCON_GLOBAL(z_false);
}
if (zend_is_true(safe)) {
PHALCON_INIT_VAR(from);
ZVAL_STRING(from, "-_", 1);
PHALCON_INIT_VAR(to);
ZVAL_STRING(to, "+/", 1);
php_strtr(Z_STRVAL_P(text), Z_STRLEN_P(text), Z_STRVAL_P(from), Z_STRVAL_P(to), MIN(Z_STRLEN_P(from), Z_STRLEN_P(to)));
}
PHALCON_INIT_VAR(decrypt_text);
phalcon_base64_decode(decrypt_text, text);
phalcon_call_method_p2_key(return_value, this_ptr, "decrypt", 325472000UL, decrypt_text, key);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Crypt, getAvailableCiphers){
phalcon_call_func_params(return_value, return_value_ptr, SL("mcrypt_list_algorithms") TSRMLS_CC, 0);
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
static PHP_METHOD(Phalcon_Crypt, getAvailableModes){
phalcon_call_func_params(return_value, return_value_ptr, SL("mcrypt_list_modes") TSRMLS_CC, 0);
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
zend_class_entry *phalcon_cryptinterface_ce;
static const zend_function_entry phalcon_cryptinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_CryptInterface, setCipher, arginfo_phalcon_cryptinterface_setcipher)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, getCipher, NULL)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, setMode, arginfo_phalcon_cryptinterface_setmode)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, getMode, NULL)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, setKey, arginfo_phalcon_cryptinterface_setkey)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, getKey, NULL)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, encrypt, arginfo_phalcon_cryptinterface_encrypt)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, decrypt, arginfo_phalcon_cryptinterface_decrypt)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, encryptBase64, arginfo_phalcon_cryptinterface_encryptbase64)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, decryptBase64, arginfo_phalcon_cryptinterface_decryptbase64)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, getAvailableCiphers, NULL)
PHP_ABSTRACT_ME(Phalcon_CryptInterface, getAvailableModes, NULL)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_CryptInterface){
PHALCON_REGISTER_INTERFACE(Phalcon, CryptInterface, cryptinterface, phalcon_cryptinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_db_ce;
static PHP_METHOD(Phalcon_Db, setup);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_setup, 0, 0, 1)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_db_method_entry[] = {
PHP_ME(Phalcon_Db, setup, arginfo_phalcon_db_setup, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Db){
PHALCON_REGISTER_CLASS(Phalcon, Db, db, phalcon_db_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_USE_DEFAULT"), (long int)PDO_FETCH_USE_DEFAULT TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_LAZY"), (long int)PDO_FETCH_LAZY TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_ASSOC"), (long int)PDO_FETCH_ASSOC TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NUM"), (long int)PDO_FETCH_NUM TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOTH"), (long int)PDO_FETCH_BOTH TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_OBJ"), (long int)PDO_FETCH_OBJ TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOUND"), (long int)PDO_FETCH_BOUND TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_COLUMN"), (long int)PDO_FETCH_COLUMN TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_CLASS"), (long int)PDO_FETCH_CLASS TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_INTO"), (long int)PDO_FETCH_INTO TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_FUNC"), (long int)PDO_FETCH_FUNC TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NAMED"), (long int)PDO_FETCH_NAMED TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_KEY_PAIR") , (long int)PDO_FETCH_KEY_PAIR TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_GROUP"), (long int)PDO_FETCH_GROUP TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_UNIQUE"), (long int)PDO_FETCH_UNIQUE TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_CLASSTYPE"), (long int)PDO_FETCH_CLASSTYPE TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_SERIALIZE"), (long int)PDO_FETCH_SERIALIZE TSRMLS_CC);
zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_PROPS_LATE"), (long int)PDO_FETCH_PROPS_LATE TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Db, setup){
zval *options, *escape_identifiers;
phalcon_fetch_params(0, 1, 0, &options);
if (Z_TYPE_P(options) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Options must be an array");
return;
}
if (phalcon_array_isset_string_fetch(&escape_identifiers, options, SS("escapeSqlIdentifiers"))) {
PHALCON_GLOBAL(db).escape_identifiers = zend_is_true(escape_identifiers);
}
}
#include <ext/standard/php_string.h>
#include <Zend/zend_builtin_functions.h>
zend_class_entry *phalcon_debug_ce;
static PHP_METHOD(Phalcon_Debug, setUri);
static PHP_METHOD(Phalcon_Debug, setShowBackTrace);
static PHP_METHOD(Phalcon_Debug, setShowFiles);
static PHP_METHOD(Phalcon_Debug, setShowFileFragment);
static PHP_METHOD(Phalcon_Debug, listen);
static PHP_METHOD(Phalcon_Debug, listenExceptions);
static PHP_METHOD(Phalcon_Debug, listenLowSeverity);
static PHP_METHOD(Phalcon_Debug, debugVar);
static PHP_METHOD(Phalcon_Debug, clearVars);
static PHP_METHOD(Phalcon_Debug, _escapeString);
static PHP_METHOD(Phalcon_Debug, _getArrayDump);
static PHP_METHOD(Phalcon_Debug, _getVarDump);
static PHP_METHOD(Phalcon_Debug, getMajorVersion);
static PHP_METHOD(Phalcon_Debug, getVersion);
static PHP_METHOD(Phalcon_Debug, getCssSources);
static PHP_METHOD(Phalcon_Debug, getJsSources);
static PHP_METHOD(Phalcon_Debug, showTraceItem);
static PHP_METHOD(Phalcon_Debug, onUncaughtException);
static PHP_METHOD(Phalcon_Debug, getCharset);
static PHP_METHOD(Phalcon_Debug, setCharset);
static PHP_METHOD(Phalcon_Debug, getLinesBeforeContext);
static PHP_METHOD(Phalcon_Debug, setLinesBeforeContext);
static PHP_METHOD(Phalcon_Debug, getLinesAfterContext);
static PHP_METHOD(Phalcon_Debug, setLinesAfterContext);
static PHP_METHOD(Phalcon_Debug, getFileLink);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_seturi, 0, 0, 1)
ZEND_ARG_INFO(0, uri)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_setshowbacktrace, 0, 0, 1)
ZEND_ARG_INFO(0, showBackTrace)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_setshowfiles, 0, 0, 1)
ZEND_ARG_INFO(0, showFiles)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_setshowfilefragment, 0, 0, 1)
ZEND_ARG_INFO(0, showFileFragment)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_listen, 0, 0, 0)
ZEND_ARG_INFO(0, exceptions)
ZEND_ARG_INFO(0, lowSeverity)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_debugvar, 0, 0, 1)
ZEND_ARG_INFO(0, var)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_onuncaughtexception, 0, 0, 1)
ZEND_ARG_INFO(0, exception)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_setcharset, 0, 0, 1)
ZEND_ARG_INFO(0, charset)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_setlines, 0, 0, 1)
ZEND_ARG_INFO(0, lines)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_getfilelink, 0, 0, 3)
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, line)
ZEND_ARG_INFO(0, format)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_debug_method_entry[] = {
PHP_ME(Phalcon_Debug, setUri, arginfo_phalcon_debug_seturi, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setShowBackTrace, arginfo_phalcon_debug_setshowbacktrace, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setShowFiles, arginfo_phalcon_debug_setshowfiles, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setShowFileFragment, arginfo_phalcon_debug_setshowfilefragment, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, listen, arginfo_phalcon_debug_listen, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, listenExceptions, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, listenLowSeverity, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, debugVar, arginfo_phalcon_debug_debugvar, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, clearVars, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, _escapeString, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Debug, _getArrayDump, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Debug, _getVarDump, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Debug, getMajorVersion, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getVersion, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getCssSources, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getJsSources, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, showTraceItem, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Debug, onUncaughtException, arginfo_phalcon_debug_onuncaughtexception, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setCharset, arginfo_phalcon_debug_setcharset, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getLinesBeforeContext, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setLinesBeforeContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getLinesAfterContext, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setLinesAfterContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getFileLink, arginfo_phalcon_debug_getfilelink, ZEND_ACC_PROTECTED)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Debug){
PHALCON_REGISTER_CLASS(Phalcon, Debug, debug, phalcon_debug_method_entry, 0);
zend_declare_property_string(phalcon_debug_ce, SL("_uri"), "//static.phalconphp.com/debug/1.2.0/", ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_string(phalcon_debug_ce, SL("_theme"), "default", ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_bool(phalcon_debug_ce, SL("_hideDocumentRoot"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_debug_ce, SL("_showBackTrace"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_debug_ce, SL("_showFiles"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_debug_ce, SL("_showFileFragment"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_debug_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_debug_ce, SL("_isActive"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_string(phalcon_debug_ce, SL("_charset"), "utf-8", ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_long(phalcon_debug_ce, SL("_beforeContext"), 7, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(phalcon_debug_ce, SL("_afterContext"), 5, ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Debug, setUri){
zval *uri;
phalcon_fetch_params(0, 1, 0, &uri);
phalcon_update_property_this_quick(this_ptr, SL("_uri"), uri, 251146964UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, setShowBackTrace){
zval *show_back_trace;
phalcon_fetch_params(0, 1, 0, &show_back_trace);
phalcon_update_property_this_quick(this_ptr, SL("_showBackTrace"), show_back_trace, 3370024901UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, setShowFiles){
zval *show_files;
phalcon_fetch_params(0, 1, 0, &show_files);
phalcon_update_property_this_quick(this_ptr, SL("_showFiles"), show_files, 1877855960UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, setShowFileFragment){
zval *show_file_fragment;
phalcon_fetch_params(0, 1, 0, &show_file_fragment);
phalcon_update_property_this_quick(this_ptr, SL("_showFileFragment"), show_file_fragment, 3533221081UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, listen){
zval *exceptions = NULL, *low_severity = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 2, &exceptions, &low_severity);
if (!exceptions || zend_is_true(exceptions)) {
phalcon_call_method_key(NULL, this_ptr, "listenexceptions", 2156957942UL);
}
if (low_severity && zend_is_true(low_severity)) {
phalcon_call_method_key(NULL, this_ptr, "listenlowseverity", 1386787713UL);
}
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Debug, listenExceptions){
zval *handler;
PHALCON_MM_GROW();
PHALCON_INIT_VAR(handler);
array_init_size(handler, 2);
phalcon_array_append(&handler, this_ptr, PH_SEPARATE);
add_next_index_stringl(handler, SL("onUncaughtException"), 1);
phalcon_call_func_p1_noret("set_exception_handler", handler);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Debug, listenLowSeverity){
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, debugVar){
zval *var, *key = NULL, *ztime, *backtrace, *data;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &var, &key);
if (!key) {
key = PHALCON_GLOBAL(z_null);
}
PHALCON_INIT_VAR(ztime);
ZVAL_LONG(ztime, (long) time(NULL));
PHALCON_INIT_VAR(backtrace);
#if PHP_VERSION_ID < 50400
#ifdef DEBUG_BACKTRACE_PROVIDE_OBJECT
zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT TSRMLS_CC);
#else
zend_fetch_debug_backtrace(backtrace, 0, 1 TSRMLS_CC);
#endif
#else
zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT, 0 TSRMLS_CC);
#endif
PHALCON_INIT_VAR(data);
array_init_size(data, 3);
phalcon_array_append(&data, var, PH_SEPARATE);
phalcon_array_append(&data, backtrace, PH_SEPARATE);
phalcon_array_append(&data, ztime, PH_SEPARATE);
phalcon_update_property_array_append(this_ptr, SL("_data"), data TSRMLS_CC);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Debug, clearVars){
phalcon_update_property_null(this_ptr, SL("_data") TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, _escapeString){
zval *value, *charset, *replaced_value;
phalcon_fetch_params(0, 1, 0, &value);
if (Z_TYPE_P(value) == IS_STRING) {
zval line_break;
zval escaped_line_break;
charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC);
INIT_ZVAL(line_break);
ZVAL_STRING(&line_break, "\n", 0);
INIT_ZVAL(escaped_line_break);
ZVAL_STRING(&escaped_line_break, "\\n", 0);
ALLOC_INIT_ZVAL(replaced_value);
phalcon_fast_str_replace(replaced_value, &line_break, &escaped_line_break, value);
phalcon_htmlentities(return_value, replaced_value, NULL, charset TSRMLS_CC);
zval_ptr_dtor(&replaced_value);
return;
}
RETURN_ZVAL(value, 1, 0);
}
static PHP_METHOD(Phalcon_Debug, _getArrayDump){
zval *argument, *n = NULL, *number_arguments, *dump;
zval *v = NULL, *k = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL;
zval *class_name = NULL, *joined_dump;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &argument, &n);
if (!n) {
PHALCON_INIT_VAR(n);
ZVAL_LONG(n, 0);
}
PHALCON_INIT_VAR(number_arguments);
phalcon_fast_count(number_arguments, argument TSRMLS_CC);
if (PHALCON_LT_LONG(n, 3)) {
if (PHALCON_GT_LONG(number_arguments, 0)) {
if (PHALCON_LT_LONG(number_arguments, 10)) {
PHALCON_INIT_VAR(dump);
array_init(dump);
phalcon_is_iterable(argument, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(k, ah0, hp0);
PHALCON_GET_HVALUE(v);
if (PHALCON_IS_SCALAR(v)) {
if (PHALCON_IS_STRING(v, "")) {
PHALCON_INIT_NVAR(var_dump);
PHALCON_CONCAT_SVS(var_dump, "[", k, "] =&gt; (empty string)");
} else {
PHALCON_INIT_NVAR(escaped_string);
phalcon_call_method_p1_key(escaped_string, this_ptr, "_escapestring", 1235002348UL, v);
PHALCON_INIT_NVAR(var_dump);
PHALCON_CONCAT_SVSV(var_dump, "[", k, "] =&gt; ", escaped_string);
}
phalcon_array_append(&dump, var_dump, PH_SEPARATE);
} else {
if (Z_TYPE_P(v) == IS_ARRAY) {
PHALCON_INIT_NVAR(next);
phalcon_add_function(next, n, PHALCON_GLOBAL(z_one) TSRMLS_CC);
PHALCON_INIT_NVAR(array_dump);
phalcon_call_method_p2_key(array_dump, this_ptr, "_getarraydump", 2678003289UL, v, next);
PHALCON_INIT_NVAR(var_dump);
PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] =&gt; Array(", array_dump, ")");
phalcon_array_append(&dump, var_dump, PH_SEPARATE);
zend_hash_move_forward_ex(ah0, &hp0);
continue;
}
if (Z_TYPE_P(v) == IS_OBJECT) {
PHALCON_INIT_NVAR(class_name);
phalcon_get_class(class_name, v, 0 TSRMLS_CC);
PHALCON_INIT_NVAR(var_dump);
PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] =&gt; Object(", class_name, ")");
phalcon_array_append(&dump, var_dump, PH_SEPARATE);
zend_hash_move_forward_ex(ah0, &hp0);
continue;
}
if (Z_TYPE_P(v) == IS_NULL) {
PHALCON_INIT_NVAR(var_dump);
PHALCON_CONCAT_SVS(var_dump, "[", k, "] =&gt; null");
phalcon_array_append(&dump, var_dump, PH_SEPARATE);
zend_hash_move_forward_ex(ah0, &hp0);
continue;
}
PHALCON_INIT_NVAR(var_dump);
PHALCON_CONCAT_SVSV(var_dump, "[", k, "] =&gt; ", v);
phalcon_array_append(&dump, var_dump, PH_SEPARATE);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
PHALCON_INIT_VAR(joined_dump);
phalcon_fast_join_str(joined_dump, SL(", "), dump TSRMLS_CC);
RETURN_CTOR(joined_dump);
}
RETURN_NCTOR(number_arguments);
}
}
RETURN_MM_NULL();
}
static PHP_METHOD(Phalcon_Debug, _getVarDump){
zval *variable, *class_name, *dumped_object;
zval *array_dump = NULL, *dump = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &variable);
if (PHALCON_IS_SCALAR(variable)) {
if (Z_TYPE_P(variable) == IS_BOOL) {
if (zend_is_true(variable)) {
RETURN_MM_STRING("true", 1);
} else {
RETURN_MM_STRING("false", 1);
}
}
if (Z_TYPE_P(variable) == IS_STRING) {
phalcon_call_method_p1_key(return_value, this_ptr, "_escapestring", 1235002348UL, variable);
RETURN_MM();
}
RETURN_CTOR(variable);
}
if (Z_TYPE_P(variable) == IS_OBJECT) {
PHALCON_INIT_VAR(class_name);
phalcon_get_class(class_name, variable, 0 TSRMLS_CC);
if (phalcon_method_quick_exists_ex(variable, SS("dump"), 257071355UL TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_VAR(dumped_object);
phalcon_call_method_key(dumped_object, variable, "dump", 257071355UL);
PHALCON_INIT_VAR(array_dump);
phalcon_call_method_p1_key(array_dump, this_ptr, "_getarraydump", 2678003289UL, dumped_object);
PHALCON_INIT_VAR(dump);
PHALCON_CONCAT_SVSVS(dump, "Object(", class_name, ": ", array_dump, ")");
} else {
PHALCON_INIT_NVAR(dump);
PHALCON_CONCAT_SVS(dump, "Object(", class_name, ")</span>");
}
RETURN_CTOR(dump);
}
if (Z_TYPE_P(variable) == IS_ARRAY) {
PHALCON_INIT_NVAR(array_dump);
phalcon_call_method_p1_key(array_dump, this_ptr, "_getarraydump", 2678003289UL, variable);
PHALCON_CONCAT_SVS(return_value, "Array(", array_dump, ")");
RETURN_MM();
}
RETURN_MM_STRING(zend_zval_type_name(variable), 1);
}
static PHP_METHOD(Phalcon_Debug, getMajorVersion){
zval *version, *parts, *major;
PHALCON_MM_GROW();
PHALCON_INIT_VAR(version);
phalcon_call_static(version, "phalcon\\version", "get");
PHALCON_INIT_VAR(parts);
phalcon_fast_explode_str(parts, SL(" "), version);
PHALCON_OBS_VAR(major);
phalcon_array_fetch_long(&major, parts, 0, PH_NOISY);
RETURN_CCTOR(major);
}
static PHP_METHOD(Phalcon_Debug, getVersion){
zval *version;
PHALCON_MM_GROW();
PHALCON_INIT_VAR(version);
phalcon_call_method_key(version, this_ptr, "getmajorversion", 1927318692UL);
PHALCON_CONCAT_SVSVS(return_value, "<div class=\"version\">Phalcon Framework <a target=\"_new\" href=\"http://docs.phalconphp.com/en/", version, "/\">", version, "</a></div>");
RETURN_MM();
}
static PHP_METHOD(Phalcon_Debug, getCssSources){
zval *uri, *sources;
PHALCON_MM_GROW();
PHALCON_OBS_VAR(uri);
phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC);
PHALCON_INIT_VAR(sources);
PHALCON_CONCAT_SVS(sources, "<link href=\"", uri, "jquery/jquery-ui.css\" type=\"text/css\" rel=\"stylesheet\" />");
PHALCON_SCONCAT_SVS(sources, "<link href=\"", uri, "themes/default/style.css\" type=\"text/css\" rel=\"stylesheet\" />");
RETURN_CTOR(sources);
}
static PHP_METHOD(Phalcon_Debug, getJsSources){
zval *uri, *sources;
PHALCON_MM_GROW();
PHALCON_OBS_VAR(uri);
phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC);
PHALCON_INIT_VAR(sources);
PHALCON_CONCAT_SVS(sources, "<script type=\"text/javascript\" src=\"", uri, "jquery/jquery.js\"></script>");
PHALCON_SCONCAT_SVS(sources, "<script type=\"text/javascript\" src=\"", uri, "jquery/jquery-ui.js\"></script>");
PHALCON_SCONCAT_SVS(sources, "<script type=\"text/javascript\" src=\"", uri, "jquery/jquery.scrollTo.js\"></script>");
PHALCON_SCONCAT_SVS(sources, "<script type=\"text/javascript\" src=\"", uri, "prettify/prettify.js\"></script>");
PHALCON_SCONCAT_SVS(sources, "<script type=\"text/javascript\" src=\"", uri, "pretty.js\"></script>");
RETURN_CTOR(sources);
}
static PHP_METHOD(Phalcon_Debug, getFileLink) {
zval **file, **line, **format;
phalcon_fetch_params_ex(3, 0, &file, &line, &format);
PHALCON_ENSURE_IS_STRING(file);
PHALCON_ENSURE_IS_STRING(line);
if (Z_TYPE_PP(format) == IS_STRING) {
char *tmp, *link;
int tmp_len, link_len;
zval z_link = zval_used_for_init;
tmp = php_str_to_str_ex(Z_STRVAL_PP(format), Z_STRLEN_PP(format), SL("%f"), Z_STRVAL_PP(file), Z_STRLEN_PP(file), &tmp_len, 1, NULL);
link = php_str_to_str_ex(tmp, tmp_len, SL("%l"), Z_STRVAL_PP(line), Z_STRLEN_PP(line), &link_len, 1, NULL);
ZVAL_STRINGL(&z_link, link, link_len, 0);
efree(tmp);
PHALCON_CONCAT_SVSVS(return_value, "<a href=\"", &z_link, "\">", *file, "</a>");
efree(link);
}
else {
RETVAL_ZVAL(*file, 1, 0);
}
}
static PHP_METHOD(Phalcon_Debug, showTraceItem){
zval *n, *trace, *link_format, *space, *two_spaces, *underscore;
zval *minus, *html, *class_name, *pattern, *is_phalcon_class;
zval *namespace_separator, *prepare_uri_class;
zval *class_reflection, *is_internal = NULL, *lower_class_name;
zval *prepare_internal_class, *type, *function_name = NULL;
zval *function_reflection, *prepared_function_name;
zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL;
zval *span_argument = NULL, *joined_arguments, *z_one;
zval *file, *line, *show_files, *lines, *number_lines;
zval *show_file_fragment, *before_context, *before_line;
zval *first_line = NULL, *after_context, *after_line, *last_line = NULL;
zval *comment_pattern, *charset, *tab;
zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL;
zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL;
zval *escaped_line = NULL, *formatted_file = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
zend_class_entry *ce0, *ce1;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 3, 0, &n, &trace, &link_format);
PHALCON_INIT_VAR(space);
ZVAL_STRING(space, " ", 1);
PHALCON_INIT_VAR(two_spaces);
ZVAL_STRING(two_spaces, " ", 1);
PHALCON_INIT_VAR(underscore);
ZVAL_STRING(underscore, "_", 1);
PHALCON_INIT_VAR(minus);
ZVAL_STRING(minus, "-", 1);
PHALCON_INIT_VAR(html);
PHALCON_CONCAT_SVS(html, "<tr><td align=\"right\" valign=\"top\" class=\"error-number\">#", n, "</td><td>");
if (phalcon_array_isset_quick_string(trace, SS("class"), 4138154555UL)) {
PHALCON_OBS_VAR(class_name);
phalcon_array_fetch_quick_string(&class_name, trace, SS("class"), 4138154555UL, PH_NOISY);
PHALCON_INIT_VAR(pattern);
ZVAL_STRING(pattern, "/^Phalcon/", 1);
PHALCON_INIT_VAR(is_phalcon_class);
phalcon_preg_match(is_phalcon_class, NULL, pattern, class_name, NULL TSRMLS_CC);
if (zend_is_true(is_phalcon_class)) {
PHALCON_INIT_VAR(namespace_separator);
ZVAL_STRING(namespace_separator, "\\", 1);
PHALCON_INIT_VAR(prepare_uri_class);
phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name);
PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://docs.phalconphp.com/en/latest/api/", prepare_uri_class, ".html\">", class_name, "</a></span>");
} else {
ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
PHALCON_INIT_VAR(class_reflection);
object_init_ex(class_reflection, ce0);
if (phalcon_has_constructor(class_reflection TSRMLS_CC)) {
phalcon_call_method_p1_key(NULL, class_reflection, "__construct", 1107214344UL, class_name);
}
PHALCON_INIT_VAR(is_internal);
phalcon_call_method_key(is_internal, class_reflection, "isinternal", 2412550174UL);
if (zend_is_true(is_internal)) {
PHALCON_INIT_VAR(lower_class_name);
phalcon_fast_strtolower(lower_class_name, class_name);
PHALCON_INIT_VAR(prepare_internal_class);
phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name);
PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://php.net/manual/en/class.", prepare_internal_class, ".php\">", class_name, "</a></span>");
} else {
PHALCON_SCONCAT_SVS(html, "<span class=\"error-class\">", class_name, "</span>");
}
}
PHALCON_OBS_VAR(type);
phalcon_array_fetch_quick_string(&type, trace, SS("type"), 276192743UL, PH_NOISY);
phalcon_concat_self(&html, type TSRMLS_CC);
}
if (phalcon_array_isset_quick_string(trace, SS("class"), 4138154555UL)) {
PHALCON_OBS_VAR(function_name);
phalcon_array_fetch_quick_string(&function_name, trace, SS("function"), 1487618475UL, PH_NOISY);
PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
} else {
PHALCON_OBS_NVAR(function_name);
phalcon_array_fetch_quick_string(&function_name, trace, SS("function"), 1487618475UL, PH_NOISY);
if (phalcon_function_exists(function_name TSRMLS_CC) == SUCCESS) {
ce1 = zend_fetch_class(SL("ReflectionFunction"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
PHALCON_INIT_VAR(function_reflection);
object_init_ex(function_reflection, ce1);
if (phalcon_has_constructor(function_reflection TSRMLS_CC)) {
phalcon_call_method_p1_key(NULL, function_reflection, "__construct", 1107214344UL, function_name);
}
PHALCON_INIT_NVAR(is_internal);
phalcon_call_method_key(is_internal, function_reflection, "isinternal", 2412550174UL);
if (zend_is_true(is_internal)) {
PHALCON_INIT_VAR(prepared_function_name);
phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name);
PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-function\"><a target=\"_new\" href=\"http://php.net/manual/en/function.", prepared_function_name, ".php\">", function_name, "</a></span>");
} else {
PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
}
} else {
PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>");
}
}
if (phalcon_array_isset_quick_string(trace, SS("args"), 253399346UL)) {
PHALCON_OBS_VAR(trace_args);
phalcon_array_fetch_quick_string(&trace_args, trace, SS("args"), 253399346UL, PH_NOISY);
if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) {
PHALCON_INIT_VAR(arguments);
array_init(arguments);
phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(argument);
PHALCON_INIT_NVAR(dumped_argument);
phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", 2922816643UL, argument);
PHALCON_INIT_NVAR(span_argument);
PHALCON_CONCAT_SVS(span_argument, "<span class=\"error-parameter\">", dumped_argument, "</span>");
phalcon_array_append(&arguments, span_argument, PH_SEPARATE);
zend_hash_move_forward_ex(ah0, &hp0);
}
PHALCON_INIT_VAR(joined_arguments);
phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC);
PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")");
} else {
phalcon_concat_self_str(&html, SL("()") TSRMLS_CC);
}
}
if (phalcon_array_isset_quick_string(trace, SS("file"), 259010501UL)) {
z_one = PHALCON_GLOBAL(z_one);
PHALCON_OBS_VAR(file);
phalcon_array_fetch_quick_string(&file, trace, SS("file"), 259010501UL, PH_NOISY);
PHALCON_OBS_VAR(line);
phalcon_array_fetch_quick_string(&line, trace, SS("line"), 266128205UL, PH_NOISY);
PHALCON_OBS_VAR(formatted_file);
phalcon_call_method_p3_ex(formatted_file, &formatted_file, getThis(), "getfilelink", file, line, link_format);
PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", formatted_file, " (", line, ")</div>");
PHALCON_OBS_VAR(show_files);
phalcon_read_property_this_quick(&show_files, this_ptr, SL("_showFiles"), 1877855960UL, PH_NOISY_CC);
if (zend_is_true(show_files)) {
PHALCON_INIT_VAR(lines);
phalcon_call_func_p1(lines, "file", file);
PHALCON_INIT_VAR(number_lines);
phalcon_fast_count(number_lines, lines TSRMLS_CC);
PHALCON_OBS_VAR(show_file_fragment);
phalcon_read_property_this_quick(&show_file_fragment, this_ptr, SL("_showFileFragment"), 3533221081UL, PH_NOISY_CC);
if (zend_is_true(show_file_fragment)) {
before_context = phalcon_fetch_nproperty_this(getThis(), SL("_beforeContext"), PH_NOISY TSRMLS_CC);
PHALCON_INIT_VAR(before_line);
sub_function(before_line, line, before_context TSRMLS_CC);
if (PHALCON_LT_LONG(before_line, 1)) {
PHALCON_CPY_WRT_CTOR(first_line, z_one);
} else {
PHALCON_CPY_WRT(first_line, before_line);
}
after_context = phalcon_fetch_nproperty_this(getThis(), SL("_afterContext"), PH_NOISY TSRMLS_CC);
PHALCON_INIT_VAR(after_line);
phalcon_add_function(after_line, line, after_context TSRMLS_CC);
if (PHALCON_GT(after_line, number_lines)) {
PHALCON_CPY_WRT(last_line, number_lines);
} else {
PHALCON_CPY_WRT(last_line, after_line);
}
PHALCON_SCONCAT_SVSVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums:", first_line, "'>");
} else {
PHALCON_CPY_WRT_CTOR(first_line, z_one);
PHALCON_CPY_WRT(last_line, number_lines);
PHALCON_SCONCAT_SVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums error-scroll'>");
}
PHALCON_INIT_VAR(comment_pattern);
ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1);
charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC);
PHALCON_INIT_VAR(tab);
ZVAL_STRING(tab, "\t", 1);
PHALCON_INIT_VAR(comment);
ZVAL_STRING(comment, "* /", 1);
PHALCON_CPY_WRT(i, first_line);
while (PHALCON_LE(i, last_line)) {
PHALCON_INIT_NVAR(line_position);
sub_function(line_position, i, z_one TSRMLS_CC);
PHALCON_OBS_NVAR(current_line);
phalcon_array_fetch(&current_line, lines, line_position, PH_NOISY);
if (zend_is_true(show_file_fragment)) {
if (PHALCON_IS_EQUAL(i, first_line)) {
PHALCON_INIT_NVAR(trimmed);
phalcon_fast_trim(trimmed, current_line, PHALCON_TRIM_RIGHT TSRMLS_CC);
PHALCON_INIT_NVAR(is_comment);
phalcon_preg_match(is_comment, NULL, comment_pattern, current_line, NULL TSRMLS_CC);
if (zend_is_true(is_comment)) {
PHALCON_INIT_NVAR(spaced_current_line);
phalcon_fast_str_replace(spaced_current_line, comment, space, current_line);
PHALCON_CPY_WRT(current_line, spaced_current_line);
}
}
}
if (PHALCON_IS_STRING(current_line, "\n")) {
phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
} else {
if (PHALCON_IS_STRING(current_line, "\r\n")) {
phalcon_concat_self_str(&html, SL("&nbsp;\n") TSRMLS_CC);
} else {
PHALCON_INIT_NVAR(spaced_current_line);
phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line);
PHALCON_INIT_NVAR(escaped_line);
phalcon_htmlentities(escaped_line, spaced_current_line, NULL, charset TSRMLS_CC);
phalcon_concat_self(&html, escaped_line TSRMLS_CC);
}
}
phalcon_increment(i);
}
phalcon_concat_self_str(&html, SL("</pre>") TSRMLS_CC);
}
}
phalcon_concat_self_str(&html, SL("</td></tr>") TSRMLS_CC);
RETURN_CTOR(html);
}
static PHP_METHOD(Phalcon_Debug, onUncaughtException){
zval *exception, *is_active = NULL, *message = NULL;
zval *class_name, *css_sources, *escaped_message = NULL;
zval *html, *version, *file, *line, *show_back_trace;
zval *data_vars, *trace, *trace_item = NULL, *n = NULL, *html_item = NULL;
zval *_REQUEST, *value = NULL, *key_request = NULL, *joined_value = NULL, *_SERVER;
zval *key_server = NULL, *files, *key_file = NULL;
zval *memory, *data_var = NULL, *key_var = NULL, *variable = NULL, *dumped_argument = NULL;
zval *js_sources, *formatted_file;
HashTable *ah0, *ah1, *ah2, *ah3, *ah4;
HashPosition hp0, hp1, hp2, hp3, hp4;
zval **hd;
char* link_format;
zend_bool ini_exists = 1;
zval z_link_format = zval_used_for_init;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &exception);
if (phalcon_ob_get_level(TSRMLS_C) > 0) {
phalcon_ob_end_clean(TSRMLS_C);
}
is_active = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_isActive") TSRMLS_CC);
if (zend_is_true(is_active)) {
PHALCON_INIT_VAR(message);
phalcon_call_method_key(message, exception, "getmessage", 4288675242UL);
zend_print_zval(message, 0);
}
zend_update_static_property_bool(phalcon_debug_ce, SL("_isActive"), 1 TSRMLS_CC);
PHALCON_INIT_VAR(class_name);
phalcon_get_class(class_name, exception, 0 TSRMLS_CC);
PHALCON_INIT_NVAR(message);
phalcon_call_method_key(message, exception, "getmessage", 4288675242UL);
PHALCON_INIT_VAR(css_sources);
phalcon_call_method_key(css_sources, this_ptr, "getcsssources", 3032989842UL);
PHALCON_CPY_WRT(escaped_message, message);
PHALCON_INIT_VAR(html);
PHALCON_CONCAT_SVSVS(html, "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/><title>", class_name, ": ", escaped_message, "</title>");
PHALCON_SCONCAT_VS(html, css_sources, "</head><body>");
PHALCON_INIT_VAR(version);
phalcon_call_method_key(version, this_ptr, "getversion", 1268766507UL);
phalcon_concat_self(&html, version TSRMLS_CC);
PHALCON_INIT_VAR(file);
phalcon_call_method_key(file, exception, "getfile", 4277240133UL);
PHALCON_INIT_VAR(line);
phalcon_call_method_key(line, exception, "getline", 4284357837UL);
link_format = zend_ini_string_ex(SS("xdebug.file_link_format"), 0, &ini_exists);
if (!link_format || !ini_exists) {
link_format = "file://%f#%l";
}
ZVAL_STRING(&z_link_format, link_format, 0);
PHALCON_OBS_VAR(formatted_file);
phalcon_call_method_p3_ex(formatted_file, &formatted_file, getThis(), "getfilelink", file, line, &z_link_format);
phalcon_concat_self_str(&html, SL("<div align=\"center\"><div class=\"error-main\">") TSRMLS_CC);
PHALCON_SCONCAT_SVSVS(html, "<h1>", class_name, ": ", escaped_message, "</h1>");
PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-file\">", formatted_file, " (", line, ")</span>");
phalcon_concat_self_str(&html, SL("</div>") TSRMLS_CC);
PHALCON_OBS_VAR(show_back_trace);
phalcon_read_property_this_quick(&show_back_trace, this_ptr, SL("_showBackTrace"), 3370024901UL, PH_NOISY_CC);
if (zend_is_true(show_back_trace)) {
PHALCON_OBS_VAR(data_vars);
phalcon_read_property_this_quick(&data_vars, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC);
phalcon_concat_self_str(&html, SL("<div class=\"error-info\"><div id=\"tabs\"><ul>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-1\">Backtrace</a></li>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-2\">Request</a></li>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-3\">Server</a></li>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-4\">Included Files</a></li>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-5\">Memory</a></li>") TSRMLS_CC);
if (Z_TYPE_P(data_vars) == IS_ARRAY) {
phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-6\">Variables</a></li>") TSRMLS_CC);
}
phalcon_concat_self_str(&html, SL("</ul>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-1\"><table cellspacing=\"0\" align=\"center\" width=\"100%\">") TSRMLS_CC);
PHALCON_INIT_VAR(trace);
phalcon_call_method_key(trace, exception, "gettrace", 4268145556UL);
phalcon_is_iterable(trace, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(n, ah0, hp0);
PHALCON_GET_HVALUE(trace_item);
PHALCON_INIT_NVAR(html_item);
phalcon_call_method_p3_key(html_item, this_ptr, "showtraceitem", 296427812UL, n, trace_item, &z_link_format);
phalcon_concat_self(&html, html_item TSRMLS_CC);
zend_hash_move_forward_ex(ah0, &hp0);
}
phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-2\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC);
phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC);
phalcon_is_iterable(_REQUEST, &ah1, &hp1, 0, 0);
while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
PHALCON_GET_HKEY(key_request, ah1, hp1);
PHALCON_GET_HVALUE(value);
if (Z_TYPE_P(value) == IS_ARRAY) {
PHALCON_INIT_NVAR(joined_value);
phalcon_call_method_p1_key(joined_value, this_ptr, "_getvardump", 2922816643UL, value);
PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_request, "</td><td>", joined_value, "</td></tr>");
} else {
PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_request, "</td><td>", value, "</td></tr>");
}
zend_hash_move_forward_ex(ah1, &hp1);
}
phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-3\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC);
phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC);
phalcon_is_iterable(_SERVER, &ah2, &hp2, 0, 0);
while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) {
PHALCON_GET_HKEY(key_server, ah2, hp2);
PHALCON_GET_HVALUE(value);
PHALCON_INIT_NVAR(dumped_argument);
phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", 2922816643UL, value);
PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_server, "</td><td>", dumped_argument, "</td></tr>");
zend_hash_move_forward_ex(ah2, &hp2);
}
phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC);
PHALCON_INIT_VAR(files);
phalcon_call_func(files, "get_included_files");
phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-4\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<tr><th>#</th><th>Path</th></tr>") TSRMLS_CC);
phalcon_is_iterable(files, &ah3, &hp3, 0, 0);
while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) {
PHALCON_GET_HKEY(key_file, ah3, hp3);
PHALCON_GET_HVALUE(value);
PHALCON_SCONCAT_SVSVS(html, "<tr><td>", key_file, "</th><td>", value, "</td></tr>");
zend_hash_move_forward_ex(ah3, &hp3);
}
phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC);
PHALCON_INIT_VAR(memory);
ZVAL_LONG(memory, zend_memory_usage(1 TSRMLS_CC));
phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-5\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC);
PHALCON_SCONCAT_SVS(html, "<tr><th colspan=\"2\">Memory</th></tr><tr><td>Usage</td><td>", memory, "</td></tr>");
phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC);
if (Z_TYPE_P(data_vars) == IS_ARRAY) {
phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-6\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC);
phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC);
phalcon_is_iterable(data_vars, &ah4, &hp4, 0, 0);
while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) {
PHALCON_GET_HKEY(key_var, ah4, hp4);
PHALCON_GET_HVALUE(data_var);
PHALCON_OBS_NVAR(variable);
phalcon_array_fetch_long(&variable, data_var, 0, PH_NOISY);
PHALCON_INIT_NVAR(dumped_argument);
phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", 2922816643UL, variable);
PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_var, "</td><td>", dumped_argument, "</td></tr>");
zend_hash_move_forward_ex(ah4, &hp4);
}
phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC);
}
phalcon_concat_self_str(&html, SL("</div>") TSRMLS_CC);
}
PHALCON_INIT_VAR(js_sources);
phalcon_call_method_key(js_sources, this_ptr, "getjssources", 3049944486UL);
PHALCON_SCONCAT_VS(html, js_sources, "</div></body></html>");
zend_print_zval(html, 0);
zend_update_static_property_bool(phalcon_debug_ce, SL("_isActive"), 0 TSRMLS_CC);
RETURN_MM_TRUE;
}
static PHP_METHOD(Phalcon_Debug, getCharset) {
RETURN_MEMBER(getThis(), "_charset");
}
static PHP_METHOD(Phalcon_Debug, setCharset) {
zval **charset;
phalcon_fetch_params_ex(1, 0, &charset);
PHALCON_ENSURE_IS_STRING(charset);
phalcon_update_property_this(getThis(), SL("_charset"), *charset TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, getLinesBeforeContext) {
RETURN_MEMBER(getThis(), "_beforeContext");
}
static PHP_METHOD(Phalcon_Debug, setLinesBeforeContext) {
zval **lines;
phalcon_fetch_params_ex(1, 0, &lines);
PHALCON_ENSURE_IS_LONG(lines);
phalcon_update_property_this(getThis(), SL("_beforeContext"), *lines TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Debug, getLinesAfterContext) {
RETURN_MEMBER(getThis(), "_afterContext");
}
static PHP_METHOD(Phalcon_Debug, setLinesAfterContext) {
zval **lines;
phalcon_fetch_params_ex(1, 0, &lines);
PHALCON_ENSURE_IS_LONG(lines);
phalcon_update_property_this(getThis(), SL("_afterContext"), *lines TSRMLS_CC);
RETURN_THISW();
}
zend_class_entry *phalcon_di_ce;
static zend_object_handlers phalcon_di_object_handlers;
typedef struct _phalcon_di_object {
zend_object obj;
HashTable* services;
HashTable* shared;
int fresh;
} phalcon_di_object;
static inline phalcon_di_object* phalcon_di_get_object(zval *obj TSRMLS_DC)
{
return (phalcon_di_object*)zend_objects_get_address(obj TSRMLS_CC);
}
static PHP_FUNCTION(phalcon_di_method_handler)
{
Z_OBJ_HANDLER_P(getThis(), call_method)(((zend_internal_function*)EG(current_execute_data)->function_state.function)->function_name, INTERNAL_FUNCTION_PARAM_PASSTHRU);
efree(((zend_internal_function*)EG(current_execute_data)->function_state.function));
}
static union _zend_function* phalcon_di_get_method(zval **object_ptr, char *method, int method_len ZLK_DC TSRMLS_DC)
{
char *lc_method_name = emalloc(method_len + 1);
phalcon_di_object *obj = phalcon_di_get_object(*object_ptr TSRMLS_CC);
zend_function fbc;
zend_str_tolower_copy(lc_method_name, method, method_len);
if (
zend_hash_find(&obj->obj.ce->function_table, lc_method_name, method_len+1, (void **)&fbc) == FAILURE
&& method_len > 3
&& (!memcmp(lc_method_name, "get", 3) || !memcmp(lc_method_name, "set", 3))
) {
zend_internal_function *f = emalloc(sizeof(zend_internal_function));
f->type = ZEND_INTERNAL_FUNCTION;
f->handler = ZEND_FN(phalcon_di_method_handler);
f->arg_info = NULL;
f->num_args = 0;
f->scope = obj->obj.ce;
f->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
f->function_name = method;
#if PHP_VERSION_ID < 50400
f->module = obj->obj.ce->module;
f->pass_rest_by_reference = 0;
f->return_reference = ZEND_RETURN_VALUE;
#else
f->module = (ZEND_INTERNAL_CLASS == obj->obj.ce->type) ? obj->obj.ce->info.internal.module : 0;
#endif
efree(lc_method_name);
return (union _zend_function*)f;
}
efree(lc_method_name);
return std_object_handlers.get_method(object_ptr, method, method_len ZLK_CC TSRMLS_CC);
}
static int phalcon_di_call_method_internal(zval *return_value, zval **return_value_ptr, zval *this_ptr, const char *method, zval *param TSRMLS_DC)
{
int method_len = strlen(method);
char *lc_method_name = emalloc(method_len + 1);
int retval = FAILURE;
zend_str_tolower_copy(lc_method_name, method, method_len);
if (method_len > 3 && (!memcmp(lc_method_name, "get", 3) || !memcmp(lc_method_name, "set", 3))) {
phalcon_di_object *obj = phalcon_di_get_object(getThis() TSRMLS_CC);
char *service = estrndup(method+3, method_len-3);
service[0] = tolower(service[0]);
if (SUCCESS == zend_symtable_exists(obj->services, method, method_len + 1)) {
zval *svc;
PHALCON_ALLOC_GHOST_ZVAL(svc);
ZVAL_STRINGL(svc, service, method_len - 3, 0);
if (lc_method_name[0] == 'g') {
retval = phalcon_call_method_params(return_value, return_value_ptr, this_ptr, SL("get"), 2090288933UL TSRMLS_CC, 2, svc, param);
}
else {
retval = phalcon_call_method_params(return_value, return_value_ptr, this_ptr, SL("set"), 2090720177UL TSRMLS_CC, 2, svc, param);
}
if (EG(exception)) {
retval = SUCCESS;
if (return_value_ptr) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
}
}
if (FAILURE == retval) {
zend_throw_exception_ex(phalcon_di_exception_ce, 0 TSRMLS_CC, "Call to undefined method or service '%s'", method);
}
efree(lc_method_name);
return retval;
}
static int phalcon_di_call_method(const char *method, INTERNAL_FUNCTION_PARAMETERS)
{
zval **param;
zval *p;
if (!ZEND_NUM_ARGS()) {
PHALCON_ALLOC_GHOST_ZVAL(p);
ZVAL_NULL(p);
param = &p;
}
else {
phalcon_fetch_parameters_ex(0 TSRMLS_CC, 1, 0, &param);
}
return phalcon_di_call_method_internal(return_value, return_value_ptr, getThis(), method, *param TSRMLS_CC);
}
static zval* phalcon_di_read_dimension_internal(zval *this_ptr, phalcon_di_object *obj, zval *offset, zval *parameters TSRMLS_DC)
{
zval *tmp = NULL;
zval **retval = &tmp, **service;
zend_class_entry *ce;
assert(Z_TYPE_P(offset) == IS_STRING);
if (UNEXPECTED(!offset)) {
return EG(uninitialized_zval_ptr);
}
if (SUCCESS == zend_symtable_find(obj->shared, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&retval)) {
obj->fresh = 0;
return *retval;
}
/* Resolve the instance normally */
if (SUCCESS == zend_symtable_find(obj->services, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&service)) {
/* The service is registered in the DI */
phalcon_call_method_params(*retval, retval, *service, SL("resolve"), 605366917UL TSRMLS_CC, 2, parameters, this_ptr);
if (EG(exception)) {
return NULL;
}
/* *retval has refcount = 1 here, it will be used in zend_symtable_update() */
ce = (Z_TYPE_PP(retval) == IS_OBJECT) ? Z_OBJCE_PP(retval) : NULL;
}
else {
/* The DI also acts as builder for any class even if it isn't defined in the DI */
if (phalcon_class_exists_ex(&ce, offset, 1 TSRMLS_CC)) {
MAKE_STD_ZVAL(*retval);
if (FAILURE == phalcon_create_instance_params_ce(*retval, ce, parameters TSRMLS_CC)) {
return NULL;
}
/* *retval has refcount = 1 here, it will be used in zend_symtable_update() */
}
else {
zend_throw_exception_ex(phalcon_di_exception_ce, 0 TSRMLS_CC, "Service '%s' was not found in the dependency injection container", Z_STRVAL_P(offset));
return NULL;
}
}
/* Pass the DI itself if the instance implements Phalcon\DI\InjectionAwareInterface */
if (ce && instanceof_function_ex(ce, phalcon_di_injectionawareinterface_ce, 1 TSRMLS_CC)) {
phalcon_call_method_params(NULL, NULL, *retval, SL("setdi"), 461718238UL TSRMLS_CC, 1, this_ptr);
if (EG(exception)) {
zval_ptr_dtor(retval);
return NULL;
}
}
assert(Z_REFCOUNT_PP(retval) == 1);
zend_symtable_update(obj->shared, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void*)retval, sizeof(zval*), NULL);
obj->fresh = 1;
return *retval;
}
static zval* phalcon_di_read_dimension(zval *object, zval *offset, int type TSRMLS_DC)
{
phalcon_di_object *obj = phalcon_di_get_object(object TSRMLS_CC);
zval tmp, *ret;
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
return zend_get_std_object_handlers()->read_dimension(object, offset, type TSRMLS_CC);
}
if (UNEXPECTED(Z_TYPE_P(offset) != IS_STRING)) {
ZVAL_ZVAL(&tmp, offset, 1, 0);
convert_to_string(&tmp);
offset = &tmp;
}
ret = phalcon_di_read_dimension_internal(object, obj, offset, PHALCON_GLOBAL(z_null) TSRMLS_CC);
if (UNEXPECTED(offset == &tmp)) {
zval_dtor(&tmp);
}
return ret;
}
static int phalcon_di_has_dimension_internal(phalcon_di_object *obj, zval *offset, int check_empty)
{
zval **tmp = phalcon_hash_get(obj->services, offset, BP_VAR_NA);
if (!tmp) {
return 0;
}
if (0 == check_empty) {
return Z_TYPE_PP(tmp) != IS_NULL;
}
if (1 == check_empty) {
return zend_is_true(*tmp);
}
return 1;
}
static int phalcon_di_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC)
{
phalcon_di_object *obj = phalcon_di_get_object(object TSRMLS_CC);
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
return zend_get_std_object_handlers()->has_dimension(object, offset, check_empty TSRMLS_CC);
}
return phalcon_di_has_dimension_internal(obj, offset, check_empty);
}
static zval* phalcon_di_write_dimension_internal(phalcon_di_object *obj, zval *offset, zval *value TSRMLS_DC)
{
zval *retval;
assert(Z_TYPE_P(offset) == IS_STRING);
MAKE_STD_ZVAL(retval);
object_init_ex(retval, phalcon_di_service_ce);
phalcon_call_method_params(NULL, NULL, retval, SL("__construct"), 1107214344UL TSRMLS_CC, 3, offset, value, PHALCON_GLOBAL(z_true));
zend_hash_update(obj->services, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, &retval, sizeof(zval*), NULL);
return retval;
}
static void phalcon_di_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC)
{
phalcon_di_object *obj = phalcon_di_get_object(object TSRMLS_CC);
zval tmp;
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
zend_get_std_object_handlers()->write_dimension(object, offset, value TSRMLS_CC);
return;
}
if (UNEXPECTED(Z_TYPE_P(offset) != IS_STRING)) {
ZVAL_ZVAL(&tmp, offset, 1, 0);
convert_to_string(&tmp);
offset = &tmp;
}
phalcon_di_write_dimension_internal(obj, offset, value TSRMLS_CC);
if (UNEXPECTED(offset == &tmp)) {
zval_dtor(&tmp);
}
}
static inline void phalcon_di_unset_dimension_internal(phalcon_di_object *obj, zval *offset)
{
assert(Z_TYPE_P(offset) == IS_STRING);
zend_symtable_del(obj->services, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1);
}
static void phalcon_di_unset_dimension(zval *object, zval *offset TSRMLS_DC)
{
phalcon_di_object *obj = phalcon_di_get_object(object TSRMLS_CC);
zval tmp;
if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
zend_get_std_object_handlers()->unset_dimension(object, offset TSRMLS_CC);
return;
}
if (UNEXPECTED(Z_TYPE_P(offset) != IS_STRING)) {
ZVAL_ZVAL(&tmp, offset, 1, 0);
convert_to_string(&tmp);
offset = &tmp;
}
phalcon_di_unset_dimension_internal(obj, offset);
if (UNEXPECTED(offset == &tmp)) {
zval_dtor(&tmp);
}
}
static HashTable* phalcon_di_get_properties(zval* object TSRMLS_DC)
{
HashTable* props = zend_std_get_properties(object TSRMLS_CC);
if (!GC_G(gc_active) && !props->nApplyCount) {
phalcon_di_object *obj = phalcon_di_get_object(object TSRMLS_CC);
zval *zv;
MAKE_STD_ZVAL(zv);
array_init_size(zv, zend_hash_num_elements(obj->services));
zend_hash_copy(Z_ARRVAL_P(zv), obj->services, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
zend_hash_quick_update(props, "_services", sizeof("_services"), 479369827UL, (void*)&zv, sizeof(zval*), NULL);
MAKE_STD_ZVAL(zv);
array_init_size(zv, zend_hash_num_elements(obj->shared));
zend_hash_copy(Z_ARRVAL_P(zv), obj->shared, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
zend_hash_quick_update(props, "_sharedInstances", sizeof("_sharedInstances"), 479369827UL, (void*)&zv, sizeof(zval*), NULL);
MAKE_STD_ZVAL(zv);
ZVAL_BOOL(zv, obj->fresh);
zend_hash_quick_update(props, "_freshInstance", sizeof("_freshInstance"), 1734543825UL, (void*)&zv, sizeof(zval*), NULL);
}
return props;
}
static void phalcon_di_dtor(void *v TSRMLS_DC)
{
phalcon_di_object *obj = v;
zend_hash_destroy(obj->services);
zend_hash_destroy(obj->shared);
FREE_HASHTABLE(obj->services);
FREE_HASHTABLE(obj->shared);
zend_object_std_dtor(&obj->obj TSRMLS_CC);
efree(obj);
}
static zend_object_value phalcon_di_ctor(zend_class_entry* ce TSRMLS_DC)
{
phalcon_di_object *obj = ecalloc(1, sizeof(phalcon_di_object));
zend_object_value retval;
zend_object_std_init(&obj->obj, ce TSRMLS_CC);
#if PHP_VERSION_ID >= 50400
object_properties_init(&obj->obj, ce);
#endif
ALLOC_HASHTABLE(obj->services);
ALLOC_HASHTABLE(obj->shared);
zend_hash_init(obj->services, 32, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_init(obj->shared, 8, NULL, ZVAL_PTR_DTOR, 0);
retval.handle = zend_objects_store_put(
obj,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
phalcon_di_dtor,
NULL TSRMLS_CC
);
retval.handlers = &phalcon_di_object_handlers;
return retval;
}
static zend_object_value phalcon_di_clone_obj(zval *zobject TSRMLS_DC)
{
zend_object_value new_obj_val;
phalcon_di_object *old_object;
phalcon_di_object *new_object;
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
old_object = phalcon_di_get_object(zobject TSRMLS_CC);
new_obj_val = phalcon_di_ctor(Z_OBJCE_P(zobject) TSRMLS_CC);
new_object = zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
zend_objects_clone_members(&new_object->obj, new_obj_val, &old_object->obj, handle TSRMLS_CC);
zend_hash_copy(new_object->services, old_object->services, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
zend_hash_copy(new_object->shared, old_object->shared, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
new_object->fresh = old_object->fresh;
return new_obj_val;
}
static void phalcon_di_set_services(zval *this_ptr, zval *services TSRMLS_DC)
{
phalcon_di_object *obj = phalcon_di_get_object(this_ptr TSRMLS_CC);
zend_hash_copy(obj->services, Z_ARRVAL_P(services), (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
}
static PHP_METHOD(Phalcon_DI, __construct);
static PHP_METHOD(Phalcon_DI, set);
static PHP_METHOD(Phalcon_DI, setShared);
static PHP_METHOD(Phalcon_DI, remove);
static PHP_METHOD(Phalcon_DI, attempt);
static PHP_METHOD(Phalcon_DI, setRaw);
static PHP_METHOD(Phalcon_DI, getRaw);
static PHP_METHOD(Phalcon_DI, getService);
static PHP_METHOD(Phalcon_DI, get);
static PHP_METHOD(Phalcon_DI, getShared);
static PHP_METHOD(Phalcon_DI, has);
static PHP_METHOD(Phalcon_DI, wasFreshInstance);
static PHP_METHOD(Phalcon_DI, getServices);
static PHP_METHOD(Phalcon_DI, __call);
static PHP_METHOD(Phalcon_DI, setDefault);
static PHP_METHOD(Phalcon_DI, getDefault);
static PHP_METHOD(Phalcon_DI, reset);
static PHP_METHOD(Phalcon_DI, __clone);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_di___call, 0, 0, 1)
ZEND_ARG_INFO(0, method)
ZEND_ARG_INFO(0, arguments)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_di_method_entry[] = {
PHP_ME(Phalcon_DI, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_DI, set, arginfo_phalcon_diinterface_set, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, setShared, arginfo_phalcon_diinterface_setshared, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, remove, arginfo_phalcon_diinterface_remove, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, attempt, arginfo_phalcon_diinterface_attempt, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, setRaw, arginfo_phalcon_diinterface_setraw, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, getRaw, arginfo_phalcon_diinterface_getraw, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, getService, arginfo_phalcon_diinterface_getservice, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, get, arginfo_phalcon_diinterface_get, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, getShared, arginfo_phalcon_diinterface_getshared, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, has, arginfo_phalcon_diinterface_has, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, wasFreshInstance, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, getServices, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_DI, offsetExists, has, arginfo_phalcon_diinterface_has, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_DI, offsetSet, setShared, arginfo_phalcon_diinterface_setshared, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_DI, offsetGet, getShared, arginfo_phalcon_diinterface_getshared, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_DI, offsetUnset, remove, arginfo_phalcon_diinterface_remove, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, __call, arginfo_phalcon_di___call, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_DI, setDefault, arginfo_phalcon_diinterface_setdefault, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_DI, getDefault, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_DI, reset, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_DI, __clone, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_DI){
PHALCON_REGISTER_CLASS(Phalcon, DI, di, phalcon_di_method_entry, 0);
zend_declare_property_null(phalcon_di_ce, SL("_default"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_class_implements(phalcon_di_ce TSRMLS_CC, 1, phalcon_diinterface_ce);
phalcon_di_ce->create_object = phalcon_di_ctor;
phalcon_di_ce->serialize = zend_class_serialize_deny;
phalcon_di_ce->unserialize = zend_class_unserialize_deny;
phalcon_di_object_handlers = *zend_get_std_object_handlers();
phalcon_di_object_handlers.read_dimension = phalcon_di_read_dimension;
phalcon_di_object_handlers.has_dimension = phalcon_di_has_dimension;
phalcon_di_object_handlers.write_dimension = phalcon_di_write_dimension;
phalcon_di_object_handlers.unset_dimension = phalcon_di_unset_dimension;
phalcon_di_object_handlers.get_method = phalcon_di_get_method;
phalcon_di_object_handlers.call_method = (zend_object_call_method_t)phalcon_di_call_method;
phalcon_di_object_handlers.clone_obj = phalcon_di_clone_obj;
if (!nusphere_dbg_present) {
phalcon_di_object_handlers.get_properties = phalcon_di_get_properties;
}
return SUCCESS;
}
static PHP_METHOD(Phalcon_DI, __construct){
zval *default_di;
default_di = phalcon_fetch_static_property_ce(phalcon_di_ce, SL("_default") TSRMLS_CC);
if (Z_TYPE_P(default_di) == IS_NULL) {
phalcon_update_static_property_ce(phalcon_di_ce, SL("_default"), this_ptr TSRMLS_CC);
}
}
static PHP_METHOD(Phalcon_DI, set) {
zval **name, **definition, **shared = NULL, *service;
phalcon_di_object *obj;
phalcon_fetch_params_ex(2, 1, &name, &definition, &shared);
PHALCON_ENSURE_IS_STRING(name);
if (!shared) {
shared = &PHALCON_GLOBAL(z_false);
}
MAKE_STD_ZVAL(service);
object_init_ex(service, phalcon_di_service_ce);
/* Won't throw exceptions */
phalcon_call_method_params(NULL, NULL, service, SL("__construct"), 1107214344UL TSRMLS_CC, 3, *name, *definition, *shared);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
zend_hash_update(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1, &service, sizeof(zval*), NULL);
RETURN_ZVAL(service, 1, 0);
}
static PHP_METHOD(Phalcon_DI, setShared){
zval **name, **definition, *retval;
phalcon_di_object *obj;
phalcon_fetch_params_ex(2, 0, &name, &definition);
PHALCON_ENSURE_IS_STRING(name);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
retval = phalcon_di_write_dimension_internal(obj, *name, *definition TSRMLS_CC);
RETURN_ZVAL(retval, 1, 0);
}
static PHP_METHOD(Phalcon_DI, remove){
zval **name;
phalcon_di_object *obj;
phalcon_fetch_params_ex(1, 0, &name);
PHALCON_ENSURE_IS_STRING(name);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
phalcon_di_unset_dimension_internal(obj, *name);
}
static PHP_METHOD(Phalcon_DI, attempt){
zval **name, **definition, **shared = NULL;
phalcon_di_object *obj;
phalcon_fetch_params_ex(2, 1, &name, &definition, &shared);
PHALCON_ENSURE_IS_STRING(name);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
if (!zend_symtable_exists(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1)) {
PHALCON_MM_GROW();
if (!shared) {
shared = &PHALCON_GLOBAL(z_false);
}
object_init_ex(return_value, phalcon_di_service_ce);
phalcon_call_method_p3_key(NULL, return_value, "__construct", 1107214344UL, *name, *definition, *shared);
Z_ADDREF_P(return_value);
zend_hash_update(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1, &return_value, sizeof(zval*), NULL);
PHALCON_MM_RESTORE();
}
}
static PHP_METHOD(Phalcon_DI, setRaw){
zval **name, **raw_definition;
phalcon_di_object *obj;
phalcon_fetch_params_ex(2, 0, &name, &raw_definition);
PHALCON_ENSURE_IS_STRING(name);
PHALCON_VERIFY_INTERFACE_EX(*raw_definition, phalcon_di_serviceinterface_ce, phalcon_di_exception_ce, 0);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
Z_ADDREF_PP(raw_definition);
zend_hash_update(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1, (void*)raw_definition, sizeof(zval*), NULL);
RETURN_ZVAL(*raw_definition, 1, 0);
}
static PHP_METHOD(Phalcon_DI, getRaw){
zval **name, **service;
phalcon_di_object *obj;
phalcon_fetch_params_ex(1, 0, &name);
PHALCON_ENSURE_IS_STRING(name);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
if (SUCCESS == zend_symtable_find(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1, (void**)&service)) {
PHALCON_MM_GROW();
phalcon_return_call_method_p0(*service, "getdefinition");
RETURN_MM();
}
zend_throw_exception_ex(phalcon_di_exception_ce, 0 TSRMLS_CC, "Service '%s' was not found in the dependency injection container", Z_STRVAL_PP(name));
}
static PHP_METHOD(Phalcon_DI, getService){
zval **name, **service;
phalcon_di_object *obj;
phalcon_fetch_params_ex(1, 0, &name);
PHALCON_ENSURE_IS_STRING(name);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
if (SUCCESS == zend_symtable_find(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1, (void**)&service)) {
RETURN_ZVAL(*service, 1, 0);
}
zend_throw_exception_ex(phalcon_di_exception_ce, 0 TSRMLS_CC, "Service '%s' was not found in the dependency injection container", Z_STRVAL_PP(name));
}
static PHP_METHOD(Phalcon_DI, get){
zval **name, **parameters = NULL, **service;
phalcon_di_object *obj;
zend_class_entry *ce;
phalcon_fetch_params_ex(1, 1, &name, &parameters);
PHALCON_ENSURE_IS_STRING(name);
if (!parameters) {
parameters = &PHALCON_GLOBAL(z_null);
}
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
if (SUCCESS == zend_symtable_find(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1, (void**)&service)) {
/* The service is registered in the DI */
phalcon_call_method_params(return_value, return_value_ptr, *service, SL("resolve"), 605366917UL TSRMLS_CC, 2, *parameters, this_ptr);
if (EG(exception)) {
if (return_value_ptr) {
ALLOC_INIT_ZVAL(*return_value_ptr);
return;
}
}
if (return_value_ptr) {
return_value = *return_value_ptr;
}
ce = (Z_TYPE_P(return_value) == IS_OBJECT) ? Z_OBJCE_P(return_value) : NULL;
}
else {
/* The DI also acts as builder for any class even if it isn't defined in the DI */
if (phalcon_class_exists_ex(&ce, *name, 1 TSRMLS_CC)) {
if (FAILURE == phalcon_create_instance_params_ce(return_value, ce, *parameters TSRMLS_CC)) {
return;
}
}
else {
zend_throw_exception_ex(phalcon_di_exception_ce, 0 TSRMLS_CC, "Service '%s' was not found in the dependency injection container", Z_STRVAL_PP(name));
return;
}
}
/* Pass the DI itself if the instance implements Phalcon\DI\InjectionAwareInterface */
if (ce && instanceof_function_ex(ce, phalcon_di_injectionawareinterface_ce, 1 TSRMLS_CC)) {
phalcon_call_method_params(NULL, NULL, return_value, SL("setdi"), 461718238UL TSRMLS_CC, 1, this_ptr);
}
}
static PHP_METHOD(Phalcon_DI, getShared){
zval **name, **parameters = NULL;
zval *retval;
phalcon_di_object *obj;
phalcon_fetch_params_ex(1, 1, &name, &parameters);
PHALCON_ENSURE_IS_STRING(name);
if (!parameters) {
parameters = &PHALCON_GLOBAL(z_null);
}
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
retval = phalcon_di_read_dimension_internal(getThis(), obj, *name, *parameters TSRMLS_CC);
if (retval) {
RETURN_ZVAL(retval, 1, 0);
}
RETURN_NULL();
}
static PHP_METHOD(Phalcon_DI, has){
zval **name;
phalcon_di_object *obj;
phalcon_fetch_params_ex(1, 0, &name);
PHALCON_ENSURE_IS_STRING(name);
obj = phalcon_di_get_object(getThis() TSRMLS_CC);
RETURN_BOOL(zend_symtable_exists(obj->services, Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1));
}
static PHP_METHOD(Phalcon_DI, wasFreshInstance){
phalcon_di_object *obj = phalcon_di_get_object(getThis() TSRMLS_CC);
RETURN_BOOL(obj->fresh);
}
static PHP_METHOD(Phalcon_DI, getServices){
phalcon_di_object *obj = phalcon_di_get_object(getThis() TSRMLS_CC);
array_init_size(return_value, zend_hash_num_elements(obj->services));
zend_hash_copy(Z_ARRVAL_P(return_value), obj->services, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
}
static PHP_METHOD(Phalcon_DI, __call){
zval **method, **arguments = NULL;
phalcon_fetch_params_ex(1, 1, &method, &arguments);
PHALCON_ENSURE_IS_STRING(method);
if (!arguments) {
arguments = &PHALCON_GLOBAL(z_null);
}
phalcon_di_call_method_internal(return_value, return_value_ptr, getThis(), Z_STRVAL_PP(method), *arguments TSRMLS_CC);
}
static PHP_METHOD(Phalcon_DI, setDefault){
zval *dependency_injector;
phalcon_fetch_params(0, 1, 0, &dependency_injector);
phalcon_update_static_property_ce(phalcon_di_ce, SL("_default"), dependency_injector TSRMLS_CC);
}
static PHP_METHOD(Phalcon_DI, getDefault){
zval *default_di;
default_di = phalcon_fetch_static_property_ce(phalcon_di_ce, SL("_default") TSRMLS_CC);
RETURN_CTORW(default_di);
}
static PHP_METHOD(Phalcon_DI, reset){
zend_update_static_property_null(phalcon_di_ce, SL("_default") TSRMLS_CC);
}
static PHP_METHOD(Phalcon_DI, __clone) {
}
#include <Zend/zend_interfaces.h>
zend_class_entry *phalcon_diinterface_ce;
static const zend_function_entry phalcon_diinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_DiInterface, set, arginfo_phalcon_diinterface_set)
PHP_ABSTRACT_ME(Phalcon_DiInterface, setShared, arginfo_phalcon_diinterface_setshared)
PHP_ABSTRACT_ME(Phalcon_DiInterface, remove, arginfo_phalcon_diinterface_remove)
PHP_ABSTRACT_ME(Phalcon_DiInterface, attempt, arginfo_phalcon_diinterface_attempt)
PHP_ABSTRACT_ME(Phalcon_DiInterface, get, arginfo_phalcon_diinterface_get)
PHP_ABSTRACT_ME(Phalcon_DiInterface, getShared, arginfo_phalcon_diinterface_getshared)
PHP_ABSTRACT_ME(Phalcon_DiInterface, setRaw, arginfo_phalcon_diinterface_setraw)
PHP_ABSTRACT_ME(Phalcon_DiInterface, getRaw, arginfo_phalcon_diinterface_getraw)
PHP_ABSTRACT_ME(Phalcon_DiInterface, getService, arginfo_phalcon_diinterface_getservice)
PHP_ABSTRACT_ME(Phalcon_DiInterface, has, arginfo_phalcon_diinterface_has)
PHP_ABSTRACT_ME(Phalcon_DiInterface, wasFreshInstance, NULL)
PHP_ABSTRACT_ME(Phalcon_DiInterface, getServices, NULL)
ZEND_FENTRY(setDefault, NULL, arginfo_phalcon_diinterface_setdefault, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)
ZEND_FENTRY(getDefault, NULL, NULL, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)
ZEND_FENTRY(reset, NULL, NULL, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_DiInterface){
PHALCON_REGISTER_INTERFACE_EX(Phalcon, DiInterface, diinterface, zend_ce_arrayaccess, phalcon_diinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_dispatcher_ce;
static PHP_METHOD(Phalcon_Dispatcher, __construct);
static PHP_METHOD(Phalcon_Dispatcher, setDI);
static PHP_METHOD(Phalcon_Dispatcher, getDI);
static PHP_METHOD(Phalcon_Dispatcher, setEventsManager);
static PHP_METHOD(Phalcon_Dispatcher, getEventsManager);
static PHP_METHOD(Phalcon_Dispatcher, setActionSuffix);
static PHP_METHOD(Phalcon_Dispatcher, setModuleName);
static PHP_METHOD(Phalcon_Dispatcher, getModuleName);
static PHP_METHOD(Phalcon_Dispatcher, setNamespaceName);
static PHP_METHOD(Phalcon_Dispatcher, getNamespaceName);
static PHP_METHOD(Phalcon_Dispatcher, setDefaultNamespace);
static PHP_METHOD(Phalcon_Dispatcher, getDefaultNamespace);
static PHP_METHOD(Phalcon_Dispatcher, setDefaultAction);
static PHP_METHOD(Phalcon_Dispatcher, setActionName);
static PHP_METHOD(Phalcon_Dispatcher, getActionName);
static PHP_METHOD(Phalcon_Dispatcher, setParams);
static PHP_METHOD(Phalcon_Dispatcher, getParams);
static PHP_METHOD(Phalcon_Dispatcher, setParam);
static PHP_METHOD(Phalcon_Dispatcher, getParam);
static PHP_METHOD(Phalcon_Dispatcher, getActiveMethod);
static PHP_METHOD(Phalcon_Dispatcher, isFinished);
static PHP_METHOD(Phalcon_Dispatcher, setReturnedValue);
static PHP_METHOD(Phalcon_Dispatcher, getReturnedValue);
static PHP_METHOD(Phalcon_Dispatcher, dispatch);
static PHP_METHOD(Phalcon_Dispatcher, forward);
static PHP_METHOD(Phalcon_Dispatcher, wasForwarded);
static PHP_METHOD(Phalcon_Dispatcher, getHandlerClass);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_dispatcher_setmodulename, 0, 0, 1)
ZEND_ARG_INFO(0, moduleName)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_dispatcher_setnamespacename, 0, 0, 1)
ZEND_ARG_INFO(0, namespaceName)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_dispatcher_setreturnedvalue, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_dispatcher_method_entry[] = {
PHP_ME(Phalcon_Dispatcher, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Dispatcher, setDI, arginfo_phalcon_di_injectionawareinterface_setdi, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getDI, arginfo_phalcon_di_injectionawareinterface_getdi, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setEventsManager, arginfo_phalcon_events_eventsawareinterface_seteventsmanager, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getEventsManager, arginfo_phalcon_events_eventsawareinterface_geteventsmanager, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setActionSuffix, arginfo_phalcon_dispatcherinterface_setactionsuffix, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setModuleName, arginfo_phalcon_dispatcher_setmodulename, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getModuleName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setNamespaceName, arginfo_phalcon_dispatcher_setnamespacename, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getNamespaceName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setDefaultNamespace, arginfo_phalcon_dispatcherinterface_setdefaultnamespace, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getDefaultNamespace, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setDefaultAction, arginfo_phalcon_dispatcherinterface_setdefaultaction, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setActionName, arginfo_phalcon_dispatcherinterface_setactionname, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getActionName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setParams, arginfo_phalcon_dispatcherinterface_setparams, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getParams, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setParam, arginfo_phalcon_dispatcherinterface_setparam, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getParam, arginfo_phalcon_dispatcherinterface_getparam, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getActiveMethod, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, isFinished, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, setReturnedValue, arginfo_phalcon_dispatcher_setreturnedvalue, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getReturnedValue, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, dispatch, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, forward, arginfo_phalcon_dispatcherinterface_forward, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, wasForwarded, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getHandlerClass, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Dispatcher){
PHALCON_REGISTER_CLASS(Phalcon, Dispatcher, dispatcher, phalcon_dispatcher_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_activeHandler"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_finished"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_dispatcher_ce, SL("_forwarded"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_moduleName"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_namespaceName"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_handlerName"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_actionName"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_returnedValue"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_lastHandler"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_defaultNamespace"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_defaultHandler"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_dispatcher_ce, SL("_defaultAction"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_dispatcher_ce, SL("_handlerSuffix"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_dispatcher_ce, SL("_actionSuffix"), "Action", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_previousHandlerName"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_dispatcher_ce, SL("_previousActionName"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_NO_DI"), 0 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_CYCLIC_ROUTING"), 1 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_HANDLER_NOT_FOUND"), 2 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_INVALID_HANDLER"), 3 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_INVALID_PARAMS"), 4 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_ACTION_NOT_FOUND"), 5 TSRMLS_CC);
zend_class_implements(phalcon_dispatcher_ce TSRMLS_CC, 3, phalcon_dispatcherinterface_ce, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Dispatcher, __construct){
phalcon_update_property_empty_array(phalcon_dispatcher_ce, this_ptr, SL("_params") TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, setDI){
zval *dependency_injector;
phalcon_fetch_params(0, 1, 0, &dependency_injector);
PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_exception_ce, 0);
phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getDI){
RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setEventsManager){
zval *events_manager;
phalcon_fetch_params(0, 1, 0, &events_manager);
phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getEventsManager){
RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setActionSuffix){
zval *action_suffix;
phalcon_fetch_params(0, 1, 0, &action_suffix);
phalcon_update_property_this_quick(this_ptr, SL("_actionSuffix"), action_suffix, 879621975UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, setModuleName){
zval *module_name;
phalcon_fetch_params(0, 1, 0, &module_name);
phalcon_update_property_this_quick(this_ptr, SL("_moduleName"), module_name, 4053279339UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getModuleName){
RETURN_MEMBER_QUICK(this_ptr, "_moduleName", 4053279339UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setNamespaceName){
zval *namespace_name;
phalcon_fetch_params(0, 1, 0, &namespace_name);
phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getNamespaceName){
RETURN_MEMBER_QUICK(this_ptr, "_namespaceName", 816833906UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setDefaultNamespace){
zval *namespace;
phalcon_fetch_params(0, 1, 0, &namespace);
phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace, 761145590UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getDefaultNamespace){
RETURN_MEMBER_QUICK(this_ptr, "_defaultNamespace", 761145590UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setDefaultAction){
zval *action_name;
phalcon_fetch_params(0, 1, 0, &action_name);
phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, setActionName){
zval *action_name;
phalcon_fetch_params(0, 1, 0, &action_name);
phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getActionName){
RETURN_MEMBER_QUICK(this_ptr, "_actionName", 2975797059UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setParams){
zval *params, *exception_message;
phalcon_fetch_params(0, 1, 0, &params);
if (Z_TYPE_P(params) != IS_ARRAY) {
PHALCON_MM_GROW();
PHALCON_INIT_VAR(exception_message);
ZVAL_STRING(exception_message, "Parameters must be an Array", 1);
phalcon_call_method_p1_key(NULL, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message);
RETURN_MM_NULL();
}
phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getParams){
RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setParam){
zval *param, *value;
phalcon_fetch_params(0, 2, 0, &param, &value);
phalcon_update_property_array(this_ptr, SL("_params"), param, value TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getParam){
zval *param, *filters = NULL, *default_value = NULL;
zval *exception_code;
zval *exception_message, *service, *filter;
zval *params, *param_value, *dependency_injector;
phalcon_fetch_params(0, 1, 2, &param, &filters, &default_value);
params = phalcon_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC);
if (phalcon_array_isset_fetch(&param_value, params, param)) {
if (filters && Z_TYPE_P(filters) != IS_NULL) {
PHALCON_MM_GROW();
dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_INIT_VAR(exception_code);
ZVAL_LONG(exception_code, 0);
PHALCON_INIT_VAR(exception_message);
ZVAL_STRING(exception_message, "A dependency injection object is required to access the 'filter' service", 1);
phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message, exception_code);
RETURN_MM();
}
PHALCON_INIT_VAR(service);
ZVAL_STRING(service, "filter", 1);
PHALCON_INIT_VAR(filter);
phalcon_call_method_p1_key(filter, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(filter, phalcon_filterinterface_ce);
phalcon_call_method_p2_key(return_value, filter, "sanitize", 3688332940UL, param_value, filters);
RETURN_MM();
} else {
RETURN_ZVAL(param_value, 1, 0);
}
}
if (default_value) {
RETURN_ZVAL(default_value, 1, 0);
}
RETURN_NULL();
}
static PHP_METHOD(Phalcon_Dispatcher, getActiveMethod){
zval *suffix, *action_name;
suffix = phalcon_fetch_nproperty_this(this_ptr, SL("_actionSuffix"), PH_NOISY_CC);
action_name = phalcon_fetch_nproperty_this(this_ptr, SL("_actionName"), PH_NOISY_CC);
PHALCON_CONCAT_VV(return_value, action_name, suffix);
}
static PHP_METHOD(Phalcon_Dispatcher, isFinished){
RETURN_MEMBER_QUICK(this_ptr, "_finished", 385784334UL);
}
static PHP_METHOD(Phalcon_Dispatcher, setReturnedValue){
zval *value;
phalcon_fetch_params(0, 1, 0, &value);
phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, getReturnedValue){
RETURN_MEMBER_QUICK(this_ptr, "_returnedValue", 4143876906UL);
}
static inline int phalcon_dispatcher_fire_event(zval *return_value, zval *mgr, const char *event, zval *source, zval *data TSRMLS_DC)
{
if (mgr) {
zval *event_name;
int status;
MAKE_STD_ZVAL(event_name);
ZVAL_STRING(event_name, event, 0);
status = phalcon_call_method_params(return_value, NULL, mgr, SL("fire"), 259017035UL TSRMLS_CC, (data ? 3 : 2), event_name, source, data);
ZVAL_NULL(event_name);
zval_ptr_dtor(&event_name);
return status;
}
return SUCCESS;
}
static PHP_METHOD(Phalcon_Dispatcher, dispatch){
zval *exception_code = NULL;
zval *exception_message = NULL;
zval *status = NULL, *value = NULL, *handler = NULL;
zval *camelized_class = NULL, *handler_class = NULL, *has_service = NULL;
zval *was_fresh = NULL, *action_method = NULL, *params = NULL, *call_object = NULL;
zval *exception = NULL;
zval *dependency_injector, *events_manager, *tmp;
zval *handler_suffix, *action_suffix, *namespace_name, *handler_name, *action_name;
int number_dispatches = 0;
PHALCON_MM_GROW();
dependency_injector = phalcon_fetch_property_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
if (!dependency_injector || Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_INIT_VAR(exception_code);
ZVAL_LONG(exception_code, 0);
PHALCON_INIT_VAR(exception_message);
ZVAL_STRING(exception_message, "A dependency injection container is required to access related dispatching services", 1);
phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message, exception_code);
RETURN_MM();
}
events_manager = phalcon_fetch_property_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
if (events_manager && Z_TYPE_P(events_manager) != IS_OBJECT) {
events_manager = NULL;
}
PHALCON_INIT_NVAR(status);
if (FAILURE == phalcon_dispatcher_fire_event(status, events_manager, "dispatch:beforeDispatchLoop", this_ptr, NULL TSRMLS_CC)) {
RETURN_MM();
}
if (PHALCON_IS_FALSE(status)) {
RETURN_MM_FALSE;
}
PHALCON_INIT_VAR(value);
PHALCON_INIT_VAR(handler);
handler_suffix = phalcon_fetch_nproperty_this(this_ptr, SL("_handlerSuffix"), PH_NOISY_CC);
action_suffix = phalcon_fetch_nproperty_this(this_ptr, SL("_actionSuffix"), PH_NOISY_CC);
phalcon_update_property_this(this_ptr, SL("_finished"), PHALCON_GLOBAL(z_false) TSRMLS_CC);
while (1) {
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (zend_is_true(tmp)) {
break;
}
++number_dispatches;
if (number_dispatches == 256) {
PHALCON_INIT_NVAR(exception_code);
ZVAL_LONG(exception_code, 1);
PHALCON_INIT_NVAR(exception_message);
ZVAL_STRING(exception_message, "Dispatcher has detected a cyclic routing causing stability problems", 1);
phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message, exception_code);
break;
}
phalcon_update_property_this(this_ptr, SL("_finished"), PHALCON_GLOBAL(z_true) TSRMLS_CC);
namespace_name = phalcon_fetch_nproperty_this(this_ptr, SL("_namespaceName"), PH_NOISY_CC);
if (!zend_is_true(namespace_name)) {
namespace_name = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultNamespace"), PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC);
}
handler_name = phalcon_fetch_nproperty_this(this_ptr, SL("_handlerName"), PH_NOISY_CC);
if (!zend_is_true(handler_name)) {
handler_name = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultHandler"), PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), handler_name, 2743819555UL TSRMLS_CC);
}
action_name = phalcon_fetch_nproperty_this(this_ptr, SL("_actionName"), PH_NOISY_CC);
if (!zend_is_true(action_name)) {
action_name = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultAction"), PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC);
}
if (events_manager) {
PHALCON_INIT_NVAR(status);
if (FAILURE == phalcon_dispatcher_fire_event(status, events_manager, "dispatch:beforeDispatch", this_ptr, NULL TSRMLS_CC)) {
RETURN_MM();
}
if (PHALCON_IS_FALSE(status)) {
continue;
}
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
if (!phalcon_memnstr_str(handler_name, SL("\\"))) {
PHALCON_INIT_NVAR(camelized_class);
phalcon_camelize(camelized_class, handler_name);
} else {
camelized_class = handler_name;
}
PHALCON_INIT_NVAR(handler_class);
if (zend_is_true(namespace_name)) {
if (phalcon_end_with_str(namespace_name, SL("\\"))) {
PHALCON_CONCAT_VVV(handler_class, namespace_name, camelized_class, handler_suffix);
} else {
PHALCON_CONCAT_VSVV(handler_class, namespace_name, "\\", camelized_class, handler_suffix);
}
} else {
PHALCON_CONCAT_VV(handler_class, camelized_class, handler_suffix);
}
PHALCON_INIT_NVAR(has_service);
phalcon_call_method_p1_key(has_service, dependency_injector, "has", 2090320481UL, handler_class);
if (!zend_is_true(has_service)) {
PHALCON_INIT_NVAR(has_service);
ZVAL_LONG(has_service, phalcon_class_exists(handler_class, 1 TSRMLS_CC));
}
if (!zend_is_true(has_service)) {
PHALCON_INIT_NVAR(exception_code);
ZVAL_LONG(exception_code, 2);
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_VS(exception_message, handler_class, " handler class cannot be loaded");
PHALCON_INIT_NVAR(status);
phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message, exception_code);
if (PHALCON_IS_FALSE(status)) {
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
break;
}
PHALCON_INIT_NVAR(handler);
phalcon_call_method_p1_key(handler, dependency_injector, "getshared", 1727570332UL, handler_class);
if (Z_TYPE_P(handler) != IS_OBJECT) {
PHALCON_INIT_NVAR(exception_code);
ZVAL_LONG(exception_code, 3);
PHALCON_INIT_NVAR(exception_message);
ZVAL_STRING(exception_message, "Invalid handler returned from the services container", 1);
PHALCON_INIT_NVAR(status);
phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message, exception_code);
if (PHALCON_IS_FALSE(status)) {
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
break;
}
PHALCON_INIT_NVAR(was_fresh);
phalcon_call_method_key(was_fresh, dependency_injector, "wasfreshinstance", 2047300349UL);
phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), handler, 2923197278UL TSRMLS_CC);
PHALCON_INIT_NVAR(action_method);
PHALCON_CONCAT_VV(action_method, action_name, action_suffix);
if (phalcon_method_exists(handler, action_method TSRMLS_CC) == FAILURE) {
if (events_manager) {
PHALCON_INIT_NVAR(status);
if (FAILURE == phalcon_dispatcher_fire_event(status, events_manager, "dispatch:beforeNotFoundAction", this_ptr, NULL TSRMLS_CC)) {
RETURN_MM();
}
if (PHALCON_IS_FALSE(status)) {
continue;
}
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
PHALCON_INIT_NVAR(exception_code);
ZVAL_LONG(exception_code, 5);
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVSVS(exception_message, "Action '", action_name, "' was not found on handler '", handler_name, "'");
PHALCON_INIT_NVAR(status);
phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message, exception_code);
if (PHALCON_IS_FALSE(status)) {
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
break;
}
if (events_manager) {
PHALCON_INIT_NVAR(status);
if (FAILURE == phalcon_dispatcher_fire_event(status, events_manager, "dispatch:beforeExecuteRoute", this_ptr, NULL TSRMLS_CC)) {
RETURN_MM();
}
if (PHALCON_IS_FALSE(status)) {
continue;
}
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
if (phalcon_method_quick_exists_ex(handler, SS("beforeexecuteroute"), 3852116986UL TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_NVAR(status);
phalcon_call_method_p1_key(status, handler, "beforeexecuteroute", 3852116986UL, this_ptr);
if (PHALCON_IS_FALSE(status)) {
continue;
}
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
if (PHALCON_IS_TRUE(was_fresh)) {
if (phalcon_method_quick_exists_ex(handler, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) {
phalcon_call_method_key(NULL, handler, "initialize", 2896075127UL);
}
if (events_manager) {
PHALCON_INIT_NVAR(status);
if (FAILURE == phalcon_dispatcher_fire_event(status, events_manager, "dispatch:afterInitialize", this_ptr, NULL TSRMLS_CC)) {
RETURN_MM();
}
if (PHALCON_IS_FALSE(status)) {
continue;
}
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
}
PHALCON_OBS_NVAR(params);
phalcon_read_property_this_quick(&params, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC);
if (Z_TYPE_P(params) != IS_ARRAY) {
PHALCON_INIT_NVAR(exception_code);
ZVAL_LONG(exception_code, 4);
PHALCON_INIT_NVAR(exception_message);
ZVAL_STRING(exception_message, "Action parameters must be an Array", 1);
PHALCON_INIT_NVAR(status);
phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message, exception_code);
if (PHALCON_IS_FALSE(status)) {
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
break;
}
PHALCON_INIT_NVAR(call_object);
array_init_size(call_object, 2);
phalcon_array_append(&call_object, handler, 0);
phalcon_array_append(&call_object, action_method, 0);
if (events_manager) {
PHALCON_INIT_NVAR(value);
PHALCON_CALL_USER_FUNC_ARRAY_NOEX(value, call_object, params);
if (EG(exception)) {
PHALCON_CPY_WRT(exception, EG(exception));
zend_clear_exception(TSRMLS_C);
PHALCON_INIT_NVAR(status);
phalcon_call_method_p1_key(status, this_ptr, "_handleexception", 2165668191UL, exception);
if (PHALCON_IS_FALSE(status)) {
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
} else {
phalcon_throw_exception(exception TSRMLS_CC);
RETURN_MM();
}
} else {
phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
}
} else {
PHALCON_INIT_NVAR(value);
PHALCON_CALL_USER_FUNC_ARRAY(value, call_object, params);
phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
}
phalcon_update_property_this_quick(this_ptr, SL("_lastHandler"), handler, 1315517974UL TSRMLS_CC);
if (events_manager) {
PHALCON_INIT_NVAR(status);
if (FAILURE == phalcon_dispatcher_fire_event(status, events_manager, "dispatch:afterExecuteRoute", this_ptr, value TSRMLS_CC)) {
RETURN_MM();
}
if (PHALCON_IS_FALSE(status)) {
continue;
}
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
if (FAILURE == phalcon_dispatcher_fire_event(NULL, events_manager, "dispatch:afterDispatch", this_ptr, NULL TSRMLS_CC)) {
RETURN_MM();
}
}
if (phalcon_method_quick_exists_ex(handler, SS("afterexecuteroute"), 2573764025UL TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_NVAR(status);
phalcon_call_method_p2_key(status, handler, "afterexecuteroute", 2573764025UL, this_ptr, value);
if (PHALCON_IS_FALSE(status)) {
continue;
}
tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(tmp)) {
continue;
}
}
}
if (FAILURE == phalcon_dispatcher_fire_event(NULL, events_manager, "dispatch:afterDispatchLoop", this_ptr, NULL TSRMLS_CC)) {
RETURN_MM();
}
RETURN_CCTOR(handler);
}
static PHP_METHOD(Phalcon_Dispatcher, forward){
zval *forward, *exception_message;
zval *namespace_name, *controller_name, *task_name, *action_name, *params, *previous_controller_name, *previous_action_name;
phalcon_fetch_params(0, 1, 0, &forward);
if (Z_TYPE_P(forward) != IS_ARRAY) {
PHALCON_MM_GROW();
PHALCON_INIT_VAR(exception_message);
ZVAL_STRING(exception_message, "Forward parameter must be an Array", 1);
phalcon_call_method_p1_key(NULL, this_ptr, "_throwdispatchexception", 3996129271UL, exception_message);
RETURN_MM_NULL();
}
previous_controller_name = phalcon_fetch_nproperty_this(this_ptr, SL("_handlerName"), PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_previousHandlerName"), previous_controller_name, 1385015136UL TSRMLS_CC);
previous_action_name = phalcon_fetch_nproperty_this(this_ptr, SL("_actionName"), PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_previousActionName"), previous_action_name, 3455223264UL TSRMLS_CC);
if (phalcon_array_isset_string_fetch(&namespace_name, forward, SS("namespace"))) {
phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC);
}
if (phalcon_array_isset_string_fetch(&controller_name, forward, SS("controller"))) {
phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), controller_name, 2743819555UL TSRMLS_CC);
} else if (phalcon_array_isset_string_fetch(&task_name, forward, SS("task"))) {
phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), task_name, 2743819555UL TSRMLS_CC);
}
if (phalcon_array_isset_string_fetch(&action_name, forward, SS("action"))) {
phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC);
}
if (phalcon_array_isset_string_fetch(&params, forward, SS("params"))) {
phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC);
}
phalcon_update_property_this(this_ptr, SL("_finished"), PHALCON_GLOBAL(z_false) TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_forwarded"), PHALCON_GLOBAL(z_true) TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Dispatcher, wasForwarded){
RETURN_MEMBER_QUICK(this_ptr, "_forwarded", 1865074274UL);
}
static PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){
zval *camelized_class = NULL;
zval *handler_suffix, *namespace_name, *handler_name;
PHALCON_MM_GROW();
handler_suffix = phalcon_fetch_nproperty_this(this_ptr, SL("_handlerSuffix"), PH_NOISY_CC);
namespace_name = phalcon_fetch_nproperty_this(this_ptr, SL("_namespaceName"), PH_NOISY_CC);
if (!zend_is_true(namespace_name)) {
namespace_name = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultNamespace"), PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC);
}
handler_name = phalcon_fetch_nproperty_this(this_ptr, SL("_handlerName"), PH_NOISY_CC);
if (!zend_is_true(handler_name)) {
handler_name = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultHandler"), PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), handler_name, 2743819555UL TSRMLS_CC);
}
if (!phalcon_memnstr_str(handler_name, SL("\\"))) {
PHALCON_INIT_VAR(camelized_class);
phalcon_camelize(camelized_class, handler_name);
} else {
camelized_class = handler_name;
}
if (zend_is_true(namespace_name)) {
if (phalcon_end_with_str(namespace_name, SL("\\"))) {
PHALCON_CONCAT_VVV(return_value, namespace_name, camelized_class, handler_suffix);
} else {
PHALCON_CONCAT_VSVV(return_value, namespace_name, "\\", camelized_class, handler_suffix);
}
} else {
PHALCON_CONCAT_VV(return_value, camelized_class, handler_suffix);
}
PHALCON_MM_RESTORE();
}
zend_class_entry *phalcon_dispatcherinterface_ce;
static const zend_function_entry phalcon_dispatcherinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, setActionSuffix, arginfo_phalcon_dispatcherinterface_setactionsuffix)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, setDefaultNamespace, arginfo_phalcon_dispatcherinterface_setdefaultnamespace)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, setDefaultAction, arginfo_phalcon_dispatcherinterface_setdefaultaction)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, setActionName, arginfo_phalcon_dispatcherinterface_setactionname)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, getActionName, NULL)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, setParams, arginfo_phalcon_dispatcherinterface_setparams)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, getParams, NULL)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, setParam, arginfo_phalcon_dispatcherinterface_setparam)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, getParam, arginfo_phalcon_dispatcherinterface_getparam)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, isFinished, NULL)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, getReturnedValue, NULL)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, dispatch, NULL)
PHP_ABSTRACT_ME(Phalcon_DispatcherInterface, forward, arginfo_phalcon_dispatcherinterface_forward)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_DispatcherInterface){
PHALCON_REGISTER_INTERFACE(Phalcon, DispatcherInterface, dispatcherinterface, phalcon_dispatcherinterface_method_entry);
return SUCCESS;
}
#include <ext/standard/html.h>
zend_class_entry *phalcon_escaper_ce;
static PHP_METHOD(Phalcon_Escaper, setEncoding);
static PHP_METHOD(Phalcon_Escaper, getEncoding);
static PHP_METHOD(Phalcon_Escaper, setHtmlQuoteType);
static PHP_METHOD(Phalcon_Escaper, detectEncoding);
static PHP_METHOD(Phalcon_Escaper, normalizeEncoding);
static PHP_METHOD(Phalcon_Escaper, escapeHtml);
static PHP_METHOD(Phalcon_Escaper, escapeHtmlAttr);
static PHP_METHOD(Phalcon_Escaper, escapeCss);
static PHP_METHOD(Phalcon_Escaper, escapeJs);
static PHP_METHOD(Phalcon_Escaper, escapeUrl);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_escaper_detectencoding, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_escaper_normalizeencoding, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_escaper_method_entry[] = {
PHP_ME(Phalcon_Escaper, setEncoding, arginfo_phalcon_escaperinterface_setencoding, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, getEncoding, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, setHtmlQuoteType, arginfo_phalcon_escaperinterface_sethtmlquotetype, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, detectEncoding, arginfo_phalcon_escaper_detectencoding, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, normalizeEncoding, arginfo_phalcon_escaper_normalizeencoding, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, escapeHtml, arginfo_phalcon_escaperinterface_escapehtml, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, escapeHtmlAttr, arginfo_phalcon_escaperinterface_escapehtmlattr, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, escapeCss, arginfo_phalcon_escaperinterface_escapecss, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, escapeJs, arginfo_phalcon_escaperinterface_escapejs, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Escaper, escapeUrl, arginfo_phalcon_escaperinterface_escapeurl, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Escaper){
PHALCON_REGISTER_CLASS(Phalcon, Escaper, escaper, phalcon_escaper_method_entry, 0);
zend_declare_property_string(phalcon_escaper_ce, SL("_encoding"), "utf-8", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_escaper_ce, SL("_htmlEscapeMap"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(phalcon_escaper_ce, SL("_htmlQuoteType"), 3, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_escaper_ce TSRMLS_CC, 1, phalcon_escaperinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Escaper, setEncoding){
zval *encoding;
phalcon_fetch_params(0, 1, 0, &encoding);
if (unlikely(Z_TYPE_P(encoding) != IS_STRING)) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_escaper_exception_ce, "The character set must be string");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_encoding"), encoding, 4261080171UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Escaper, getEncoding){
RETURN_MEMBER_QUICK(this_ptr, "_encoding", 4261080171UL);
}
static PHP_METHOD(Phalcon_Escaper, setHtmlQuoteType){
zval *quote_type;
phalcon_fetch_params(0, 1, 0, &quote_type);
if (Z_TYPE_P(quote_type) != IS_LONG) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_escaper_exception_ce, "The quoting type is not valid");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_htmlQuoteType"), quote_type, 477993385UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Escaper, detectEncoding){
zval *str, *charset = NULL, *strict_check, *detected = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &str);
PHALCON_INIT_VAR(charset);
phalcon_is_basic_charset(charset, str);
if (Z_TYPE_P(charset) == IS_STRING) {
RETURN_CTOR(charset);
}
if (phalcon_function_quick_exists_ex(SS("mb_detect_encoding"), 2715391634UL TSRMLS_CC) == FAILURE) {
RETURN_MM_NULL();
}
strict_check = PHALCON_GLOBAL(z_true);
PHALCON_INIT_NVAR(charset);
ZVAL_STRING(charset, "UTF-32", 1);
PHALCON_INIT_VAR(detected);
phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check);
if (zend_is_true(detected)) {
RETURN_CTOR(charset);
}
PHALCON_INIT_NVAR(charset);
ZVAL_STRING(charset, "UTF-16", 1);
PHALCON_INIT_NVAR(detected);
phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check);
if (zend_is_true(detected)) {
RETURN_CTOR(charset);
}
PHALCON_INIT_NVAR(charset);
ZVAL_STRING(charset, "UTF-8", 1);
PHALCON_INIT_NVAR(detected);
phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check);
if (zend_is_true(detected)) {
RETURN_CTOR(charset);
}
PHALCON_INIT_NVAR(charset);
ZVAL_STRING(charset, "ISO-8859-1", 1);
PHALCON_INIT_NVAR(detected);
phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check);
if (zend_is_true(detected)) {
RETURN_CTOR(charset);
}
PHALCON_INIT_NVAR(charset);
ZVAL_STRING(charset, "ASCII", 1);
PHALCON_INIT_NVAR(detected);
phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check);
if (zend_is_true(detected)) {
RETURN_CTOR(charset);
}
phalcon_call_func_p1(return_value, "mb_detect_encoding", str);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Escaper, normalizeEncoding){
zval *str, *encoding, *charset;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &str);
if (phalcon_function_quick_exists_ex(SS("mb_convert_encoding"), 2165643194UL TSRMLS_CC) == FAILURE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_escaper_exception_ce, "Extension 'mbstring' is required");
return;
}
PHALCON_INIT_VAR(encoding);
phalcon_call_method_p1_key(encoding, this_ptr, "detectencoding", 3095134469UL, str);
PHALCON_INIT_VAR(charset);
ZVAL_STRING(charset, "UTF-32", 1);
phalcon_call_func_p3(return_value, "mb_convert_encoding", str, charset, encoding);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Escaper, escapeHtml){
zval *text;
zval *html_quote_type, *encoding;
phalcon_fetch_params(0, 1, 0, &text);
if (Z_TYPE_P(text) == IS_STRING) {
html_quote_type = phalcon_fetch_nproperty_this(this_ptr, SL("_htmlQuoteType"), PH_NOISY_CC);
encoding = phalcon_fetch_nproperty_this(this_ptr, SL("_encoding"), PH_NOISY_CC);
phalcon_htmlspecialchars(return_value, text, html_quote_type, encoding TSRMLS_CC);
return;
}
RETURN_ZVAL(text, 1, 0);
}
static PHP_METHOD(Phalcon_Escaper, escapeHtmlAttr){
zval *attribute, *encoding;
phalcon_fetch_params(0, 1, 0, &attribute);
if (Z_TYPE_P(attribute) == IS_STRING && zend_is_true(attribute)) {
zval quoting;
INIT_ZVAL(quoting);
ZVAL_LONG(&quoting, ENT_QUOTES);
encoding = phalcon_fetch_nproperty_this(this_ptr, SL("_encoding"), PH_NOISY_CC);
phalcon_htmlspecialchars(return_value, attribute, &quoting, encoding TSRMLS_CC);
return;
}
RETURN_ZVAL(attribute, 1, 0);
}
static PHP_METHOD(Phalcon_Escaper, escapeCss){
zval *css, *normalized;
phalcon_fetch_params(0, 1, 0, &css);
if (Z_TYPE_P(css) == IS_STRING && zend_is_true(css)) {
PHALCON_MM_GROW();
PHALCON_INIT_VAR(normalized);
phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", 3216085085UL, css);
phalcon_escape_css(return_value, normalized);
RETURN_MM();
}
RETURN_ZVAL(css, 1, 0);
}
static PHP_METHOD(Phalcon_Escaper, escapeJs){
zval *js, *normalized;
phalcon_fetch_params(0, 1, 0, &js);
if (Z_TYPE_P(js) == IS_STRING && zend_is_true(js)) {
PHALCON_MM_GROW();
PHALCON_INIT_VAR(normalized);
phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", 3216085085UL, js);
phalcon_escape_js(return_value, normalized);
RETURN_MM();
}
RETURN_ZVAL(js, 1, 0);
}
static PHP_METHOD(Phalcon_Escaper, escapeUrl){
zval *url;
phalcon_fetch_params(0, 1, 0, &url);
phalcon_raw_url_encode(return_value, url);
return;
}
zend_class_entry *phalcon_escaperinterface_ce;
static const zend_function_entry phalcon_escaperinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, setEncoding, arginfo_phalcon_escaperinterface_setencoding)
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, getEncoding, NULL)
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, setHtmlQuoteType, arginfo_phalcon_escaperinterface_sethtmlquotetype)
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, escapeHtml, arginfo_phalcon_escaperinterface_escapehtml)
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, escapeHtmlAttr, arginfo_phalcon_escaperinterface_escapehtmlattr)
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, escapeCss, arginfo_phalcon_escaperinterface_escapecss)
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, escapeJs, arginfo_phalcon_escaperinterface_escapejs)
PHP_ABSTRACT_ME(Phalcon_EscaperInterface, escapeUrl, arginfo_phalcon_escaperinterface_escapeurl)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_EscaperInterface){
PHALCON_REGISTER_INTERFACE(Phalcon, EscaperInterface, escaperinterface, phalcon_escaperinterface_method_entry);
return SUCCESS;
}
#include <Zend/zend_exceptions.h>
zend_class_entry *phalcon_exception_ce;
PHALCON_INIT_CLASS(Phalcon_Exception){
PHALCON_REGISTER_CLASS_EX(Phalcon, Exception, exception, zend_exception_get_default(TSRMLS_C), NULL, 0);
return SUCCESS;
}
zend_class_entry *phalcon_filter_ce;
static PHP_METHOD(Phalcon_Filter, add);
static PHP_METHOD(Phalcon_Filter, sanitize);
static PHP_METHOD(Phalcon_Filter, _sanitize);
static PHP_METHOD(Phalcon_Filter, getFilters);
static const zend_function_entry phalcon_filter_method_entry[] = {
PHP_ME(Phalcon_Filter, add, arginfo_phalcon_filterinterface_add, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Filter, sanitize, arginfo_phalcon_filterinterface_sanitize, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Filter, _sanitize, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Filter, getFilters, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Filter){
PHALCON_REGISTER_CLASS(Phalcon, Filter, filter, phalcon_filter_method_entry, 0);
zend_declare_property_null(phalcon_filter_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_filter_ce TSRMLS_CC, 1, phalcon_filterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Filter, add){
zval **name, **handler;
phalcon_fetch_params_ex(2, 0, &name, &handler);
PHALCON_ENSURE_IS_STRING(name);
if (Z_TYPE_PP(handler) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_filter_exception_ce, "Filter must be an object");
return;
}
phalcon_update_property_array(this_ptr, SL("_filters"), *name, *handler TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Filter, sanitize){
zval *value, *filters, *norecursive = NULL, *new_value = NULL, *filter = NULL, *array_value = NULL;
zval *item_value = NULL, *item_key = NULL, *filter_value = NULL, *sanizited_value = NULL;
zval *key = NULL;
HashTable *ah0, *ah1, *ah2;
HashPosition hp0, hp1, hp2;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 1, &value, &filters, &norecursive);
if (!norecursive) {
norecursive = PHALCON_GLOBAL(z_false);
}
if (Z_TYPE_P(filters) == IS_ARRAY) {
PHALCON_CPY_WRT(new_value, value);
if (Z_TYPE_P(value) != IS_NULL) {
phalcon_is_iterable(filters, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(filter);
if (Z_TYPE_P(new_value) == IS_ARRAY && !zend_is_true(norecursive)) {
PHALCON_INIT_NVAR(array_value);
array_init(array_value);
phalcon_is_iterable(new_value, &ah1, &hp1, 0, 0);
while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
PHALCON_GET_HKEY(item_key, ah1, hp1);
PHALCON_GET_HVALUE(item_value);
PHALCON_INIT_NVAR(filter_value);
phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", 2673127019UL, item_value, filter);
phalcon_array_update_zval(&array_value, item_key, &filter_value, PH_COPY | PH_SEPARATE);
zend_hash_move_forward_ex(ah1, &hp1);
}
PHALCON_CPY_WRT(new_value, array_value);
} else {
PHALCON_INIT_NVAR(filter_value);
phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", 2673127019UL, new_value, filter);
PHALCON_CPY_WRT(new_value, filter_value);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
}
RETURN_CCTOR(new_value);
}
if (Z_TYPE_P(value) == IS_ARRAY && !zend_is_true(norecursive)) {
PHALCON_INIT_VAR(sanizited_value);
array_init(sanizited_value);
phalcon_is_iterable(value, &ah2, &hp2, 0, 0);
while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) {
PHALCON_GET_HKEY(key, ah2, hp2);
PHALCON_GET_HVALUE(item_value);
PHALCON_INIT_NVAR(filter_value);
phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", 2673127019UL, item_value, filters);
phalcon_array_update_zval(&sanizited_value, key, &filter_value, PH_COPY | PH_SEPARATE);
zend_hash_move_forward_ex(ah2, &hp2);
}
} else {
PHALCON_INIT_NVAR(sanizited_value);
phalcon_call_method_p2_key(sanizited_value, this_ptr, "_sanitize", 2673127019UL, value, filters);
}
RETURN_CCTOR(sanizited_value);
}
static PHP_METHOD(Phalcon_Filter, _sanitize){
zval *value, *filter, *filters, *filter_object;
zval *arguments, *type = NULL, *quote, *empty_str, *escaped;
zval *filtered = NULL, *allow_fraction, *options, *exception_message;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &value, &filter);
PHALCON_OBS_VAR(filters);
phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC);
if (phalcon_array_isset(filters, filter)) {
PHALCON_OBS_VAR(filter_object);
phalcon_array_fetch(&filter_object, filters, filter, PH_NOISY);
if (phalcon_is_instance_of(filter_object, SL("Closure") TSRMLS_CC)) {
PHALCON_INIT_VAR(arguments);
array_init_size(arguments, 1);
phalcon_array_append(&arguments, value, PH_SEPARATE);
PHALCON_CALL_USER_FUNC_ARRAY(return_value, filter_object, arguments);
RETURN_MM();
}
phalcon_call_method_p1_key(return_value, filter_object, "filter", 2890214155UL, value);
RETURN_MM();
}
if (PHALCON_IS_STRING(filter, "email")) {
PHALCON_INIT_VAR(type);
ZVAL_LONG(type, 517); /* FILTER_SANITIZE_EMAIL */
PHALCON_INIT_VAR(quote);
ZVAL_STRING(quote, "'", 1);
PHALCON_INIT_VAR(empty_str);
ZVAL_STRING(empty_str, "", 1);
PHALCON_INIT_VAR(escaped);
phalcon_fast_str_replace(escaped, quote, empty_str, value);
PHALCON_INIT_VAR(filtered);
phalcon_call_func_p2(filtered, "filter_var", escaped, type);
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "int")) {
PHALCON_INIT_NVAR(type);
ZVAL_LONG(type, 519); /* FILTER_SANITIZE_NUMBER_INT */
PHALCON_INIT_NVAR(filtered);
phalcon_call_func_p2(filtered, "filter_var", value, type);
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "string")) {
PHALCON_INIT_NVAR(type);
ZVAL_LONG(type, 513); /* FILTER_SANITIZE_STRING */
PHALCON_INIT_NVAR(filtered);
phalcon_call_func_p2(filtered, "filter_var", value, type);
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "float")) {
PHALCON_INIT_VAR(allow_fraction);
ZVAL_LONG(allow_fraction, 4096);
PHALCON_INIT_VAR(options);
array_init_size(options, 1);
phalcon_array_update_quick_string(&options, SS("flags"), 4255547666UL, &allow_fraction, PH_COPY | PH_SEPARATE);
PHALCON_INIT_NVAR(type);
ZVAL_LONG(type, 520);
PHALCON_INIT_NVAR(filtered);
phalcon_call_func_p3(filtered, "filter_var", value, type, options);
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "alphanum")) {
PHALCON_INIT_NVAR(filtered);
phalcon_filter_alphanum(filtered, value);
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "trim")) {
PHALCON_INIT_NVAR(filtered);
phalcon_fast_trim(filtered, value, PHALCON_TRIM_BOTH TSRMLS_CC);
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "striptags")) {
PHALCON_INIT_NVAR(filtered);
phalcon_fast_strip_tags(filtered, value);
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "lower")) {
if (phalcon_function_quick_exists_ex(SS("mb_strtolower"), 3802586680UL TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_NVAR(filtered);
phalcon_call_func_p1(filtered, "mb_strtolower", value);
} else {
PHALCON_INIT_NVAR(filtered);
phalcon_fast_strtolower(filtered, value);
}
goto ph_end_0;
}
if (PHALCON_IS_STRING(filter, "upper")) {
if (phalcon_function_quick_exists_ex(SS("mb_strtoupper"), 4155739579UL TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_NVAR(filtered);
phalcon_call_func_p1(filtered, "mb_strtoupper", value);
} else {
PHALCON_INIT_NVAR(filtered);
phalcon_fast_strtoupper(filtered, value);
}
goto ph_end_0;
}
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Sanitize filter ", filter, " is not supported");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_filter_exception_ce, exception_message);
return;
ph_end_0:
RETURN_CCTOR(filtered);
}
static PHP_METHOD(Phalcon_Filter, getFilters){
RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL);
}
zend_class_entry *phalcon_filterinterface_ce;
static const zend_function_entry phalcon_filterinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_FilterInterface, add, arginfo_phalcon_filterinterface_add)
PHP_ABSTRACT_ME(Phalcon_FilterInterface, sanitize, arginfo_phalcon_filterinterface_sanitize)
PHP_ABSTRACT_ME(Phalcon_FilterInterface, getFilters, NULL)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_FilterInterface){
PHALCON_REGISTER_INTERFACE(Phalcon, FilterInterface, filterinterface, phalcon_filterinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_flash_ce;
static PHP_METHOD(Phalcon_Flash, __construct);
static PHP_METHOD(Phalcon_Flash, setImplicitFlush);
static PHP_METHOD(Phalcon_Flash, setAutomaticHtml);
static PHP_METHOD(Phalcon_Flash, setCssClasses);
static PHP_METHOD(Phalcon_Flash, error);
static PHP_METHOD(Phalcon_Flash, notice);
static PHP_METHOD(Phalcon_Flash, success);
static PHP_METHOD(Phalcon_Flash, warning);
static PHP_METHOD(Phalcon_Flash, outputMessage);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_flash___construct, 0, 0, 0)
ZEND_ARG_INFO(0, cssClasses)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_flash_setimplicitflush, 0, 0, 1)
ZEND_ARG_INFO(0, implicitFlush)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_flash_setautomatichtml, 0, 0, 1)
ZEND_ARG_INFO(0, automaticHtml)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_flash_setcssclasses, 0, 0, 1)
ZEND_ARG_INFO(0, cssClasses)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_flash_outputmessage, 0, 0, 2)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, message)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_flash_method_entry[] = {
PHP_ME(Phalcon_Flash, __construct, arginfo_phalcon_flash___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Flash, setImplicitFlush, arginfo_phalcon_flash_setimplicitflush, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Flash, setAutomaticHtml, arginfo_phalcon_flash_setautomatichtml, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Flash, setCssClasses, arginfo_phalcon_flash_setcssclasses, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Flash, error, arginfo_phalcon_flashinterface_error, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Flash, notice, arginfo_phalcon_flashinterface_notice, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Flash, success, arginfo_phalcon_flashinterface_success, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Flash, warning, arginfo_phalcon_flashinterface_warning, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Flash, outputMessage, arginfo_phalcon_flash_outputmessage, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Flash){
PHALCON_REGISTER_CLASS(Phalcon, Flash, flash, phalcon_flash_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_property_null(phalcon_flash_ce, SL("_cssClasses"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_flash_ce, SL("_implicitFlush"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_flash_ce, SL("_automaticHtml"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Flash, __construct){
zval *css_classes = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &css_classes);
if (!css_classes) {
PHALCON_INIT_VAR(css_classes);
} else {
PHALCON_SEPARATE_PARAM(css_classes);
}
if (Z_TYPE_P(css_classes) != IS_ARRAY) {
PHALCON_INIT_NVAR(css_classes);
array_init_size(css_classes, 4);
add_assoc_stringl_ex(css_classes, SS("error"), SL("errorMessage"), 1);
add_assoc_stringl_ex(css_classes, SS("notice"), SL("noticeMessage"), 1);
add_assoc_stringl_ex(css_classes, SS("success"), SL("successMessage"), 1);
add_assoc_stringl_ex(css_classes, SS("warning"), SL("warningMessage"), 1);
}
phalcon_update_property_this_quick(this_ptr, SL("_cssClasses"), css_classes, 1944388667UL TSRMLS_CC);
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Flash, setImplicitFlush){
zval *implicit_flush;
phalcon_fetch_params(0, 1, 0, &implicit_flush);
phalcon_update_property_this_quick(this_ptr, SL("_implicitFlush"), implicit_flush, 521244897UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Flash, setAutomaticHtml){
zval *automatic_html;
phalcon_fetch_params(0, 1, 0, &automatic_html);
phalcon_update_property_this_quick(this_ptr, SL("_automaticHtml"), automatic_html, 1414140864UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Flash, setCssClasses){
zval *css_classes;
phalcon_fetch_params(0, 1, 0, &css_classes);
if (Z_TYPE_P(css_classes) == IS_ARRAY) {
phalcon_update_property_this_quick(this_ptr, SL("_cssClasses"), css_classes, 1944388667UL TSRMLS_CC);
RETURN_THISW();
}
PHALCON_THROW_EXCEPTION_STRW(phalcon_flash_exception_ce, "CSS classes must be an Array");
return;
}
static PHP_METHOD(Phalcon_Flash, error){
zval *message, *type;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &message);
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "error", 1);
phalcon_call_method_p2_key(return_value, this_ptr, "message", 2265848874UL, type, message);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Flash, notice){
zval *message, *type;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &message);
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "notice", 1);
phalcon_call_method_p2_key(return_value, this_ptr, "message", 2265848874UL, type, message);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Flash, success){
zval *message, *type;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &message);
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "success", 1);
phalcon_call_method_p2_key(return_value, this_ptr, "message", 2265848874UL, type, message);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Flash, warning){
zval *message, *type;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &message);
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "warning", 1);
phalcon_call_method_p2_key(return_value, this_ptr, "message", 2265848874UL, type, message);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Flash, outputMessage){
zval *type, *message, *automatic_html, *classes;
zval *type_classes, *joined_classes, *css_classes = NULL;
zval *implicit_flush, *content, *msg = NULL, *html_message = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
int flag_automatic_html;
int flag_implicit_flush;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &type, &message);
PHALCON_OBS_VAR(automatic_html);
phalcon_read_property_this_quick(&automatic_html, this_ptr, SL("_automaticHtml"), 1414140864UL, PH_NOISY_CC);
flag_automatic_html = PHALCON_IS_TRUE(automatic_html) ? 1 : 0;
if (flag_automatic_html) {
PHALCON_OBS_VAR(classes);
phalcon_read_property_this_quick(&classes, this_ptr, SL("_cssClasses"), 1944388667UL, PH_NOISY_CC);
if (phalcon_array_isset(classes, type)) {
PHALCON_OBS_VAR(type_classes);
phalcon_array_fetch(&type_classes, classes, type, PH_NOISY);
if (Z_TYPE_P(type_classes) == IS_ARRAY) {
PHALCON_INIT_VAR(joined_classes);
phalcon_fast_join_str(joined_classes, SL(" "), type_classes TSRMLS_CC);
PHALCON_INIT_VAR(css_classes);
PHALCON_CONCAT_SVS(css_classes, " class=\"", joined_classes, "\"");
} else {
PHALCON_INIT_NVAR(css_classes);
PHALCON_CONCAT_SVS(css_classes, " class=\"", type_classes, "\"");
}
} else {
PHALCON_INIT_NVAR(css_classes);
ZVAL_STRING(css_classes, "", 1);
}
}
PHALCON_OBS_VAR(implicit_flush);
phalcon_read_property_this_quick(&implicit_flush, this_ptr, SL("_implicitFlush"), 521244897UL, PH_NOISY_CC);
flag_implicit_flush = PHALCON_IS_TRUE(implicit_flush) ? 1 : 0;
if (Z_TYPE_P(message) == IS_ARRAY) {
if (!flag_implicit_flush) {
PHALCON_INIT_VAR(content);
ZVAL_EMPTY_STRING(content);
}
phalcon_is_iterable(message, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(msg);
if (flag_automatic_html) {
PHALCON_INIT_NVAR(html_message);
PHALCON_CONCAT_SVSVS(html_message, "<div", css_classes, ">", msg, "</div>" PHP_EOL);
} else {
PHALCON_CPY_WRT(html_message, msg);
}
if (flag_implicit_flush) {
zend_print_zval(html_message, 0);
} else {
phalcon_concat_self(&content, html_message TSRMLS_CC);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
if (!flag_implicit_flush) {
RETURN_CTOR(content);
}
} else {
if (flag_automatic_html) {
PHALCON_INIT_NVAR(html_message);
PHALCON_CONCAT_SVSVS(html_message, "<div", css_classes, ">", message, "</div>" PHP_EOL);
} else {
PHALCON_CPY_WRT(html_message, message);
}
if (flag_implicit_flush) {
zend_print_zval(html_message, 0);
} else {
RETURN_CCTOR(html_message);
}
}
PHALCON_MM_RESTORE();
}
zend_class_entry *phalcon_flashinterface_ce;
static const zend_function_entry phalcon_flashinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_FlashInterface, error, arginfo_phalcon_flashinterface_error)
PHP_ABSTRACT_ME(Phalcon_FlashInterface, notice, arginfo_phalcon_flashinterface_notice)
PHP_ABSTRACT_ME(Phalcon_FlashInterface, success, arginfo_phalcon_flashinterface_success)
PHP_ABSTRACT_ME(Phalcon_FlashInterface, warning, arginfo_phalcon_flashinterface_warning)
PHP_ABSTRACT_ME(Phalcon_FlashInterface, message, arginfo_phalcon_flashinterface_message)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_FlashInterface){
PHALCON_REGISTER_INTERFACE(Phalcon, FlashInterface, flashinterface, phalcon_flashinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_image_ce;
PHALCON_INIT_CLASS(Phalcon_Image){
PHALCON_REGISTER_CLASS(Phalcon, Image, image, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
/* Resizing constraints */
zend_declare_class_constant_long(phalcon_image_ce, SL("NONE"), PHALCON_IMAGE_NONE TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("WIDTH"), PHALCON_IMAGE_WIDTH TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("HEIGHT"), PHALCON_IMAGE_HEIGHT TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("AUTO"), PHALCON_IMAGE_AUTO TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("INVERSE"), PHALCON_IMAGE_INVERSE TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("PRECISE"), PHALCON_IMAGE_PRECISE TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("TENSILE"), PHALCON_IMAGE_TENSILE TSRMLS_CC);
/* Flipping directions */
zend_declare_class_constant_long(phalcon_image_ce, SL("HORIZONTAL"), PHALCON_IMAGE_HORIZONTAL TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("VERTICAL"), PHALCON_IMAGE_VERTICAL TSRMLS_CC);
/* Driver: GD, ImageMagick, etc */
zend_declare_class_constant_long(phalcon_image_ce, SL("GD"), PHALCON_IMAGE_GD TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("IMAGICK"), PHALCON_IMAGE_IMAGICK TSRMLS_CC);
return SUCCESS;
}
const char *phalcon_interned_DELETE = NULL;
const char *phalcon_interned_GET = NULL;
const char *phalcon_interned_HEAD = NULL;
const char *phalcon_interned_OPTIONS = NULL;
const char *phalcon_interned_PATCH = NULL;
const char *phalcon_interned_POST = NULL;
const char *phalcon_interned_PUT = NULL;
const char *phalcon_interned_alias = NULL;
const char *phalcon_interned_all = NULL;
const char *phalcon_interned_arguments = NULL;
const char *phalcon_interned_balias = NULL;
const char *phalcon_interned_binary_op = NULL;
const char *phalcon_interned_column = NULL;
const char *phalcon_interned_columns = NULL;
const char *phalcon_interned_conditions = NULL;
const char *phalcon_interned_delete = NULL;
const char *phalcon_interned_distinct = NULL;
const char *phalcon_interned_domain = NULL;
const char *phalcon_interned_escaper = NULL;
const char *phalcon_interned_expr = NULL;
const char *phalcon_interned_fields = NULL;
const char *phalcon_interned_file = NULL;
const char *phalcon_interned_filter = NULL;
const char *phalcon_interned_functionCall = NULL;
const char *phalcon_interned_group = NULL;
const char *phalcon_interned_groupBy = NULL;
const char *phalcon_interned_having = NULL;
const char *phalcon_interned_items = NULL;
const char *phalcon_interned_joins = NULL;
const char *phalcon_interned_left = NULL;
const char *phalcon_interned_limit = NULL;
const char *phalcon_interned_line = NULL;
const char *phalcon_interned_model = NULL;
const char *phalcon_interned_models = NULL;
const char *phalcon_interned_modelsCache = NULL;
const char *phalcon_interned_modelsManager = NULL;
const char *phalcon_interned_modelsMetadata = NULL;
const char *phalcon_interned_name = NULL;
const char *phalcon_interned_ns_alias = NULL;
const char *phalcon_interned_number = NULL;
const char *phalcon_interned_offset = NULL;
const char *phalcon_interned_op = NULL;
const char *phalcon_interned_order = NULL;
const char *phalcon_interned_orderBy = NULL;
const char *phalcon_interned_qualified = NULL;
const char *phalcon_interned_qualifiedName = NULL;
const char *phalcon_interned_right = NULL;
const char *phalcon_interned_select = NULL;
const char *phalcon_interned_sort = NULL;
const char *phalcon_interned_source = NULL;
const char *phalcon_interned_sqlAlias = NULL;
const char *phalcon_interned_table = NULL;
const char *phalcon_interned_tables = NULL;
const char *phalcon_interned_type = NULL;
const char *phalcon_interned_update = NULL;
const char *phalcon_interned_url = NULL;
const char *phalcon_interned_value = NULL;
const char *phalcon_interned_values = NULL;
const char *phalcon_interned_where = NULL;
PHALCON_STATIC void phalcon_init_interned_strings(TSRMLS_D)
{
phalcon_interned_DELETE = zend_new_interned_string(ZEND_STRS("DELETE"), 0 TSRMLS_CC);
phalcon_interned_GET = zend_new_interned_string(ZEND_STRS("GET"), 0 TSRMLS_CC);
phalcon_interned_HEAD = zend_new_interned_string(ZEND_STRS("HEAD"), 0 TSRMLS_CC);
phalcon_interned_OPTIONS = zend_new_interned_string(ZEND_STRS("OPTIONS"), 0 TSRMLS_CC);
phalcon_interned_PATCH = zend_new_interned_string(ZEND_STRS("PATCH"), 0 TSRMLS_CC);
phalcon_interned_POST = zend_new_interned_string(ZEND_STRS("POST"), 0 TSRMLS_CC);
phalcon_interned_PUT = zend_new_interned_string(ZEND_STRS("PUT"), 0 TSRMLS_CC);
phalcon_interned_alias = zend_new_interned_string(ZEND_STRS("alias"), 0 TSRMLS_CC);
phalcon_interned_all = zend_new_interned_string(ZEND_STRS("all"), 0 TSRMLS_CC);
phalcon_interned_arguments = zend_new_interned_string(ZEND_STRS("arguments"), 0 TSRMLS_CC);
phalcon_interned_balias = zend_new_interned_string(ZEND_STRS("balias"), 0 TSRMLS_CC);
phalcon_interned_binary_op = zend_new_interned_string(ZEND_STRS("binary-op"), 0 TSRMLS_CC);
phalcon_interned_column = zend_new_interned_string(ZEND_STRS("column"), 0 TSRMLS_CC);
phalcon_interned_columns = zend_new_interned_string(ZEND_STRS("columns"), 0 TSRMLS_CC);
phalcon_interned_conditions = zend_new_interned_string(ZEND_STRS("conditions"), 0 TSRMLS_CC);
phalcon_interned_delete = zend_new_interned_string(ZEND_STRS("delete"), 0 TSRMLS_CC);
phalcon_interned_distinct = zend_new_interned_string(ZEND_STRS("distinct"), 0 TSRMLS_CC);
phalcon_interned_domain = zend_new_interned_string(ZEND_STRS("domain"), 0 TSRMLS_CC);
phalcon_interned_escaper = zend_new_interned_string(ZEND_STRS("escaper"), 0 TSRMLS_CC);
phalcon_interned_expr = zend_new_interned_string(ZEND_STRS("expr"), 0 TSRMLS_CC);
phalcon_interned_fields = zend_new_interned_string(ZEND_STRS("fields"), 0 TSRMLS_CC);
phalcon_interned_file = zend_new_interned_string(ZEND_STRS("file"), 0 TSRMLS_CC);
phalcon_interned_filter = zend_new_interned_string(ZEND_STRS("filter"), 0 TSRMLS_CC);
phalcon_interned_functionCall = zend_new_interned_string(ZEND_STRS("functionCall"), 0 TSRMLS_CC);
phalcon_interned_group = zend_new_interned_string(ZEND_STRS("group"), 0 TSRMLS_CC);
phalcon_interned_groupBy = zend_new_interned_string(ZEND_STRS("groupBy"), 0 TSRMLS_CC);
phalcon_interned_having = zend_new_interned_string(ZEND_STRS("having"), 0 TSRMLS_CC);
phalcon_interned_items = zend_new_interned_string(ZEND_STRS("items"), 0 TSRMLS_CC);
phalcon_interned_joins = zend_new_interned_string(ZEND_STRS("joins"), 0 TSRMLS_CC);
phalcon_interned_left = zend_new_interned_string(ZEND_STRS("left"), 0 TSRMLS_CC);
phalcon_interned_limit = zend_new_interned_string(ZEND_STRS("limit"), 0 TSRMLS_CC);
phalcon_interned_line = zend_new_interned_string(ZEND_STRS("line"), 0 TSRMLS_CC);
phalcon_interned_model = zend_new_interned_string(ZEND_STRS("model"), 0 TSRMLS_CC);
phalcon_interned_models = zend_new_interned_string(ZEND_STRS("models"), 0 TSRMLS_CC);
phalcon_interned_modelsCache = zend_new_interned_string(ZEND_STRS("modelsCache"), 0 TSRMLS_CC);
phalcon_interned_modelsManager = zend_new_interned_string(ZEND_STRS("modelsManager"), 0 TSRMLS_CC);
phalcon_interned_modelsMetadata = zend_new_interned_string(ZEND_STRS("modelsMetadata"), 0 TSRMLS_CC);
phalcon_interned_name = zend_new_interned_string(ZEND_STRS("name"), 0 TSRMLS_CC);
phalcon_interned_ns_alias = zend_new_interned_string(ZEND_STRS("ns-alias"), 0 TSRMLS_CC);
phalcon_interned_number = zend_new_interned_string(ZEND_STRS("number"), 0 TSRMLS_CC);
phalcon_interned_offset = zend_new_interned_string(ZEND_STRS("offset"), 0 TSRMLS_CC);
phalcon_interned_op = zend_new_interned_string(ZEND_STRS("op"), 0 TSRMLS_CC);
phalcon_interned_order = zend_new_interned_string(ZEND_STRS("order"), 0 TSRMLS_CC);
phalcon_interned_orderBy = zend_new_interned_string(ZEND_STRS("orderBy"), 0 TSRMLS_CC);
phalcon_interned_qualified = zend_new_interned_string(ZEND_STRS("qualified"), 0 TSRMLS_CC);
phalcon_interned_qualifiedName = zend_new_interned_string(ZEND_STRS("qualifiedName"), 0 TSRMLS_CC);
phalcon_interned_right = zend_new_interned_string(ZEND_STRS("right"), 0 TSRMLS_CC);
phalcon_interned_select = zend_new_interned_string(ZEND_STRS("select"), 0 TSRMLS_CC);
phalcon_interned_sort = zend_new_interned_string(ZEND_STRS("sort"), 0 TSRMLS_CC);
phalcon_interned_source = zend_new_interned_string(ZEND_STRS("source"), 0 TSRMLS_CC);
phalcon_interned_sqlAlias = zend_new_interned_string(ZEND_STRS("sqlAlias"), 0 TSRMLS_CC);
phalcon_interned_table = zend_new_interned_string(ZEND_STRS("table"), 0 TSRMLS_CC);
phalcon_interned_tables = zend_new_interned_string(ZEND_STRS("tables"), 0 TSRMLS_CC);
phalcon_interned_type = zend_new_interned_string(ZEND_STRS("type"), 0 TSRMLS_CC);
phalcon_interned_update = zend_new_interned_string(ZEND_STRS("update"), 0 TSRMLS_CC);
phalcon_interned_url = zend_new_interned_string(ZEND_STRS("url"), 0 TSRMLS_CC);
phalcon_interned_value = zend_new_interned_string(ZEND_STRS("value"), 0 TSRMLS_CC);
phalcon_interned_values = zend_new_interned_string(ZEND_STRS("values"), 0 TSRMLS_CC);
phalcon_interned_where = zend_new_interned_string(ZEND_STRS("where"), 0 TSRMLS_CC);
}
zend_class_entry *phalcon_kernel_ce;
static PHP_METHOD(Phalcon_Kernel, preComputeHashKey);
static PHP_METHOD(Phalcon_Kernel, preComputeHashKey32);
static PHP_METHOD(Phalcon_Kernel, preComputeHashKey64);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_kernel_precomputehashkey, 0, 0, 1)
ZEND_ARG_INFO(0, arrKey)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_kernel_method_entry[] = {
PHP_ME(Phalcon_Kernel, preComputeHashKey, arginfo_phalcon_kernel_precomputehashkey, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Phalcon_Kernel, preComputeHashKey32, arginfo_phalcon_kernel_precomputehashkey, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Phalcon_Kernel, preComputeHashKey64, arginfo_phalcon_kernel_precomputehashkey, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Kernel){
PHALCON_REGISTER_CLASS(Phalcon, Kernel, kernel, phalcon_kernel_method_entry, 0);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Kernel, preComputeHashKey){
char *arKey, *strKey;
unsigned int nKeyLength;
register ulong hash = 5381;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) {
RETURN_NULL();
}
nKeyLength++;
/* variant with the hash unrolled eight times */
for (; nKeyLength >= 8; nKeyLength -= 8) {
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
}
switch (nKeyLength) {
case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 1: hash = ((hash << 5) + hash) + *arKey++; break;
case 0: break;
}
strKey = emalloc(24);
sprintf(strKey, "%lu", hash);
RETURN_STRING(strKey, 0);
}
static PHP_METHOD(Phalcon_Kernel, preComputeHashKey32){
char *arKey, *strKey;
unsigned int nKeyLength;
ulong hash;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) {
RETURN_NULL();
}
nKeyLength++;
hash = zend_inline_hash_func(arKey, nKeyLength) & 0xFFFFFFFFul;
strKey = emalloc(24);
sprintf(strKey, "%lu", hash);
RETURN_STRING(strKey, 0);
}
static PHP_METHOD(Phalcon_Kernel, preComputeHashKey64){
char *arKey, *strKey;
unsigned int nKeyLength;
register unsigned long long hash = 5381;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) {
RETURN_NULL();
}
nKeyLength++;
/* variant with the hash unrolled eight times */
for (; nKeyLength >= 8; nKeyLength -= 8) {
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
}
switch (nKeyLength) {
case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
case 1: hash = ((hash << 5) + hash) + *arKey++; break;
case 0: break;
}
strKey = emalloc(24);
sprintf(strKey, "%llu", hash);
RETURN_STRING(strKey, 0);
}
zend_class_entry *phalcon_loader_ce;
static PHP_METHOD(Phalcon_Loader, __construct);
static PHP_METHOD(Phalcon_Loader, setEventsManager);
static PHP_METHOD(Phalcon_Loader, getEventsManager);
static PHP_METHOD(Phalcon_Loader, setExtensions);
static PHP_METHOD(Phalcon_Loader, getExtensions);
static PHP_METHOD(Phalcon_Loader, registerNamespaces);
static PHP_METHOD(Phalcon_Loader, getNamespaces);
static PHP_METHOD(Phalcon_Loader, registerPrefixes);
static PHP_METHOD(Phalcon_Loader, getPrefixes);
static PHP_METHOD(Phalcon_Loader, registerDirs);
static PHP_METHOD(Phalcon_Loader, getDirs);
static PHP_METHOD(Phalcon_Loader, registerClasses);
static PHP_METHOD(Phalcon_Loader, getClasses);
static PHP_METHOD(Phalcon_Loader, register);
static PHP_METHOD(Phalcon_Loader, unregister);
static PHP_METHOD(Phalcon_Loader, autoLoad);
static PHP_METHOD(Phalcon_Loader, getFoundPath);
static PHP_METHOD(Phalcon_Loader, getCheckedPath);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_loader_setextensions, 0, 0, 1)
ZEND_ARG_INFO(0, extensions)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_loader_registernamespaces, 0, 0, 1)
ZEND_ARG_INFO(0, namespaces)
ZEND_ARG_INFO(0, merge)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_loader_registerprefixes, 0, 0, 1)
ZEND_ARG_INFO(0, prefixes)
ZEND_ARG_INFO(0, merge)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_loader_registerdirs, 0, 0, 1)
ZEND_ARG_INFO(0, directories)
ZEND_ARG_INFO(0, merge)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_loader_registerclasses, 0, 0, 1)
ZEND_ARG_INFO(0, classes)
ZEND_ARG_INFO(0, merge)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_loader_autoload, 0, 0, 1)
ZEND_ARG_INFO(0, className)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_loader_method_entry[] = {
PHP_ME(Phalcon_Loader, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Loader, setEventsManager, arginfo_phalcon_events_eventsawareinterface_seteventsmanager, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getEventsManager, arginfo_phalcon_events_eventsawareinterface_geteventsmanager, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, setExtensions, arginfo_phalcon_loader_setextensions, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getExtensions, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, registerNamespaces, arginfo_phalcon_loader_registernamespaces, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getNamespaces, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, registerPrefixes, arginfo_phalcon_loader_registerprefixes, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getPrefixes, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, registerDirs, arginfo_phalcon_loader_registerdirs, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getDirs, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, registerClasses, arginfo_phalcon_loader_registerclasses, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getClasses, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, register, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, unregister, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, autoLoad, arginfo_phalcon_loader_autoload, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getFoundPath, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Loader, getCheckedPath, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Loader){
PHALCON_REGISTER_CLASS(Phalcon, Loader, loader, phalcon_loader_method_entry, 0);
zend_declare_property_null(phalcon_loader_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_loader_ce, SL("_foundPath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_loader_ce, SL("_checkedPath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_loader_ce, SL("_prefixes"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_loader_ce, SL("_classes"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_loader_ce, SL("_extensions"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_loader_ce, SL("_namespaces"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_loader_ce, SL("_directories"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_loader_ce, SL("_registered"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_loader_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Loader, __construct){
zval *extensions;
PHALCON_ALLOC_GHOST_ZVAL(extensions);
array_init_size(extensions, 1);
add_next_index_stringl(extensions, SL("php"), 1);
phalcon_update_property_this_quick(this_ptr, SL("_extensions"), extensions, 726159316UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Loader, setEventsManager){
zval *events_manager;
phalcon_fetch_params(0, 1, 0, &events_manager);
phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Loader, getEventsManager){
RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL);
}
static PHP_METHOD(Phalcon_Loader, setExtensions){
zval *extensions;
phalcon_fetch_params(0, 1, 0, &extensions);
if (Z_TYPE_P(extensions) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_loader_exception_ce, "Parameter extensions must be an array");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_extensions"), extensions, 726159316UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Loader, getExtensions){
RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL);
}
static PHP_METHOD(Phalcon_Loader, registerNamespaces){
zval *namespaces, *merge = NULL, *current_namespaces;
zval *merged_namespaces = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &namespaces, &merge);
if (Z_TYPE_P(namespaces) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter namespaces must be an array");
return;
}
if (merge && zend_is_true(merge)) {
current_namespaces = phalcon_fetch_nproperty_this(this_ptr, SL("_namespaces"), PH_NOISY_CC);
if (Z_TYPE_P(current_namespaces) == IS_ARRAY) {
PHALCON_INIT_VAR(merged_namespaces);
phalcon_fast_array_merge(merged_namespaces, &current_namespaces, &namespaces TSRMLS_CC);
} else {
merged_namespaces = namespaces;
}
phalcon_update_property_this_quick(this_ptr, SL("_namespaces"), merged_namespaces, 3363620132UL TSRMLS_CC);
} else {
phalcon_update_property_this_quick(this_ptr, SL("_namespaces"), namespaces, 3363620132UL TSRMLS_CC);
}
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Loader, getNamespaces){
RETURN_MEMBER_QUICK(this_ptr, "_namespaces", 3363620132UL);
}
static PHP_METHOD(Phalcon_Loader, registerPrefixes){
zval *prefixes, *merge = NULL, *current_prefixes, *merged_prefixes = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &prefixes, &merge);
if (Z_TYPE_P(prefixes) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter prefixes must be an array");
return;
}
if (merge && zend_is_true(merge)) {
current_prefixes = phalcon_fetch_nproperty_this(this_ptr, SL("_prefixes"), PH_NOISY_CC);
if (Z_TYPE_P(current_prefixes) == IS_ARRAY) {
PHALCON_INIT_VAR(merged_prefixes);
phalcon_fast_array_merge(merged_prefixes, &current_prefixes, &prefixes TSRMLS_CC);
} else {
merged_prefixes = prefixes;
}
phalcon_update_property_this_quick(this_ptr, SL("_prefixes"), merged_prefixes, 900970058UL TSRMLS_CC);
} else {
phalcon_update_property_this_quick(this_ptr, SL("_prefixes"), prefixes, 900970058UL TSRMLS_CC);
}
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Loader, getPrefixes){
RETURN_MEMBER_QUICK(this_ptr, "_prefixes", 900970058UL);
}
static PHP_METHOD(Phalcon_Loader, registerDirs){
zval *directories, *merge = NULL, *current_directories;
zval *merged_directories = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &directories, &merge);
if (Z_TYPE_P(directories) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter directories must be an array");
return;
}
if (merge && zend_is_true(merge)) {
current_directories = phalcon_fetch_nproperty_this(this_ptr, SL("_directories"), PH_NOISY_CC);
if (Z_TYPE_P(current_directories) == IS_ARRAY) {
PHALCON_INIT_VAR(merged_directories);
phalcon_fast_array_merge(merged_directories, &current_directories, &directories TSRMLS_CC);
} else {
merged_directories = directories;
}
phalcon_update_property_this_quick(this_ptr, SL("_directories"), merged_directories, 3207828897UL TSRMLS_CC);
} else {
phalcon_update_property_this_quick(this_ptr, SL("_directories"), directories, 3207828897UL TSRMLS_CC);
}
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Loader, getDirs){
RETURN_MEMBER_QUICK(this_ptr, "_directories", 3207828897UL);
}
static PHP_METHOD(Phalcon_Loader, registerClasses){
zval *classes, *merge = NULL, *current_classes, *merged_classes = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &classes, &merge);
if (Z_TYPE_P(classes) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter classes must be an array");
return;
}
if (merge && zend_is_true(merge)) {
current_classes = phalcon_fetch_nproperty_this(this_ptr, SL("_classes"), PH_NOISY_CC);
if (Z_TYPE_P(current_classes) == IS_ARRAY) {
PHALCON_INIT_VAR(merged_classes);
phalcon_fast_array_merge(merged_classes, &current_classes, &classes TSRMLS_CC);
} else {
merged_classes = classes;
}
phalcon_update_property_this_quick(this_ptr, SL("_classes"), merged_classes, 3992428914UL TSRMLS_CC);
} else {
phalcon_update_property_this_quick(this_ptr, SL("_classes"), classes, 3992428914UL TSRMLS_CC);
}
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Loader, getClasses){
RETURN_MEMBER_QUICK(this_ptr, "_classes", 3992428914UL);
}
static PHP_METHOD(Phalcon_Loader, register){
zval *registered, *autoloader;
PHALCON_MM_GROW();
registered = phalcon_fetch_nproperty_this(this_ptr, SL("_registered"), PH_NOISY_CC);
if (PHALCON_IS_FALSE(registered)) {
PHALCON_INIT_VAR(autoloader);
array_init_size(autoloader, 2);
phalcon_array_append(&autoloader, this_ptr, 0);
add_next_index_stringl(autoloader, SL("autoLoad"), 1);
phalcon_call_func_p1_noret("spl_autoload_register", autoloader);
phalcon_update_property_this(this_ptr, SL("_registered"), PHALCON_GLOBAL(z_true) TSRMLS_CC);
}
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Loader, unregister){
zval *registered, *autoloader;
PHALCON_MM_GROW();
registered = phalcon_fetch_nproperty_this(this_ptr, SL("_registered"), PH_NOISY_CC);
if (PHALCON_IS_TRUE(registered)) {
PHALCON_INIT_VAR(autoloader);
array_init_size(autoloader, 2);
phalcon_array_append(&autoloader, this_ptr, 0);
add_next_index_stringl(autoloader, SL("autoLoad"), 1);
phalcon_call_func_p1_noret("spl_autoload_unregister", autoloader);
phalcon_update_property_this(this_ptr, SL("_registered"), PHALCON_GLOBAL(z_false) TSRMLS_CC);
}
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Loader, autoLoad){
zval *class_name, *events_manager, *event_name = NULL;
zval *classes, *file_path = NULL, *extensions, *ds, *namespace_separator;
zval *empty_str, *namespaces, *directory = NULL;
zval *ns_prefix = NULL, *file_name = NULL, *fixed_directory = NULL;
zval *extension = NULL, *pseudo_separator, *prefixes;
zval *prefix = NULL, *ds_class_name, *ns_class_name;
zval *directories;
HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5;
HashPosition hp0, hp1, hp2, hp3, hp4, hp5;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &class_name);
PHALCON_OBS_VAR(events_manager);
phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
PHALCON_INIT_VAR(event_name);
ZVAL_STRING(event_name, "loader:beforeCheckClass", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, class_name);
}
PHALCON_OBS_VAR(classes);
phalcon_read_property_this_quick(&classes, this_ptr, SL("_classes"), 3992428914UL, PH_NOISY_CC);
if (Z_TYPE_P(classes) == IS_ARRAY) {
if (phalcon_array_isset(classes, class_name)) {
PHALCON_OBS_VAR(file_path);
phalcon_array_fetch(&file_path, classes, class_name, PH_NOISY);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC);
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:pathFound", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, file_path);
}
if (phalcon_require(file_path TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
RETURN_MM_TRUE;
}
}
PHALCON_OBS_VAR(extensions);
phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC);
PHALCON_INIT_VAR(ds);
ZVAL_STRING(ds, PHALCON_DIRECTORY_SEPARATOR, 1);
PHALCON_INIT_VAR(namespace_separator);
ZVAL_STRING(namespace_separator, "\\", 1);
PHALCON_INIT_VAR(empty_str);
ZVAL_EMPTY_STRING(empty_str);
PHALCON_OBS_VAR(namespaces);
phalcon_read_property_this_quick(&namespaces, this_ptr, SL("_namespaces"), 3363620132UL, PH_NOISY_CC);
if (Z_TYPE_P(namespaces) == IS_ARRAY) {
phalcon_is_iterable(namespaces, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(ns_prefix, ah0, hp0);
PHALCON_GET_HVALUE(directory);
if (phalcon_start_with(class_name, ns_prefix, NULL)) {
PHALCON_INIT_NVAR(file_name);
phalcon_possible_autoload_filepath(file_name, ns_prefix, class_name, ds, NULL TSRMLS_CC);
if (zend_is_true(file_name)) {
PHALCON_INIT_NVAR(fixed_directory);
phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC);
phalcon_is_iterable(extensions, &ah1, &hp1, 0, 0);
while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
PHALCON_GET_HVALUE(extension);
PHALCON_INIT_NVAR(file_path);
PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC);
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:beforeCheckPath", 1);
phalcon_call_method_p2_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr);
}
if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) {
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC);
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:pathFound", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, file_path);
}
if (phalcon_require(file_path TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
RETURN_MM_TRUE;
}
zend_hash_move_forward_ex(ah1, &hp1);
}
}
}
zend_hash_move_forward_ex(ah0, &hp0);
}
}
PHALCON_INIT_VAR(pseudo_separator);
ZVAL_STRING(pseudo_separator, "_", 1);
PHALCON_OBS_VAR(prefixes);
phalcon_read_property_this_quick(&prefixes, this_ptr, SL("_prefixes"), 900970058UL, PH_NOISY_CC);
if (Z_TYPE_P(prefixes) == IS_ARRAY) {
phalcon_is_iterable(prefixes, &ah2, &hp2, 0, 0);
while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) {
PHALCON_GET_HKEY(prefix, ah2, hp2);
PHALCON_GET_HVALUE(directory);
if (phalcon_start_with(class_name, prefix, NULL)) {
PHALCON_INIT_NVAR(file_name);
phalcon_possible_autoload_filepath(file_name, prefix, class_name, ds, pseudo_separator TSRMLS_CC);
if (zend_is_true(file_name)) {
PHALCON_INIT_NVAR(fixed_directory);
phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC);
phalcon_is_iterable(extensions, &ah3, &hp3, 0, 0);
while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) {
PHALCON_GET_HVALUE(extension);
PHALCON_INIT_NVAR(file_path);
PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC);
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:beforeCheckPath", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, file_path);
}
if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) {
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC);
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:pathFound", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, file_path);
}
if (phalcon_require(file_path TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
RETURN_MM_TRUE;
}
zend_hash_move_forward_ex(ah3, &hp3);
}
}
}
zend_hash_move_forward_ex(ah2, &hp2);
}
}
PHALCON_INIT_VAR(ds_class_name);
phalcon_fast_str_replace(ds_class_name, pseudo_separator, ds, class_name);
PHALCON_INIT_VAR(ns_class_name);
phalcon_fast_str_replace(ns_class_name, namespace_separator, ds, ds_class_name);
PHALCON_OBS_VAR(directories);
phalcon_read_property_this_quick(&directories, this_ptr, SL("_directories"), 3207828897UL, PH_NOISY_CC);
if (Z_TYPE_P(directories) == IS_ARRAY) {
phalcon_is_iterable(directories, &ah4, &hp4, 0, 0);
while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) {
PHALCON_GET_HVALUE(directory);
PHALCON_INIT_NVAR(fixed_directory);
phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC);
phalcon_is_iterable(extensions, &ah5, &hp5, 0, 0);
while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) {
PHALCON_GET_HVALUE(extension);
PHALCON_INIT_NVAR(file_path);
PHALCON_CONCAT_VVSV(file_path, fixed_directory, ns_class_name, ".", extension);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC);
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:beforeCheckPath", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, file_path);
}
if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) {
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC);
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:pathFound", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, file_path);
}
if (phalcon_require(file_path TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
RETURN_MM_TRUE;
}
zend_hash_move_forward_ex(ah5, &hp5);
}
zend_hash_move_forward_ex(ah4, &hp4);
}
}
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "loader:afterCheckClass", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, class_name);
}
RETURN_MM_FALSE;
}
static PHP_METHOD(Phalcon_Loader, getFoundPath){
RETURN_MEMBER_QUICK(this_ptr, "_foundPath", 2210068013UL);
}
static PHP_METHOD(Phalcon_Loader, getCheckedPath){
RETURN_MEMBER_QUICK(this_ptr, "_checkedPath", 2930914648UL);
}
zend_class_entry *phalcon_logger_ce;
PHALCON_INIT_CLASS(Phalcon_Logger){
PHALCON_REGISTER_CLASS(Phalcon, Logger, logger, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_class_constant_long(phalcon_logger_ce, SL("SPECIAL"), PHALCON_LOGGER_SPECIAL TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("CUSTOM"), PHALCON_LOGGER_CUSTOM TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("DEBUG"), PHALCON_LOGGER_DEBUG TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("INFO"), PHALCON_LOGGER_INFO TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("NOTICE"), PHALCON_LOGGER_NOTICE TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("WARNING"), PHALCON_LOGGER_WARNING TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("ERROR"), PHALCON_LOGGER_ERROR TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("ALERT"), PHALCON_LOGGER_ALERT TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("CRITICAL"), PHALCON_LOGGER_CRITICAL TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("EMERGENCE"), PHALCON_LOGGER_EMERGENCY TSRMLS_CC);
zend_declare_class_constant_long(phalcon_logger_ce, SL("EMERGENCY"), PHALCON_LOGGER_EMERGENCY TSRMLS_CC);
return SUCCESS;
}
#include <math.h>
#ifdef PHALCON_USE_PHP_HASH
#include <ext/hash/php_hash.h>
#endif
zend_class_entry *phalcon_security_ce;
static PHP_METHOD(Phalcon_Security, setDI);
static PHP_METHOD(Phalcon_Security, getDI);
static PHP_METHOD(Phalcon_Security, setRandomBytes);
static PHP_METHOD(Phalcon_Security, getRandomBytes);
static PHP_METHOD(Phalcon_Security, setWorkFactor);
static PHP_METHOD(Phalcon_Security, getWorkFactor);
static PHP_METHOD(Phalcon_Security, getSaltBytes);
static PHP_METHOD(Phalcon_Security, hash);
static PHP_METHOD(Phalcon_Security, checkHash);
static PHP_METHOD(Phalcon_Security, isLegacyHash);
static PHP_METHOD(Phalcon_Security, getTokenKey);
static PHP_METHOD(Phalcon_Security, getToken);
static PHP_METHOD(Phalcon_Security, checkToken);
static PHP_METHOD(Phalcon_Security, getSessionToken);
static PHP_METHOD(Phalcon_Security, computeHmac);
static PHP_METHOD(Phalcon_Security, deriveKey);
static PHP_METHOD(Phalcon_Security, pbkdf2);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_setdi, 0, 0, 1)
ZEND_ARG_INFO(0, dependencyInjector)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_setrandombytes, 0, 0, 1)
ZEND_ARG_INFO(0, randomBytes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_setworkfactor, 0, 0, 1)
ZEND_ARG_INFO(0, workFactor)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_hash, 0, 0, 1)
ZEND_ARG_INFO(0, password)
ZEND_ARG_INFO(0, workFactor)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_checkhash, 0, 0, 2)
ZEND_ARG_INFO(0, password)
ZEND_ARG_INFO(0, passwordHash)
ZEND_ARG_INFO(0, maxPasswordLength)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_islegacyhash, 0, 0, 1)
ZEND_ARG_INFO(0, passwordHash)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_gettokenkey, 0, 0, 0)
ZEND_ARG_INFO(0, numberBytes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_gettoken, 0, 0, 0)
ZEND_ARG_INFO(0, numberBytes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_checktoken, 0, 0, 0)
ZEND_ARG_INFO(0, tokenKey)
ZEND_ARG_INFO(0, tokenValue)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_computehmac, 0, 0, 3)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, algo)
ZEND_ARG_INFO(0, raw)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_security_derivekey, 0, 0, 2)
ZEND_ARG_INFO(0, password)
ZEND_ARG_INFO(0, salt)
ZEND_ARG_INFO(0, hash)
ZEND_ARG_INFO(0, iterations)
ZEND_ARG_INFO(0, size)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_security_method_entry[] = {
PHP_ME(Phalcon_Security, setDI, arginfo_phalcon_security_setdi, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, getDI, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, setRandomBytes, arginfo_phalcon_security_setrandombytes, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, getRandomBytes, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, setWorkFactor, arginfo_phalcon_security_setworkfactor, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, getWorkFactor, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, getSaltBytes, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, hash, arginfo_phalcon_security_hash, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, checkHash, arginfo_phalcon_security_checkhash, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, isLegacyHash, arginfo_phalcon_security_islegacyhash, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, getTokenKey, arginfo_phalcon_security_gettokenkey, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, getToken, arginfo_phalcon_security_gettoken, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, checkToken, arginfo_phalcon_security_checktoken, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, getSessionToken, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Security, computeHmac, arginfo_phalcon_security_computehmac, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Phalcon_Security, deriveKey, arginfo_phalcon_security_derivekey, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Phalcon_Security, pbkdf2, arginfo_phalcon_security_derivekey, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Security){
PHALCON_REGISTER_CLASS(Phalcon, Security, security, phalcon_security_method_entry, 0);
zend_declare_property_null(phalcon_security_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(phalcon_security_ce, SL("_workFactor"), 8, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(phalcon_security_ce, SL("_numberBytes"), 16, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_security_ce, SL("_csrf"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_security_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Security, setDI){
zval *dependency_injector;
phalcon_fetch_params(0, 1, 0, &dependency_injector);
PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_security_exception_ce, 0);
phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Security, getDI){
RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL);
}
static PHP_METHOD(Phalcon_Security, setRandomBytes){
zval **random_bytes;
phalcon_fetch_params_ex(1, 0, &random_bytes);
PHALCON_ENSURE_IS_LONG(random_bytes);
if (PHALCON_LT_LONG(*random_bytes, 16)) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "At least 16 bytes are needed to produce a correct salt");
return;
}
phalcon_update_property_this(this_ptr, SL("_numberBytes"), *random_bytes TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Security, getRandomBytes){
RETURN_MEMBER_QUICK(this_ptr, "_numberBytes", 1300189556UL);
}
static PHP_METHOD(Phalcon_Security, setWorkFactor){
zval **work_factor;
phalcon_fetch_params_ex(1, 0, &work_factor);
PHALCON_ENSURE_IS_LONG(work_factor);
phalcon_update_property_this(this_ptr, SL("_workFactor"), *work_factor TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Security, getWorkFactor){
RETURN_MEMBER_QUICK(this_ptr, "_workFactor", 3598705926UL);
}
static PHP_METHOD(Phalcon_Security, getSaltBytes){
zval *number_bytes, *random_bytes = NULL, *base64bytes = NULL;
zval *safe_bytes = NULL, *bytes_length = NULL;
PHALCON_MM_GROW();
if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded");
return;
}
PHALCON_OBS_VAR(number_bytes);
phalcon_read_property_this_quick(&number_bytes, this_ptr, SL("_numberBytes"), 1300189556UL, PH_NOISY_CC);
while (1) {
PHALCON_INIT_NVAR(random_bytes);
phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes);
PHALCON_INIT_NVAR(base64bytes);
phalcon_base64_encode(base64bytes, random_bytes);
PHALCON_INIT_NVAR(safe_bytes);
phalcon_filter_alphanum(safe_bytes, base64bytes);
if (!zend_is_true(safe_bytes)) {
continue;
}
PHALCON_INIT_NVAR(bytes_length);
phalcon_fast_strlen(bytes_length, safe_bytes);
if (PHALCON_LT_LONG(bytes_length, 22)) {
continue;
}
break;
}
RETURN_CTOR(safe_bytes);
}
static PHP_METHOD(Phalcon_Security, hash){
zval *password, *work_factor = NULL, *format, *factor;
zval *salt_bytes, *salt;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &password, &work_factor);
if (!work_factor || Z_TYPE_P(work_factor) == IS_NULL) {
work_factor = phalcon_fetch_nproperty_this(this_ptr, SL("_workFactor"), PH_NOISY_CC);
}
PHALCON_INIT_VAR(format);
ZVAL_STRING(format, "%02s", 1);
PHALCON_INIT_VAR(factor);
phalcon_call_func_p2(factor, "sprintf", format, work_factor);
PHALCON_INIT_VAR(salt_bytes);
phalcon_call_method_key(salt_bytes, this_ptr, "getsaltbytes", 2293626208UL);
PHALCON_INIT_VAR(salt);
PHALCON_CONCAT_SVSV(salt, "$2a$", factor, "$", salt_bytes);
phalcon_call_func_p2(return_value, "crypt", password, salt);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Security, checkHash){
zval **password, **password_hash, **max_pass_length = NULL, *hash = NULL;
int check = 0;
phalcon_fetch_params_ex(2, 1, &password, &password_hash, &max_pass_length);
PHALCON_ENSURE_IS_STRING(password);
if (max_pass_length) {
PHALCON_ENSURE_IS_LONG(max_pass_length);
if (Z_LVAL_PP(max_pass_length) > 0 && Z_STRLEN_PP(password) > Z_LVAL_PP(max_pass_length)) {
RETURN_FALSE;
}
}
phalcon_call_func_params(hash, &hash, SL("crypt") TSRMLS_CC, 2, *password, *password_hash);
if (UNEXPECTED(EG(exception) != NULL)) {
RETURN_NULL();
}
if (UNEXPECTED(Z_TYPE_P(hash) != IS_STRING)) {
convert_to_string(hash);
}
if (Z_STRLEN_P(hash) == Z_STRLEN_PP(password_hash)) {
int n = Z_STRLEN_P(hash);
char *h1 = Z_STRVAL_P(hash);
char *h2 = Z_STRVAL_PP(password_hash);
while (n) {
check |= ((unsigned int)*h1) ^ ((unsigned int)*h2);
++h1;
++h2;
--n;
}
zval_ptr_dtor(&hash);
}
RETURN_BOOL(check == 0);
}
static PHP_METHOD(Phalcon_Security, isLegacyHash){
zval *password_hash;
phalcon_fetch_params(0, 1, 0, &password_hash);
if (phalcon_start_with_str(password_hash, SL("$2a$"))) {
RETURN_TRUE;
}
RETURN_FALSE;
}
static PHP_METHOD(Phalcon_Security, getTokenKey){
zval *number_bytes = NULL, *random_bytes, *base64bytes;
zval *safe_bytes, *dependency_injector, *service;
zval *session, *key;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &number_bytes);
if (!number_bytes) {
PHALCON_INIT_VAR(number_bytes);
ZVAL_LONG(number_bytes, 12);
}
if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded");
return;
}
PHALCON_INIT_VAR(random_bytes);
phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes);
PHALCON_INIT_VAR(base64bytes);
phalcon_base64_encode(base64bytes, random_bytes);
PHALCON_INIT_VAR(safe_bytes);
phalcon_filter_alphanum(safe_bytes, base64bytes);
PHALCON_OBS_VAR(dependency_injector);
phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "A dependency injection container is required to access the 'session' service");
return;
}
PHALCON_INIT_VAR(service);
ZVAL_STRING(service, "session", 1);
PHALCON_INIT_VAR(session);
phalcon_call_method_p1_key(session, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(session, phalcon_session_adapterinterface_ce);
PHALCON_INIT_VAR(key);
ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1);
phalcon_call_method_p2_key(NULL, session, "set", 2090720177UL, key, safe_bytes);
RETURN_CTOR(safe_bytes);
}
static PHP_METHOD(Phalcon_Security, getToken){
zval *number_bytes = NULL, *random_bytes, *token, *dependency_injector;
zval *service, *session, *key;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &number_bytes);
if (!number_bytes) {
PHALCON_INIT_VAR(number_bytes);
ZVAL_LONG(number_bytes, 12);
}
if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded");
return;
}
PHALCON_INIT_VAR(random_bytes);
phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes);
PHALCON_INIT_VAR(token);
phalcon_md5(token, random_bytes);
dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "A dependency injection container is required to access the 'session' service");
return;
}
PHALCON_ALLOC_GHOST_ZVAL(service);
ZVAL_STRING(service, "session", 1);
PHALCON_INIT_VAR(session);
phalcon_call_method_p1_key(session, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(session, phalcon_session_adapterinterface_ce);
PHALCON_ALLOC_GHOST_ZVAL(key);
ZVAL_STRING(key, "$PHALCON/CSRF$", 1);
phalcon_call_method_p2_key(NULL, session, "set", 2090720177UL, key, token);
RETURN_CTOR(token);
}
static PHP_METHOD(Phalcon_Security, checkToken){
zval *token_key = NULL, *token_value = NULL, *dependency_injector;
zval *service = NULL, *session, *key = NULL, *request, *token = NULL, *session_token;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 2, &token_key, &token_value);
if (!token_value) {
token_value = PHALCON_GLOBAL(z_null);
}
PHALCON_OBS_VAR(dependency_injector);
phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "A dependency injection container is required to access the 'session' service");
return;
}
PHALCON_INIT_VAR(service);
ZVAL_STRING(service, "session", 1);
PHALCON_INIT_VAR(session);
phalcon_call_method_p1_key(session, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(session, phalcon_session_adapterinterface_ce);
if (!token_key || Z_TYPE_P(token_key) == IS_NULL) {
PHALCON_INIT_VAR(key);
ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1);
PHALCON_INIT_VAR(token_key);
phalcon_call_method_p1_key(token_key, session, "get", 2090288933UL, key);
}
if (Z_TYPE_P(token_value) == IS_NULL) {
PHALCON_INIT_NVAR(service);
ZVAL_STRING(service, "request", 1);
PHALCON_INIT_VAR(request);
phalcon_call_method_p1_key(request, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(request, phalcon_http_requestinterface_ce);
PHALCON_INIT_VAR(token);
phalcon_call_method_p1_key(token, request, "getpost", 4289323083UL, token_key);
} else {
PHALCON_CPY_WRT(token, token_value);
}
PHALCON_INIT_NVAR(key);
ZVAL_STRING(key, "$PHALCON/CSRF$", 1);
PHALCON_INIT_VAR(session_token);
phalcon_call_method_p1_key(session_token, session, "get", 2090288933UL, key);
is_equal_function(return_value, token, session_token TSRMLS_CC);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Security, getSessionToken){
zval *dependency_injector, *service, *session;
zval *key;
PHALCON_MM_GROW();
dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "A dependency injection container is required to access the 'session' service");
return;
}
PHALCON_ALLOC_GHOST_ZVAL(service);
ZVAL_STRING(service, "session", 1);
PHALCON_INIT_VAR(session);
phalcon_call_method_p1_key(session, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(session, phalcon_session_adapterinterface_ce);
PHALCON_ALLOC_GHOST_ZVAL(key);
ZVAL_STRING(key, "$PHALCON/CSRF$", 1);
phalcon_return_call_method_p1(session, "get", key);
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Security, computeHmac)
{
zval **data, **key, **algo, **raw = NULL;
#ifdef PHALCON_USE_PHP_HASH
const php_hash_ops *ops;
void *context;
unsigned char *block, *digest;
int i;
#endif
phalcon_fetch_params_ex(3, 1, &data, &key, &algo, &raw);
if (!raw) {
raw = &(PHALCON_GLOBAL(z_false));
}
#ifdef PHALCON_USE_PHP_HASH
PHALCON_ENSURE_IS_STRING(data);
PHALCON_ENSURE_IS_STRING(key);
PHALCON_ENSURE_IS_STRING(algo);
ops = php_hash_fetch_ops(Z_STRVAL_PP(algo), Z_STRLEN_PP(algo));
if (!ops) {
zend_throw_exception_ex(phalcon_security_exception_ce, 0 TSRMLS_CC, "Unknown hashing algorithm: %s", Z_STRVAL_PP(algo));
return;
}
/* Allocate all memory we need in one chunk */
context = ecalloc(1, ops->context_size + ops->block_size);
block = (unsigned char*)context + ops->context_size;
digest = ecalloc(1, ops->digest_size + 1);
ops->hash_init(context);
if (Z_STRLEN_PP(key) > ops->block_size) {
/* Reduce the key */
ops->hash_update(context, (unsigned char*)(Z_STRVAL_PP(key)), Z_STRLEN_PP(key));
ops->hash_final(block, context);
/* Reinitialize the context */
ops->hash_init(context);
}
else {
memcpy(block, Z_STRVAL_PP(key), Z_STRLEN_PP(key));
}
for (i=0; i<ops->block_size; ++i) {
block[i] ^= 0x36;
}
ops->hash_update(context, block, ops->block_size);
ops->hash_update(context, (unsigned char*)(Z_STRVAL_PP(data)), Z_STRLEN_PP(data));
ops->hash_final(digest, context);
for(i=0; i < ops->block_size; i++) {
block[i] ^= 0x6A;
}
ops->hash_init(context);
ops->hash_update(context, block, ops->block_size);
ops->hash_update(context, digest, ops->digest_size);
ops->hash_final(digest, context);
memset(block, 0, ops->block_size);
efree(context);
if (!zend_is_true(*raw)) {
char *hex_digest = safe_emalloc(ops->digest_size, 2, 1);
php_hash_bin2hex(hex_digest, digest, ops->digest_size);
efree(digest);
hex_digest[2 * ops->digest_size] = 0;
RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0);
}
RETURN_STRINGL((char*)digest, ops->digest_size, 0);
#else
phalcon_call_func_params(return_value, return_value_ptr, SL("hash_hmac") TSRMLS_CC, 4, *algo, *data, *key, *raw);
if (unlikely(EG(exception) != NULL) && return_value_ptr) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
#endif
}
static PHP_METHOD(Phalcon_Security, pbkdf2)
{
zval **password, **salt, **hash = NULL, **iterations = NULL, **size = NULL;
char* s_hash;
int i_iterations = 0, i_size = 0;
phalcon_fetch_params_ex(2, 3, &password, &salt, &hash, &iterations, &size);
PHALCON_ENSURE_IS_STRING(password);
PHALCON_ENSURE_IS_STRING(salt);
if (Z_STRLEN_PP(salt) > INT_MAX - 4) {
zend_throw_exception_ex(phalcon_security_exception_ce, 0 TSRMLS_CC, "Salt is too long: %d", Z_STRLEN_PP(salt));
return;
}
s_hash = (!hash || Z_TYPE_PP(hash) != IS_STRING) ? "sha512" : Z_STRVAL_PP(hash);
if (iterations) {
PHALCON_ENSURE_IS_LONG(iterations);
i_iterations = Z_LVAL_PP(iterations);
}
if (i_iterations <= 0) {
i_iterations = 5000;
}
if (size) {
PHALCON_ENSURE_IS_LONG(size);
i_size = Z_LVAL_PP(size);
}
if (i_size < 0) {
i_size = 0;
}
{
zval *algo, *tmp, *K1 = NULL, *K2 = NULL, *computed_salt, *result;
int i_hash_len, block_count, i, j, k;
int salt_len = Z_STRLEN_PP(salt);
char *s;
PHALCON_MM_GROW();
PHALCON_INIT_VAR(algo);
ZVAL_STRING(algo, s_hash, 1);
PHALCON_OBS_VAR(tmp);
phalcon_call_func_p3_ex(tmp, &tmp, "hash", algo, PHALCON_GLOBAL(z_null), PHALCON_GLOBAL(z_true));
if (PHALCON_IS_FALSE(tmp) || Z_TYPE_P(tmp) != IS_STRING) {
RETURN_MM_FALSE;
}
i_hash_len = Z_STRLEN_P(tmp);
if (!i_size) {
i_size = i_hash_len;
}
PHALCON_INIT_VAR(computed_salt);
s = safe_emalloc(salt_len, 1, 5);
s[salt_len + 4] = 0;
memcpy(s, Z_STRVAL_PP(salt), salt_len);
ZVAL_STRINGL(computed_salt, s, salt_len + 4, 0);
PHALCON_INIT_VAR(result);
block_count = ceil((float)i_size / i_hash_len);
for (i=1; i<=block_count; ++i) {
s[salt_len+0] = (unsigned char)(i >> 24);
s[salt_len+1] = (unsigned char)(i >> 16);
s[salt_len+2] = (unsigned char)(i >> 8);
s[salt_len+3] = (unsigned char)(i);
PHALCON_INIT_NVAR(K1);
phalcon_call_func_p4(K1, "hash_hmac", algo, computed_salt, *password, PHALCON_GLOBAL(z_true));
PHALCON_CPY_WRT_CTOR(K2, K1);
for (j=1; j<i_iterations; ++j) {
char *k1, *k2;
PHALCON_INIT_NVAR(tmp);
phalcon_call_func_p4(tmp, "hash_hmac", algo, K1, *password, PHALCON_GLOBAL(z_true));
PHALCON_CPY_WRT(K1, tmp);
k1 = Z_STRVAL_P(K1);
k2 = Z_STRVAL_P(K2);
for (k=0; k<Z_STRLEN_P(K2); ++k) {
k2[k] ^= k1[k];
}
}
phalcon_concat_self(&result, K2 TSRMLS_CC);
}
if (i_size == i_hash_len) {
RETVAL_STRINGL(Z_STRVAL_P(result), Z_STRLEN_P(result), 0);
ZVAL_NULL(result);
}
else {
phalcon_substr(return_value, result, 0, i_size);
}
PHALCON_MM_RESTORE();
}
}
static PHP_METHOD(Phalcon_Security, deriveKey)
{
zval **password, **salt, **hash = NULL, **iterations = NULL, **size = NULL;
char* s_hash;
int i_iterations = 0, i_size = 0;
phalcon_fetch_params_ex(2, 3, &password, &salt, &hash, &iterations, &size);
PHALCON_ENSURE_IS_STRING(password);
PHALCON_ENSURE_IS_STRING(salt);
if (Z_STRLEN_PP(salt) > INT_MAX - 4) {
zend_throw_exception_ex(phalcon_security_exception_ce, 0 TSRMLS_CC, "Salt is too long: %d", Z_STRLEN_PP(salt));
return;
}
s_hash = (!hash || Z_TYPE_PP(hash) != IS_STRING) ? "sha512" : Z_STRVAL_PP(hash);
if (iterations) {
PHALCON_ENSURE_IS_LONG(iterations);
i_iterations = Z_LVAL_PP(iterations);
}
if (i_iterations <= 0) {
i_iterations = 5000;
}
if (size) {
PHALCON_ENSURE_IS_LONG(size);
i_size = Z_LVAL_PP(size);
}
if (i_size < 0) {
i_size = 0;
}
#if defined(PHALCON_USE_PHP_HASH)
{
const php_hash_ops *ops = php_hash_fetch_ops(s_hash, Z_STRLEN_PP(hash));
void *context;
unsigned char *K1, *K2, *digest, *temp, *result, *computed_salt;
long int i, j, loops, digest_length;
int salt_len = Z_STRLEN_PP(salt);
int pass_len = Z_STRLEN_PP(password);
int k;
if (!ops) {
zend_throw_exception_ex(phalcon_security_exception_ce, 0 TSRMLS_CC, "Unknown hashing algorithm: %s", s_hash);
return;
}
context = emalloc(ops->context_size);
ops->hash_init(context);
K1 = emalloc(2 * ops->block_size + 2 * ops->digest_size);
K2 = K1 + ops->block_size;
digest = K2 + ops->block_size;
temp = digest + ops->digest_size;
/* Set up keys that will be used for all HMAC rounds */
memset(K1, 0, ops->block_size);
if (pass_len > ops->block_size) {
ops->hash_init(context);
ops->hash_update(context, (unsigned char*)Z_STRVAL_PP(password), pass_len);
ops->hash_final(K1, context);
}
else {
memcpy(K1, Z_STRVAL_PP(password), pass_len);
}
for (i=0; i<ops->block_size; ++i) {
K2[i] = K1[i] ^ 0x5C;
K1[i] = K1[i] ^ 0x36;
}
digest_length = (i_size) ? i_size : ops->digest_size;
loops = ceil((float)digest_length / (float)ops->digest_size);
result = safe_emalloc(loops, ops->digest_size, 1);
computed_salt = safe_emalloc(salt_len, 1, 4);
memcpy(computed_salt, Z_STRVAL_PP(salt), salt_len);
for (i=1; i<=loops; ++i) {
computed_salt[salt_len+0] = (unsigned char)(i >> 24);
computed_salt[salt_len+1] = (unsigned char)(i >> 16);
computed_salt[salt_len+2] = (unsigned char)(i >> 8);
computed_salt[salt_len+3] = (unsigned char)(i);
ops->hash_init(context);
ops->hash_update(context, K1, ops->block_size);
ops->hash_update(context, computed_salt, (long int)(salt_len) + 4);
ops->hash_final(digest, context);
ops->hash_init(context);
ops->hash_update(context, K2, ops->block_size);
ops->hash_update(context, digest, ops->digest_size);
ops->hash_final(digest, context);
memcpy(temp, digest, ops->digest_size);
for (j=1; j<i_iterations; ++j) {
ops->hash_init(context);
ops->hash_update(context, K1, ops->block_size);
ops->hash_update(context, digest, ops->digest_size);
ops->hash_final(digest, context);
ops->hash_init(context);
ops->hash_update(context, K2, ops->block_size);
ops->hash_update(context, digest, ops->digest_size);
ops->hash_final(digest, context);
for (k=0; k<ops->digest_size; ++k) {
temp[k] ^= digest[k];
}
}
memcpy(result + (i-1)*ops->digest_size, temp, ops->digest_size);
}
memset(K1, 0, 2*ops->block_size);
memset(computed_salt, 0, salt_len + 4);
efree(K1);
efree(computed_salt);
efree(context);
if (digest_length != ops->digest_size) {
char *retval = safe_emalloc(i_size, 1, 1);
memcpy(retval, result, i_size);
retval[i_size] = 0;
efree(result);
RETVAL_STRINGL(retval, i_size, 0);
}
else {
result[digest_length] = 0;
RETVAL_STRINGL((char*)result, digest_length, 0);
}
}
#elif PHP_VERSION_ID >= 50000
{
zval *algo, *iter, *len;
MAKE_STD_ZVAL(algo);
ZVAL_STRING(algo, s_hash, 1);
MAKE_STD_ZVAL(iter);
ZVAL_LONG(iter, i_iterations);
MAKE_STD_ZVAL(len);
ZVAL_LONG(len, i_size);
phalcon_call_func_params(
return_value, return_value_ptr, SL("hash_pbkdf2") TSRMLS_CC, 6,
algo, *password, *salt, iter, len, PHALCON_GLOBAL(z_true)
);
if (UNEXPECTED(EG(exception) && return_value_ptr)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
zval_ptr_dtor(&algo);
zval_ptr_dtor(&iter);
zval_ptr_dtor(&len);
}
#else
ZEND_MN(Phalcon_Security_pbkdf2)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
#endif
}
zend_class_entry *phalcon_tag_ce;
static PHP_METHOD(Phalcon_Tag, setDI);
static PHP_METHOD(Phalcon_Tag, getDI);
static PHP_METHOD(Phalcon_Tag, getUrlService);
static PHP_METHOD(Phalcon_Tag, getEscaperService);
static PHP_METHOD(Phalcon_Tag, getAutoescape);
static PHP_METHOD(Phalcon_Tag, setAutoescape);
static PHP_METHOD(Phalcon_Tag, setDefault);
static PHP_METHOD(Phalcon_Tag, setDefaults);
static PHP_METHOD(Phalcon_Tag, hasValue);
static PHP_METHOD(Phalcon_Tag, getValue);
static PHP_METHOD(Phalcon_Tag, resetInput);
static PHP_METHOD(Phalcon_Tag, linkTo);
static PHP_METHOD(Phalcon_Tag, _inputField);
static PHP_METHOD(Phalcon_Tag, _inputFieldChecked);
static PHP_METHOD(Phalcon_Tag, colorField);
static PHP_METHOD(Phalcon_Tag, textField);
static PHP_METHOD(Phalcon_Tag, numericField);
static PHP_METHOD(Phalcon_Tag, rangeField);
static PHP_METHOD(Phalcon_Tag, emailField);
static PHP_METHOD(Phalcon_Tag, dateField);
static PHP_METHOD(Phalcon_Tag, dateTimeField);
static PHP_METHOD(Phalcon_Tag, dateTimeLocalField);
static PHP_METHOD(Phalcon_Tag, monthField);
static PHP_METHOD(Phalcon_Tag, timeField);
static PHP_METHOD(Phalcon_Tag, weekField);
static PHP_METHOD(Phalcon_Tag, passwordField);
static PHP_METHOD(Phalcon_Tag, hiddenField);
static PHP_METHOD(Phalcon_Tag, fileField);
static PHP_METHOD(Phalcon_Tag, checkField);
static PHP_METHOD(Phalcon_Tag, radioField);
static PHP_METHOD(Phalcon_Tag, imageInput);
static PHP_METHOD(Phalcon_Tag, searchField);
static PHP_METHOD(Phalcon_Tag, telField);
static PHP_METHOD(Phalcon_Tag, urlField);
static PHP_METHOD(Phalcon_Tag, submitButton);
static PHP_METHOD(Phalcon_Tag, selectStatic);
static PHP_METHOD(Phalcon_Tag, select);
static PHP_METHOD(Phalcon_Tag, textArea);
static PHP_METHOD(Phalcon_Tag, form);
static PHP_METHOD(Phalcon_Tag, endForm);
static PHP_METHOD(Phalcon_Tag, setTitle);
static PHP_METHOD(Phalcon_Tag, setTitleSeparator);
static PHP_METHOD(Phalcon_Tag, appendTitle);
static PHP_METHOD(Phalcon_Tag, prependTitle);
static PHP_METHOD(Phalcon_Tag, getTitleSeparator);
static PHP_METHOD(Phalcon_Tag, getTitle);
static PHP_METHOD(Phalcon_Tag, stylesheetLink);
static PHP_METHOD(Phalcon_Tag, javascriptInclude);
static PHP_METHOD(Phalcon_Tag, image);
static PHP_METHOD(Phalcon_Tag, friendlyTitle);
static PHP_METHOD(Phalcon_Tag, setDocType);
static PHP_METHOD(Phalcon_Tag, getDocType);
static PHP_METHOD(Phalcon_Tag, tagHtml);
static PHP_METHOD(Phalcon_Tag, tagHtmlClose);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_setdi, 0, 0, 1)
ZEND_ARG_INFO(0, dependencyInjector)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_setautoescape, 0, 0, 1)
ZEND_ARG_INFO(0, autoescape)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_setdefault, 0, 0, 2)
ZEND_ARG_INFO(0, id)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_setdefaults, 0, 0, 1)
ZEND_ARG_INFO(0, values)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_hasvalue, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_getvalue, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, params)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_linkto, 0, 0, 1)
ZEND_ARG_INFO(0, parameters)
ZEND_ARG_INFO(0, text)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_generic_field, 0, 0, 1)
ZEND_ARG_INFO(0, parameters)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_selectstatic, 0, 0, 1)
ZEND_ARG_INFO(0, parameters)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_select, 0, 0, 1)
ZEND_ARG_INFO(0, parameters)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_textarea, 0, 0, 1)
ZEND_ARG_INFO(0, parameters)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_form, 0, 0, 0)
ZEND_ARG_INFO(0, parameters)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_settitle, 0, 0, 1)
ZEND_ARG_INFO(0, title)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_settitleseparator, 0, 0, 1)
ZEND_ARG_INFO(0, separator)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_appendtitle, 0, 0, 1)
ZEND_ARG_INFO(0, title)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_prependtitle, 0, 0, 1)
ZEND_ARG_INFO(0, title)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_gettitle, 0, 0, 0)
ZEND_ARG_INFO(0, tags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_stylesheetlink, 0, 0, 0)
ZEND_ARG_INFO(0, parameters)
ZEND_ARG_INFO(0, local)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_javascriptinclude, 0, 0, 0)
ZEND_ARG_INFO(0, parameters)
ZEND_ARG_INFO(0, local)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_image, 0, 0, 0)
ZEND_ARG_INFO(0, parameters)
ZEND_ARG_INFO(0, local)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_friendlytitle, 0, 0, 1)
ZEND_ARG_INFO(0, text)
ZEND_ARG_INFO(0, separator)
ZEND_ARG_INFO(0, lowercase)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_setdoctype, 0, 0, 1)
ZEND_ARG_INFO(0, doctype)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_taghtml, 0, 0, 1)
ZEND_ARG_INFO(0, tagName)
ZEND_ARG_INFO(0, parameters)
ZEND_ARG_INFO(0, selfClose)
ZEND_ARG_INFO(0, onlyStart)
ZEND_ARG_INFO(0, useEol)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_taghtmlclose, 0, 0, 1)
ZEND_ARG_INFO(0, tagName)
ZEND_ARG_INFO(0, useEol)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_tag_method_entry[] = {
PHP_ME(Phalcon_Tag, setDI, arginfo_phalcon_tag_setdi, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getDI, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getUrlService, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getEscaperService, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getAutoescape, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setAutoescape, arginfo_phalcon_tag_setautoescape, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setDefault, arginfo_phalcon_tag_setdefault, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setDefaults, arginfo_phalcon_tag_setdefaults, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(Phalcon_Tag, displayTo, setDefault, arginfo_phalcon_tag_setdefault, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, hasValue, arginfo_phalcon_tag_hasvalue, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getValue, arginfo_phalcon_tag_getvalue, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, resetInput, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, linkTo, arginfo_phalcon_tag_linkto, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, _inputField, NULL, ZEND_ACC_STATIC|ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Tag, _inputFieldChecked, NULL, ZEND_ACC_STATIC|ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Tag, colorField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, textField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, numericField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, rangeField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, emailField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, dateField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, dateTimeField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, dateTimeLocalField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, monthField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, timeField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, weekField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, passwordField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, hiddenField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, searchField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, telField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, urlField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, fileField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, checkField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, radioField, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, imageInput, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, submitButton, arginfo_phalcon_tag_generic_field, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, selectStatic, arginfo_phalcon_tag_selectstatic, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, select, arginfo_phalcon_tag_select, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, textArea, arginfo_phalcon_tag_textarea, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Tag, form, arginfo_phalcon_tag_form, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, endForm, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setTitle, arginfo_phalcon_tag_settitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setTitleSeparator, arginfo_phalcon_tag_settitleseparator, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, appendTitle, arginfo_phalcon_tag_appendtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, prependTitle, arginfo_phalcon_tag_prependtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getTitle, arginfo_phalcon_tag_gettitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getTitleSeparator, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, stylesheetLink, arginfo_phalcon_tag_stylesheetlink, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, javascriptInclude, arginfo_phalcon_tag_javascriptinclude, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, image, arginfo_phalcon_tag_image, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, friendlyTitle, arginfo_phalcon_tag_friendlytitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setDocType, arginfo_phalcon_tag_setdoctype, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getDocType, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, tagHtml, arginfo_phalcon_tag_taghtml, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, tagHtmlClose, arginfo_phalcon_tag_taghtmlclose, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Tag){
PHALCON_REGISTER_CLASS(Phalcon, Tag, tag, phalcon_tag_method_entry, 0);
zend_declare_property_null(phalcon_tag_ce, SL("_displayValues"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_documentTitle"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_documentTitleSeparator"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_long(phalcon_tag_ce, SL("_documentType"), 11, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_urlService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_dispatcherService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_escaperService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_bool(phalcon_tag_ce, SL("_autoEscape"), 1, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML32"), 1 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_STRICT"), 2 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_TRANSITIONAL"), 3 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_FRAMESET"), 4 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML5"), 5 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_STRICT"), 6 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_TRANSITIONAL"), 7 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_FRAMESET"), 8 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML11"), 9 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML20"), 10 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML5"), 11 TSRMLS_CC);
return SUCCESS;
}
static void phalcon_tag_get_escaper(zval **return_value_ptr, zval *params TSRMLS_DC)
{
zval *autoescape, *result = NULL;
if (!phalcon_array_isset_string_fetch(&autoescape, params, SS("escape"))) {
autoescape = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_autoEscape") TSRMLS_CC);
}
if (zend_is_true(autoescape)) {
phalcon_call_static_func_params(result, &result, SL("phalcon\\tag"), SL("getescaperservice") TSRMLS_CC, 0);
if (EG(exception)) {
assert(result == NULL);
}
}
*return_value_ptr = result;
}
static zend_bool phalcon_tag_attribute_filter(HashTable *ht, void *pData, zend_hash_key *hash_key, void *pParam)
{
zval **z = (zval**)pData;
return hash_key->arKey && hash_key->nKeyLength && Z_TYPE_PP(z) != IS_ARRAY;
}
PHALCON_STATIC void phalcon_tag_render_attributes(zval *code, zval *attributes TSRMLS_DC)
{
zval *escaper, *escaped = NULL, *attrs;
zval **value;
HashPosition hp;
int i;
struct str_size_t {
const char *str;
uint size;
};
static const struct str_size_t order[9] = {
{ SS("type") },
{ SS("for") },
{ SS("src") },
{ SS("href") },
{ SS("action") },
{ SS("id") },
{ SS("name") },
{ SS("value") },
{ SS("class") },
};
assert(Z_TYPE_P(attributes) == IS_ARRAY);
PHALCON_MM_GROW();
PHALCON_OBS_VAR(escaper);
phalcon_tag_get_escaper(&escaper, attributes TSRMLS_CC);
if (EG(exception)) {
assert(escaper == NULL);
PHALCON_MM_RESTORE();
return;
}
PHALCON_INIT_VAR(attrs);
array_init_size(attrs, zend_hash_num_elements(Z_ARRVAL_P(attributes)));
for (i=0; i<sizeof(order)/sizeof(order[0]); ++i) {
if (phalcon_hash_find(Z_ARRVAL_P(attributes), order[i].str, order[i].size, (void**)&value) == SUCCESS) {
Z_ADDREF_PP(value);
add_assoc_zval_ex(attrs, order[i].str, order[i].size, *value);
}
}
zend_hash_merge_ex(Z_ARRVAL_P(attrs), Z_ARRVAL_P(attributes), (copy_ctor_func_t)zval_add_ref, sizeof(zval*), phalcon_tag_attribute_filter, NULL);
if (phalcon_array_isset_quick_string(attrs, SS("escape"), 1978755574UL)) {
phalcon_array_unset_string(&attrs, SS("escape"), 0);
}
if (escaper) {
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attrs), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(attrs), (void**)&value, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(attrs), &hp)
) {
zval key = phalcon_get_current_key_w(Z_ARRVAL_P(attrs), &hp);
if (Z_TYPE_P(&key) == IS_STRING) {
PHALCON_INIT_NVAR(escaped);
phalcon_call_method_p1_key(escaped, escaper, "escapehtmlattr", 4208410982UL, *value);
PHALCON_SCONCAT_SVSVS(code, " ", &key, "=\"", escaped, "\"");
}
}
}
else {
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attrs), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(attrs), (void**)&value, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(attrs), &hp)
) {
zval key = phalcon_get_current_key_w(Z_ARRVAL_P(attrs), &hp);
if (Z_TYPE_P(&key) == IS_STRING) {
PHALCON_SCONCAT_SVSVS(code, " ", &key, "=\"", *value, "\"");
}
}
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, setDI){
zval *dependency_injector;
phalcon_fetch_params(0, 1, 0, &dependency_injector);
PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_tag_exception_ce, 0);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_dependencyInjector"), dependency_injector TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Tag, getDI){
zval *dependency_injector;
dependency_injector = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_dependencyInjector") TSRMLS_CC);
RETURN_CTORW(dependency_injector);
}
static PHP_METHOD(Phalcon_Tag, getUrlService){
zval *url, *dependency_injector = NULL, *service;
PHALCON_MM_GROW();
url = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_urlService") TSRMLS_CC);
if (Z_TYPE_P(url) != IS_OBJECT) {
dependency_injector = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_dependencyInjector") TSRMLS_CC);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_INIT_VAR(dependency_injector);
phalcon_call_static(dependency_injector, "phalcon\\di", "getdefault");
}
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"url\" service");
return;
}
PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce);
PHALCON_INIT_VAR(service);
PHALCON_ZVAL_MAYBE_INTERNED_STRING(service, phalcon_interned_url);
PHALCON_INIT_VAR(url);
phalcon_call_method_p1_key(url, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(url, phalcon_mvc_urlinterface_ce);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_urlService"), url TSRMLS_CC);
}
RETURN_CTOR(url);
}
static PHP_METHOD(Phalcon_Tag, getEscaperService){
zval *escaper = NULL, *dependency_injector = NULL, *service;
PHALCON_MM_GROW();
escaper = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_escaperService") TSRMLS_CC);
if (Z_TYPE_P(escaper) != IS_OBJECT) {
dependency_injector = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_dependencyInjector") TSRMLS_CC);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_INIT_VAR(dependency_injector);
phalcon_call_static(dependency_injector, "phalcon\\di", "getdefault");
}
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"escaper\" service");
return;
}
PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce);
PHALCON_ALLOC_GHOST_ZVAL(service);
PHALCON_ZVAL_MAYBE_INTERNED_STRING(service, phalcon_interned_escaper);
PHALCON_INIT_VAR(escaper);
phalcon_call_method_p1_key(escaper, dependency_injector, "getshared", 1727570332UL, service);
PHALCON_VERIFY_INTERFACE(escaper, phalcon_escaperinterface_ce);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_escaperService"), escaper TSRMLS_CC);
}
RETURN_CTOR(escaper);
}
static PHP_METHOD(Phalcon_Tag, getAutoescape) {
zval *autoescape;
autoescape = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_autoEscape") TSRMLS_CC);
RETURN_ZVAL(autoescape, 1, 0);
}
static PHP_METHOD(Phalcon_Tag, setAutoescape){
zval *autoescape;
phalcon_fetch_params(0, 1, 0, &autoescape);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_autoEscape"), autoescape TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Tag, setDefault){
zval *id, *value, *t0;
int separate = 0;
phalcon_fetch_params(0, 2, 0, &id, &value);
if (Z_TYPE_P(value) != IS_NULL) {
if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "Only scalar values can be assigned to UI components");
return;
}
}
t0 = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_displayValues") TSRMLS_CC);
if (Z_REFCOUNT_P(t0) > 1) {
separate = 1;
ALLOC_INIT_ZVAL(t0);
Z_DELREF_P(t0);
}
if (Z_TYPE_P(t0) == IS_NULL) {
array_init_size(t0, 1);
}
else if (Z_TYPE_P(t0) != IS_ARRAY) {
convert_to_array(t0);
}
phalcon_array_update_zval(&t0, id, &value, PH_COPY);
if (separate) {
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), t0 TSRMLS_CC);
}
}
static PHP_METHOD(Phalcon_Tag, setDefaults){
zval *values;
phalcon_fetch_params(0, 1, 0, &values);
if (Z_TYPE_P(values) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values");
return;
}
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Tag, hasValue){
zval *name, *display_values, *_POST;
phalcon_fetch_params(0, 1, 0, &name);
display_values = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_displayValues") TSRMLS_CC);
if (phalcon_array_isset(display_values, name)) {
RETURN_TRUE;
}
PHALCON_MM_GROW();
phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC);
if (phalcon_array_isset(_POST, name)) {
RETURN_MM_TRUE;
}
RETURN_MM_FALSE;
}
static PHP_METHOD(Phalcon_Tag, getValue){
zval *name, *params = NULL, *display_values, *value = NULL, *_POST;
phalcon_fetch_params(0, 1, 1, &name, &params);
if (!params || !phalcon_array_isset_string_fetch(&value, params, SS("value"))) {
display_values = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_displayValues") TSRMLS_CC);
assert(value == NULL);
if (!phalcon_array_isset_fetch(&value, display_values, name)) {
assert(value == NULL);
PHALCON_MM_GROW();
phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC);
if (!phalcon_array_isset_fetch(&value, _POST, name)) {
RETURN_MM_NULL();
}
PHALCON_MM_RESTORE();
}
}
assert(value != NULL);
RETURN_ZVAL(value, 1, 0);
}
static PHP_METHOD(Phalcon_Tag, resetInput){
zval *empty_array;
MAKE_STD_ZVAL(empty_array);
array_init(empty_array);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), empty_array TSRMLS_CC);
phalcon_set_symbol_str(SS("_POST"), empty_array TSRMLS_CC);
zval_ptr_dtor(&empty_array);
}
static PHP_METHOD(Phalcon_Tag, linkTo){
zval *parameters, *text = NULL, *local = NULL, *params = NULL, *action, *url, *internal_url, *link_text, *z_local;
zval *code;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 2, &parameters, &text, &local);
if (!text) {
text = PHALCON_GLOBAL(z_null);
}
if (!local) {
local = PHALCON_GLOBAL(z_true);
}
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 3);
phalcon_array_append(&params, parameters, 0);
phalcon_array_append(&params, text, 0);
phalcon_array_append(&params, local, 0);
} else {
PHALCON_CPY_WRT_CTOR(params, parameters);
}
if (phalcon_array_isset_long_fetch(&action, params, 0)) {
} else if (phalcon_array_isset_string_fetch(&action, params, SS("action"))) {
phalcon_array_unset_string(&params, SS("action"), 0);
}
else {
PHALCON_INIT_VAR(action);
ZVAL_EMPTY_STRING(action);
}
if (phalcon_array_isset_long_fetch(&link_text, params, 1)) {
} else if (phalcon_array_isset_string_fetch(&link_text, params, SS("text"))) {
phalcon_array_unset_string(&params, SS("text"), 0);
}
else {
PHALCON_INIT_VAR(link_text);
ZVAL_EMPTY_STRING(link_text);
}
if (phalcon_array_isset_long_fetch(&z_local, params, 2)) {
} else if (phalcon_array_isset_string_fetch(&z_local, params, SS("local"))) {
phalcon_array_unset_string(&params, SS("local"), 0);
} else {
PHALCON_INIT_VAR(z_local);
ZVAL_TRUE(z_local);
}
if (zend_is_true(z_local)) {
PHALCON_INIT_VAR(url);
phalcon_call_self(url, this_ptr, "geturlservice");
PHALCON_INIT_VAR(internal_url);
phalcon_call_method_p1_key(internal_url, url, "get", 2090288933UL, action);
phalcon_array_update_quick_string(&params, SS("href"), 261698186UL, &internal_url, PH_COPY);
} else {
phalcon_array_update_quick_string(&params, SS("href"), 261698186UL, &action, PH_COPY);
}
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<a", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
PHALCON_CONCAT_VSVS(return_value, code, ">", link_text, "</a>");
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, _inputField){
zval *type, *parameters, *as_value = NULL, *params = NULL, *value = NULL;
zval *id = NULL, *name, *code, *doctype, *escaper;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 1, &type, &parameters, &as_value);
if (!as_value) {
as_value = PHALCON_GLOBAL(z_false);
}
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 1);
phalcon_array_append(&params, parameters, 0);
} else {
PHALCON_CPY_WRT_CTOR(params, parameters);
}
if (PHALCON_IS_FALSE(as_value)) {
PHALCON_INIT_VAR(value);
if (!phalcon_array_isset_long_fetch(&id, params, 0)) {
PHALCON_OBS_VAR(id);
phalcon_array_fetch_quick_string(&id, params, SS("id"), 193494642UL, PH_NOISY);
phalcon_array_update_long(&params, 0, &id, PH_COPY);
}
if (phalcon_array_isset_string_fetch(&name, params, SS("name"))) {
if (!zend_is_true(name)) {
phalcon_array_update_string(&params, ISL(name), &id, PH_COPY);
}
}
else {
phalcon_array_update_string(&params, ISL(name), &id, PH_COPY);
}
if (!phalcon_memnstr_str(id, SL("["))) {
if (!phalcon_array_isset_quick_string(params, SS("id"), 193494642UL)) {
phalcon_array_update_quick_string(&params, SS("id"), 193494642UL, &id, PH_COPY);
}
}
phalcon_call_self_p2(value, this_ptr, "getvalue", id, params);
phalcon_array_update_string(&params, ISL(value), &value, PH_COPY);
} else {
if (!phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) {
if (phalcon_array_isset_long_fetch(&value, params, 0)) {
phalcon_array_update_string(&params, ISL(value), &value, PH_COPY);
}
}
}
PHALCON_OBS_VAR(escaper);
phalcon_tag_get_escaper(&escaper, params TSRMLS_CC);
if (EG(exception)) {
assert(escaper == NULL);
PHALCON_MM_RESTORE();
return;
}
phalcon_array_update_string(&params, ISL(type), &type, PH_COPY);
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<input", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
doctype = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentType") TSRMLS_CC);
if (PHALCON_GT_LONG(doctype, 5)) {
PHALCON_CONCAT_VS(return_value, code, " />");
} else {
PHALCON_CONCAT_VS(return_value, code, ">");
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, _inputFieldChecked){
zval *type, *parameters, *params = NULL, *value = NULL, *id = NULL, *name;
zval *current_value, *code, *doctype;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &type, &parameters);
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 1);
phalcon_array_append(&params, parameters, 0);
} else {
PHALCON_CPY_WRT_CTOR(params, parameters);
}
if (!phalcon_array_isset_long_fetch(&id, params, 0)) {
PHALCON_OBS_VAR(id);
phalcon_array_fetch_quick_string(&id, params, SS("id"), 193494642UL, PH_NOISY);
phalcon_array_update_long(&params, 0, &id, PH_COPY);
}
if (!phalcon_array_isset_string_fetch(&name, params, SS("name"))) {
phalcon_array_update_string(&params, ISL(name), &id, PH_COPY);
} else {
if (!zend_is_true(name)) {
phalcon_array_update_string(&params, ISL(name), &id, PH_COPY);
}
}
if (!phalcon_memnstr_str(id, SL("["))) {
if (!phalcon_array_isset_quick_string(params, SS("id"), 193494642UL)) {
phalcon_array_update_quick_string(&params, SS("id"), 193494642UL, &id, PH_COPY);
}
}
PHALCON_INIT_VAR(value);
if (phalcon_array_isset_string_fetch(&current_value, params, SS("value"))) {
phalcon_array_unset_string(&params, SS("value"), 0);
phalcon_call_self_p2(value, this_ptr, "getvalue", id, params);
if (Z_TYPE_P(value) != IS_NULL && PHALCON_IS_EQUAL(current_value, value)) {
phalcon_array_update_string_string(&params, SL("checked"), SL("checked"), 0);
}
phalcon_array_update_string(&params, ISL(value), &current_value, PH_COPY);
} else {
phalcon_call_self_p2(value, this_ptr, "getvalue", id, params);
if (zend_is_true(value)) {
phalcon_array_update_string_string(&params, SL("checked"), SL("checked"), 0);
}
phalcon_array_update_string(&params, ISL(value), &value, PH_COPY);
}
phalcon_array_update_string(&params, ISL(type), &type, PH_COPY);
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<input", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
doctype = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentType") TSRMLS_CC);
if (PHALCON_GT_LONG(doctype, 5)) {
PHALCON_CONCAT_VS(return_value, code, " />");
} else {
PHALCON_CONCAT_VS(return_value, code, ">");
}
PHALCON_MM_RESTORE();
}
static void phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAMETERS, const char* type, int as_value)
{
zval *parameters, *field_type;
phalcon_fetch_params(0, 1, 0, &parameters);
PHALCON_ALLOC_GHOST_ZVAL(field_type);
ZVAL_STRING(field_type, type, 1);
if (as_value) {
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfield") TSRMLS_CC, 3, field_type, parameters, PHALCON_GLOBAL(z_true));
}
else {
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfield") TSRMLS_CC, 2, field_type, parameters);
}
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
static void phalcon_tag_generic_field_checked(INTERNAL_FUNCTION_PARAMETERS, const char* type)
{
zval *parameters, *field_type;
phalcon_fetch_params(0, 1, 0, &parameters);
MAKE_STD_ZVAL(field_type);
ZVAL_STRING(field_type, type, 1);
Z_DELREF_P(field_type);
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfieldchecked") TSRMLS_CC, 2, field_type, parameters);
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}
}
static PHP_METHOD(Phalcon_Tag, colorField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "color", 0);
}
static PHP_METHOD(Phalcon_Tag, textField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "text", 0);
}
static PHP_METHOD(Phalcon_Tag, numericField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "number", 0);
}
static PHP_METHOD(Phalcon_Tag, rangeField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "range", 0);
}
static PHP_METHOD(Phalcon_Tag, emailField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "email", 0);
}
static PHP_METHOD(Phalcon_Tag, dateField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "date", 0);
}
static PHP_METHOD(Phalcon_Tag, dateTimeField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "datetime", 0);
}
static PHP_METHOD(Phalcon_Tag, dateTimeLocalField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "datetime-local", 0);
}
static PHP_METHOD(Phalcon_Tag, monthField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "month", 0);
}
static PHP_METHOD(Phalcon_Tag, timeField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "time", 0);
}
static PHP_METHOD(Phalcon_Tag, weekField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "week", 0);
}
static PHP_METHOD(Phalcon_Tag, passwordField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "password", 0);
}
static PHP_METHOD(Phalcon_Tag, hiddenField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "hidden", 0);
}
static PHP_METHOD(Phalcon_Tag, fileField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "file", 0);
}
static PHP_METHOD(Phalcon_Tag, searchField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "search", 0);
}
static PHP_METHOD(Phalcon_Tag, telField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "tel", 0);
}
static PHP_METHOD(Phalcon_Tag, urlField){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "url", 0);
}
static PHP_METHOD(Phalcon_Tag, checkField){
phalcon_tag_generic_field_checked(INTERNAL_FUNCTION_PARAM_PASSTHRU, "checkbox");
}
static PHP_METHOD(Phalcon_Tag, radioField){
phalcon_tag_generic_field_checked(INTERNAL_FUNCTION_PARAM_PASSTHRU, "radio");
}
static PHP_METHOD(Phalcon_Tag, imageInput){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "image", 1);
}
static PHP_METHOD(Phalcon_Tag, submitButton){
phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAM_PASSTHRU, "submit", 1);
}
static PHP_METHOD(Phalcon_Tag, selectStatic){
zval *parameters, *data = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &parameters, &data);
if (!data) {
data = PHALCON_GLOBAL(z_null);
}
phalcon_return_call_static_p2("phalcon\\tag\\select", "selectfield", parameters, data);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Tag, select){
zval *parameters, *data = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &parameters, &data);
if (!data) {
data = PHALCON_GLOBAL(z_null);
}
phalcon_call_static_p2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Tag, textArea){
zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code;
zval *escaped, *escaper;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &parameters);
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 1);
phalcon_array_append(&params, parameters, 0);
} else {
PHALCON_CPY_WRT(params, parameters);
}
if (!phalcon_array_isset_long_fetch(&id, params, 0)) {
if (phalcon_array_isset_string_fetch(&id, params, SS("id"))) {
phalcon_array_update_long(&params, 0, &id, PH_COPY | PH_SEPARATE);
}
}
if (!phalcon_array_isset_string_fetch(&name, params, SS("name"))) {
phalcon_array_update_string(&params, ISL(name), &id, PH_COPY | PH_SEPARATE);
} else {
if (!zend_is_true(name)) {
phalcon_array_update_string(&params, ISL(name), &id, PH_COPY | PH_SEPARATE);
}
}
if (!phalcon_array_isset_quick_string(params, SS("id"), 193494642UL)) {
phalcon_array_update_quick_string(&params, SS("id"), 193494642UL, &id, PH_COPY | PH_SEPARATE);
}
PHALCON_INIT_NVAR(content);
phalcon_call_self_p2(content, this_ptr, "getvalue", id, params);
PHALCON_OBS_VAR(escaper);
phalcon_tag_get_escaper(&escaper, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
if (escaper) {
PHALCON_INIT_VAR(escaped);
phalcon_call_method_p1_key(escaped, escaper, "escapehtml", 2340217579UL, content);
}
else {
escaped = content;
}
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<textarea", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
PHALCON_CONCAT_VSVS(return_value, code, ">", escaped, "</textarea>");
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, form){
zval *parameters = NULL, *params = NULL, *params_action = NULL, *action = NULL;
zval *url, *code;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &parameters);
if (!parameters) {
PHALCON_INIT_VAR(parameters);
} else {
PHALCON_SEPARATE_PARAM(parameters);
}
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 1);
phalcon_array_append(&params, parameters, PH_SEPARATE);
} else {
PHALCON_CPY_WRT(params, parameters);
}
if (!phalcon_array_isset_long_fetch(&params_action, params, 0)) {
if (!phalcon_array_isset_string_fetch(&params_action, params, SS("action"))) {
assert(params_action == NULL);
PHALCON_INIT_VAR(params_action);
}
}
if (!phalcon_array_isset_quick_string(params, SS("method"), 3193080326UL)) {
phalcon_array_update_string_string(&params, SL("method"), SL("post"), PH_SEPARATE);
}
PHALCON_INIT_VAR(action);
if (Z_TYPE_P(params_action) != IS_NULL) {
PHALCON_INIT_VAR(url);
phalcon_call_self(url, this_ptr, "geturlservice");
phalcon_call_method_p1_key(action, url, "get", 2090288933UL, params_action);
}
if (phalcon_array_isset_string_fetch(&parameters, params, SS("parameters"))) {
PHALCON_SCONCAT_SV(action, "?", parameters);
}
if (Z_TYPE_P(action) != IS_NULL) {
phalcon_array_update_quick_string(&params, SS("action"), 502132067UL, &action, PH_COPY | PH_SEPARATE);
}
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<form", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
PHALCON_CONCAT_VS(return_value, code, ">");
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, endForm){
RETURN_STRING("</form>", 1);
}
static PHP_METHOD(Phalcon_Tag, setTitle){
zval *title;
phalcon_fetch_params(0, 1, 0, &title);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitle"), title TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Tag, setTitleSeparator){
zval *title_separator;
phalcon_fetch_params(0, 1, 0, &title_separator);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator"), title_separator TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Tag, appendTitle){
zval *title, *document_title, *document_title_separator, *r0;
phalcon_fetch_params(0, 1, 0, &title);
document_title = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC);
document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC);
ALLOC_INIT_ZVAL(r0);
PHALCON_CONCAT_VVV(r0, document_title, document_title_separator, title);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitle"), r0 TSRMLS_CC);
zval_ptr_dtor(&r0);
}
static PHP_METHOD(Phalcon_Tag, prependTitle){
zval *title, *document_title, *document_title_separator, *r0;
phalcon_fetch_params(0, 1, 0, &title);
document_title = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC);
document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC);
ALLOC_INIT_ZVAL(r0);
PHALCON_CONCAT_VVV(r0, title, document_title_separator, document_title);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitle"), r0 TSRMLS_CC);
zval_ptr_dtor(&r0);
}
static PHP_METHOD(Phalcon_Tag, getTitle){
zval *tags = NULL, *document_title;
phalcon_fetch_params(0, 0, 1, &tags);
document_title = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC);
if (!tags || zend_is_true(tags)) {
PHALCON_CONCAT_SVS(return_value, "<title>", document_title, "</title>" PHP_EOL);
}
else {
RETURN_ZVAL(document_title, 1, 0);
}
}
static PHP_METHOD(Phalcon_Tag, getTitleSeparator){
zval *document_title_separator;
document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC);
RETURN_ZVAL(document_title_separator, 1, 0);
}
static PHP_METHOD(Phalcon_Tag, stylesheetLink){
zval *parameters = NULL, *local = NULL, *params = NULL, *first_param;
zval *url, *url_href, *href, *code, *doctype, *z_local;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 2, &parameters, &local);
if (!parameters) {
parameters = PHALCON_GLOBAL(z_null);
}
if (!local) {
local = PHALCON_GLOBAL(z_true);
}
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 2);
phalcon_array_append(&params, parameters, 0);
phalcon_array_append(&params, local, 0);
} else {
PHALCON_CPY_WRT(params, parameters);
}
if (!phalcon_array_isset_quick_string(params, SS("href"), 261698186UL)) {
if (phalcon_array_isset_long_fetch(&first_param, params, 0)) {
phalcon_array_update_quick_string(&params, SS("href"), 261698186UL, &first_param, PH_COPY | PH_SEPARATE);
} else {
phalcon_array_update_string_string(&params, SL("href"), SL(""), PH_SEPARATE);
}
}
if (phalcon_array_isset_long_fetch(&z_local, params, 1)) {
} else if (phalcon_array_isset_string_fetch(&z_local, params, SS("local"))) {
phalcon_array_unset_string(&params, SS("local"), PH_SEPARATE);
}
else {
PHALCON_INIT_VAR(z_local);
ZVAL_TRUE(z_local);
}
if (!phalcon_array_isset_quick_string(params, SS("type"), 276192743UL)) {
phalcon_array_update_string_string(&params, ISL(type), SL("text/css"), PH_SEPARATE);
}
if (zend_is_true(z_local)) {
PHALCON_INIT_VAR(url);
phalcon_call_self(url, this_ptr, "geturlservice");
PHALCON_OBS_VAR(url_href);
phalcon_array_fetch_quick_string(&url_href, params, SS("href"), 261698186UL, PH_NOISY);
PHALCON_INIT_VAR(href);
phalcon_call_method_p1_key(href, url, "getstatic", 2197271245UL, url_href);
phalcon_array_update_quick_string(&params, SS("href"), 261698186UL, &href, PH_COPY | PH_SEPARATE);
}
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<link rel=\"stylesheet\"", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
doctype = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentType") TSRMLS_CC);
if (PHALCON_GT_LONG(doctype, 5)) {
PHALCON_CONCAT_VS(return_value, code, " />" PHP_EOL);
} else {
PHALCON_CONCAT_VS(return_value, code, ">" PHP_EOL);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, javascriptInclude){
zval *parameters = NULL, *local = NULL, *params = NULL, *first_param;
zval *url, *params_src, *src, *code, *z_local;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 2, &parameters, &local);
if (!parameters) {
parameters = PHALCON_GLOBAL(z_null);
}
if (!local) {
local = PHALCON_GLOBAL(z_true);
}
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 2);
phalcon_array_append(&params, parameters, 0);
phalcon_array_append(&params, local, 0);
} else {
PHALCON_CPY_WRT(params, parameters);
}
if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) {
if (phalcon_array_isset_long_fetch(&first_param, params, 0)) {
phalcon_array_update_quick_string(&params, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE);
} else {
phalcon_array_update_string_string(&params, SL("src"), SL(""), PH_SEPARATE);
}
}
if (phalcon_array_isset_long_fetch(&z_local, params, 1)) {
} else if (phalcon_array_isset_string_fetch(&z_local, params, SS("local"))) {
phalcon_array_unset_string(&params, SS("local"), PH_SEPARATE);
} else {
PHALCON_INIT_VAR(z_local);
ZVAL_TRUE(z_local);
}
if (!phalcon_array_isset_quick_string(params, SS("type"), 276192743UL)) {
phalcon_array_update_string_string(&params, ISL(type), SL("text/javascript"), PH_SEPARATE);
}
if (zend_is_true(z_local)) {
PHALCON_INIT_VAR(url);
phalcon_call_self(url, this_ptr, "geturlservice");
PHALCON_OBS_VAR(params_src);
phalcon_array_fetch_quick_string(&params_src, params, SS("src"), 2090733773UL, PH_NOISY);
PHALCON_INIT_VAR(src);
phalcon_call_method_p1_key(src, url, "getstatic", 2197271245UL, params_src);
phalcon_array_update_quick_string(&params, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE);
}
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<script", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
PHALCON_CONCAT_VS(return_value, code, "></script>" PHP_EOL);
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, image){
zval *parameters = NULL, *local = NULL, *params = NULL, *first_param, *second_param;
zval *url, *url_src, *src, *code, *doctype;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 2, &parameters, &local);
if (!parameters) {
parameters = PHALCON_GLOBAL(z_null);
}
if (!local) {
PHALCON_INIT_VAR(local);
if (Z_TYPE_P(parameters) == IS_ARRAY && phalcon_array_isset_long_fetch(&second_param, parameters, 1)) {
ZVAL_BOOL(local, zend_is_true(second_param));
} else {
ZVAL_TRUE(local);
}
}
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 1);
phalcon_array_append(&params, parameters, 0);
} else {
PHALCON_CPY_WRT(params, parameters);
}
if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) {
if (phalcon_array_isset_long_fetch(&first_param, params, 0)) {
phalcon_array_update_quick_string(&params, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE);
} else {
phalcon_array_update_string_string(&params, SL("src"), SL(""), PH_SEPARATE);
}
}
if (zend_is_true(local)) {
PHALCON_INIT_VAR(url);
phalcon_call_self(url, this_ptr, "geturlservice");
PHALCON_OBS_VAR(url_src);
phalcon_array_fetch_quick_string(&url_src, params, SS("src"), 2090733773UL, PH_NOISY);
PHALCON_INIT_VAR(src);
phalcon_call_method_p1_key(src, url, "getstatic", 2197271245UL, url_src);
phalcon_array_update_quick_string(&params, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE);
}
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<img", 1);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
doctype = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentType") TSRMLS_CC);
if (PHALCON_GT_LONG(doctype, 5)) {
PHALCON_CONCAT_VS(return_value, code, " />");
} else {
PHALCON_CONCAT_VS(return_value, code, ">");
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, friendlyTitle){
zval *text, *separator = NULL, *lowercase = NULL, *pattern, *friendly;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 2, &text, &separator, &lowercase);
if (!separator) {
PHALCON_INIT_VAR(separator);
ZVAL_STRING(separator, "-", 1);
}
if (!lowercase) {
lowercase = PHALCON_GLOBAL(z_true);
}
PHALCON_INIT_VAR(pattern);
ZVAL_STRING(pattern, "~[^a-z0-9A-Z]+~", 1);
PHALCON_INIT_VAR(friendly);
phalcon_call_func_p3(friendly, "preg_replace", pattern, separator, text);
if (zend_is_true(lowercase)) {
phalcon_fast_strtolower(return_value, friendly);
} else {
RETVAL_ZVAL(friendly, 1, 0);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Tag, setDocType){
zval *doctype;
phalcon_fetch_params(0, 1, 0, &doctype);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentType"), doctype TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Tag, getDocType){
zval *doctype;
doctype = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentType") TSRMLS_CC);
switch (phalcon_get_intval(doctype)) {
case 1: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" PHP_EOL, 1);
/* no break */
case 2: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"" PHP_EOL "\t\"http://www.w3.org/TR/html4/strict.dtd\">" PHP_EOL, 1);
/* no break */
case 3: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" PHP_EOL "\t\"http://www.w3.org/TR/html4/loose.dtd\">" PHP_EOL, 1);
/* no break */
case 4: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"" PHP_EOL"\t\"http://www.w3.org/TR/html4/frameset.dtd\">" PHP_EOL, 1);
/* no break */
case 5: RETURN_STRING("<!DOCTYPE html>" PHP_EOL, 1);
/* no break */
case 6: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" PHP_EOL "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" PHP_EOL, 1);
/* no break */
case 7: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" PHP_EOL "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" PHP_EOL, 1);
/* no break */
case 8: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"" PHP_EOL "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">" PHP_EOL, 1);
/* no break */
case 9: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"" PHP_EOL"\t\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">" PHP_EOL, 1);
/* no break */
case 10: RETURN_STRING("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 2.0//EN\"" PHP_EOL "\t\"http://www.w3.org/MarkUp/DTD/xhtml2.dtd\">" PHP_EOL, 1);
/* no break */
default: RETURN_EMPTY_STRING();
}
}
static PHP_METHOD(Phalcon_Tag, tagHtml){
zval *tag_name, *parameters = NULL, *self_close = NULL, *only_start = NULL;
zval *use_eol = NULL, *params = NULL, *local_code, *doctype;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 4, &tag_name, &parameters, &self_close, &only_start, &use_eol);
if (!parameters) {
parameters = PHALCON_GLOBAL(z_null);
}
if (!self_close) {
self_close = PHALCON_GLOBAL(z_false);
}
if (!only_start) {
only_start = PHALCON_GLOBAL(z_false);
}
if (!use_eol) {
use_eol = PHALCON_GLOBAL(z_false);
}
if (Z_TYPE_P(parameters) != IS_ARRAY) {
PHALCON_INIT_VAR(params);
array_init_size(params, 1);
phalcon_array_append(&params, parameters, 0);
} else {
PHALCON_CPY_WRT(params, parameters);
}
PHALCON_INIT_VAR(local_code);
PHALCON_CONCAT_SV(local_code, "<", tag_name);
phalcon_tag_render_attributes(local_code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
}
doctype = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentType") TSRMLS_CC);
if (PHALCON_GT_LONG(doctype, 5)) {
if (zend_is_true(self_close)) {
phalcon_concat_self_str(&local_code, SL(" />") TSRMLS_CC);
} else {
phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC);
}
} else {
if (zend_is_true(only_start)) {
phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC);
} else {
PHALCON_SCONCAT_SVS(local_code, "></", tag_name, ">");
}
}
if (zend_is_true(use_eol)) {
phalcon_concat_self_str(&local_code, SL(PHP_EOL) TSRMLS_CC);
}
RETURN_CTOR(local_code);
}
static PHP_METHOD(Phalcon_Tag, tagHtmlClose){
zval *tag_name, *use_eol = NULL, *local_code;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &tag_name, &use_eol);
if (!use_eol) {
use_eol = PHALCON_GLOBAL(z_false);
}
PHALCON_INIT_VAR(local_code);
PHALCON_CONCAT_SVS(local_code, "</", tag_name, ">");
if (zend_is_true(use_eol)) {
phalcon_concat_self_str(&local_code, SL(PHP_EOL) TSRMLS_CC);
}
RETURN_CTOR(local_code);
}
zend_class_entry *phalcon_text_ce;
static PHP_METHOD(Phalcon_Text, camelize);
static PHP_METHOD(Phalcon_Text, uncamelize);
static PHP_METHOD(Phalcon_Text, increment);
static PHP_METHOD(Phalcon_Text, random);
static PHP_METHOD(Phalcon_Text, startsWith);
static PHP_METHOD(Phalcon_Text, endsWith);
static PHP_METHOD(Phalcon_Text, lower);
static PHP_METHOD(Phalcon_Text, upper);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_camelize, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_uncamelize, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_increment, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, separator)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_random, 0, 0, 1)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, length)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_startswith, 0, 0, 2)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, ignoreCase)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_endswith, 0, 0, 2)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, end)
ZEND_ARG_INFO(0, ignoreCase)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_lower, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_upper, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_text_method_entry[] = {
PHP_ME(Phalcon_Text, camelize, arginfo_phalcon_text_camelize, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Text, uncamelize, arginfo_phalcon_text_uncamelize, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Text, increment, arginfo_phalcon_text_increment, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Text, random, arginfo_phalcon_text_random, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Text, startsWith, arginfo_phalcon_text_startswith, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Text, endsWith, arginfo_phalcon_text_endswith, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Text, lower, arginfo_phalcon_text_lower, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Text, upper, arginfo_phalcon_text_upper, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Text){
PHALCON_REGISTER_CLASS(Phalcon, Text, text, phalcon_text_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_ALNUM"), PHALCON_TEXT_RANDOM_ALNUM TSRMLS_CC);
zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_ALPHA"), PHALCON_TEXT_RANDOM_ALPHA TSRMLS_CC);
zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_HEXDEC"), PHALCON_TEXT_RANDOM_HEXDEC TSRMLS_CC);
zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_NUMERIC"), PHALCON_TEXT_RANDOM_NUMERIC TSRMLS_CC);
zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_NOZERO"), PHALCON_TEXT_RANDOM_NOZERO TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Text, camelize){
zval *str;
phalcon_fetch_params(0, 1, 0, &str);
phalcon_camelize(return_value, str);
return;
}
static PHP_METHOD(Phalcon_Text, uncamelize){
zval *str;
phalcon_fetch_params(0, 1, 0, &str);
phalcon_uncamelize(return_value, str);
return;
}
static PHP_METHOD(Phalcon_Text, increment){
zval *str, *separator = NULL, *parts, *number = NULL, *first_part;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &str, &separator);
if (!separator) {
PHALCON_INIT_VAR(separator);
} else {
PHALCON_SEPARATE_PARAM(separator);
}
if (Z_TYPE_P(separator) == IS_NULL) {
PHALCON_INIT_NVAR(separator);
ZVAL_STRING(separator, "_", 1);
}
PHALCON_INIT_VAR(parts);
phalcon_fast_explode(parts, separator, str);
if (phalcon_array_isset_long(parts, 1)) {
PHALCON_OBS_VAR(number);
phalcon_array_fetch_long(&number, parts, 1, PH_NOISY);
SEPARATE_ZVAL(&number);
phalcon_increment(number);
} else {
number = PHALCON_GLOBAL(z_one);
}
PHALCON_OBS_VAR(first_part);
phalcon_array_fetch_long(&first_part, parts, 0, PH_NOISY);
PHALCON_CONCAT_VVV(return_value, first_part, separator, number);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Text, random){
zval *type, *length = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &type, &length);
if (!length) {
PHALCON_INIT_VAR(length);
ZVAL_LONG(length, 8);
}
phalcon_random_string(return_value, type, length TSRMLS_CC);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Text, startsWith){
zval *str, *start, *ignore_case = NULL;
zval *case_sensitive;
phalcon_fetch_params(0, 2, 1, &str, &start, &ignore_case);
if (!ignore_case) {
case_sensitive = PHALCON_GLOBAL(z_false);
}
else {
case_sensitive = zend_is_true(ignore_case) ? PHALCON_GLOBAL(z_false) : PHALCON_GLOBAL(z_true);
}
RETURN_BOOL(phalcon_start_with(str, start, case_sensitive));
}
static PHP_METHOD(Phalcon_Text, endsWith){
zval *str, *end, *ignore_case = NULL;
zval *case_sensitive;
phalcon_fetch_params(0, 2, 1, &str, &end, &ignore_case);
if (!ignore_case) {
case_sensitive = PHALCON_GLOBAL(z_false);
}
else {
case_sensitive = zend_is_true(ignore_case) ? PHALCON_GLOBAL(z_false) : PHALCON_GLOBAL(z_true);
}
RETURN_BOOL(phalcon_end_with(str, end, case_sensitive));
}
static PHP_METHOD(Phalcon_Text, lower){
zval *str;
phalcon_fetch_params(0, 1, 0, &str);
if (phalcon_function_quick_exists_ex(SS("mb_strtolower"), 3802586680UL TSRMLS_CC) == SUCCESS) {
PHALCON_MM_GROW();
phalcon_call_func_p1(return_value, "mb_strtolower", str);
RETURN_MM();
}
phalcon_fast_strtolower(return_value, str);
}
static PHP_METHOD(Phalcon_Text, upper){
zval *str;
phalcon_fetch_params(0, 1, 0, &str);
if (phalcon_function_quick_exists_ex(SS("mb_strtoupper"), 4155739579UL TSRMLS_CC) == SUCCESS) {
PHALCON_MM_GROW();
phalcon_call_func_p1(return_value, "mb_strtoupper", str);
RETURN_MM();
}
phalcon_fast_strtoupper(return_value, str);
}
zend_class_entry *phalcon_validation_ce;
static PHP_METHOD(Phalcon_Validation, __construct);
static PHP_METHOD(Phalcon_Validation, validate);
static PHP_METHOD(Phalcon_Validation, add);
static PHP_METHOD(Phalcon_Validation, setFilters);
static PHP_METHOD(Phalcon_Validation, getFilters);
static PHP_METHOD(Phalcon_Validation, getValidators);
static PHP_METHOD(Phalcon_Validation, getEntity);
static PHP_METHOD(Phalcon_Validation, getMessages);
static PHP_METHOD(Phalcon_Validation, appendMessage);
static PHP_METHOD(Phalcon_Validation, bind);
static PHP_METHOD(Phalcon_Validation, getValue);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation___construct, 0, 0, 0)
ZEND_ARG_INFO(0, validators)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_validate, 0, 0, 0)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, entity)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_add, 0, 0, 2)
ZEND_ARG_INFO(0, attribute)
ZEND_ARG_INFO(0, validator)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_setfilters, 0, 0, 2)
ZEND_ARG_INFO(0, attribute)
ZEND_ARG_INFO(0, filters)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_getfilters, 0, 0, 0)
ZEND_ARG_INFO(0, attribute)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_appendmessage, 0, 0, 1)
ZEND_ARG_INFO(0, message)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_bind, 0, 0, 2)
ZEND_ARG_INFO(0, entity)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_getvalue, 0, 0, 1)
ZEND_ARG_INFO(0, attribute)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_validation_method_entry[] = {
PHP_ME(Phalcon_Validation, __construct, arginfo_phalcon_validation___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Validation, validate, arginfo_phalcon_validation_validate, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, add, arginfo_phalcon_validation_add, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, setFilters, arginfo_phalcon_validation_setfilters, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getFilters, arginfo_phalcon_validation_getfilters, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getValidators, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getEntity, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getMessages, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, appendMessage, arginfo_phalcon_validation_appendmessage, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, bind, arginfo_phalcon_validation_bind, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getValue, arginfo_phalcon_validation_getvalue, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Validation){
PHALCON_REGISTER_CLASS_EX(Phalcon, Validation, validation, phalcon_di_injectable_ce, phalcon_validation_method_entry, 0);
zend_declare_property_null(phalcon_validation_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_entity"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_validators"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_values"), ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Validation, __construct){
zval *validators = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &validators);
if (!validators) {
validators = PHALCON_GLOBAL(z_null);
}
if (Z_TYPE_P(validators) != IS_NULL) {
if (Z_TYPE_P(validators) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Validators must be an array");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_validators"), validators, 2342846045UL TSRMLS_CC);
}
if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) {
phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Validation, validate){
zval *data = NULL, *entity = NULL, *validators, *messages = NULL, *status = NULL;
zval *cancel_on_fail, *scope = NULL, *attribute = NULL, *validator = NULL;
zval *must_cancel = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 2, &data, &entity);
if (!data) {
data = PHALCON_GLOBAL(z_null);
}
if (!entity) {
entity = PHALCON_GLOBAL(z_null);
}
PHALCON_OBS_VAR(validators);
phalcon_read_property_this_quick(&validators, this_ptr, SL("_validators"), 2342846045UL, PH_NOISY_CC);
if (Z_TYPE_P(validators) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There are no validators to validate");
return;
}
phalcon_update_property_null(this_ptr, SL("_values") TSRMLS_CC);
PHALCON_INIT_VAR(messages);
object_init_ex(messages, phalcon_validation_message_group_ce);
phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL);
if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_VAR(status);
phalcon_call_method_p3_key(status, this_ptr, "beforevalidation", 4025473891UL, data, entity, messages);
if (PHALCON_IS_FALSE(status)) {
RETURN_CCTOR(status);
}
}
phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC);
if (Z_TYPE_P(data) == IS_ARRAY || Z_TYPE_P(data) == IS_OBJECT) {
phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC);
}
PHALCON_INIT_VAR(cancel_on_fail);
ZVAL_STRING(cancel_on_fail, "cancelOnFail", 1);
phalcon_is_iterable(validators, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(scope);
if (Z_TYPE_P(scope) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator scope is not valid");
return;
}
PHALCON_OBS_NVAR(attribute);
phalcon_array_fetch_long(&attribute, scope, 0, PH_NOISY);
PHALCON_OBS_NVAR(validator);
phalcon_array_fetch_long(&validator, scope, 1, PH_NOISY);
if (Z_TYPE_P(validator) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "One of the validators is not valid");
return;
}
PHALCON_INIT_NVAR(status);
phalcon_call_method_p2_key(status, validator, "validate", 2654098287UL, this_ptr, attribute);
if (PHALCON_IS_FALSE(status)) {
PHALCON_INIT_NVAR(must_cancel);
phalcon_call_method_p1_key(must_cancel, validator, "getoption", 1191969182UL, cancel_on_fail);
if (zend_is_true(must_cancel)) {
break;
}
}
zend_hash_move_forward_ex(ah0, &hp0);
}
PHALCON_OBS_NVAR(messages);
phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC);
if (phalcon_method_quick_exists_ex(this_ptr, SS("aftervalidation"), 1795965282UL TSRMLS_CC) == SUCCESS) {
phalcon_call_method_p3_key(NULL, this_ptr, "aftervalidation", 1795965282UL, data, entity, messages);
}
RETURN_CCTOR(messages);
}
static PHP_METHOD(Phalcon_Validation, add){
zval *attribute, *validator, *scope;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &attribute, &validator);
if (Z_TYPE_P(attribute) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string");
return;
}
if (Z_TYPE_P(validator) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator must be an object");
return;
}
PHALCON_INIT_VAR(scope);
array_init_size(scope, 2);
phalcon_array_append(&scope, attribute, 0);
phalcon_array_append(&scope, validator, 0);
phalcon_update_property_array_append(this_ptr, SL("_validators"), scope TSRMLS_CC);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Validation, setFilters){
zval *attribute, *filters;
phalcon_fetch_params(0, 2, 0, &attribute, &filters);
phalcon_update_property_array(this_ptr, SL("_filters"), attribute, filters TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Validation, getFilters){
zval *attribute = NULL, *filters, *attribute_filters;
phalcon_fetch_params(0, 0, 1, &attribute);
filters = phalcon_fetch_nproperty_this(this_ptr, SL("_filters"), PH_NOISY_CC);
if (attribute && Z_TYPE_P(attribute) == IS_STRING) {
if (phalcon_array_isset_fetch(&attribute_filters, filters, attribute)) {
RETURN_ZVAL(attribute_filters, 1, 0);
}
RETURN_NULL();
}
RETURN_ZVAL(filters, 1, 0);
}
static PHP_METHOD(Phalcon_Validation, getValidators){
RETURN_MEMBER_QUICK(this_ptr, "_validators", 2342846045UL);
}
static PHP_METHOD(Phalcon_Validation, getEntity){
RETURN_MEMBER_QUICK(this_ptr, "_entity", 2413912609UL);
}
static PHP_METHOD(Phalcon_Validation, getMessages){
RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL);
}
static PHP_METHOD(Phalcon_Validation, appendMessage){
zval *message, *messages;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &message);
PHALCON_OBS_VAR(messages);
phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC);
phalcon_call_method_p1_key(NULL, messages, "appendmessage", 2313005058UL, message);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Validation, bind){
zval *entity, *data;
phalcon_fetch_params(0, 2, 0, &entity, &data);
if (Z_TYPE_P(entity) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The entity must be an object");
return;
}
if (Z_TYPE_P(data) != IS_ARRAY) {
if (Z_TYPE_P(data) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The data to validate must be an array or object");
return;
}
}
phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 2413912609UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Validation, getValue){
zval *attribute, *entity, *method, *value = NULL, *data, *values;
zval *filters, *field_filters, *service_name;
zval *dependency_injector = NULL, *filter_service;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &attribute);
PHALCON_OBS_VAR(entity);
phalcon_read_property_this_quick(&entity, this_ptr, SL("_entity"), 2413912609UL, PH_NOISY_CC);
if (Z_TYPE_P(entity) == IS_OBJECT) {
PHALCON_INIT_VAR(method);
PHALCON_CONCAT_SV(method, "get", attribute);
if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_VAR(value);
phalcon_call_method_zval(value, entity, method);
} else if (phalcon_method_quick_exists_ex(entity, SS("readattribute"), 95450773UL TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_VAR(value);
phalcon_call_method_p1_key(value, entity, "readattribute", 95450773UL, attribute);
} else if (phalcon_isset_property_zval(entity, attribute TSRMLS_CC)) {
PHALCON_OBS_VAR(value);
phalcon_read_property_zval(&value, entity, attribute, PH_NOISY_CC);
} else {
PHALCON_INIT_VAR(value);
}
RETURN_CCTOR(value);
}
PHALCON_OBS_VAR(data);
phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC);
if (Z_TYPE_P(data) != IS_ARRAY) {
if (Z_TYPE_P(data) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There is no data to validate");
return;
}
}
PHALCON_OBS_VAR(values);
phalcon_read_property_this_quick(&values, this_ptr, SL("_values"), 2376198836UL, PH_NOISY_CC);
if (phalcon_array_isset(values, attribute)) {
PHALCON_OBS_NVAR(value);
phalcon_array_fetch(&value, values, attribute, PH_NOISY);
RETURN_CCTOR(value);
}
PHALCON_INIT_NVAR(value);
if (Z_TYPE_P(data) == IS_ARRAY) {
if (phalcon_array_isset(data, attribute)) {
PHALCON_OBS_NVAR(value);
phalcon_array_fetch(&value, data, attribute, PH_NOISY);
}
} else {
if (Z_TYPE_P(data) == IS_OBJECT) {
if (phalcon_isset_property_zval(data, attribute TSRMLS_CC)) {
PHALCON_OBS_NVAR(value);
phalcon_read_property_zval(&value, data, attribute, PH_NOISY_CC);
}
}
}
if (Z_TYPE_P(value) != IS_NULL) {
PHALCON_OBS_VAR(filters);
phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC);
if (Z_TYPE_P(filters) == IS_ARRAY) {
if (phalcon_array_isset(filters, attribute)) {
PHALCON_OBS_VAR(field_filters);
phalcon_array_fetch(&field_filters, filters, attribute, PH_NOISY);
if (zend_is_true(field_filters)) {
PHALCON_INIT_VAR(service_name);
ZVAL_STRING(service_name, "filter", 1);
PHALCON_INIT_VAR(dependency_injector);
phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL);
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_INIT_NVAR(dependency_injector);
phalcon_call_static(dependency_injector, "phalcon\\di", "getdefault");
if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "A dependency injector is required to obtain the 'filter' service");
return;
}
}
PHALCON_INIT_VAR(filter_service);
phalcon_call_method_p1_key(filter_service, dependency_injector, "getshared", 1727570332UL, service_name);
if (Z_TYPE_P(filter_service) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Returned 'filter' service is invalid");
return;
}
PHALCON_VERIFY_INTERFACE(filter_service, phalcon_filterinterface_ce);
phalcon_call_method_p2_key(return_value, filter_service, "sanitize", 3688332940UL, value, field_filters);
RETURN_MM();
}
}
}
phalcon_update_property_array(this_ptr, SL("_values"), attribute, value TSRMLS_CC);
RETURN_CCTOR(value);
}
RETURN_MM_NULL();
}
zend_class_entry *phalcon_version_ce;
static PHP_METHOD(Phalcon_Version, _getVersion);
static PHP_METHOD(Phalcon_Version, get);
static PHP_METHOD(Phalcon_Version, getId);
static const zend_function_entry phalcon_version_method_entry[] = {
PHP_ME(Phalcon_Version, _getVersion, NULL, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Version, get, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Version, getId, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Version){
PHALCON_REGISTER_CLASS(Phalcon, Version, version, phalcon_version_method_entry, 0);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Version, _getVersion){
array_init_size(return_value, 5);
add_next_index_long(return_value, 1);
add_next_index_long(return_value, 3);
add_next_index_long(return_value, 0);
add_next_index_long(return_value, 2);
add_next_index_long(return_value, 1);
}
static PHP_METHOD(Phalcon_Version, get){
zval *version, *major, *medium, *minor, *special, *special_number;
zval *result, *suffix = NULL;
PHALCON_MM_GROW();
PHALCON_INIT_VAR(version);
phalcon_call_self(version, this_ptr, "_getversion");
PHALCON_OBS_VAR(major);
phalcon_array_fetch_long(&major, version, 0, PH_NOISY);
PHALCON_OBS_VAR(medium);
phalcon_array_fetch_long(&medium, version, 1, PH_NOISY);
PHALCON_OBS_VAR(minor);
phalcon_array_fetch_long(&minor, version, 2, PH_NOISY);
PHALCON_OBS_VAR(special);
phalcon_array_fetch_long(&special, version, 3, PH_NOISY);
PHALCON_OBS_VAR(special_number);
phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY);
PHALCON_INIT_VAR(result);
PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " ");
switch (phalcon_get_intval(special)) {
case 1:
PHALCON_INIT_VAR(suffix);
PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number);
break;
case 2:
PHALCON_INIT_NVAR(suffix);
PHALCON_CONCAT_SV(suffix, "BETA ", special_number);
break;
case 3:
PHALCON_INIT_NVAR(suffix);
PHALCON_CONCAT_SV(suffix, "RC ", special_number);
break;
default:
PHALCON_INIT_NVAR(suffix);
ZVAL_STRING(suffix, "", 1);
break;
}
phalcon_concat_self(&result, suffix TSRMLS_CC);
phalcon_fast_trim(return_value, result, PHALCON_TRIM_BOTH TSRMLS_CC);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Version, getId){
zval *version, *major, *medium, *minor, *special, *special_number;
zval *format, *real_medium, *real_minor;
PHALCON_MM_GROW();
PHALCON_INIT_VAR(version);
phalcon_call_self(version, this_ptr, "_getversion");
PHALCON_OBS_VAR(major);
phalcon_array_fetch_long(&major, version, 0, PH_NOISY);
PHALCON_OBS_VAR(medium);
phalcon_array_fetch_long(&medium, version, 1, PH_NOISY);
PHALCON_OBS_VAR(minor);
phalcon_array_fetch_long(&minor, version, 2, PH_NOISY);
PHALCON_OBS_VAR(special);
phalcon_array_fetch_long(&special, version, 3, PH_NOISY);
PHALCON_OBS_VAR(special_number);
phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY);
PHALCON_INIT_VAR(format);
ZVAL_STRING(format, "%02s", 1);
PHALCON_INIT_VAR(real_medium);
phalcon_call_func_p2(real_medium, "sprintf", format, medium);
PHALCON_INIT_VAR(real_minor);
phalcon_call_func_p2(real_minor, "sprintf", format, minor);
PHALCON_CONCAT_VVVVV(return_value, major, real_medium, real_minor, special, special_number);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Acl_Adapter, setEventsManager);
static PHP_METHOD(Phalcon_Acl_Adapter, getEventsManager);
static PHP_METHOD(Phalcon_Acl_Adapter, setDefaultAction);
static PHP_METHOD(Phalcon_Acl_Adapter, getDefaultAction);
static PHP_METHOD(Phalcon_Acl_Adapter, getActiveRole);
static PHP_METHOD(Phalcon_Acl_Adapter, getActiveResource);
static PHP_METHOD(Phalcon_Acl_Adapter, getActiveAccess);
zend_class_entry *phalcon_acl_adapter_ce;
static const zend_function_entry phalcon_acl_adapter_method_entry[] = {
PHP_ME(Phalcon_Acl_Adapter, setEventsManager, arginfo_phalcon_events_eventsawareinterface_seteventsmanager, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter, getEventsManager, arginfo_phalcon_events_eventsawareinterface_geteventsmanager, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter, setDefaultAction, arginfo_phalcon_acl_adapter_setdefaultaction, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter, getDefaultAction, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter, getActiveRole, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter, getActiveResource, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter, getActiveAccess, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Acl_Adapter){
PHALCON_REGISTER_CLASS(Phalcon\\Acl, Adapter, acl_adapter, phalcon_acl_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_property_null(phalcon_acl_adapter_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(phalcon_acl_adapter_ce, SL("_defaultAccess"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_acl_adapter_ce, SL("_accessGranted"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeRole"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeResource"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeAccess"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_acl_adapter_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Acl_Adapter, setEventsManager){
zval *events_manager;
phalcon_fetch_params(0, 1, 0, &events_manager);
phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Acl_Adapter, getEventsManager){
RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL);
}
static PHP_METHOD(Phalcon_Acl_Adapter, setDefaultAction){
zval *default_access;
phalcon_fetch_params(0, 1, 0, &default_access);
phalcon_update_property_this_quick(this_ptr, SL("_defaultAccess"), default_access, 875397115UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Acl_Adapter, getDefaultAction){
RETURN_MEMBER_QUICK(this_ptr, "_defaultAccess", 875397115UL);
}
static PHP_METHOD(Phalcon_Acl_Adapter, getActiveRole){
RETURN_MEMBER_QUICK(this_ptr, "_activeRole", 3079165426UL);
}
static PHP_METHOD(Phalcon_Acl_Adapter, getActiveResource){
RETURN_MEMBER_QUICK(this_ptr, "_activeResource", 1323587080UL);
}
static PHP_METHOD(Phalcon_Acl_Adapter, getActiveAccess){
RETURN_MEMBER_QUICK(this_ptr, "_activeAccess", 2176370066UL);
}
zend_class_entry *phalcon_acl_adapterinterface_ce;
static const zend_function_entry phalcon_acl_adapterinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, setDefaultAction, arginfo_phalcon_acl_adapterinterface_setdefaultaction)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, getDefaultAction, arginfo_phalcon_acl_adapterinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, addRole, arginfo_phalcon_acl_adapterinterface_addrole)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, addInherit, arginfo_phalcon_acl_adapterinterface_addinherit)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, isRole, arginfo_phalcon_acl_adapterinterface_isrole)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, isResource, arginfo_phalcon_acl_adapterinterface_isresource)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, addResource, arginfo_phalcon_acl_adapterinterface_addresource)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, addResourceAccess, arginfo_phalcon_acl_adapterinterface_addresourceaccess)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, dropResourceAccess, arginfo_phalcon_acl_adapterinterface_dropresourceaccess)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, allow, arginfo_phalcon_acl_adapterinterface_allow)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, deny, arginfo_phalcon_acl_adapterinterface_allow)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, isAllowed, arginfo_phalcon_acl_adapterinterface_isallowed)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, getActiveRole, arginfo_phalcon_acl_adapterinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, getActiveResource, arginfo_phalcon_acl_adapterinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, getActiveAccess, arginfo_phalcon_acl_adapterinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, getRoles, arginfo_phalcon_acl_adapterinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Acl_AdapterInterface, getResources, arginfo_phalcon_acl_adapterinterface_empty)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Acl_AdapterInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, AdapterInterface, acl_adapterinterface, phalcon_acl_adapterinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_acl_exception_ce;
PHALCON_INIT_CLASS(Phalcon_Acl_Exception){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Acl, Exception, acl_exception, phalcon_exception_ce, NULL, 0);
return SUCCESS;
}
zend_class_entry *phalcon_acl_resource_ce;
static PHP_METHOD(Phalcon_Acl_Resource, __construct);
static PHP_METHOD(Phalcon_Acl_Resource, getName);
static PHP_METHOD(Phalcon_Acl_Resource, getDescription);
static PHP_METHOD(Phalcon_Acl_Resource, __toString);
static const zend_function_entry phalcon_acl_resource_method_entry[] = {
PHP_ME(Phalcon_Acl_Resource, __construct, arginfo_phalcon_acl_resourceinterface___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Acl_Resource, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Resource, getDescription, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Resource, __toString, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Acl_Resource){
PHALCON_REGISTER_CLASS(Phalcon\\Acl, Resource, acl_resource, phalcon_acl_resource_method_entry, 0);
zend_declare_property_null(phalcon_acl_resource_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_resource_ce, SL("_description"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_acl_resource_ce TSRMLS_CC, 1, phalcon_acl_resourceinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Acl_Resource, __construct){
zval *name, *description = NULL;
phalcon_fetch_params(0, 1, 1, &name, &description);
if (PHALCON_IS_STRING(name, "*")) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_acl_exception_ce, "Resource name cannot be \"*\"");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC);
if (description && Z_TYPE_P(description) != IS_NULL) {
phalcon_update_property_this_quick(this_ptr, SL("_description"), description, 1348915240UL TSRMLS_CC);
}
}
static PHP_METHOD(Phalcon_Acl_Resource, getName){
RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL);
}
static PHP_METHOD(Phalcon_Acl_Resource, getDescription){
RETURN_MEMBER_QUICK(this_ptr, "_description", 1348915240UL);
}
static PHP_METHOD(Phalcon_Acl_Resource, __toString){
RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL);
}
zend_class_entry *phalcon_acl_resourceinterface_ce;
static const zend_function_entry phalcon_acl_resourceinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Acl_ResourceInterface, __construct, arginfo_phalcon_acl_resourceinterface___construct)
PHP_ABSTRACT_ME(Phalcon_Acl_ResourceInterface, getName, NULL)
PHP_ABSTRACT_ME(Phalcon_Acl_ResourceInterface, getDescription, NULL)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Acl_ResourceInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, ResourceInterface, acl_resourceinterface, phalcon_acl_resourceinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_acl_role_ce;
static PHP_METHOD(Phalcon_Acl_Role, __construct);
static PHP_METHOD(Phalcon_Acl_Role, getName);
static PHP_METHOD(Phalcon_Acl_Role, getDescription);
static PHP_METHOD(Phalcon_Acl_Role, __toString);
static const zend_function_entry phalcon_acl_role_method_entry[] = {
PHP_ME(Phalcon_Acl_Role, __construct, arginfo_phalcon_acl_roleinterface___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Acl_Role, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Role, getDescription, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Role, __toString, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Acl_Role){
PHALCON_REGISTER_CLASS(Phalcon\\Acl, Role, acl_role, phalcon_acl_role_method_entry, 0);
zend_declare_property_null(phalcon_acl_role_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_role_ce, SL("_description"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_acl_role_ce TSRMLS_CC, 1, phalcon_acl_roleinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Acl_Role, __construct){
zval *name, *description = NULL;
phalcon_fetch_params(0, 1, 1, &name, &description);
if (PHALCON_IS_STRING(name, "*")) {
PHALCON_THROW_EXCEPTION_STR(phalcon_acl_exception_ce, "Role name cannot be \"*\"");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC);
if (description && Z_TYPE_P(description) != IS_NULL) {
phalcon_update_property_this_quick(this_ptr, SL("_description"), description, 1348915240UL TSRMLS_CC);
}
}
static PHP_METHOD(Phalcon_Acl_Role, getName){
RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL);
}
static PHP_METHOD(Phalcon_Acl_Role, getDescription){
RETURN_MEMBER_QUICK(this_ptr, "_description", 1348915240UL);
}
static PHP_METHOD(Phalcon_Acl_Role, __toString){
RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL);
}
zend_class_entry *phalcon_acl_roleinterface_ce;
static const zend_function_entry phalcon_acl_roleinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Acl_RoleInterface, __construct, arginfo_phalcon_acl_roleinterface___construct)
PHP_ABSTRACT_ME(Phalcon_Acl_RoleInterface, getName, NULL)
PHP_ABSTRACT_ME(Phalcon_Acl_RoleInterface, getDescription, NULL)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Acl_RoleInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, RoleInterface, acl_roleinterface, phalcon_acl_roleinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_acl_adapter_memory_ce;
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addInherit);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isRole);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isResource);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, dropResourceAccess);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, _allowOrDeny);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, allow);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, deny);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isAllowed);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getRoles);
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getResources);
static const zend_function_entry phalcon_acl_adapter_memory_method_entry[] = {
PHP_ME(Phalcon_Acl_Adapter_Memory, __construct, arginfo_phalcon_acl_adapterinterface_empty, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Acl_Adapter_Memory, addRole, arginfo_phalcon_acl_adapterinterface_addrole, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, addInherit, arginfo_phalcon_acl_adapterinterface_addinherit, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, isRole, arginfo_phalcon_acl_adapterinterface_isrole, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, isResource, arginfo_phalcon_acl_adapterinterface_isresource, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, addResource, arginfo_phalcon_acl_adapterinterface_addresource, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, addResourceAccess, arginfo_phalcon_acl_adapterinterface_addresourceaccess, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, dropResourceAccess, arginfo_phalcon_acl_adapterinterface_dropresourceaccess, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, _allowOrDeny, arginfo_phalcon_acl_adapterinterface_empty, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Acl_Adapter_Memory, allow, arginfo_phalcon_acl_adapterinterface_allow, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, deny, arginfo_phalcon_acl_adapterinterface_allow, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, isAllowed, arginfo_phalcon_acl_adapterinterface_isallowed, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, getRoles, arginfo_phalcon_acl_adapterinterface_empty, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Acl_Adapter_Memory, getResources, arginfo_phalcon_acl_adapterinterface_empty, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Acl_Adapter_Memory){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Acl\\Adapter, Memory, acl_adapter_memory, phalcon_acl_adapter_ce, phalcon_acl_adapter_memory_method_entry, 0);
zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_rolesNames"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_roles"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_resourcesNames"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_resources"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_access"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_roleInherits"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_accessList"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_acl_adapter_memory_ce TSRMLS_CC, 1, phalcon_acl_adapterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct){
zval *resources_names, *access_list;
PHALCON_MM_GROW();
PHALCON_INIT_VAR(resources_names);
array_init_size(resources_names, 1);
phalcon_array_update_string(&resources_names, SL("*"), &PHALCON_GLOBAL(z_true), PH_COPY);
phalcon_update_property_this_quick(this_ptr, SL("_resourcesNames"), resources_names, 2424408563UL TSRMLS_CC);
PHALCON_INIT_VAR(access_list);
array_init_size(access_list, 1);
phalcon_array_update_string(&access_list, SL("*!*"), &PHALCON_GLOBAL(z_true), PH_COPY);
phalcon_update_property_this_quick(this_ptr, SL("_accessList"), access_list, 2206680658UL TSRMLS_CC);
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){
zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL;
zval *roles_names, *default_access;
zval *key;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &role, &access_inherits);
if (!access_inherits) {
access_inherits = PHALCON_GLOBAL(z_null);
}
if (Z_TYPE_P(role) == IS_OBJECT) {
PHALCON_INIT_VAR(role_name);
phalcon_call_method_key(role_name, role, "getname", 4286441094UL);
PHALCON_CPY_WRT(object, role);
} else {
PHALCON_CPY_WRT(role_name, role);
PHALCON_INIT_NVAR(object);
object_init_ex(object, phalcon_acl_role_ce);
phalcon_call_method_p1_key(NULL, object, "__construct", 1107214344UL, role);
}
roles_names = phalcon_fetch_nproperty_this(this_ptr, SL("_rolesNames"), PH_NOISY_CC);
if (phalcon_array_isset(roles_names, role_name)) {
RETURN_MM_FALSE;
}
phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC);
phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, PHALCON_GLOBAL(z_true) TSRMLS_CC);
default_access = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultAccess"), PH_NOISY_CC);
PHALCON_INIT_VAR(key);
PHALCON_CONCAT_VS(key, role_name, "!*!*");
phalcon_update_property_array(this_ptr, SL("_access"), key, default_access TSRMLS_CC);
if (Z_TYPE_P(access_inherits) != IS_NULL) {
phalcon_call_method_p2_key(return_value, this_ptr, "addinherit", 2093626145UL, role_name, access_inherits);
RETURN_MM();
}
RETURN_MM_TRUE;
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addInherit){
zval *role_name, *role_to_inherit, *roles_names;
zval *exception_message = NULL, *role_inherit_name = NULL;
zval *roles_inherits, *empty_arr, *_roleInherits;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &role_name, &role_to_inherit);
PHALCON_OBS_VAR(roles_names);
phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC);
if (!phalcon_array_isset(roles_names, role_name)) {
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Role '", role_name, "' does not exist in the role list");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
return;
}
if (Z_TYPE_P(role_to_inherit) == IS_OBJECT) {
PHALCON_INIT_VAR(role_inherit_name);
phalcon_call_method_key(role_inherit_name, role_to_inherit, "getname", 4286441094UL);
} else {
PHALCON_CPY_WRT(role_inherit_name, role_to_inherit);
}
if (!phalcon_array_isset(roles_names, role_inherit_name)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Role '", role_inherit_name, "' (to inherit) does not exist in the role list");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
return;
}
if (PHALCON_IS_EQUAL(role_inherit_name, role_name)) {
RETURN_MM_FALSE;
}
PHALCON_OBS_VAR(roles_inherits);
phalcon_read_property_this_quick(&roles_inherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC);
if (!phalcon_array_isset(roles_inherits, role_name)) {
PHALCON_INIT_VAR(empty_arr);
array_init(empty_arr);
phalcon_update_property_array(this_ptr, SL("_roleInherits"), role_name, empty_arr TSRMLS_CC);
}
PHALCON_OBS_VAR(_roleInherits);
phalcon_read_property_this_quick(&_roleInherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC);
phalcon_array_update_append_multi_2(&_roleInherits, role_name, role_inherit_name, 0);
phalcon_update_property_this_quick(this_ptr, SL("_roleInherits"), _roleInherits, 1806479324UL TSRMLS_CC);
RETURN_MM_TRUE;
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isRole){
zval *role_name, *roles_names;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &role_name);
PHALCON_OBS_VAR(roles_names);
phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC);
if (phalcon_array_isset(roles_names, role_name)) {
RETURN_MM_TRUE;
}
RETURN_MM_FALSE;
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isResource){
zval *resource_name, *resources_names;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &resource_name);
PHALCON_OBS_VAR(resources_names);
phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC);
if (phalcon_array_isset(resources_names, resource_name)) {
RETURN_MM_TRUE;
}
RETURN_MM_FALSE;
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){
zval *resource, *access_list = NULL, *resource_name = NULL;
zval *object = NULL, *resources_names;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &resource, &access_list);
if (!access_list) {
access_list = PHALCON_GLOBAL(z_null);
}
if (Z_TYPE_P(resource) == IS_OBJECT) {
PHALCON_INIT_VAR(resource_name);
phalcon_call_method_key(resource_name, resource, "getname", 4286441094UL);
PHALCON_CPY_WRT(object, resource);
} else {
PHALCON_CPY_WRT(resource_name, resource);
PHALCON_INIT_NVAR(object);
object_init_ex(object, phalcon_acl_resource_ce);
phalcon_call_method_p1_key(NULL, object, "__construct", 1107214344UL, resource_name);
}
PHALCON_OBS_VAR(resources_names);
phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC);
if (!phalcon_array_isset(resources_names, resource_name)) {
phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC);
phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, PHALCON_GLOBAL(z_true) TSRMLS_CC);
}
phalcon_call_method_p2_key(return_value, this_ptr, "addresourceaccess", 3379195048UL, resource_name, access_list);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){
zval *resource_name, *access_list, *resources_names;
zval *exception_message, *internal_access_list;
zval *access_name = NULL, *access_key = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &resource_name, &access_list);
PHALCON_OBS_VAR(resources_names);
phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC);
if (!phalcon_array_isset(resources_names, resource_name)) {
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Resource '", resource_name, "' does not exist in ACL");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
return;
}
PHALCON_OBS_VAR(internal_access_list);
phalcon_read_property_this_quick(&internal_access_list, this_ptr, SL("_accessList"), 2206680658UL, PH_NOISY_CC);
if (Z_TYPE_P(access_list) == IS_ARRAY) {
phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(access_name);
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name);
if (!phalcon_array_isset(internal_access_list, access_key)) {
phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, PHALCON_GLOBAL(z_true) TSRMLS_CC);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
} else {
if (Z_TYPE_P(access_list) == IS_STRING) {
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_list);
if (!phalcon_array_isset(internal_access_list, access_key)) {
phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, PHALCON_GLOBAL(z_true) TSRMLS_CC);
}
}
}
RETURN_MM_TRUE;
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, dropResourceAccess){
zval *resource_name, *access_list, *access_name = NULL;
zval *access_key = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &resource_name, &access_list);
if (Z_TYPE_P(access_list) == IS_ARRAY) {
phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(access_name);
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name);
phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC);
zend_hash_move_forward_ex(ah0, &hp0);
}
} else {
PHALCON_INIT_VAR(access_key);
PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_list);
phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, _allowOrDeny){
zval *role_name, *resource_name, *access, *action;
zval *roles_names, *exception_message = NULL, *resources_names;
zval *default_access, *access_list, *internal_access;
zval *access_name = NULL, *access_key = NULL, *access_key_all = NULL;
HashTable *ah0, *ah1;
HashPosition hp0, hp1;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 4, 0, &role_name, &resource_name, &access, &action);
PHALCON_OBS_VAR(roles_names);
phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC);
if (!phalcon_array_isset(roles_names, role_name)) {
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Role \"", role_name, "\" does not exist in ACL");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
return;
}
PHALCON_OBS_VAR(resources_names);
phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC);
if (!phalcon_array_isset(resources_names, resource_name)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Resource \"", resource_name, "\" does not exist in ACL");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
return;
}
PHALCON_OBS_VAR(default_access);
phalcon_read_property_this_quick(&default_access, this_ptr, SL("_defaultAccess"), 875397115UL, PH_NOISY_CC);
PHALCON_OBS_VAR(access_list);
phalcon_read_property_this_quick(&access_list, this_ptr, SL("_accessList"), 2206680658UL, PH_NOISY_CC);
PHALCON_OBS_VAR(internal_access);
phalcon_read_property_this_quick(&internal_access, this_ptr, SL("_access"), 1092213014UL, PH_NOISY_CC);
if (Z_TYPE_P(access) == IS_ARRAY) {
phalcon_is_iterable(access, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(access_name);
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name);
if (!phalcon_array_isset(access_list, access_key)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access_name, "' does not exist in resource '", resource_name, "'");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
return;
}
zend_hash_move_forward_ex(ah0, &hp0);
}
phalcon_is_iterable(access, &ah1, &hp1, 0, 0);
while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
PHALCON_GET_HVALUE(access_name);
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSVSV(access_key, role_name, "!", resource_name, "!", access_name);
phalcon_update_property_array(this_ptr, SL("_access"), access_key, action TSRMLS_CC);
if (!PHALCON_IS_STRING(access_name, "*")) {
PHALCON_INIT_NVAR(access_key_all);
PHALCON_CONCAT_VSVS(access_key_all, role_name, "!", resource_name, "!*");
if (!phalcon_array_isset(internal_access, access_key_all)) {
phalcon_update_property_array(this_ptr, SL("_access"), access_key_all, default_access TSRMLS_CC);
}
}
zend_hash_move_forward_ex(ah1, &hp1);
}
} else {
if (!PHALCON_IS_STRING(access, "*")) {
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSV(access_key, resource_name, "!", access);
if (!phalcon_array_isset(access_list, access_key)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access, "' does not exist in resource '", resource_name, "'");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message);
return;
}
}
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSVSV(access_key, role_name, "!", resource_name, "!", access);
phalcon_update_property_array(this_ptr, SL("_access"), access_key, action TSRMLS_CC);
if (!PHALCON_IS_STRING(access, "*")) {
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSVS(access_key, role_name, "!", resource_name, "!*");
if (!phalcon_array_isset(internal_access, access_key)) {
phalcon_update_property_array(this_ptr, SL("_access"), access_key, default_access TSRMLS_CC);
}
}
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, allow){
zval *role_name, *resource_name, *access, *action, *roles_names;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 3, 0, &role_name, &resource_name, &access);
PHALCON_INIT_VAR(action);
ZVAL_LONG(action, 1);
if (!PHALCON_IS_STRING(role_name, "*")) {
phalcon_call_method_p4_key(return_value, this_ptr, "_allowordeny", 726543028UL, role_name, resource_name, access, action);
} else {
PHALCON_SEPARATE_PARAM(role_name);
PHALCON_OBS_VAR(roles_names);
phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC);
phalcon_is_iterable(roles_names, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(role_name, ah0, hp0);
phalcon_call_method_p4_key(NULL, this_ptr, "_allowordeny", 726543028UL, role_name, resource_name, access, action);
zend_hash_move_forward_ex(ah0, &hp0);
}
}
RETURN_MM();
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, deny){
zval *role_name, *resource_name, *access, *action, *roles_names;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 3, 0, &role_name, &resource_name, &access);
PHALCON_INIT_VAR(action);
ZVAL_LONG(action, 0);
if (!PHALCON_IS_STRING(role_name, "*")) {
phalcon_call_method_p4_key(return_value, this_ptr, "_allowordeny", 726543028UL, role_name, resource_name, access, action);
} else {
PHALCON_SEPARATE_PARAM(role_name);
PHALCON_OBS_VAR(roles_names);
phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC);
phalcon_is_iterable(roles_names, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(role_name, ah0, hp0);
phalcon_call_method_p4_key(NULL, this_ptr, "_allowordeny", 726543028UL, role_name, resource_name, access, action);
zend_hash_move_forward_ex(ah0, &hp0);
}
}
RETURN_MM();
}
#define PHALCON_ACL_NO 0
#define PHALCON_ACL_YES 1
#define PHALCON_ACL_DUNNO -1
static int phalcon_role_adapter_memory_check_inheritance(zval *role, zval *resource, zval *access, zval *access_list, zval* role_inherits TSRMLS_DC)
{
zval *inherited_roles, *access_key;
zval **parent_role;
int result = PHALCON_ACL_DUNNO;
HashPosition hp;
assert(Z_TYPE_P(role) == IS_STRING);
assert(Z_TYPE_P(resource) == IS_STRING);
assert(Z_TYPE_P(access) == IS_STRING);
assert(Z_TYPE_P(access_list) == IS_ARRAY);
if (!phalcon_array_isset_fetch(&inherited_roles, role_inherits, role) || Z_TYPE_P(inherited_roles) != IS_ARRAY) {
return PHALCON_ACL_DUNNO;
}
ALLOC_INIT_ZVAL(access_key);
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(inherited_roles), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(inherited_roles), (void**)&parent_role, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(inherited_roles), &hp)
) {
int found;
zval *have_access;
phalcon_concat_vsvsv(&access_key, *parent_role, SL("!"), resource, SL("!"), access, 0 TSRMLS_CC);
found = phalcon_array_isset_fetch(&have_access, access_list, access_key);
zval_dtor(access_key);
ZVAL_NULL(access_key);
if (found) {
result = zend_is_true(have_access) ? PHALCON_ACL_YES : PHALCON_ACL_NO;
}
else {
result = phalcon_role_adapter_memory_check_inheritance(*parent_role, resource, access, access_list, role_inherits TSRMLS_CC);
}
if (PHALCON_ACL_DUNNO != result) {
break;
}
}
zval_ptr_dtor(&access_key);
return result;
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isAllowed){
zval *role, *resource, *access, *events_manager, *role_inherits;
zval *event_name = NULL, *status, *default_access, *roles_names;
zval *have_access = NULL, *access_list, *access_key = NULL;
zval star;
int allow_access;
PHALCON_MM_GROW();
INIT_ZVAL(star);
ZVAL_STRING(&star, "*", 0);
phalcon_fetch_params(1, 3, 0, &role, &resource, &access);
phalcon_update_property_this_quick(this_ptr, SL("_activeRole"), role, 3079165426UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_activeResource"), resource, 1323587080UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_activeAccess"), access, 2176370066UL TSRMLS_CC);
events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
PHALCON_INIT_VAR(event_name);
ZVAL_STRING(event_name, "acl:beforeCheckAccess", 1);
PHALCON_INIT_VAR(status);
phalcon_call_method_p2_key(status, events_manager, "fire", 259017035UL, event_name, this_ptr);
if (PHALCON_IS_FALSE(status)) {
RETURN_CTOR(status);
}
}
default_access = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultAccess"), PH_NOISY_CC);
roles_names = phalcon_fetch_nproperty_this(this_ptr, SL("_rolesNames"), PH_NOISY_CC);
if (!phalcon_array_isset(roles_names, role)) {
RETURN_CTOR(default_access);
}
access_list = phalcon_fetch_nproperty_this(this_ptr, SL("_access"), PH_NOISY_CC);
PHALCON_INIT_VAR(access_key);
PHALCON_CONCAT_VSVSV(access_key, role, "!", resource, "!", access);
if (phalcon_array_isset_fetch(&have_access, access_list, access_key)) {
allow_access = zend_is_true(have_access) ? PHALCON_ACL_YES : PHALCON_ACL_NO;
}
else {
allow_access = PHALCON_ACL_DUNNO;
}
if (PHALCON_ACL_DUNNO == allow_access) {
role_inherits = phalcon_fetch_nproperty_this(this_ptr, SL("_roleInherits"), PH_NOISY TSRMLS_CC);
allow_access = phalcon_role_adapter_memory_check_inheritance(role, resource, access, access_list, role_inherits TSRMLS_CC);
}
if (PHALCON_ACL_DUNNO == allow_access) {
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VSVS(access_key, role, "!", resource, "!*");
if (phalcon_array_isset_fetch(&have_access, access_list, access_key)) {
allow_access = zend_is_true(have_access) ? PHALCON_ACL_YES : PHALCON_ACL_NO;
}
else {
allow_access = phalcon_role_adapter_memory_check_inheritance(role, resource, &star, access_list, role_inherits TSRMLS_CC);
}
}
if (PHALCON_ACL_DUNNO == allow_access) {
PHALCON_INIT_NVAR(access_key);
PHALCON_CONCAT_VS(access_key, role, "!*!*");
if (phalcon_array_isset_fetch(&have_access, access_list, access_key)) {
allow_access = zend_is_true(have_access) ? PHALCON_ACL_YES : PHALCON_ACL_NO;
}
else {
allow_access = phalcon_role_adapter_memory_check_inheritance(role, &star, &star, access_list, role_inherits TSRMLS_CC);
}
}
ZVAL_BOOL(return_value, PHALCON_ACL_YES == allow_access);
phalcon_update_property_this_quick(this_ptr, SL("_accessGranted"), return_value, 3188809627UL TSRMLS_CC);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "acl:afterCheckAccess", 1);
phalcon_call_method_p3_key(NULL, events_manager, "fire", 259017035UL, event_name, this_ptr, return_value);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getRoles){
RETURN_MEMBER_QUICK(this_ptr, "_roles", 2795361801UL);
}
static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getResources){
RETURN_MEMBER_QUICK(this_ptr, "_resources", 3320036063UL);
}
zend_class_entry *phalcon_annotations_adapter_ce;
static PHP_METHOD(Phalcon_Annotations_Adapter, setReader);
static PHP_METHOD(Phalcon_Annotations_Adapter, getReader);
static PHP_METHOD(Phalcon_Annotations_Adapter, get);
static PHP_METHOD(Phalcon_Annotations_Adapter, getMethods);
static PHP_METHOD(Phalcon_Annotations_Adapter, getMethod);
static PHP_METHOD(Phalcon_Annotations_Adapter, getProperties);
static PHP_METHOD(Phalcon_Annotations_Adapter, getProperty);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_setreader, 0, 0, 1)
ZEND_ARG_INFO(0, reader)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_get, 0, 0, 1)
ZEND_ARG_INFO(0, className)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_getmethods, 0, 0, 1)
ZEND_ARG_INFO(0, className)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_getmethod, 0, 0, 2)
ZEND_ARG_INFO(0, className)
ZEND_ARG_INFO(0, methodName)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_getproperties, 0, 0, 1)
ZEND_ARG_INFO(0, className)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_getproperty, 0, 0, 2)
ZEND_ARG_INFO(0, className)
ZEND_ARG_INFO(0, propertyName)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_adapter_method_entry[] = {
PHP_ME(Phalcon_Annotations_Adapter, setReader, arginfo_phalcon_annotations_adapter_setreader, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter, getReader, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter, get, arginfo_phalcon_annotations_adapter_get, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter, getMethods, arginfo_phalcon_annotations_adapter_getmethods, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter, getMethod, arginfo_phalcon_annotations_adapter_getmethod, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter, getProperties, arginfo_phalcon_annotations_adapter_getproperties, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter, getProperty, arginfo_phalcon_annotations_adapter_getproperty, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter){
PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Adapter, annotations_adapter, phalcon_annotations_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_property_null(phalcon_annotations_adapter_ce, SL("_reader"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_annotations_adapter_ce, SL("_annotations"), ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Adapter, setReader){
zval *reader;
phalcon_fetch_params(0, 1, 0, &reader);
if (Z_TYPE_P(reader) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Invalid annotations reader");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_reader"), reader, 1648179735UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Annotations_Adapter, getReader){
zval *reader;
reader = phalcon_fetch_nproperty_this(this_ptr, SL("_reader"), PH_NOISY_CC);
if (Z_TYPE_P(reader) != IS_OBJECT) {
object_init_ex(return_value, phalcon_annotations_reader_ce);
phalcon_update_property_this_quick(this_ptr, SL("_reader"), return_value, 1648179735UL TSRMLS_CC);
return;
}
RETURN_ZVAL(reader, 1, 0);
}
static PHP_METHOD(Phalcon_Annotations_Adapter, get){
zval *class_name, *real_class_name = NULL, *annotations;
zval *class_annotations = NULL, *reader, *parsed_annotations;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &class_name);
if (Z_TYPE_P(class_name) == IS_OBJECT) {
PHALCON_INIT_VAR(real_class_name);
phalcon_get_class(real_class_name, class_name, 0 TSRMLS_CC);
} else {
PHALCON_CPY_WRT(real_class_name, class_name);
}
PHALCON_OBS_VAR(annotations);
phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC);
if (Z_TYPE_P(annotations) == IS_ARRAY) {
if (phalcon_array_isset(annotations, real_class_name)) {
PHALCON_OBS_VAR(class_annotations);
phalcon_array_fetch(&class_annotations, annotations, real_class_name, PH_NOISY);
RETURN_CCTOR(class_annotations);
}
}
PHALCON_INIT_NVAR(class_annotations);
phalcon_call_method_p1_key(class_annotations, this_ptr, "read", 273085793UL, real_class_name);
if (Z_TYPE_P(class_annotations) == IS_NULL) {
PHALCON_INIT_VAR(reader);
phalcon_call_method_key(reader, this_ptr, "getreader", 318193528UL);
PHALCON_INIT_VAR(parsed_annotations);
phalcon_call_method_p1_key(parsed_annotations, reader, "parse", 339512704UL, real_class_name);
if (Z_TYPE_P(parsed_annotations) == IS_ARRAY) {
PHALCON_INIT_NVAR(class_annotations);
object_init_ex(class_annotations, phalcon_annotations_reflection_ce);
phalcon_call_method_p1_key(NULL, class_annotations, "__construct", 1107214344UL, parsed_annotations);
phalcon_update_property_array(this_ptr, SL("_annotations"), real_class_name, class_annotations TSRMLS_CC);
phalcon_call_method_p2_key(NULL, this_ptr, "write", 633298768UL, real_class_name, class_annotations);
}
}
RETURN_CCTOR(class_annotations);
}
static PHP_METHOD(Phalcon_Annotations_Adapter, getMethods){
zval *class_name, *class_annotations;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &class_name);
PHALCON_INIT_VAR(class_annotations);
phalcon_call_method_p1_key(class_annotations, this_ptr, "get", 2090288933UL, class_name);
if (Z_TYPE_P(class_annotations) == IS_OBJECT) {
phalcon_call_method_key(return_value, class_annotations, "getmethodsannotations", 2860599943UL);
RETURN_MM();
}
RETURN_MM_EMPTY_ARRAY();
}
static PHP_METHOD(Phalcon_Annotations_Adapter, getMethod){
zval *class_name, *method_name, *class_annotations;
zval *methods, *method = NULL, *name = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &class_name, &method_name);
PHALCON_INIT_VAR(class_annotations);
phalcon_call_method_p1_key(class_annotations, this_ptr, "get", 2090288933UL, class_name);
if (Z_TYPE_P(class_annotations) == IS_OBJECT) {
PHALCON_INIT_VAR(methods);
phalcon_call_method_key(methods, class_annotations, "getmethodsannotations", 2860599943UL);
if (Z_TYPE_P(methods) == IS_ARRAY) {
phalcon_is_iterable(methods, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(name, ah0, hp0);
PHALCON_GET_HVALUE(method);
if (PHALCON_IS_EQUAL(name, method_name)) {
RETURN_CCTOR(method);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
}
}
object_init_ex(return_value, phalcon_annotations_collection_ce);
phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Annotations_Adapter, getProperties){
zval *class_name, *class_annotations;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &class_name);
PHALCON_INIT_VAR(class_annotations);
phalcon_call_method_p1_key(class_annotations, this_ptr, "get", 2090288933UL, class_name);
if (Z_TYPE_P(class_annotations) == IS_OBJECT) {
phalcon_call_method_key(return_value, class_annotations, "getpropertiesannotations", 3353352384UL);
RETURN_MM();
}
RETURN_MM_EMPTY_ARRAY();
}
static PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){
zval *class_name, *property_name, *class_annotations;
zval *properties, *property = NULL, *name = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &class_name, &property_name);
PHALCON_INIT_VAR(class_annotations);
phalcon_call_method_p1_key(class_annotations, this_ptr, "get", 2090288933UL, class_name);
if (Z_TYPE_P(class_annotations) == IS_OBJECT) {
PHALCON_INIT_VAR(properties);
phalcon_call_method_key(properties, class_annotations, "getpropertiesannotations", 3353352384UL);
if (Z_TYPE_P(properties) == IS_ARRAY) {
phalcon_is_iterable(properties, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(name, ah0, hp0);
PHALCON_GET_HVALUE(property);
if (PHALCON_IS_EQUAL(name, property_name)) {
RETURN_CCTOR(property);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
}
}
object_init_ex(return_value, phalcon_annotations_collection_ce);
phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL);
RETURN_MM();
}
zend_class_entry *phalcon_annotations_adapterinterface_ce;
static const zend_function_entry phalcon_annotations_adapterinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Annotations_AdapterInterface, setReader, arginfo_phalcon_annotations_adapterinterface_setreader)
PHP_ABSTRACT_ME(Phalcon_Annotations_AdapterInterface, getReader, NULL)
PHP_ABSTRACT_ME(Phalcon_Annotations_AdapterInterface, get, arginfo_phalcon_annotations_adapterinterface_get)
PHP_ABSTRACT_ME(Phalcon_Annotations_AdapterInterface, getMethods, arginfo_phalcon_annotations_adapterinterface_getmethods)
PHP_ABSTRACT_ME(Phalcon_Annotations_AdapterInterface, getMethod, arginfo_phalcon_annotations_adapterinterface_getmethod)
PHP_ABSTRACT_ME(Phalcon_Annotations_AdapterInterface, getProperties, arginfo_phalcon_annotations_adapterinterface_getproperties)
PHP_ABSTRACT_ME(Phalcon_Annotations_AdapterInterface, getProperty, arginfo_phalcon_annotations_adapterinterface_getproperty)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_AdapterInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, AdapterInterface, annotations_adapterinterface, phalcon_annotations_adapterinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_annotations_annotation_ce;
static PHP_METHOD(Phalcon_Annotations_Annotation, __construct);
static PHP_METHOD(Phalcon_Annotations_Annotation, getName);
static PHP_METHOD(Phalcon_Annotations_Annotation, getExpression);
static PHP_METHOD(Phalcon_Annotations_Annotation, getExprArguments);
static PHP_METHOD(Phalcon_Annotations_Annotation, getArguments);
static PHP_METHOD(Phalcon_Annotations_Annotation, numberArguments);
static PHP_METHOD(Phalcon_Annotations_Annotation, getArgument);
static PHP_METHOD(Phalcon_Annotations_Annotation, hasArgument);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_annotation___construct, 0, 0, 1)
ZEND_ARG_INFO(0, reflectionData)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_annotation_getexpression, 0, 0, 1)
ZEND_ARG_INFO(0, expr)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_annotation_getargument, 0, 0, 1)
ZEND_ARG_INFO(0, position)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_annotation_hasargument, 0, 0, 1)
ZEND_ARG_INFO(0, position)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_annotation_method_entry[] = {
PHP_ME(Phalcon_Annotations_Annotation, __construct, arginfo_phalcon_annotations_annotation___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Annotations_Annotation, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Annotation, getExpression, arginfo_phalcon_annotations_annotation_getexpression, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Annotation, getExprArguments, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Annotation, getArguments, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Annotation, numberArguments, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Annotation, getArgument, arginfo_phalcon_annotations_annotation_getargument, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Annotation, hasArgument, arginfo_phalcon_annotations_annotation_hasargument, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_Annotations_Annotation, getNamedArgument, getArgument, arginfo_phalcon_annotations_annotation_getargument, ZEND_ACC_PUBLIC)
PHP_MALIAS(Phalcon_Annotations_Annotation, getNamedParameter, getArgument, arginfo_phalcon_annotations_annotation_getargument, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED)
PHP_MALIAS(Phalcon_Annotations_Annotation, hasNamedArgument, hasArgument, arginfo_phalcon_annotations_annotation_hasargument, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Annotation){
PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Annotation, annotations_annotation, phalcon_annotations_annotation_method_entry, 0);
zend_declare_property_null(phalcon_annotations_annotation_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_annotations_annotation_ce, SL("_arguments"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_annotations_annotation_ce, SL("_exprArguments"), ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Annotation, __construct){
zval *reflection_data, *name = NULL, *arguments, *expr_arguments;
zval *argument = NULL, *expr = NULL, *resolved_argument = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &reflection_data);
if (Z_TYPE_P(reflection_data) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Reflection data must be an array");
return;
}
PHALCON_OBS_VAR(name);
phalcon_array_fetch_quick_string(&name, reflection_data, SS("name"), 268211462UL, PH_NOISY);
phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC);
if (phalcon_array_isset_string_fetch(&expr_arguments, reflection_data, SS("arguments"))) {
phalcon_is_iterable(expr_arguments, &ah0, &hp0, 0, 0);
PHALCON_INIT_VAR(arguments);
array_init_size(arguments, zend_hash_num_elements(ah0));
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
zval *n;
PHALCON_GET_HVALUE(argument);
PHALCON_OBS_NVAR(expr);
phalcon_array_fetch_quick_string(&expr, argument, SS("expr"), 258368420UL, PH_NOISY);
PHALCON_INIT_NVAR(resolved_argument);
phalcon_call_method_p1_key(resolved_argument, this_ptr, "getexpression", 2208543925UL, expr);
if (phalcon_array_isset_string_fetch(&n, argument, SS("name"))) {
phalcon_array_update_zval(&arguments, n, &resolved_argument, PH_COPY);
} else {
phalcon_array_append(&arguments, resolved_argument, 0);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
phalcon_update_property_this_quick(this_ptr, SL("_arguments"), arguments, 314247962UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_exprArguments"), expr_arguments, 3152251737UL TSRMLS_CC);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Annotations_Annotation, getName){
RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL);
}
static PHP_METHOD(Phalcon_Annotations_Annotation, getExpression){
zval *expr = NULL, *type, *items, *item = NULL;
zval *resolved_item = NULL, *exception_message;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &expr);
PHALCON_SEPARATE_PARAM(expr);
if (Z_TYPE_P(expr) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "The expression is not valid");
return;
}
PHALCON_OBS_VAR(type);
phalcon_array_fetch_quick_string(&type, expr, SS("type"), 276192743UL, PH_NOISY);
switch (phalcon_get_intval(type)) {
case PHANNOT_T_INTEGER:
case PHANNOT_T_DOUBLE:
case PHANNOT_T_STRING:
case PHANNOT_T_IDENTIFIER:
if (return_value_ptr) {
zval_ptr_dtor(return_value_ptr);
phalcon_array_fetch_string(return_value_ptr, expr, SL("value"), PH_NOISY);
}
else {
phalcon_array_fetch_quick_string(&return_value, expr, SS("value"), 574111618UL, PH_NOISY);
}
RETURN_MM();
/* no break because of implicit return */
case PHANNOT_T_NULL:
RETURN_MM_NULL();
/* no break because of implicit return */
case PHANNOT_T_FALSE:
RETURN_MM_FALSE;
/* no break because of implicit return */
case PHANNOT_T_TRUE:
RETURN_MM_TRUE;
/* no break because of implicit return */
case PHANNOT_T_ARRAY:
PHALCON_OBS_VAR(items);
phalcon_array_fetch_quick_string(&items, expr, SS("items"), 87624199UL, PH_NOISY);
phalcon_is_iterable(items, &ah0, &hp0, 0, 0);
array_init_size(return_value, zend_hash_num_elements(ah0));
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
zval *name;
PHALCON_GET_HVALUE(item);
PHALCON_OBS_NVAR(expr);
phalcon_array_fetch_quick_string(&expr, item, SS("expr"), 258368420UL, PH_NOISY);
PHALCON_INIT_NVAR(resolved_item);
phalcon_call_method_p1_key(resolved_item, this_ptr, "getexpression", 2208543925UL, expr);
if (phalcon_array_isset_string_fetch(&name, item, SS("name"))) {
phalcon_array_update_zval(&return_value, name, &resolved_item, PH_COPY);
} else {
phalcon_array_append(&return_value, resolved_item, 0);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
RETURN_MM();
/* no break because of implicit return */
case PHANNOT_T_ANNOTATION:
object_init_ex(return_value, phalcon_annotations_annotation_ce);
phalcon_call_method_p1_key(NULL, return_value, "__construct", 1107214344UL, expr);
RETURN_MM();
/* no break because of implicit return */
default:
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "The expression ", type, " is unknown");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_annotations_exception_ce, exception_message);
return;
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Annotations_Annotation, getExprArguments){
RETURN_MEMBER_QUICK(this_ptr, "_exprArguments", 3152251737UL);
}
static PHP_METHOD(Phalcon_Annotations_Annotation, getArguments){
RETURN_MEMBER_QUICK(this_ptr, "_arguments", 314247962UL);
}
static PHP_METHOD(Phalcon_Annotations_Annotation, numberArguments){
zval *arguments;
arguments = phalcon_fetch_nproperty_this(this_ptr, SL("_arguments"), PH_NOISY_CC);
phalcon_fast_count(return_value, arguments TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Annotations_Annotation, getArgument){
zval *position, *arguments, *tmp;
phalcon_fetch_params(0, 1, 0, &position);
arguments = phalcon_fetch_nproperty_this(this_ptr, SL("_arguments"), PH_NOISY_CC);
if (phalcon_array_isset_fetch(&tmp, arguments, position)) {
RETURN_ZVAL(tmp, 1, 0);
}
}
static PHP_METHOD(Phalcon_Annotations_Annotation, hasArgument){
zval *position, *arguments;
phalcon_fetch_params(0, 1, 0, &position);
arguments = phalcon_fetch_nproperty_this(this_ptr, SL("_arguments"), PH_NOISY_CC);
RETURN_BOOL(phalcon_array_isset(arguments, position));
}
zend_class_entry *phalcon_annotations_collection_ce;
static PHP_METHOD(Phalcon_Annotations_Collection, __construct);
static PHP_METHOD(Phalcon_Annotations_Collection, count);
static PHP_METHOD(Phalcon_Annotations_Collection, rewind);
static PHP_METHOD(Phalcon_Annotations_Collection, current);
static PHP_METHOD(Phalcon_Annotations_Collection, key);
static PHP_METHOD(Phalcon_Annotations_Collection, next);
static PHP_METHOD(Phalcon_Annotations_Collection, valid);
static PHP_METHOD(Phalcon_Annotations_Collection, getAnnotations);
static PHP_METHOD(Phalcon_Annotations_Collection, get);
static PHP_METHOD(Phalcon_Annotations_Collection, getAll);
static PHP_METHOD(Phalcon_Annotations_Collection, has);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_collection___construct, 0, 0, 0)
ZEND_ARG_INFO(0, reflectionData)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_collection_get, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_collection_getall, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_collection_has, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_collection_method_entry[] = {
PHP_ME(Phalcon_Annotations_Collection, __construct, arginfo_phalcon_annotations_collection___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Annotations_Collection, count, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, rewind, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, current, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, key, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, next, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, valid, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, getAnnotations, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, get, arginfo_phalcon_annotations_collection_get, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, getAll, arginfo_phalcon_annotations_collection_getall, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Collection, has, arginfo_phalcon_annotations_collection_has, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Collection){
PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Collection, annotations_collection, phalcon_annotations_collection_method_entry, 0);
zend_declare_property_long(phalcon_annotations_collection_ce, SL("_position"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_annotations_collection_ce, SL("_annotations"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_annotations_collection_ce TSRMLS_CC, 2, zend_ce_iterator, spl_ce_Countable);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Collection, __construct){
zval *reflection_data = NULL, *annotations, *annotation_data = NULL;
zval *annotation = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &reflection_data);
if (!reflection_data) {
reflection_data = PHALCON_GLOBAL(z_null);
}
if (Z_TYPE_P(reflection_data) != IS_NULL) {
if (Z_TYPE_P(reflection_data) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Reflection data must be an array");
return;
}
}
if (Z_TYPE_P(reflection_data) == IS_ARRAY) {
PHALCON_INIT_VAR(annotations);
array_init(annotations);
phalcon_is_iterable(reflection_data, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(annotation_data);
PHALCON_INIT_NVAR(annotation);
object_init_ex(annotation, phalcon_annotations_annotation_ce);
phalcon_call_method_p1_key(NULL, annotation, "__construct", 1107214344UL, annotation_data);
phalcon_array_append(&annotations, annotation, 0);
zend_hash_move_forward_ex(ah0, &hp0);
}
phalcon_update_property_this_quick(this_ptr, SL("_annotations"), annotations, 1219636498UL TSRMLS_CC);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Annotations_Collection, count){
zval *annotations;
PHALCON_MM_GROW();
PHALCON_OBS_VAR(annotations);
phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC);
phalcon_fast_count(return_value, annotations TSRMLS_CC);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Annotations_Collection, rewind){
phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Annotations_Collection, current){
zval *position, *annotations, *annotation;
position = phalcon_fetch_nproperty_this(this_ptr, SL("_position"), PH_NOISY_CC);
annotations = phalcon_fetch_nproperty_this(this_ptr, SL("_annotations"), PH_NOISY_CC);
if (phalcon_array_isset_fetch(&annotation, annotations, position)) {
RETURN_ZVAL(annotation, 1, 0);
}
RETURN_NULL();
}
static PHP_METHOD(Phalcon_Annotations_Collection, key){
RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL);
}
static PHP_METHOD(Phalcon_Annotations_Collection, next){
phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Annotations_Collection, valid){
zval *position, *annotations;
PHALCON_MM_GROW();
PHALCON_OBS_VAR(position);
phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC);
PHALCON_OBS_VAR(annotations);
phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC);
if (phalcon_array_isset(annotations, position)) {
RETURN_MM_TRUE;
}
RETURN_MM_FALSE;
}
static PHP_METHOD(Phalcon_Annotations_Collection, getAnnotations){
RETURN_MEMBER_QUICK(this_ptr, "_annotations", 1219636498UL);
}
static PHP_METHOD(Phalcon_Annotations_Collection, get){
zval *name, *annotations, *annotation = NULL, *annotation_name = NULL;
zval *exception_message;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &name);
PHALCON_OBS_VAR(annotations);
phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC);
if (Z_TYPE_P(annotations) == IS_ARRAY) {
phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(annotation);
PHALCON_INIT_NVAR(annotation_name);
phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL);
if (PHALCON_IS_EQUAL(name, annotation_name)) {
RETURN_CCTOR(annotation);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
}
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "The collection doesn't have an annotation called '", name, "'");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_annotations_exception_ce, exception_message);
return;
}
static PHP_METHOD(Phalcon_Annotations_Collection, getAll){
zval *name, *found, *annotations, *annotation = NULL, *annotation_name = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &name);
PHALCON_INIT_VAR(found);
array_init(found);
PHALCON_OBS_VAR(annotations);
phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC);
if (Z_TYPE_P(annotations) == IS_ARRAY) {
phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(annotation);
PHALCON_INIT_NVAR(annotation_name);
phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL);
if (PHALCON_IS_EQUAL(name, annotation_name)) {
phalcon_array_append(&found, annotation, PH_SEPARATE);
}
zend_hash_move_forward_ex(ah0, &hp0);
}
}
RETURN_CTOR(found);
}
static PHP_METHOD(Phalcon_Annotations_Collection, has){
zval *name, *annotations, *annotation = NULL, *annotation_name = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &name);
PHALCON_OBS_VAR(annotations);
phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC);
if (Z_TYPE_P(annotations) == IS_ARRAY) {
phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(annotation);
PHALCON_INIT_NVAR(annotation_name);
phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL);
if (PHALCON_IS_EQUAL(name, annotation_name)) {
RETURN_MM_TRUE;
}
zend_hash_move_forward_ex(ah0, &hp0);
}
}
RETURN_MM_FALSE;
}
zend_class_entry *phalcon_annotations_exception_ce;
PHALCON_INIT_CLASS(Phalcon_Annotations_Exception){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations, Exception, annotations_exception, phalcon_exception_ce, NULL, 0);
return SUCCESS;
}
/* Driver template for the LEMON parser generator.
** The author disclaims copyright to this source code.
*/
/* First off, code is include which follows the "include" declaration
** in the input file. */
#include <stdio.h>
/* #line 28 "parser.y" */
#include <ext/standard/php_smart_str.h>
static zval *phannot_ret_literal_zval(int type, phannot_parser_token *T)
{
zval *ret;
MAKE_STD_ZVAL(ret);
array_init_size(ret, 2);
add_assoc_long(ret, phalcon_interned_type, type);
if (T) {
add_assoc_stringl(ret, phalcon_interned_value, T->token, T->token_len, 0);
efree(T);
}
return ret;
}
static zval *phannot_ret_array(zval *items)
{
zval *ret;
MAKE_STD_ZVAL(ret);
array_init_size(ret, 2);
add_assoc_long(ret, phalcon_interned_type, PHANNOT_T_ARRAY);
if (items) {
add_assoc_zval(ret, phalcon_interned_items, items);
}
return ret;
}
static zval *phannot_ret_zval_list(zval *list_left, zval *right_list)
{
zval *ret;
HashPosition pos;
HashTable *list;
MAKE_STD_ZVAL(ret);
array_init(ret);
if (list_left) {
list = Z_ARRVAL_P(list_left);
if (zend_hash_index_exists(list, 0)) {
zend_hash_internal_pointer_reset_ex(list, &pos);
for (;; zend_hash_move_forward_ex(list, &pos)) {
zval ** item;
if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) {
break;
}
Z_ADDREF_PP(item);
add_next_index_zval(ret, *item);
}
zval_ptr_dtor(&list_left);
} else {
add_next_index_zval(ret, list_left);
}
}
add_next_index_zval(ret, right_list);
return ret;
}
static zval *phannot_ret_named_item(phannot_parser_token *name, zval *expr)
{
zval *ret;
MAKE_STD_ZVAL(ret);
array_init_size(ret, 2);
add_assoc_zval(ret, phalcon_interned_expr, expr);
if (name != NULL) {
add_assoc_stringl(ret, phalcon_interned_name, name->token, name->token_len, 0);
efree(name);
}
return ret;
}
static zval *phannot_ret_annotation(phannot_parser_token *name, zval *arguments, phannot_scanner_state *state)
{
zval *ret;
MAKE_STD_ZVAL(ret);
array_init_size(ret, 5);
add_assoc_long(ret, phalcon_interned_type, PHANNOT_T_ANNOTATION);
if (name) {
add_assoc_stringl(ret, phalcon_interned_name, name->token, name->token_len, 0);
efree(name);
}
if (arguments) {
add_assoc_zval(ret, phalcon_interned_arguments, arguments);
}
Z_ADDREF_P(state->active_file);
add_assoc_zval(ret, phalcon_interned_file, state->active_file);
add_assoc_long(ret, phalcon_interned_line, state->active_line);
return ret;
}
/* #line 139 "parser.c" */
/* Next is all token values, in a form suitable for use by makeheaders.
** This section will be null unless lemon is run with the -m switch.
*/
/* Make sure the INTERFACE macro is defined.
*/
#ifndef INTERFACE
# define INTERFACE 1
#endif
/* The next thing included is series of defines which control
** various aspects of the generated parser.
** JJCODETYPE is the data type used for storing terminal
** and nonterminal numbers. "unsigned char" is
** used if there are fewer than 250 terminals
** and nonterminals. "int" is used otherwise.
** JJNOCODE is a number of type JJCODETYPE which corresponds
** to no legal terminal or nonterminal number. This
** number is used to fill in empty slots of the hash
** table.
** JJFALLBACK If defined, this indicates that one or more tokens
** have fall-back values which should be used if the
** original value of the token will not parse.
** JJACTIONTYPE is the data type used for storing terminal
** and nonterminal numbers. "unsigned char" is
** used if there are fewer than 250 rules and
** states combined. "int" is used otherwise.
** phannot_JTOKENTYPE is the data type used for minor tokens given
** directly to the parser from the tokenizer.
** JJMINORTYPE is the data type used for all minor tokens.
** This is typically a union of many types, one of
** which is phannot_JTOKENTYPE. The entry in the union
** for base tokens is called "jj0".
** JJSTACKDEPTH is the maximum depth of the parser's stack.
** phannot_ARG_SDECL A static variable declaration for the %extra_argument
** phannot_ARG_PDECL A parameter declaration for the %extra_argument
** phannot_ARG_STORE Code to store %extra_argument into jjpParser
** phannot_ARG_FETCH Code to extract %extra_argument from jjpParser
** JJNSTATE the combined number of states.
** JJNRULE the number of rules in the grammar
** JJERRORSYMBOL is the code number of the error symbol. If not
** defined, then do no error processing.
*/
#define JJCODETYPE unsigned char
#define JJNOCODE 28
#define JJACTIONTYPE unsigned char
#define phannot_JTOKENTYPE phannot_parser_token*
typedef union {
phannot_JTOKENTYPE jj0;
zval* jj36;
int jj55;
} JJMINORTYPE;
#define JJSTACKDEPTH 100
#define phannot_ARG_SDECL phannot_parser_status *status;
#define phannot_ARG_PDECL ,phannot_parser_status *status
#define phannot_ARG_FETCH phannot_parser_status *status = jjpParser->status
#define phannot_ARG_STORE jjpParser->status = status
#define JJNSTATE 40
#define JJNRULE 25
#define JJERRORSYMBOL 18
#define JJERRSYMDT jj55
#define JJ_NO_ACTION (JJNSTATE+JJNRULE+2)
#define JJ_ACCEPT_ACTION (JJNSTATE+JJNRULE+1)
#define JJ_ERROR_ACTION (JJNSTATE+JJNRULE)
/* Next are that tables used to determine what action to take based on the
** current state and lookahead token. These tables are used to implement
** functions that take a state number and lookahead value and return an
** action integer.
**
** Suppose the action integer is N. Then the action is determined as
** follows
**
** 0 <= N < JJNSTATE Shift N. That is, push the lookahead
** token onto the stack and goto state N.
**
** JJNSTATE <= N < JJNSTATE+JJNRULE Reduce by rule N-JJNSTATE.
**
** N == JJNSTATE+JJNRULE A syntax error has occurred.
**
** N == JJNSTATE+JJNRULE+1 The parser accepts its input.
**
** N == JJNSTATE+JJNRULE+2 No such action. Denotes unused
** slots in the jj_action[] table.
**
** The action table is constructed as a single large table named jj_action[].
** Given state S and lookahead X, the action is computed as
**
** jj_action[ jj_shift_ofst[S] + X ]
**
** If the index value jj_shift_ofst[S]+X is out of range or if the value
** jj_lookahead[jj_shift_ofst[S]+X] is not equal to X or if jj_shift_ofst[S]
** is equal to JJ_SHIFT_USE_DFLT, it means that the action is not in the table
** and that jj_default[S] should be used instead.
**
** The formula above is for computing the action when the lookahead is
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
** a reduce action) then the jj_reduce_ofst[] array is used in place of
** the jj_shift_ofst[] array and JJ_REDUCE_USE_DFLT is used in place of
** JJ_SHIFT_USE_DFLT.
**
** The following are the tables generated in this section:
**
** jj_action[] A single table containing all actions.
** jj_lookahead[] A table containing the lookahead for each entry in
** jj_action. Used to detect hash collisions.
** jj_shift_ofst[] For each state, the offset into jj_action for
** shifting terminals.
** jj_reduce_ofst[] For each state, the offset into jj_action for
** shifting non-terminals after a reduce.
** jj_default[] Default action for each state.
*/
static JJACTIONTYPE jj_action[] = {
/* 0 */ 4, 28, 15, 38, 12, 14, 16, 18, 20, 21,
/* 10 */ 22, 23, 24, 4, 31, 4, 28, 15, 40, 12,
/* 20 */ 30, 16, 18, 20, 21, 22, 23, 24, 3, 31,
/* 30 */ 4, 17, 15, 6, 19, 35, 16, 18, 20, 21,
/* 40 */ 22, 23, 24, 5, 31, 15, 7, 27, 11, 16,
/* 50 */ 54, 54, 15, 25, 27, 11, 16, 15, 32, 27,
/* 60 */ 11, 16, 66, 1, 2, 39, 41, 15, 4, 10,
/* 70 */ 11, 16, 15, 9, 9, 37, 16, 8, 13, 36,
/* 80 */ 9, 29, 34, 54, 54, 54, 54, 54, 26, 54,
/* 90 */ 54, 54, 54, 54, 54, 54, 33,
};
static JJCODETYPE jj_lookahead[] = {
/* 0 */ 2, 3, 22, 5, 6, 25, 26, 9, 10, 11,
/* 10 */ 12, 13, 14, 2, 16, 2, 3, 22, 0, 6,
/* 20 */ 25, 26, 9, 10, 11, 12, 13, 14, 22, 16,
/* 30 */ 2, 3, 22, 4, 6, 25, 26, 9, 10, 11,
/* 40 */ 12, 13, 14, 3, 16, 22, 23, 24, 25, 26,
/* 50 */ 27, 27, 22, 23, 24, 25, 26, 22, 23, 24,
/* 60 */ 25, 26, 19, 20, 21, 22, 0, 22, 2, 24,
/* 70 */ 25, 26, 22, 1, 1, 25, 26, 5, 7, 8,
/* 80 */ 1, 7, 8, 27, 27, 27, 27, 27, 15, 27,
/* 90 */ 27, 27, 27, 27, 27, 27, 17,
};
#define JJ_SHIFT_USE_DFLT (-3)
static signed char jj_shift_ofst[] = {
/* 0 */ 11, 18, 66, -3, 40, 29, -2, 72, -3, 13,
/* 10 */ -3, -3, 71, 28, -3, -3, -3, -3, -3, -3,
/* 20 */ -3, -3, -3, -3, 13, 73, -3, -3, 74, 28,
/* 30 */ -3, 13, 79, -3, 28, -3, 28, -3, -3, -3,
};
#define JJ_REDUCE_USE_DFLT (-21)
static signed char jj_reduce_ofst[] = {
/* 0 */ 43, -21, 6, -21, -21, -21, 23, -21, -21, 45,
/* 10 */ -21, -21, -21, -20, -21, -21, -21, -21, -21, -21,
/* 20 */ -21, -21, -21, -21, 30, -21, -21, -21, -21, -5,
/* 30 */ -21, 35, -21, -21, 10, -21, 50, -21, -21, -21,
};
static JJACTIONTYPE jj_default[] = {
/* 0 */ 65, 65, 65, 42, 65, 46, 65, 65, 44, 65,
/* 10 */ 47, 49, 58, 65, 50, 54, 55, 56, 57, 58,
/* 20 */ 59, 60, 61, 62, 65, 65, 63, 48, 56, 65,
/* 30 */ 52, 65, 65, 64, 65, 53, 65, 51, 45, 43,
};
#define JJ_SZ_ACTTAB (sizeof(jj_action)/sizeof(jj_action[0]))
/* The next table maps tokens into fallback tokens. If a construct
** like the following:
**
** %fallback ID X Y Z.
**
** appears in the grammer, then ID becomes a fallback token for X, Y,
** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
** but it does not parse, the type of the token is changed to ID and
** the parse is retried before an error is thrown.
*/
#ifdef JJFALLBACK
static const JJCODETYPE jjFallback[] = {
};
#endif /* JJFALLBACK */
/* The following structure represents a single element of the
** parser's stack. Information stored includes:
**
** + The state number for the parser at this level of the stack.
**
** + The value of the token stored at this level of the stack.
** (In other words, the "major" token.)
**
** + The semantic value stored at this level of the stack. This is
** the information used by the action routines in the grammar.
** It is sometimes called the "minor" token.
*/
struct jjStackEntry {
int stateno; /* The state-number */
int major; /* The major token value. This is the code
** number for the token at this stack level */
JJMINORTYPE minor; /* The user-supplied minor token value. This
** is the value of the token */
};
typedef struct jjStackEntry jjStackEntry;
/* The state of the parser is completely contained in an instance of
** the following structure */
struct jjParser {
int jjidx; /* Index of top element in stack */
int jjerrcnt; /* Shifts left before out of the error */
phannot_ARG_SDECL /* A place to hold %extra_argument */
jjStackEntry jjstack[JJSTACKDEPTH]; /* The parser's stack */
};
typedef struct jjParser jjParser;
#ifndef NDEBUG
#include <stdio.h>
static FILE *jjTraceFILE = 0;
static char *jjTracePrompt = 0;
#endif /* NDEBUG */
#ifndef NDEBUG
static void phannot_Trace(FILE *TraceFILE, char *zTracePrompt){
jjTraceFILE = TraceFILE;
jjTracePrompt = zTracePrompt;
if( jjTraceFILE==0 ) jjTracePrompt = 0;
else if( jjTracePrompt==0 ) jjTraceFILE = 0;
}
#endif /* NDEBUG */
#ifndef NDEBUG
/* For tracing shifts, the names of all terminals and nonterminals
** are required. The following table supplies these names */
static const char *jjTokenName[] = {
"$", "COMMA", "AT", "IDENTIFIER",
"PARENTHESES_OPEN", "PARENTHESES_CLOSE", "STRING", "EQUALS",
"COLON", "INTEGER", "DOUBLE", "NULL",
"FALSE", "TRUE", "BRACKET_OPEN", "BRACKET_CLOSE",
"SBRACKET_OPEN", "SBRACKET_CLOSE", "error", "program",
"annotation_language", "annotation_list", "annotation", "argument_list",
"argument_item", "expr", "array",
};
#endif /* NDEBUG */
#ifndef NDEBUG
/* For tracing reduce actions, the names of all rules are required.
*/
static const char *jjRuleName[] = {
/* 0 */ "program ::= annotation_language",
/* 1 */ "annotation_language ::= annotation_list",
/* 2 */ "annotation_list ::= annotation_list annotation",
/* 3 */ "annotation_list ::= annotation",
/* 4 */ "annotation ::= AT IDENTIFIER PARENTHESES_OPEN argument_list PARENTHESES_CLOSE",
/* 5 */ "annotation ::= AT IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE",
/* 6 */ "annotation ::= AT IDENTIFIER",
/* 7 */ "argument_list ::= argument_list COMMA argument_item",
/* 8 */ "argument_list ::= argument_item",
/* 9 */ "argument_item ::= expr",
/* 10 */ "argument_item ::= STRING EQUALS expr",
/* 11 */ "argument_item ::= STRING COLON expr",
/* 12 */ "argument_item ::= IDENTIFIER EQUALS expr",
/* 13 */ "argument_item ::= IDENTIFIER COLON expr",
/* 14 */ "expr ::= annotation",
/* 15 */ "expr ::= array",
/* 16 */ "expr ::= IDENTIFIER",
/* 17 */ "expr ::= INTEGER",
/* 18 */ "expr ::= STRING",
/* 19 */ "expr ::= DOUBLE",
/* 20 */ "expr ::= NULL",
/* 21 */ "expr ::= FALSE",
/* 22 */ "expr ::= TRUE",
/* 23 */ "array ::= BRACKET_OPEN argument_list BRACKET_CLOSE",
/* 24 */ "array ::= SBRACKET_OPEN argument_list SBRACKET_CLOSE",
};
#endif /* NDEBUG */
const char *phannot_TokenName(int tokenType){
#ifndef NDEBUG
if( tokenType>0 && tokenType<(sizeof(jjTokenName)/sizeof(jjTokenName[0])) ){
return jjTokenName[tokenType];
}else{
return "Unknown";
}
#else
return "";
#endif
}
void *phannot_Alloc(void *(*mallocProc)(size_t)){
jjParser *pParser;
pParser = (jjParser*)(*mallocProc)( (size_t)sizeof(jjParser) );
if( pParser ){
pParser->jjidx = -1;
}
return pParser;
}
/* The following function deletes the value associated with a
** symbol. The symbol can be either a terminal or nonterminal.
** "jjmajor" is the symbol code, and "jjpminor" is a pointer to
** the value.
*/
static void jj_destructor(JJCODETYPE jjmajor, JJMINORTYPE *jjpminor){
switch( jjmajor ){
/* Here is inserted the actions which take place when a
** terminal or non-terminal is destroyed. This can happen
** when the symbol is popped from the stack during a
** reduce or during error processing or when a parser is
** being destroyed before it is finished parsing.
**
** Note: during a reduce, the only symbols destroyed are those
** which appear on the RHS of the rule, but which are not used
** inside the C code.
*/
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
/* #line 222 "parser.y" */
{
if ((jjpminor->jj0)) {
if ((jjpminor->jj0)->free_flag) {
efree((jjpminor->jj0)->token);
}
efree((jjpminor->jj0));
}
}
/* #line 507 "parser.c" */
break;
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
/* #line 235 "parser.y" */
{ zval_ptr_dtor(&(jjpminor->jj36)); }
/* #line 517 "parser.c" */
break;
default: break; /* If no destructor action specified: do nothing */
}
}
static int jj_pop_parser_stack(jjParser *pParser){
JJCODETYPE jjmajor;
jjStackEntry *jjtos = &pParser->jjstack[pParser->jjidx];
if( pParser->jjidx<0 ) return 0;
#ifndef NDEBUG
if( jjTraceFILE && pParser->jjidx>=0 ){
fprintf(jjTraceFILE,"%sPopping %s\n",
jjTracePrompt,
jjTokenName[jjtos->major]);
}
#endif
jjmajor = jjtos->major;
jj_destructor( jjmajor, &jjtos->minor);
pParser->jjidx--;
return jjmajor;
}
static void phannot_Free(
void *p, /* The parser to be deleted */
void (*freeProc)(void*) /* Function used to reclaim memory */
){
jjParser *pParser = (jjParser*)p;
if( pParser==0 ) return;
while( pParser->jjidx>=0 ) jj_pop_parser_stack(pParser);
(*freeProc)((void*)pParser);
}
static int jj_find_shift_action(
jjParser *pParser, /* The parser */
int iLookAhead /* The look-ahead token */
){
int i;
int stateno = pParser->jjstack[pParser->jjidx].stateno;
/* if( pParser->jjidx<0 ) return JJ_NO_ACTION; */
i = jj_shift_ofst[stateno];
if( i==JJ_SHIFT_USE_DFLT ){
return jj_default[stateno];
}
if( iLookAhead==JJNOCODE ){
return JJ_NO_ACTION;
}
i += iLookAhead;
if( i<0 || i>=JJ_SZ_ACTTAB || jj_lookahead[i]!=iLookAhead ){
#ifdef JJFALLBACK
int iFallback; /* Fallback token */
if( iLookAhead<sizeof(jjFallback)/sizeof(jjFallback[0])
&& (iFallback = jjFallback[iLookAhead])!=0 ){
#ifndef NDEBUG
if( jjTraceFILE ){
fprintf(jjTraceFILE, "%sFALLBACK %s => %s\n",
jjTracePrompt, jjTokenName[iLookAhead], jjTokenName[iFallback]);
}
#endif
return jj_find_shift_action(pParser, iFallback);
}
#endif
return jj_default[stateno];
}else{
return jj_action[i];
}
}
static int jj_find_reduce_action(
jjParser *pParser, /* The parser */
int iLookAhead /* The look-ahead token */
){
int i;
int stateno = pParser->jjstack[pParser->jjidx].stateno;
i = jj_reduce_ofst[stateno];
if( i==JJ_REDUCE_USE_DFLT ){
return jj_default[stateno];
}
if( iLookAhead==JJNOCODE ){
return JJ_NO_ACTION;
}
i += iLookAhead;
if( i<0 || i>=JJ_SZ_ACTTAB || jj_lookahead[i]!=iLookAhead ){
return jj_default[stateno];
}else{
return jj_action[i];
}
}
static void jj_shift(
jjParser *jjpParser, /* The parser to be shifted */
int jjNewState, /* The new state to shift in */
int jjMajor, /* The major token to shift in */
JJMINORTYPE *jjpMinor /* Pointer ot the minor token to shift in */
){
jjStackEntry *jjtos;
jjpParser->jjidx++;
if( jjpParser->jjidx>=JJSTACKDEPTH ){
phannot_ARG_FETCH;
jjpParser->jjidx--;
#ifndef NDEBUG
if( jjTraceFILE ){
fprintf(jjTraceFILE,"%sStack Overflow!\n",jjTracePrompt);
}
#endif
while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser);
/* Here code is inserted which will execute if the parser
** stack every overflows */
phannot_ARG_STORE; /* Suppress warning about unused %extra_argument var */
return;
}
jjtos = &jjpParser->jjstack[jjpParser->jjidx];
jjtos->stateno = jjNewState;
jjtos->major = jjMajor;
jjtos->minor = *jjpMinor;
#ifndef NDEBUG
if( jjTraceFILE && jjpParser->jjidx>0 ){
int i;
fprintf(jjTraceFILE,"%sShift %d\n",jjTracePrompt,jjNewState);
fprintf(jjTraceFILE,"%sStack:",jjTracePrompt);
for(i=1; i<=jjpParser->jjidx; i++)
fprintf(jjTraceFILE," %s",jjTokenName[jjpParser->jjstack[i].major]);
fprintf(jjTraceFILE,"\n");
}
#endif
}
/* The following table contains information about every rule that
** is used during the reduce.
*/
static struct {
JJCODETYPE lhs; /* Symbol on the left-hand side of the rule */
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
} jjRuleInfo[] = {
{ 19, 1 },
{ 20, 1 },
{ 21, 2 },
{ 21, 1 },
{ 22, 5 },
{ 22, 4 },
{ 22, 2 },
{ 23, 3 },
{ 23, 1 },
{ 24, 1 },
{ 24, 3 },
{ 24, 3 },
{ 24, 3 },
{ 24, 3 },
{ 25, 1 },
{ 25, 1 },
{ 25, 1 },
{ 25, 1 },
{ 25, 1 },
{ 25, 1 },
{ 25, 1 },
{ 25, 1 },
{ 25, 1 },
{ 26, 3 },
{ 26, 3 },
};
static void jj_accept(jjParser*); /* Forward Declaration */
static void jj_reduce(
jjParser *jjpParser, /* The parser */
int jjruleno /* Number of the rule by which to reduce */
){
int jjgoto; /* The next state */
int jjact; /* The next action */
JJMINORTYPE jjgotominor; /* The LHS of the rule reduced */
jjStackEntry *jjmsp; /* The top of the parser's stack */
int jjsize; /* Amount to pop the stack */
phannot_ARG_FETCH;
jjmsp = &jjpParser->jjstack[jjpParser->jjidx];
#ifndef NDEBUG
if( jjTraceFILE && jjruleno>=0
&& jjruleno<sizeof(jjRuleName)/sizeof(jjRuleName[0]) ){
fprintf(jjTraceFILE, "%sReduce [%s].\n", jjTracePrompt,
jjRuleName[jjruleno]);
}
#endif /* NDEBUG */
switch( jjruleno ){
/* Beginning here are the reduction cases. A typical example
** follows:
** case 0:
** #line <lineno> <grammarfile>
** { ... } // User supplied code
** #line <lineno> <thisfile>
** break;
*/
case 0:
/* #line 231 "parser.y" */
{
status->ret = jjmsp[0].minor.jj36;
}
/* #line 759 "parser.c" */
break;
case 1:
case 14:
case 15:
/* #line 237 "parser.y" */
{
jjgotominor.jj36 = jjmsp[0].minor.jj36;
}
/* #line 768 "parser.c" */
break;
case 2:
/* #line 243 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_zval_list(jjmsp[-1].minor.jj36, jjmsp[0].minor.jj36);
}
/* #line 775 "parser.c" */
break;
case 3:
case 8:
/* #line 247 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_zval_list(NULL, jjmsp[0].minor.jj36);
}
/* #line 783 "parser.c" */
break;
case 4:
/* #line 254 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_annotation(jjmsp[-3].minor.jj0, jjmsp[-1].minor.jj36, status->scanner_state);
jj_destructor(2,&jjmsp[-4].minor);
jj_destructor(4,&jjmsp[-2].minor);
jj_destructor(5,&jjmsp[0].minor);
}
/* #line 793 "parser.c" */
break;
case 5:
/* #line 258 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_annotation(jjmsp[-2].minor.jj0, NULL, status->scanner_state);
jj_destructor(2,&jjmsp[-3].minor);
jj_destructor(4,&jjmsp[-1].minor);
jj_destructor(5,&jjmsp[0].minor);
}
/* #line 803 "parser.c" */
break;
case 6:
/* #line 262 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_annotation(jjmsp[0].minor.jj0, NULL, status->scanner_state);
jj_destructor(2,&jjmsp[-1].minor);
}
/* #line 811 "parser.c" */
break;
case 7:
/* #line 268 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_zval_list(jjmsp[-2].minor.jj36, jjmsp[0].minor.jj36);
jj_destructor(1,&jjmsp[-1].minor);
}
/* #line 819 "parser.c" */
break;
case 9:
/* #line 278 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_named_item(NULL, jjmsp[0].minor.jj36);
}
/* #line 826 "parser.c" */
break;
case 10:
case 12:
/* #line 282 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_named_item(jjmsp[-2].minor.jj0, jjmsp[0].minor.jj36);
jj_destructor(7,&jjmsp[-1].minor);
}
/* #line 835 "parser.c" */
break;
case 11:
case 13:
/* #line 286 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_named_item(jjmsp[-2].minor.jj0, jjmsp[0].minor.jj36);
jj_destructor(8,&jjmsp[-1].minor);
}
/* #line 844 "parser.c" */
break;
case 16:
/* #line 308 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_IDENTIFIER, jjmsp[0].minor.jj0);
}
/* #line 851 "parser.c" */
break;
case 17:
/* #line 312 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_INTEGER, jjmsp[0].minor.jj0);
}
/* #line 858 "parser.c" */
break;
case 18:
/* #line 316 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_STRING, jjmsp[0].minor.jj0);
}
/* #line 865 "parser.c" */
break;
case 19:
/* #line 320 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_DOUBLE, jjmsp[0].minor.jj0);
}
/* #line 872 "parser.c" */
break;
case 20:
/* #line 324 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_NULL, NULL);
jj_destructor(11,&jjmsp[0].minor);
}
/* #line 880 "parser.c" */
break;
case 21:
/* #line 328 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_FALSE, NULL);
jj_destructor(12,&jjmsp[0].minor);
}
/* #line 888 "parser.c" */
break;
case 22:
/* #line 332 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_TRUE, NULL);
jj_destructor(13,&jjmsp[0].minor);
}
/* #line 896 "parser.c" */
break;
case 23:
/* #line 336 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_array(jjmsp[-1].minor.jj36);
jj_destructor(14,&jjmsp[-2].minor);
jj_destructor(15,&jjmsp[0].minor);
}
/* #line 905 "parser.c" */
break;
case 24:
/* #line 340 "parser.y" */
{
jjgotominor.jj36 = phannot_ret_array(jjmsp[-1].minor.jj36);
jj_destructor(16,&jjmsp[-2].minor);
jj_destructor(17,&jjmsp[0].minor);
}
/* #line 914 "parser.c" */
break;
};
jjgoto = jjRuleInfo[jjruleno].lhs;
jjsize = jjRuleInfo[jjruleno].nrhs;
jjpParser->jjidx -= jjsize;
jjact = jj_find_reduce_action(jjpParser,jjgoto);
if( jjact < JJNSTATE ){
jj_shift(jjpParser,jjact,jjgoto,&jjgotominor);
}else if( jjact == JJNSTATE + JJNRULE + 1 ){
jj_accept(jjpParser);
}
}
static void jj_parse_failed(
jjParser *jjpParser /* The parser */
){
phannot_ARG_FETCH;
#ifndef NDEBUG
if( jjTraceFILE ){
fprintf(jjTraceFILE,"%sFail!\n",jjTracePrompt);
}
#endif
while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser);
/* Here code is inserted which will be executed whenever the
** parser fails */
phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
static void jj_syntax_error(
jjParser *jjpParser, /* The parser */
int jjmajor, /* The major type of the error token */
JJMINORTYPE jjminor /* The minor type of the error token */
){
phannot_ARG_FETCH;
#define JTOKEN (jjminor.jj0)
/* #line 159 "parser.y" */
if (status->scanner_state->start_length) {
{
char *token_name = NULL;
const phannot_token_names *tokens = phannot_tokens;
int token_found = 0;
int active_token = status->scanner_state->active_token;
int near_length = status->scanner_state->start_length;
if (active_token) {
do {
if (tokens->code == active_token) {
token_found = 1;
token_name = tokens->name;
break;
}
++tokens;
} while (tokens[0].code != 0);
}
if (!token_name) {
token_found = 0;
token_name = estrndup("UNKNOWN", strlen("UNKNOWN"));
}
status->syntax_error_len = 128 + strlen(token_name) + Z_STRLEN_P(status->scanner_state->active_file);
status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len);
if (near_length > 0) {
if (status->token->value) {
snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), near to '%s' in %s on line %d", token_name, status->token->value, status->scanner_state->start, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line);
} else {
snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, near to '%s' in %s on line %d", token_name, status->scanner_state->start, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line);
}
} else {
if (active_token != PHANNOT_T_IGNORE) {
if (status->token->value) {
snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), at the end of docblock in %s on line %d", token_name, status->token->value, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line);
} else {
snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, at the end of docblock in %s on line %d", token_name, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line);
}
} else {
snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected EOF, at the end of docblock in %s on line %d", Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line);
}
status->syntax_error[status->syntax_error_len-1] = '\0';
}
if (!token_found) {
if (token_name) {
efree(token_name);
}
}
}
} else {
status->syntax_error_len = 48 + Z_STRLEN_P(status->scanner_state->active_file);
status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len);
sprintf(status->syntax_error, "Syntax error, unexpected EOF in %s", Z_STRVAL_P(status->scanner_state->active_file));
}
status->status = PHANNOT_PARSING_FAILED;
/* #line 1019 "parser.c" */
phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
static void jj_accept(
jjParser *jjpParser /* The parser */
){
phannot_ARG_FETCH;
#ifndef NDEBUG
if( jjTraceFILE ){
fprintf(jjTraceFILE,"%sAccept!\n",jjTracePrompt);
}
#endif
while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser);
/* Here code is inserted which will be executed whenever the
** parser accepts */
phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
/* The main parser program.
** The first argument is a pointer to a structure obtained from
** "phannot_Alloc" which describes the current state of the parser.
** The second argument is the major token number. The third is
** the minor token. The fourth optional argument is whatever the
** user wants (and specified in the grammar) and is available for
** use by the action routines.
**
** Inputs:
** <ul>
** <li> A pointer to the parser (an opaque structure.)
** <li> The major token number.
** <li> The minor token number.
** <li> An option argument of a grammar-specified type.
** </ul>
**
** Outputs:
** None.
*/
static void phannot_(
void *jjp, /* The parser */
int jjmajor, /* The major token code number */
phannot_JTOKENTYPE jjminor /* The value for the token */
phannot_ARG_PDECL /* Optional %extra_argument parameter */
){
JJMINORTYPE jjminorunion;
int jjact; /* The parser action. */
int jjendofinput; /* True if we are at the end of input */
int jjerrorhit = 0; /* True if jjmajor has invoked an error */
jjParser *jjpParser; /* The parser */
/* (re)initialize the parser, if necessary */
jjpParser = (jjParser*)jjp;
if( jjpParser->jjidx<0 ){
if( jjmajor==0 ) return;
jjpParser->jjidx = 0;
jjpParser->jjerrcnt = -1;
jjpParser->jjstack[0].stateno = 0;
jjpParser->jjstack[0].major = 0;
}
jjminorunion.jj0 = jjminor;
jjendofinput = (jjmajor==0);
phannot_ARG_STORE;
#ifndef NDEBUG
if( jjTraceFILE ){
fprintf(jjTraceFILE,"%sInput %s\n",jjTracePrompt,jjTokenName[jjmajor]);
}
#endif
do{
jjact = jj_find_shift_action(jjpParser,jjmajor);
if( jjact<JJNSTATE ){
jj_shift(jjpParser,jjact,jjmajor,&jjminorunion);
jjpParser->jjerrcnt--;
if( jjendofinput && jjpParser->jjidx>=0 ){
jjmajor = 0;
}else{
jjmajor = JJNOCODE;
}
}else if( jjact < JJNSTATE + JJNRULE ){
jj_reduce(jjpParser,jjact-JJNSTATE);
}else if( jjact == JJ_ERROR_ACTION ){
int jjmx;
#ifndef NDEBUG
if( jjTraceFILE ){
fprintf(jjTraceFILE,"%sSyntax Error!\n",jjTracePrompt);
}
#endif
#ifdef JJERRORSYMBOL
/* A syntax error has occurred.
** The response to an error depends upon whether or not the
** grammar defines an error token "ERROR".
**
** This is what we do if the grammar does define ERROR:
**
** * Call the %syntax_error function.
**
** * Begin popping the stack until we enter a state where
** it is legal to shift the error symbol, then shift
** the error symbol.
**
** * Set the error count to three.
**
** * Begin accepting and shifting new tokens. No new error
** processing will occur until three tokens have been
** shifted successfully.
**
*/
if( jjpParser->jjerrcnt<0 ){
jj_syntax_error(jjpParser,jjmajor,jjminorunion);
}
jjmx = jjpParser->jjstack[jjpParser->jjidx].major;
if( jjmx==JJERRORSYMBOL || jjerrorhit ){
#ifndef NDEBUG
if( jjTraceFILE ){
fprintf(jjTraceFILE,"%sDiscard input token %s\n",
jjTracePrompt,jjTokenName[jjmajor]);
}
#endif
jj_destructor(jjmajor,&jjminorunion);
jjmajor = JJNOCODE;
}else{
while(
jjpParser->jjidx >= 0 &&
jjmx != JJERRORSYMBOL &&
(jjact = jj_find_shift_action(jjpParser,JJERRORSYMBOL)) >= JJNSTATE
){
jj_pop_parser_stack(jjpParser);
}
if( jjpParser->jjidx < 0 || jjmajor==0 ){
jj_destructor(jjmajor,&jjminorunion);
jj_parse_failed(jjpParser);
jjmajor = JJNOCODE;
}else if( jjmx!=JJERRORSYMBOL ){
JJMINORTYPE u2;
u2.JJERRSYMDT = 0;
jj_shift(jjpParser,jjact,JJERRORSYMBOL,&u2);
}
}
jjpParser->jjerrcnt = 3;
jjerrorhit = 1;
#else /* JJERRORSYMBOL is not defined */
/* This is what we do if the grammar does not define ERROR:
**
** * Report an error message, and throw away the input token.
**
** * If the input token is $, then fail the parse.
**
** As before, subsequent error messages are suppressed until
** three input tokens have been successfully shifted.
*/
if( jjpParser->jjerrcnt<=0 ){
jj_syntax_error(jjpParser,jjmajor,jjminorunion);
}
jjpParser->jjerrcnt = 3;
jj_destructor(jjmajor,&jjminorunion);
if( jjendofinput ){
jj_parse_failed(jjpParser);
}
jjmajor = JJNOCODE;
#endif
}else{
jj_accept(jjpParser);
jjmajor = JJNOCODE;
}
}while( jjmajor!=JJNOCODE && jjpParser->jjidx>=0 );
return;
}
const phannot_token_names phannot_tokens[] =
{
{ "INTEGER", PHANNOT_T_INTEGER },
{ "DOUBLE", PHANNOT_T_DOUBLE },
{ "STRING", PHANNOT_T_STRING },
{ "IDENTIFIER", PHANNOT_T_IDENTIFIER },
{ "@", PHANNOT_T_AT },
{ ",", PHANNOT_T_COMMA },
{ "=", PHANNOT_T_EQUALS },
{ ":", PHANNOT_T_COLON },
{ "(", PHANNOT_T_PARENTHESES_OPEN },
{ ")", PHANNOT_T_PARENTHESES_CLOSE },
{ "{", PHANNOT_T_BRACKET_OPEN },
{ "}", PHANNOT_T_BRACKET_CLOSE },
{ "[", PHANNOT_T_SBRACKET_OPEN },
{ "]", PHANNOT_T_SBRACKET_CLOSE },
{ "ARBITRARY TEXT", PHANNOT_T_ARBITRARY_TEXT },
{ NULL, 0 }
};
static void *phannot_wrapper_alloc(size_t bytes){
return emalloc(bytes);
}
static void phannot_wrapper_free(void *pointer){
efree(pointer);
}
static void phannot_parse_with_token(void* phannot_parser, int opcode, int parsercode, phannot_scanner_token *token, phannot_parser_status *parser_status){
phannot_parser_token *pToken;
pToken = emalloc(sizeof(phannot_parser_token));
pToken->opcode = opcode;
pToken->token = token->value;
pToken->token_len = token->len;
pToken->free_flag = 1;
phannot_(phannot_parser, parsercode, pToken, parser_status);
token->value = NULL;
token->len = 0;
}
static void phannot_scanner_error_msg(phannot_parser_status *parser_status, zval **error_msg TSRMLS_DC){
int error_length;
char *error, *error_part;
phannot_scanner_state *state = parser_status->scanner_state;
MAKE_STD_ZVAL(*error_msg);
if (state->start) {
error_length = 128 + state->start_length + Z_STRLEN_P(state->active_file);
error = emalloc(sizeof(char) * error_length);
if (state->start_length > 16) {
error_part = estrndup(state->start, 16);
snprintf(error, 64 + state->start_length, "Scanning error before '%s...' in %s on line %d", error_part, Z_STRVAL_P(state->active_file), state->active_line);
efree(error_part);
} else {
snprintf(error, error_length - 1, "Scanning error before '%s' in %s on line %d", state->start, Z_STRVAL_P(state->active_file), state->active_line);
}
error[error_length - 1] = '\0';
ZVAL_STRING(*error_msg, error, 1);
} else {
error_length = sizeof(char) * (64 + Z_STRLEN_P(state->active_file));
error = emalloc(error_length);
snprintf(error, error_length - 1, "Scanning error near to EOF in %s", Z_STRVAL_P(state->active_file));
ZVAL_STRING(*error_msg, error, 1);
error[error_length - 1] = '\0';
}
efree(error);
}
static int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval *line TSRMLS_DC){
zval *error_msg = NULL;
ZVAL_NULL(result);
if (Z_TYPE_P(comment) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Comment must be a string");
return FAILURE;
}
if (phannot_internal_parse_annotations(&result, comment, file_path, line, &error_msg TSRMLS_CC) == FAILURE) {
if (likely(error_msg != NULL)) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg));
zval_ptr_dtor(&error_msg);
}
else {
PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Error parsing annotation");
}
return FAILURE;
}
return SUCCESS;
}
static void phannot_remove_comment_separators(zval *return_value, char *comment, int length, int *start_lines) {
int start_mode = 1, j, i, open_parentheses;
smart_str processed_str = {0};
char ch;
(*start_lines) = 0;
for (i = 0; i < length; i++) {
ch = comment[i];
if (start_mode) {
if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) {
continue;
}
start_mode = 0;
}
if (ch == '@') {
smart_str_appendc(&processed_str, ch);
i++;
open_parentheses = 0;
for (j = i; j < length; j++) {
ch = comment[j];
if (start_mode) {
if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) {
continue;
}
start_mode = 0;
}
if (open_parentheses == 0) {
if (isalnum(ch) || '_' == ch || '\\' == ch) {
smart_str_appendc(&processed_str, ch);
continue;
}
if (ch == '(') {
smart_str_appendc(&processed_str, ch);
open_parentheses++;
continue;
}
} else {
smart_str_appendc(&processed_str, ch);
if (ch == '(') {
open_parentheses++;
} else if (ch == ')') {
open_parentheses--;
} else if (ch == '\n') {
(*start_lines)++;
start_mode = 1;
}
if (open_parentheses > 0) {
continue;
}
}
i = j;
smart_str_appendc(&processed_str, ' ');
break;
}
}
if (ch == '\n') {
(*start_lines)++;
start_mode = 1;
}
}
smart_str_0(&processed_str);
if (processed_str.len) {
RETURN_STRINGL(processed_str.c, processed_str.len, 0);
} else {
RETURN_EMPTY_STRING();
}
}
static int phannot_internal_parse_annotations(zval **result, zval *comment, zval *file_path, zval *line, zval **error_msg TSRMLS_DC) {
char *error;
phannot_scanner_state *state;
phannot_scanner_token token;
int scanner_status, status = SUCCESS, start_lines, error_length;
phannot_parser_status *parser_status = NULL;
void* phannot_parser;
zval processed_comment;
*error_msg = NULL;
if (unlikely(Z_TYPE_P(comment) != IS_STRING) || unlikely(Z_STRVAL_P(comment) == NULL)) {
ZVAL_BOOL(*result, 0);
return FAILURE;
}
if (Z_STRLEN_P(comment) < 2) {
ZVAL_BOOL(*result, 0);
return SUCCESS;
}
phannot_remove_comment_separators(&processed_comment, Z_STRVAL_P(comment), Z_STRLEN_P(comment), &start_lines);
if (Z_STRLEN(processed_comment) < 2) {
ZVAL_BOOL(*result, 0);
efree(Z_STRVAL(processed_comment));
return SUCCESS;
}
phannot_parser = phannot_Alloc(phannot_wrapper_alloc);
if (unlikely(!phannot_parser)) {
ZVAL_BOOL(*result, 0);
return FAILURE;
}
parser_status = emalloc(sizeof(phannot_parser_status));
state = emalloc(sizeof(phannot_scanner_state));
parser_status->status = PHANNOT_PARSING_OK;
parser_status->scanner_state = state;
parser_status->ret = NULL;
parser_status->token = &token;
parser_status->syntax_error = NULL;
state->active_token = 0;
state->start = Z_STRVAL(processed_comment);
state->start_length = 0;
state->mode = PHANNOT_MODE_RAW;
state->active_file = file_path;
token.value = NULL;
token.len = 0;
if (Z_TYPE_P(line) == IS_LONG) {
state->active_line = Z_LVAL_P(line) - start_lines;
} else {
state->active_line = 1;
}
state->end = state->start;
while(0 <= (scanner_status = phannot_get_token(state, &token))) {
state->active_token = token.opcode;
state->start_length = (Z_STRVAL(processed_comment) + Z_STRLEN(processed_comment) - state->start);
switch (token.opcode) {
case PHANNOT_T_IGNORE:
break;
case PHANNOT_T_AT:
phannot_(phannot_parser, PHANNOT_AT, NULL, parser_status);
break;
case PHANNOT_T_COMMA:
phannot_(phannot_parser, PHANNOT_COMMA, NULL, parser_status);
break;
case PHANNOT_T_EQUALS:
phannot_(phannot_parser, PHANNOT_EQUALS, NULL, parser_status);
break;
case PHANNOT_T_COLON:
phannot_(phannot_parser, PHANNOT_COLON, NULL, parser_status);
break;
case PHANNOT_T_PARENTHESES_OPEN:
phannot_(phannot_parser, PHANNOT_PARENTHESES_OPEN, NULL, parser_status);
break;
case PHANNOT_T_PARENTHESES_CLOSE:
phannot_(phannot_parser, PHANNOT_PARENTHESES_CLOSE, NULL, parser_status);
break;
case PHANNOT_T_BRACKET_OPEN:
phannot_(phannot_parser, PHANNOT_BRACKET_OPEN, NULL, parser_status);
break;
case PHANNOT_T_BRACKET_CLOSE:
phannot_(phannot_parser, PHANNOT_BRACKET_CLOSE, NULL, parser_status);
break;
case PHANNOT_T_SBRACKET_OPEN:
phannot_(phannot_parser, PHANNOT_SBRACKET_OPEN, NULL, parser_status);
break;
case PHANNOT_T_SBRACKET_CLOSE:
phannot_(phannot_parser, PHANNOT_SBRACKET_CLOSE, NULL, parser_status);
break;
case PHANNOT_T_NULL:
phannot_(phannot_parser, PHANNOT_NULL, NULL, parser_status);
break;
case PHANNOT_T_TRUE:
phannot_(phannot_parser, PHANNOT_TRUE, NULL, parser_status);
break;
case PHANNOT_T_FALSE:
phannot_(phannot_parser, PHANNOT_FALSE, NULL, parser_status);
break;
case PHANNOT_T_INTEGER:
phannot_parse_with_token(phannot_parser, PHANNOT_T_INTEGER, PHANNOT_INTEGER, &token, parser_status);
break;
case PHANNOT_T_DOUBLE:
phannot_parse_with_token(phannot_parser, PHANNOT_T_DOUBLE, PHANNOT_DOUBLE, &token, parser_status);
break;
case PHANNOT_T_STRING:
phannot_parse_with_token(phannot_parser, PHANNOT_T_STRING, PHANNOT_STRING, &token, parser_status);
break;
case PHANNOT_T_IDENTIFIER:
phannot_parse_with_token(phannot_parser, PHANNOT_T_IDENTIFIER, PHANNOT_IDENTIFIER, &token, parser_status);
break;
/*case PHANNOT_T_ARBITRARY_TEXT:
phannot_parse_with_token(phannot_parser, PHANNOT_T_ARBITRARY_TEXT, PHANNOT_ARBITRARY_TEXT, &token, parser_status);
break;*/
default:
parser_status->status = PHANNOT_PARSING_FAILED;
if (!*error_msg) {
error_length = sizeof(char) * (48 + Z_STRLEN_P(state->active_file));
error = emalloc(error_length);
snprintf(error, error_length - 1, "Scanner: unknown opcode %d on in %s line %d", token.opcode, Z_STRVAL_P(state->active_file), state->active_line);
error[error_length - 1] = '\0';
MAKE_STD_ZVAL(*error_msg);
ZVAL_STRING(*error_msg, error, 1);
efree(error);
}
break;
}
if (parser_status->status != PHANNOT_PARSING_OK) {
status = FAILURE;
break;
}
state->end = state->start;
}
if (status != FAILURE) {
switch (scanner_status) {
case PHANNOT_SCANNER_RETCODE_ERR:
case PHANNOT_SCANNER_RETCODE_IMPOSSIBLE:
if (!*error_msg) {
phannot_scanner_error_msg(parser_status, error_msg TSRMLS_CC);
}
status = FAILURE;
break;
default:
phannot_(phannot_parser, 0, NULL, parser_status);
}
}
state->active_token = 0;
state->start = NULL;
if (parser_status->status != PHANNOT_PARSING_OK) {
status = FAILURE;
if (parser_status->syntax_error) {
if (!*error_msg) {
MAKE_STD_ZVAL(*error_msg);
ZVAL_STRING(*error_msg, parser_status->syntax_error, 1);
}
efree(parser_status->syntax_error);
}
}
phannot_Free(phannot_parser, phannot_wrapper_free);
if (status != FAILURE) {
if (parser_status->status == PHANNOT_PARSING_OK) {
if (parser_status->ret) {
ZVAL_ZVAL(*result, parser_status->ret, 0, 0);
ZVAL_NULL(parser_status->ret);
zval_ptr_dtor(&parser_status->ret);
} else {
array_init(*result);
}
}
}
efree(Z_STRVAL(processed_comment));
efree(parser_status);
efree(state);
return status;
}
zend_class_entry *phalcon_annotations_reader_ce;
static PHP_METHOD(Phalcon_Annotations_Reader, parse);
static PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock);
static const zend_function_entry phalcon_annotations_reader_method_entry[] = {
PHP_ME(Phalcon_Annotations_Reader, parse, arginfo_phalcon_annotations_readerinterface_parse, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Reader, parseDocBlock, arginfo_phalcon_annotations_readerinterface_parsedocblock, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Reader){
PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reader, annotations_reader, phalcon_annotations_reader_method_entry, 0);
zend_class_implements(phalcon_annotations_reader_ce TSRMLS_CC, 1, phalcon_annotations_readerinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Reader, parse){
zval *class_name, *annotations, *reflection;
zval *comment = NULL, *file = NULL, *line = NULL, *class_annotations;
zval *properties, *annotations_properties;
zval *property = NULL, *property_annotations = NULL, *name = NULL;
zval *methods, *annotations_methods, *method = NULL;
zval *method_annotations = NULL;
HashTable *ah0, *ah1;
HashPosition hp0, hp1;
zval **hd;
zend_class_entry *ce0;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &class_name);
if (unlikely(Z_TYPE_P(class_name) != IS_STRING)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "The class name must be an object");
return;
}
PHALCON_INIT_VAR(annotations);
array_init(annotations);
ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
PHALCON_INIT_VAR(reflection);
object_init_ex(reflection, ce0);
if (phalcon_has_constructor(reflection TSRMLS_CC)) {
phalcon_call_method_p1_key(NULL, reflection, "__construct", 1107214344UL, class_name);
}
PHALCON_INIT_VAR(comment);
phalcon_call_method_key(comment, reflection, "getdoccomment", 185815758UL);
if (Z_TYPE_P(comment) == IS_STRING) {
PHALCON_INIT_VAR(file);
phalcon_call_method_key(file, reflection, "getfilename", 984101030UL);
PHALCON_INIT_VAR(line);
phalcon_call_method_key(line, reflection, "getstartline", 2520085083UL);
PHALCON_INIT_VAR(class_annotations);
if (phannot_parse_annotations(class_annotations, comment, file, line TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
if (Z_TYPE_P(class_annotations) == IS_ARRAY) {
phalcon_array_update_quick_string(&annotations, SS("class"), 4138154555UL, &class_annotations, PH_COPY | PH_SEPARATE);
}
}
PHALCON_INIT_VAR(properties);
phalcon_call_method_key(properties, reflection, "getproperties", 3608986354UL);
if (phalcon_fast_count_ev(properties TSRMLS_CC)) {
PHALCON_INIT_NVAR(line);
ZVAL_LONG(line, 1);
PHALCON_INIT_VAR(annotations_properties);
array_init(annotations_properties);
phalcon_is_iterable(properties, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(property);
PHALCON_INIT_NVAR(comment);
phalcon_call_method_key(comment, property, "getdoccomment", 185815758UL);
if (Z_TYPE_P(comment) == IS_STRING) {
PHALCON_INIT_NVAR(file);
phalcon_call_method_key(file, reflection, "getfilename", 984101030UL);
PHALCON_INIT_NVAR(property_annotations);
if (phannot_parse_annotations(property_annotations, comment, file, line TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
if (Z_TYPE_P(property_annotations) == IS_ARRAY) {
PHALCON_OBS_NVAR(name);
phalcon_read_property(&name, property, SL("name"), PH_NOISY_CC);
phalcon_array_update_zval(&annotations_properties, name, &property_annotations, PH_COPY | PH_SEPARATE);
}
}
zend_hash_move_forward_ex(ah0, &hp0);
}
if (phalcon_fast_count_ev(annotations_properties TSRMLS_CC)) {
phalcon_array_update_quick_string(&annotations, SS("properties"), 1619284338UL, &annotations_properties, PH_COPY | PH_SEPARATE);
}
}
PHALCON_INIT_VAR(methods);
phalcon_call_method_key(methods, reflection, "getmethods", 20298521UL);
if (phalcon_fast_count_ev(methods TSRMLS_CC)) {
PHALCON_INIT_VAR(annotations_methods);
array_init(annotations_methods);
phalcon_is_iterable(methods, &ah1, &hp1, 0, 0);
while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
PHALCON_GET_HVALUE(method);
PHALCON_INIT_NVAR(comment);
phalcon_call_method_key(comment, method, "getdoccomment", 185815758UL);
if (Z_TYPE_P(comment) == IS_STRING) {
PHALCON_INIT_NVAR(file);
phalcon_call_method_key(file, method, "getfilename", 984101030UL);
PHALCON_INIT_NVAR(line);
phalcon_call_method_key(line, method, "getstartline", 2520085083UL);
PHALCON_INIT_NVAR(method_annotations);
if (phannot_parse_annotations(method_annotations, comment, file, line TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
if (Z_TYPE_P(method_annotations) == IS_ARRAY) {
PHALCON_OBS_NVAR(name);
phalcon_read_property(&name, method, SL("name"), PH_NOISY_CC);
phalcon_array_update_zval(&annotations_methods, name, &method_annotations, PH_COPY | PH_SEPARATE);
}
}
zend_hash_move_forward_ex(ah1, &hp1);
}
if (phalcon_fast_count_ev(annotations_methods TSRMLS_CC)) {
phalcon_array_update_quick_string(&annotations, SS("methods"), 2292439449UL, &annotations_methods, PH_COPY | PH_SEPARATE);
}
}
RETURN_CTOR(annotations);
}
static PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock){
zval *doc_block, *file = NULL, *line = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 2, &doc_block, &file, &line);
if (!file) {
PHALCON_INIT_VAR(file);
} else {
PHALCON_SEPARATE_PARAM(file);
}
if (!line) {
line = PHALCON_GLOBAL(z_null);
}
if (Z_TYPE_P(file) != IS_STRING) {
PHALCON_INIT_NVAR(file);
ZVAL_STRING(file, "eval code", 1);
}
if (phannot_parse_annotations(return_value, doc_block, file, line TSRMLS_CC) == FAILURE) {
RETURN_MM();
}
RETURN_MM();
}
zend_class_entry *phalcon_annotations_readerinterface_ce;
static const zend_function_entry phalcon_annotations_readerinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Annotations_ReaderInterface, parse, arginfo_phalcon_annotations_readerinterface_parse)
ZEND_FENTRY(parseDocBlock, NULL, arginfo_phalcon_annotations_readerinterface_parsedocblock, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_ReaderInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, ReaderInterface, annotations_readerinterface, phalcon_annotations_readerinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_annotations_reflection_ce;
static PHP_METHOD(Phalcon_Annotations_Reflection, __construct);
static PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations);
static PHP_METHOD(Phalcon_Annotations_Reflection, getMethodsAnnotations);
static PHP_METHOD(Phalcon_Annotations_Reflection, getPropertiesAnnotations);
static PHP_METHOD(Phalcon_Annotations_Reflection, getReflectionData);
static PHP_METHOD(Phalcon_Annotations_Reflection, __set_state);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_reflection___construct, 0, 0, 0)
ZEND_ARG_INFO(0, reflectionData)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_reflection___set_state, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_reflection_method_entry[] = {
PHP_ME(Phalcon_Annotations_Reflection, __construct, arginfo_phalcon_annotations_reflection___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Annotations_Reflection, getClassAnnotations, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Reflection, getMethodsAnnotations, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Reflection, getPropertiesAnnotations, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Reflection, getReflectionData, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Reflection, __set_state, arginfo_phalcon_annotations_reflection___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Reflection){
PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reflection, annotations_reflection, phalcon_annotations_reflection_method_entry, 0);
zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_reflectionData"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_classAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_methodAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_propertyAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Reflection, __construct){
zval *reflection_data = NULL;
phalcon_fetch_params(0, 0, 1, &reflection_data);
if (reflection_data && Z_TYPE_P(reflection_data) == IS_ARRAY) {
phalcon_update_property_this_quick(this_ptr, SL("_reflectionData"), reflection_data, 3848141129UL TSRMLS_CC);
}
}
static PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations){
zval *annotations, *reflection_data, *reflection_class;
PHALCON_MM_GROW();
annotations = phalcon_fetch_nproperty_this(this_ptr, SL("_classAnnotations"), PH_NOISY_CC);
if (Z_TYPE_P(annotations) != IS_OBJECT) {
reflection_data = phalcon_fetch_nproperty_this(this_ptr, SL("_reflectionData"), PH_NOISY_CC);
if (phalcon_array_isset_string_fetch(&reflection_class, reflection_data, SS("class"))) {
object_init_ex(return_value, phalcon_annotations_collection_ce);
phalcon_call_method_p1_key(NULL, return_value, "__construct", 1107214344UL, reflection_class);
phalcon_update_property_this_quick(this_ptr, SL("_classAnnotations"), return_value, 372163368UL TSRMLS_CC);
RETURN_MM();
}
phalcon_update_property_this(this_ptr, SL("_classAnnotations"), PHALCON_GLOBAL(z_false) TSRMLS_CC);
RETURN_MM_FALSE;
}
RETURN_CTOR(annotations);
}
static PHP_METHOD(Phalcon_Annotations_Reflection, getMethodsAnnotations){
zval *annotations, *reflection_data, *reflection_methods;
zval *reflection_method = NULL, *method_name = NULL;
zval *collection = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
annotations = phalcon_fetch_nproperty_this(this_ptr, SL("_methodAnnotations"), PH_NOISY_CC);
if (Z_TYPE_P(annotations) != IS_OBJECT) {
reflection_data = phalcon_fetch_nproperty_this(this_ptr, SL("_reflectionData"), PH_NOISY_CC);
if (phalcon_array_isset_string_fetch(&reflection_methods, reflection_data, SS("methods"))) {
if (phalcon_fast_count_ev(reflection_methods TSRMLS_CC)) {
array_init(return_value);
phalcon_is_iterable(reflection_methods, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(method_name, ah0, hp0);
PHALCON_GET_HVALUE(reflection_method);
PHALCON_INIT_NVAR(collection);
object_init_ex(collection, phalcon_annotations_collection_ce);
phalcon_call_method_p1_key(NULL, collection, "__construct", 1107214344UL, reflection_method);
phalcon_array_update_zval(&return_value, method_name, &collection, PH_COPY);
zend_hash_move_forward_ex(ah0, &hp0);
}
phalcon_update_property_this_quick(this_ptr, SL("_methodAnnotations"), return_value, 4229536243UL TSRMLS_CC);
RETURN_MM();
}
}
phalcon_update_property_bool(this_ptr, SL("_methodAnnotations"), 0 TSRMLS_CC);
RETURN_MM_FALSE;
}
RETURN_CTOR(annotations);
}
static PHP_METHOD(Phalcon_Annotations_Reflection, getPropertiesAnnotations){
zval *annotations, *reflection_data, *reflection_properties;
zval *reflection_property = NULL, *property = NULL;
zval *collection = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
PHALCON_MM_GROW();
annotations = phalcon_fetch_nproperty_this(this_ptr, SL("_propertyAnnotations"), PH_NOISY_CC);
if (Z_TYPE_P(annotations) != IS_OBJECT) {
reflection_data = phalcon_fetch_nproperty_this(this_ptr, SL("_reflectionData"), PH_NOISY_CC);
if (phalcon_array_isset_string_fetch(&reflection_properties, reflection_data, SS("properties"))) {
if (phalcon_fast_count_ev(reflection_properties TSRMLS_CC)) {
array_init(return_value);
phalcon_is_iterable(reflection_properties, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(property, ah0, hp0);
PHALCON_GET_HVALUE(reflection_property);
PHALCON_INIT_NVAR(collection);
object_init_ex(collection, phalcon_annotations_collection_ce);
phalcon_call_method_p1_key(NULL, collection, "__construct", 1107214344UL, reflection_property);
phalcon_array_update_zval(&return_value, property, &collection, PH_COPY);
zend_hash_move_forward_ex(ah0, &hp0);
}
phalcon_update_property_this_quick(this_ptr, SL("_propertyAnnotations"), return_value, 762458551UL TSRMLS_CC);
RETURN_MM();
}
}
phalcon_update_property_bool(this_ptr, SL("_propertyAnnotations"), 0 TSRMLS_CC);
RETURN_MM_FALSE;
}
RETURN_CTOR(annotations);
}
static PHP_METHOD(Phalcon_Annotations_Reflection, getReflectionData){
RETURN_MEMBER_QUICK(this_ptr, "_reflectionData", 3848141129UL);
}
static PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){
zval *data, *reflection_data;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &data);
if (Z_TYPE_P(data) == IS_ARRAY) {
if (phalcon_array_isset_quick_string(data, SS("_reflectionData"), 3848141129UL)) {
PHALCON_OBS_VAR(reflection_data);
phalcon_array_fetch_quick_string(&reflection_data, data, SS("_reflectionData"), 3848141129UL, PH_NOISY);
object_init_ex(return_value, phalcon_annotations_reflection_ce);
phalcon_call_method_p1_key(NULL, return_value, "__construct", 1107214344UL, reflection_data);
RETURN_MM();
}
}
object_init_ex(return_value, phalcon_annotations_reflection_ce);
phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL);
RETURN_MM();
}
/* Generated by re2c 0.13.5 on Sun Dec 1 23:47:17 2013 */
/* #line 1 "scanner.re" */
#define JJCTYPE unsigned char
#define JJCURSOR (s->start)
#define JJLIMIT (s->end)
#define JJMARKER q
static int phannot_get_token(phannot_scanner_state *s, phannot_scanner_token *token) {
char next, *q = JJCURSOR, *start = JJCURSOR;
int status = PHANNOT_SCANNER_RETCODE_IMPOSSIBLE;
while (PHANNOT_SCANNER_RETCODE_IMPOSSIBLE == status) {
if (s->mode == PHANNOT_MODE_RAW) {
if (*JJCURSOR == '\n') {
s->active_line++;
}
next = *(JJCURSOR+1);
if (*JJCURSOR == '\0' || *JJCURSOR == '@') {
if ((next >= 'A' && next <= 'Z') || (next >= 'a' && next <= 'z')) {
s->mode = PHANNOT_MODE_ANNOTATION;
continue;
}
}
++JJCURSOR;
token->opcode = PHANNOT_T_IGNORE;
return 0;
} else {
/* #line 66 "scanner.c" */
{
JJCTYPE jjch;
unsigned int jjaccept = 0;
static const unsigned char jjbm[] = {
0, 96, 96, 96, 96, 96, 96, 96,
96, 104, 96, 96, 96, 104, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
104, 96, 32, 96, 96, 96, 96, 64,
96, 96, 96, 96, 96, 96, 96, 96,
240, 240, 240, 240, 240, 240, 240, 240,
240, 240, 96, 96, 96, 96, 96, 96,
96, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 96, 0, 96, 96, 112,
96, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
96, 96, 96, 96, 96, 96, 96, 96,
};
jjch = *JJCURSOR;
switch (jjch) {
case 0x00: goto jj38;
case '\t':
case '\r':
case ' ': goto jj34;
case '\n': goto jj36;
case '"': goto jj10;
case '\'': goto jj11;
case '(': goto jj14;
case ')': goto jj16;
case ',': goto jj32;
case '-': goto jj2;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': goto jj4;
case ':': goto jj30;
case '=': goto jj28;
case '@': goto jj26;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z': goto jj13;
case 'F':
case 'f': goto jj8;
case 'N':
case 'n': goto jj6;
case 'T':
case 't': goto jj9;
case '[': goto jj22;
case '\\': goto jj12;
case ']': goto jj24;
case '{': goto jj18;
case '}': goto jj20;
default: goto jj40;
}
jj2:
++JJCURSOR;
if (jjbm[0+(jjch = *JJCURSOR)] & 128) {
goto jj71;
}
jj3:
/* #line 183 "scanner.re" */
{
status = PHANNOT_SCANNER_RETCODE_ERR;
break;
}
/* #line 202 "scanner.c" */
jj4:
jjaccept = 0;
jjch = *(JJMARKER = ++JJCURSOR);
goto jj72;
jj5:
/* #line 67 "scanner.re" */
{
token->opcode = PHANNOT_T_INTEGER;
token->value = estrndup(start, JJCURSOR - start);
token->len = JJCURSOR - start;
q = JJCURSOR;
return 0;
}
/* #line 216 "scanner.c" */
jj6:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'U') goto jj66;
if (jjch == 'u') goto jj66;
goto jj44;
jj7:
/* #line 109 "scanner.re" */
{
token->opcode = PHANNOT_T_IDENTIFIER;
token->value = estrndup(start, JJCURSOR - start);
token->len = JJCURSOR - start;
q = JJCURSOR;
return 0;
}
/* #line 232 "scanner.c" */
jj8:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'A') goto jj61;
if (jjch == 'a') goto jj61;
goto jj44;
jj9:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'R') goto jj57;
if (jjch == 'r') goto jj57;
goto jj44;
jj10:
jjaccept = 2;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch <= 0x00) goto jj3;
goto jj55;
jj11:
jjaccept = 2;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch <= 0x00) goto jj3;
goto jj50;
jj12:
jjch = *++JJCURSOR;
if (jjch <= '^') {
if (jjch <= '@') goto jj3;
if (jjch <= 'Z') goto jj43;
goto jj3;
} else {
if (jjch == '`') goto jj3;
if (jjch <= 'z') goto jj43;
goto jj3;
}
jj13:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
goto jj44;
jj14:
++JJCURSOR;
/* #line 117 "scanner.re" */
{
token->opcode = PHANNOT_T_PARENTHESES_OPEN;
return 0;
}
/* #line 277 "scanner.c" */
jj16:
++JJCURSOR;
/* #line 122 "scanner.re" */
{
token->opcode = PHANNOT_T_PARENTHESES_CLOSE;
return 0;
}
/* #line 285 "scanner.c" */
jj18:
++JJCURSOR;
/* #line 127 "scanner.re" */
{
token->opcode = PHANNOT_T_BRACKET_OPEN;
return 0;
}
/* #line 293 "scanner.c" */
jj20:
++JJCURSOR;
/* #line 132 "scanner.re" */
{
token->opcode = PHANNOT_T_BRACKET_CLOSE;
return 0;
}
/* #line 301 "scanner.c" */
jj22:
++JJCURSOR;
/* #line 137 "scanner.re" */
{
token->opcode = PHANNOT_T_SBRACKET_OPEN;
return 0;
}
/* #line 309 "scanner.c" */
jj24:
++JJCURSOR;
/* #line 142 "scanner.re" */
{
token->opcode = PHANNOT_T_SBRACKET_CLOSE;
return 0;
}
/* #line 317 "scanner.c" */
jj26:
++JJCURSOR;
/* #line 147 "scanner.re" */
{
token->opcode = PHANNOT_T_AT;
return 0;
}
/* #line 325 "scanner.c" */
jj28:
++JJCURSOR;
/* #line 152 "scanner.re" */
{
token->opcode = PHANNOT_T_EQUALS;
return 0;
}
/* #line 333 "scanner.c" */
jj30:
++JJCURSOR;
/* #line 157 "scanner.re" */
{
token->opcode = PHANNOT_T_COLON;
return 0;
}
/* #line 341 "scanner.c" */
jj32:
++JJCURSOR;
/* #line 162 "scanner.re" */
{
token->opcode = PHANNOT_T_COMMA;
return 0;
}
/* #line 349 "scanner.c" */
jj34:
++JJCURSOR;
jjch = *JJCURSOR;
goto jj42;
jj35:
/* #line 167 "scanner.re" */
{
token->opcode = PHANNOT_T_IGNORE;
return 0;
}
/* #line 360 "scanner.c" */
jj36:
++JJCURSOR;
/* #line 172 "scanner.re" */
{
s->active_line++;
token->opcode = PHANNOT_T_IGNORE;
return 0;
}
/* #line 369 "scanner.c" */
jj38:
++JJCURSOR;
/* #line 178 "scanner.re" */
{
status = PHANNOT_SCANNER_RETCODE_EOF;
break;
}
/* #line 377 "scanner.c" */
jj40:
jjch = *++JJCURSOR;
goto jj3;
jj41:
++JJCURSOR;
jjch = *JJCURSOR;
jj42:
if (jjbm[0+jjch] & 8) {
goto jj41;
}
goto jj35;
jj43:
jjaccept = 1;
JJMARKER = ++JJCURSOR;
jjch = *JJCURSOR;
jj44:
if (jjbm[0+jjch] & 16) {
goto jj43;
}
if (jjch != '\\') goto jj7;
jj45:
++JJCURSOR;
jjch = *JJCURSOR;
if (jjch <= '^') {
if (jjch <= '@') goto jj46;
if (jjch <= 'Z') goto jj47;
} else {
if (jjch == '`') goto jj46;
if (jjch <= 'z') goto jj47;
}
jj46:
JJCURSOR = JJMARKER;
if (jjaccept <= 2) {
if (jjaccept <= 1) {
if (jjaccept <= 0) {
goto jj5;
} else {
goto jj7;
}
} else {
goto jj3;
}
} else {
if (jjaccept <= 4) {
if (jjaccept <= 3) {
goto jj60;
} else {
goto jj65;
}
} else {
goto jj69;
}
}
jj47:
jjaccept = 1;
JJMARKER = ++JJCURSOR;
jjch = *JJCURSOR;
if (jjch <= '[') {
if (jjch <= '9') {
if (jjch <= '/') goto jj7;
goto jj47;
} else {
if (jjch <= '@') goto jj7;
if (jjch <= 'Z') goto jj47;
goto jj7;
}
} else {
if (jjch <= '_') {
if (jjch <= '\\') goto jj45;
if (jjch <= '^') goto jj7;
goto jj47;
} else {
if (jjch <= '`') goto jj7;
if (jjch <= 'z') goto jj47;
goto jj7;
}
}
jj49:
++JJCURSOR;
jjch = *JJCURSOR;
jj50:
if (jjbm[0+jjch] & 32) {
goto jj49;
}
if (jjch <= 0x00) goto jj46;
if (jjch <= '[') goto jj52;
++JJCURSOR;
jjch = *JJCURSOR;
if (jjch == '\n') goto jj46;
goto jj49;
jj52:
++JJCURSOR;
/* #line 100 "scanner.re" */
{
token->opcode = PHANNOT_T_STRING;
token->value = estrndup(q, JJCURSOR - q - 1);
token->len = JJCURSOR - q - 1;
q = JJCURSOR;
return 0;
}
/* #line 478 "scanner.c" */
jj54:
++JJCURSOR;
jjch = *JJCURSOR;
jj55:
if (jjbm[0+jjch] & 64) {
goto jj54;
}
if (jjch <= 0x00) goto jj46;
if (jjch <= '[') goto jj52;
++JJCURSOR;
jjch = *JJCURSOR;
if (jjch == '\n') goto jj46;
goto jj54;
jj57:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'U') goto jj58;
if (jjch != 'u') goto jj44;
jj58:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'E') goto jj59;
if (jjch != 'e') goto jj44;
jj59:
jjaccept = 3;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjbm[0+jjch] & 16) {
goto jj43;
}
if (jjch == '\\') goto jj45;
jj60:
/* #line 94 "scanner.re" */
{
token->opcode = PHANNOT_T_TRUE;
return 0;
}
/* #line 515 "scanner.c" */
jj61:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'L') goto jj62;
if (jjch != 'l') goto jj44;
jj62:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'S') goto jj63;
if (jjch != 's') goto jj44;
jj63:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'E') goto jj64;
if (jjch != 'e') goto jj44;
jj64:
jjaccept = 4;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjbm[0+jjch] & 16) {
goto jj43;
}
if (jjch == '\\') goto jj45;
jj65:
/* #line 89 "scanner.re" */
{
token->opcode = PHANNOT_T_FALSE;
return 0;
}
/* #line 544 "scanner.c" */
jj66:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'L') goto jj67;
if (jjch != 'l') goto jj44;
jj67:
jjaccept = 1;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjch == 'L') goto jj68;
if (jjch != 'l') goto jj44;
jj68:
jjaccept = 5;
jjch = *(JJMARKER = ++JJCURSOR);
if (jjbm[0+jjch] & 16) {
goto jj43;
}
if (jjch == '\\') goto jj45;
jj69:
/* #line 84 "scanner.re" */
{
token->opcode = PHANNOT_T_NULL;
return 0;
}
/* #line 568 "scanner.c" */
jj70:
jjch = *++JJCURSOR;
if (jjch <= '/') goto jj46;
if (jjch <= '9') goto jj73;
goto jj46;
jj71:
jjaccept = 0;
JJMARKER = ++JJCURSOR;
jjch = *JJCURSOR;
jj72:
if (jjbm[0+jjch] & 128) {
goto jj71;
}
if (jjch == '.') goto jj70;
goto jj5;
jj73:
++JJCURSOR;
jjch = *JJCURSOR;
if (jjch <= '/') goto jj75;
if (jjch <= '9') goto jj73;
jj75:
/* #line 76 "scanner.re" */
{
token->opcode = PHANNOT_T_DOUBLE;
token->value = estrndup(start, JJCURSOR - start);
token->len = JJCURSOR - start;
q = JJCURSOR;
return 0;
}
/* #line 598 "scanner.c" */
}
/* #line 188 "scanner.re" */
}
}
return status;
}
zend_class_entry *phalcon_annotations_adapter_apc_ce;
static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, read);
static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, write);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_apc_read, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_apc_write, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_adapter_apc_method_entry[] = {
PHP_ME(Phalcon_Annotations_Adapter_Apc, read, arginfo_phalcon_annotations_adapter_apc_read, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter_Apc, write, arginfo_phalcon_annotations_adapter_apc_write, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Apc){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Apc, annotations_adapter_apc, phalcon_annotations_adapter_ce, phalcon_annotations_adapter_apc_method_entry, 0);
zend_class_implements(phalcon_annotations_adapter_apc_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, read){
zval *key, *prefixed_key;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &key);
PHALCON_INIT_VAR(prefixed_key);
PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key);
phalcon_strtolower_inplace(prefixed_key);
if (unlikely(!return_value_ptr)) {
return_value_ptr = &return_value;
}
phalcon_return_call_func_p1("apc_fetch", prefixed_key);
if (Z_TYPE_PP(return_value_ptr) != IS_OBJECT) {
zval_dtor(*return_value_ptr);
ZVAL_NULL(*return_value_ptr);
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, write){
zval *key, *data, *prefixed_key;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &key, &data);
PHALCON_INIT_VAR(prefixed_key);
PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key);
phalcon_strtolower_inplace(prefixed_key);
phalcon_call_func_p2_noret("apc_store", prefixed_key, data);
PHALCON_MM_RESTORE();
}
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_var.h>
zend_class_entry *phalcon_annotations_adapter_files_ce;
static PHP_METHOD(Phalcon_Annotations_Adapter_Files, __construct);
static PHP_METHOD(Phalcon_Annotations_Adapter_Files, read);
static PHP_METHOD(Phalcon_Annotations_Adapter_Files, write);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_files___construct, 0, 0, 0)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_files_read, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_files_write, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_adapter_files_method_entry[] = {
PHP_ME(Phalcon_Annotations_Adapter_Files, __construct, arginfo_phalcon_annotations_adapter_files___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Annotations_Adapter_Files, read, arginfo_phalcon_annotations_adapter_files_read, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter_Files, write, arginfo_phalcon_annotations_adapter_files_write, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Files){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Files, annotations_adapter_files, phalcon_annotations_adapter_ce, phalcon_annotations_adapter_files_method_entry, 0);
zend_declare_property_string(phalcon_annotations_adapter_files_ce, SL("_annotationsDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_annotations_adapter_files_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Files, __construct){
zval *options = NULL, *annotations_dir;
phalcon_fetch_params(0, 0, 1, &options);
if (options && Z_TYPE_P(options) == IS_ARRAY) {
if (phalcon_array_isset_string_fetch(&annotations_dir, options, SS("annotationsDir"))) {
phalcon_update_property_this_quick(this_ptr, SL("_annotationsDir"), annotations_dir, 4233102065UL TSRMLS_CC);
}
}
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Files, read){
zval *key, *annotations_dir, *virtual_key, *path;
zval separator;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &key);
annotations_dir = phalcon_fetch_nproperty_this(this_ptr, SL("_annotationsDir"), PH_NOISY_CC);
INIT_ZVAL(separator);
ZVAL_STRINGL(&separator, "_", 1, 0);
PHALCON_INIT_VAR(virtual_key);
phalcon_prepare_virtual_path(virtual_key, key, &separator TSRMLS_CC);
PHALCON_INIT_VAR(path);
PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php");
if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) {
if (phalcon_require_ret(return_value, path TSRMLS_CC) == FAILURE) {
zval_dtor(return_value);
RETVAL_NULL();
}
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){
zval *key, *data, *annotations_dir;
zval *virtual_key, *path, *php_export;
zval *status;
zval separator;
smart_str exp = { NULL, 0, 0 };
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &key, &data);
annotations_dir = phalcon_fetch_nproperty_this(this_ptr, SL("_annotationsDir"), PH_NOISY_CC);
INIT_ZVAL(separator);
ZVAL_STRINGL(&separator, "_", 1, 0);
PHALCON_INIT_VAR(virtual_key);
phalcon_prepare_virtual_path(virtual_key, key, &separator TSRMLS_CC);
PHALCON_INIT_VAR(path);
PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php");
smart_str_appends(&exp, "<?php return ");
php_var_export_ex(&data, 0, &exp TSRMLS_CC);
smart_str_appendc(&exp, ';');
smart_str_0(&exp);
PHALCON_INIT_VAR(php_export);
ZVAL_STRINGL(php_export, exp.c, exp.len, 0);
PHALCON_INIT_VAR(status);
phalcon_file_put_contents(status, path, php_export TSRMLS_CC);
if (PHALCON_IS_FALSE(status)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Annotations directory cannot be written");
return;
}
PHALCON_MM_RESTORE();
}
zend_class_entry *phalcon_annotations_adapter_memory_ce;
static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, read);
static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, write);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_memory_read, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_memory_write, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_adapter_memory_method_entry[] = {
PHP_ME(Phalcon_Annotations_Adapter_Memory, read, arginfo_phalcon_annotations_adapter_memory_read, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter_Memory, write, arginfo_phalcon_annotations_adapter_memory_write, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Memory){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Memory, annotations_adapter_memory, phalcon_annotations_adapter_ce, phalcon_annotations_adapter_memory_method_entry, 0);
zend_declare_property_null(phalcon_annotations_adapter_memory_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_annotations_adapter_memory_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, read){
zval *key, *data, *lowercased_key, *annotations;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &key);
data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY_CC);
PHALCON_INIT_VAR(lowercased_key);
phalcon_fast_strtolower(lowercased_key, key);
if (phalcon_array_isset_fetch(&annotations, data, lowercased_key)) {
RETURN_CTOR(annotations);
}
RETURN_MM_NULL();
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, write){
zval *key, *data, *lowercased_key;
phalcon_fetch_params(0, 2, 0, &key, &data);
MAKE_STD_ZVAL(lowercased_key);
phalcon_fast_strtolower(lowercased_key, key);
phalcon_update_property_array(this_ptr, SL("_data"), lowercased_key, data TSRMLS_CC);
zval_ptr_dtor(&lowercased_key);
}
zend_class_entry *phalcon_annotations_adapter_xcache_ce;
static PHP_METHOD(Phalcon_Annotations_Adapter_Xcache, read);
static PHP_METHOD(Phalcon_Annotations_Adapter_Xcache, write);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_xcache_read, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_annotations_adapter_xcache_write, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_annotations_adapter_xcache_method_entry[] = {
PHP_ME(Phalcon_Annotations_Adapter_Xcache, read, arginfo_phalcon_annotations_adapter_xcache_read, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Annotations_Adapter_Xcache, write, arginfo_phalcon_annotations_adapter_xcache_write, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Xcache){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Xcache, annotations_adapter_xcache, phalcon_annotations_adapter_ce, phalcon_annotations_adapter_xcache_method_entry, 0);
zend_class_implements(phalcon_annotations_adapter_xcache_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Xcache, read){
zval *key, *prefixed_key, *serialized;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &key);
PHALCON_INIT_VAR(prefixed_key);
PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key);
phalcon_strtolower_inplace(prefixed_key);
PHALCON_OBS_VAR(serialized);
phalcon_call_func_p1_ex(serialized, &serialized, "xcache_get", prefixed_key);
if (Z_TYPE_P(serialized) == IS_STRING) {
phalcon_unserialize(return_value, serialized TSRMLS_CC);
if (Z_TYPE_P(return_value) != IS_OBJECT) {
zval_dtor(return_value);
RETVAL_NULL();
}
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Annotations_Adapter_Xcache, write){
zval *key, *data, *prefixed_key;
zval *serialized;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &key, &data);
PHALCON_INIT_VAR(prefixed_key);
PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key);
phalcon_strtolower_inplace(prefixed_key);
PHALCON_INIT_VAR(serialized);
phalcon_serialize(serialized, &data TSRMLS_CC);
phalcon_call_func_p2_noret("xcache_set", prefixed_key, serialized);
PHALCON_MM_RESTORE();
}
zend_class_entry *phalcon_assets_collection_ce;
static PHP_METHOD(Phalcon_Assets_Collection, add);
static PHP_METHOD(Phalcon_Assets_Collection, addCss);
static PHP_METHOD(Phalcon_Assets_Collection, addJs);
static PHP_METHOD(Phalcon_Assets_Collection, getResources);
static PHP_METHOD(Phalcon_Assets_Collection, count);
static PHP_METHOD(Phalcon_Assets_Collection, rewind);
static PHP_METHOD(Phalcon_Assets_Collection, current);
static PHP_METHOD(Phalcon_Assets_Collection, key);
static PHP_METHOD(Phalcon_Assets_Collection, next);
static PHP_METHOD(Phalcon_Assets_Collection, valid);
static PHP_METHOD(Phalcon_Assets_Collection, setTargetPath);
static PHP_METHOD(Phalcon_Assets_Collection, getTargetPath);
static PHP_METHOD(Phalcon_Assets_Collection, setSourcePath);
static PHP_METHOD(Phalcon_Assets_Collection, getSourcePath);
static PHP_METHOD(Phalcon_Assets_Collection, setTargetUri);
static PHP_METHOD(Phalcon_Assets_Collection, getTargetUri);
static PHP_METHOD(Phalcon_Assets_Collection, setPrefix);
static PHP_METHOD(Phalcon_Assets_Collection, getPrefix);
static PHP_METHOD(Phalcon_Assets_Collection, setLocal);
static PHP_METHOD(Phalcon_Assets_Collection, getLocal);
static PHP_METHOD(Phalcon_Assets_Collection, setAttributes);
static PHP_METHOD(Phalcon_Assets_Collection, getAttributes);
static PHP_METHOD(Phalcon_Assets_Collection, addFilter);
static PHP_METHOD(Phalcon_Assets_Collection, setFilters);
static PHP_METHOD(Phalcon_Assets_Collection, getFilters);
static PHP_METHOD(Phalcon_Assets_Collection, join);
static PHP_METHOD(Phalcon_Assets_Collection, getJoin);
static PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath);
static PHP_METHOD(Phalcon_Assets_Collection, setTargetLocal);
static PHP_METHOD(Phalcon_Assets_Collection, getTargetLocal);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_add, 0, 0, 1)
ZEND_ARG_INFO(0, resource)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_addcss, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, local)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_addjs, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, local)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_settargetpath, 0, 0, 1)
ZEND_ARG_INFO(0, targetPath)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_setsourcepath, 0, 0, 1)
ZEND_ARG_INFO(0, sourcePath)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_settargeturi, 0, 0, 1)
ZEND_ARG_INFO(0, targetUri)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_setprefix, 0, 0, 1)
ZEND_ARG_INFO(0, prefix)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_setlocal, 0, 0, 1)
ZEND_ARG_INFO(0, local)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_setattributes, 0, 0, 1)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_addfilter, 0, 0, 1)
ZEND_ARG_INFO(0, filter)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_setfilters, 0, 0, 1)
ZEND_ARG_INFO(0, filters)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_join, 0, 0, 1)
ZEND_ARG_INFO(0, join)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_getrealtargetpath, 0, 0, 0)
ZEND_ARG_INFO(0, basePath)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_settargetlocal, 0, 0, 1)
ZEND_ARG_INFO(0, targetLocal)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_collection_method_entry[] = {
PHP_ME(Phalcon_Assets_Collection, add, arginfo_phalcon_assets_collection_add, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, addCss, arginfo_phalcon_assets_collection_addcss, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, addJs, arginfo_phalcon_assets_collection_addjs, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getResources, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, count, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, rewind, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, current, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, key, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, next, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, valid, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setTargetPath, arginfo_phalcon_assets_collection_settargetpath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getTargetPath, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setSourcePath, arginfo_phalcon_assets_collection_setsourcepath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getSourcePath, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setTargetUri, arginfo_phalcon_assets_collection_settargeturi, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getTargetUri, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setPrefix, arginfo_phalcon_assets_collection_setprefix, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getPrefix, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setLocal, arginfo_phalcon_assets_collection_setlocal, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getLocal, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setAttributes, arginfo_phalcon_assets_collection_setattributes, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getAttributes, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, addFilter, arginfo_phalcon_assets_collection_addfilter, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setFilters, arginfo_phalcon_assets_collection_setfilters, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getFilters, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, join, arginfo_phalcon_assets_collection_join, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getJoin, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getRealTargetPath, arginfo_phalcon_assets_collection_getrealtargetpath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setTargetLocal, arginfo_phalcon_assets_collection_settargetlocal, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getTargetLocal, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Collection){
PHALCON_REGISTER_CLASS(Phalcon\\Assets, Collection, assets_collection, phalcon_assets_collection_method_entry, 0);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_assets_collection_ce, SL("_local"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_resources"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_position"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_assets_collection_ce, SL("_join"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetUri"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetPath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_sourcePath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_assets_collection_ce, SL("_targetLocal"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_class_implements(phalcon_assets_collection_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Collection, add){
zval *resource;
phalcon_fetch_params(0, 1, 0, &resource);
if (Z_TYPE_P(resource) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Resource must be an object");
return;
}
phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, addCss){
zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *collection_local = NULL;
zval *collection_attributes = NULL, *resource;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes);
if (!local) {
local = PHALCON_GLOBAL(z_null);
}
if (!filter) {
filter = PHALCON_GLOBAL(z_true);
}
if (!attributes) {
attributes = PHALCON_GLOBAL(z_null);
}
if (Z_TYPE_P(local) == IS_BOOL) {
collection_local = local;
} else {
collection_local = phalcon_fetch_nproperty_this(this_ptr, SL("_local"), PH_NOISY_CC);
}
if (Z_TYPE_P(attributes) == IS_ARRAY) {
collection_attributes = attributes;
} else {
collection_attributes = phalcon_fetch_nproperty_this(this_ptr, SL("_attributes"), PH_NOISY_CC);
}
PHALCON_INIT_VAR(resource);
object_init_ex(resource, phalcon_assets_resource_css_ce);
phalcon_call_method_p4_key(NULL, resource, "__construct", 1107214344UL, path, collection_local, filter, collection_attributes);
phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Assets_Collection, addJs){
zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *collection_local = NULL;
zval *collection_attributes = NULL, *resource;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes);
if (!local) {
local = PHALCON_GLOBAL(z_null);
}
if (!filter) {
filter = PHALCON_GLOBAL(z_true);
}
if (!attributes) {
attributes = PHALCON_GLOBAL(z_null);
}
if (Z_TYPE_P(local) == IS_BOOL) {
collection_local = local;
} else {
collection_local = phalcon_fetch_nproperty_this(this_ptr, SL("_local"), PH_NOISY_CC);
}
if (Z_TYPE_P(attributes) == IS_ARRAY) {
collection_attributes = attributes;
} else {
collection_attributes = phalcon_fetch_nproperty_this(this_ptr, SL("_attributes"), PH_NOISY_CC);
}
PHALCON_INIT_VAR(resource);
object_init_ex(resource, phalcon_assets_resource_js_ce);
phalcon_call_method_p4_key(NULL, resource, "__construct", 1107214344UL, path, collection_local, filter, collection_attributes);
phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Assets_Collection, getResources){
zval *resources;
resources = phalcon_fetch_nproperty_this(this_ptr, SL("_resources"), PH_NOISY_CC);
if (Z_TYPE_P(resources) != IS_ARRAY) {
array_init(return_value);
return;
}
RETURN_ZVAL(resources, 1, 0);
}
static PHP_METHOD(Phalcon_Assets_Collection, count){
zval *resources;
PHALCON_MM_GROW();
PHALCON_OBS_VAR(resources);
phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC);
phalcon_fast_count(return_value, resources TSRMLS_CC);
RETURN_MM();
}
static PHP_METHOD(Phalcon_Assets_Collection, rewind){
phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Assets_Collection, current){
zval *position, *resources, *resource;
position = phalcon_fetch_nproperty_this(this_ptr, SL("_position"), PH_NOISY_CC);
resources = phalcon_fetch_nproperty_this(this_ptr, SL("_resources"), PH_NOISY_CC);
if (phalcon_array_isset_fetch(&resource, resources, position)) {
RETURN_ZVAL(resource, 1, 0);
}
RETURN_NULL();
}
static PHP_METHOD(Phalcon_Assets_Collection, key){
RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, next){
phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Assets_Collection, valid){
zval *position, *resources;
PHALCON_MM_GROW();
PHALCON_OBS_VAR(position);
phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC);
PHALCON_OBS_VAR(resources);
phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC);
if (phalcon_array_isset(resources, position)) {
RETURN_MM_TRUE;
}
RETURN_MM_FALSE;
}
static PHP_METHOD(Phalcon_Assets_Collection, setTargetPath){
zval *target_path;
phalcon_fetch_params(0, 1, 0, &target_path);
phalcon_update_property_this_quick(this_ptr, SL("_targetPath"), target_path, 3658201208UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getTargetPath){
RETURN_MEMBER_QUICK(this_ptr, "_targetPath", 3658201208UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, setSourcePath){
zval *source_path;
phalcon_fetch_params(0, 1, 0, &source_path);
phalcon_update_property_this_quick(this_ptr, SL("_sourcePath"), source_path, 1419415746UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getSourcePath){
RETURN_MEMBER_QUICK(this_ptr, "_sourcePath", 1419415746UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, setTargetUri){
zval *target_uri;
phalcon_fetch_params(0, 1, 0, &target_uri);
phalcon_update_property_this_quick(this_ptr, SL("_targetUri"), target_uri, 2193460699UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getTargetUri){
RETURN_MEMBER_QUICK(this_ptr, "_targetUri", 2193460699UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, setPrefix){
zval *prefix;
phalcon_fetch_params(0, 1, 0, &prefix);
phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getPrefix){
RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, setLocal){
zval *local;
phalcon_fetch_params(0, 1, 0, &local);
phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getLocal){
RETURN_MEMBER_QUICK(this_ptr, "_local", 2560221423UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, setAttributes){
zval *attributes;
phalcon_fetch_params(0, 1, 0, &attributes);
if (Z_TYPE_P(attributes) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Attributes must be an array");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getAttributes){
RETURN_MEMBER_QUICK(this_ptr, "_attributes", 1565778155UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, addFilter){
zval *filter;
phalcon_fetch_params(0, 1, 0, &filter);
phalcon_update_property_array_append(this_ptr, SL("_filters"), filter TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, setFilters){
zval *filters;
phalcon_fetch_params(0, 1, 0, &filters);
if (Z_TYPE_P(filters) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Filters must be an array of filters");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_filters"), filters, 3850488637UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getFilters){
RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, join){
zval *join;
phalcon_fetch_params(0, 1, 0, &join);
phalcon_update_property_this_quick(this_ptr, SL("_join"), join, 3979733204UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getJoin){
RETURN_MEMBER_QUICK(this_ptr, "_join", 3979733204UL);
}
static PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){
zval *base_path = NULL, *target_path, *complete_path;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &base_path);
if (!base_path) {
base_path = PHALCON_GLOBAL(z_null);
}
PHALCON_OBS_VAR(target_path);
phalcon_read_property_this_quick(&target_path, this_ptr, SL("_targetPath"), 3658201208UL, PH_NOISY_CC);
PHALCON_INIT_VAR(complete_path);
PHALCON_CONCAT_VV(complete_path, base_path, target_path);
if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) {
phalcon_realpath(return_value, complete_path TSRMLS_CC);
RETURN_MM();
}
RETURN_CTOR(complete_path);
}
static PHP_METHOD(Phalcon_Assets_Collection, setTargetLocal){
zval *target_local;
phalcon_fetch_params(0, 1, 0, &target_local);
phalcon_update_property_this_quick(this_ptr, SL("_targetLocal"), target_local, 321001910UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Collection, getTargetLocal){
RETURN_MEMBER_QUICK(this_ptr, "_targetLocal", 321001910UL);
}
zend_class_entry *phalcon_assets_exception_ce;
PHALCON_INIT_CLASS(Phalcon_Assets_Exception){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets, Exception, assets_exception, phalcon_exception_ce, NULL, 0);
return SUCCESS;
}
zend_class_entry *phalcon_assets_filterinterface_ce;
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_filterinterface_filter, 0, 0, 1)
ZEND_ARG_INFO(0, content)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_filterinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Assets_FilterInterface, filter, arginfo_phalcon_assets_filterinterface_filter)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_FilterInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Assets, FilterInterface, assets_filterinterface, phalcon_assets_filterinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_assets_manager_ce;
static PHP_METHOD(Phalcon_Assets_Manager, __construct);
static PHP_METHOD(Phalcon_Assets_Manager, setOptions);
static PHP_METHOD(Phalcon_Assets_Manager, getOptions);
static PHP_METHOD(Phalcon_Assets_Manager, useImplicitOutput);
static PHP_METHOD(Phalcon_Assets_Manager, addCss);
static PHP_METHOD(Phalcon_Assets_Manager, addJs);
static PHP_METHOD(Phalcon_Assets_Manager, addResourceByType);
static PHP_METHOD(Phalcon_Assets_Manager, addResource);
static PHP_METHOD(Phalcon_Assets_Manager, set);
static PHP_METHOD(Phalcon_Assets_Manager, get);
static PHP_METHOD(Phalcon_Assets_Manager, getCss);
static PHP_METHOD(Phalcon_Assets_Manager, getJs);
static PHP_METHOD(Phalcon_Assets_Manager, collection);
static PHP_METHOD(Phalcon_Assets_Manager, output);
static PHP_METHOD(Phalcon_Assets_Manager, outputCss);
static PHP_METHOD(Phalcon_Assets_Manager, outputJs);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager___construct, 0, 0, 0)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_setoptions, 0, 0, 1)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_useimplicitoutput, 0, 0, 1)
ZEND_ARG_INFO(0, implicitOutput)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_addcss, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, local)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_addjs, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, local)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_addresourcebytype, 0, 0, 2)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, resource)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_addresource, 0, 0, 1)
ZEND_ARG_INFO(0, resource)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_set, 0, 0, 2)
ZEND_ARG_INFO(0, id)
ZEND_ARG_INFO(0, collection)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_get, 0, 0, 1)
ZEND_ARG_INFO(0, id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_collection, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_output, 0, 0, 2)
ZEND_ARG_INFO(0, collection)
ZEND_ARG_INFO(0, callback)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_outputcss, 0, 0, 0)
ZEND_ARG_INFO(0, collectionName)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_manager_outputjs, 0, 0, 0)
ZEND_ARG_INFO(0, collectionName)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_manager_method_entry[] = {
PHP_ME(Phalcon_Assets_Manager, __construct, arginfo_phalcon_assets_manager___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Assets_Manager, setOptions, arginfo_phalcon_assets_manager_setoptions, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, getOptions, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, useImplicitOutput, arginfo_phalcon_assets_manager_useimplicitoutput, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, addCss, arginfo_phalcon_assets_manager_addcss, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, addJs, arginfo_phalcon_assets_manager_addjs, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, addResourceByType, arginfo_phalcon_assets_manager_addresourcebytype, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, addResource, arginfo_phalcon_assets_manager_addresource, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, set, arginfo_phalcon_assets_manager_set, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, get, arginfo_phalcon_assets_manager_get, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, getCss, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, getJs, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, collection, arginfo_phalcon_assets_manager_collection, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, output, arginfo_phalcon_assets_manager_output, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, outputCss, arginfo_phalcon_assets_manager_outputcss, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Manager, outputJs, arginfo_phalcon_assets_manager_outputjs, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Manager){
PHALCON_REGISTER_CLASS(Phalcon\\Assets, Manager, assets_manager, phalcon_assets_manager_method_entry, 0);
zend_declare_property_null(phalcon_assets_manager_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_manager_ce, SL("_collections"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_assets_manager_ce, SL("_implicitOutput"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Manager, __construct){
zval *options = NULL;
phalcon_fetch_params(0, 0, 1, &options);
if (options && Z_TYPE_P(options) == IS_ARRAY) {
phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC);
}
}
static PHP_METHOD(Phalcon_Assets_Manager, setOptions){
zval *options;
phalcon_fetch_params(0, 1, 0, &options);
if (Z_TYPE_P(options) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Options must be an array");
return;
}
phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Manager, getOptions){
RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL);
}
static PHP_METHOD(Phalcon_Assets_Manager, useImplicitOutput){
zval *implicit_output;
phalcon_fetch_params(0, 1, 0, &implicit_output);
phalcon_update_property_this_quick(this_ptr, SL("_implicitOutput"), implicit_output, 3405432336UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Manager, addCss){
zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes);
if (!local) {
local = PHALCON_GLOBAL(z_true);
}
if (!filter) {
filter = PHALCON_GLOBAL(z_true);
}
if (!attributes) {
attributes = PHALCON_GLOBAL(z_null);
}
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "css", 1);
PHALCON_INIT_VAR(resource);
object_init_ex(resource, phalcon_assets_resource_css_ce);
phalcon_call_method_p4_key(NULL, resource, "__construct", 1107214344UL, path, local, filter, attributes);
phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", 1257550035UL, type, resource);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Assets_Manager, addJs){
zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes);
if (!local) {
local = PHALCON_GLOBAL(z_true);
}
if (!filter) {
filter = PHALCON_GLOBAL(z_true);
}
if (!attributes) {
attributes = PHALCON_GLOBAL(z_null);
}
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "js", 1);
PHALCON_INIT_VAR(resource);
object_init_ex(resource, phalcon_assets_resource_js_ce);
phalcon_call_method_p4_key(NULL, resource, "__construct", 1107214344UL, path, local, filter, attributes);
phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", 1257550035UL, type, resource);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Assets_Manager, addResourceByType){
zval *type, *resource, *collections, *collection = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 0, &type, &resource);
PHALCON_OBS_VAR(collections);
phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC);
if (phalcon_array_isset(collections, type)) {
PHALCON_OBS_VAR(collection);
phalcon_array_fetch(&collection, collections, type, PH_NOISY);
} else {
PHALCON_INIT_NVAR(collection);
object_init_ex(collection, phalcon_assets_collection_ce);
phalcon_update_property_array(this_ptr, SL("_collections"), type, collection TSRMLS_CC);
}
phalcon_call_method_p1_key(NULL, collection, "add", 2090071694UL, resource);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Assets_Manager, addResource){
zval *resource, *type;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 0, &resource);
if (Z_TYPE_P(resource) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Resource must be an object");
return;
}
PHALCON_INIT_VAR(type);
phalcon_call_method_key(type, resource, "gettype", 4294422375UL);
phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", 1257550035UL, type, resource);
RETURN_THIS();
}
static PHP_METHOD(Phalcon_Assets_Manager, set){
zval *id, *collection;
phalcon_fetch_params(0, 2, 0, &id, &collection);
if (unlikely(Z_TYPE_P(id) != IS_STRING)) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Collection-Id must be a string");
return;
}
if (unlikely(Z_TYPE_P(collection) != IS_OBJECT)) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Collection must be an object");
return;
}
phalcon_update_property_array(this_ptr, SL("_collections"), id, collection TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Manager, get){
zval *id, *collections, *collection;
phalcon_fetch_params(0, 1, 0, &id);
if (unlikely(Z_TYPE_P(id) != IS_STRING)) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Collection-Id must be a string");
return;
}
collections = phalcon_fetch_nproperty_this(this_ptr, SL("_collections"), PH_NOISY_CC);
if (!phalcon_array_isset_fetch(&collection, collections, id)) {
PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "The collection does not exist in the manager");
return;
}
RETURN_ZVAL(collection, 1, 0);
}
static PHP_METHOD(Phalcon_Assets_Manager, getCss){
zval *collections, *collection;
collections = phalcon_fetch_nproperty_this(this_ptr, SL("_collections"), PH_NOISY_CC);
if (!phalcon_array_isset_string_fetch(&collection, collections, SS("css"))) {
object_init_ex(return_value, phalcon_assets_collection_ce);
return;
}
RETURN_ZVAL(collection, 1, 0);
}
static PHP_METHOD(Phalcon_Assets_Manager, getJs){
zval *collections, *collection;
collections = phalcon_fetch_nproperty_this(this_ptr, SL("_collections"), PH_NOISY_CC);
if (!phalcon_array_isset_string_fetch(&collection, collections, SS("js"))) {
object_init_ex(return_value, phalcon_assets_collection_ce);
return;
}
RETURN_ZVAL(collection, 1, 0);
}
static PHP_METHOD(Phalcon_Assets_Manager, collection){
zval *name, *collections, *collection = NULL;
phalcon_fetch_params(0, 1, 0, &name);
collections = phalcon_fetch_nproperty_this(this_ptr, SL("_collections"), PH_NOISY_CC);
if (phalcon_array_isset_fetch(&collection, collections, name)) {
RETURN_ZVAL(collection, 1, 0);
}
object_init_ex(return_value, phalcon_assets_collection_ce);
phalcon_update_property_array(this_ptr, SL("_collections"), name, return_value TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Assets_Manager, output){
zval *collection, *callback, *type = NULL, *output, *use_implicit_output;
zval *resources, *filters, *prefix, *source_base_path = NULL;
zval *target_base_path = NULL, *options, *collection_source_path;
zval *complete_source_path = NULL, *collection_target_path;
zval *complete_target_path = NULL, *filtered_joined_content = NULL;
zval *join, *exception_message = NULL, *is_directory;
zval *resource = NULL, *filter_needed = NULL, *local = NULL, *source_path = NULL;
zval *target_path = NULL, *path = NULL, *prefixed_path = NULL, *attributes = NULL;
zval *parameters = NULL, *html = NULL, *content = NULL, *must_filter = NULL;
zval *filter = NULL, *filtered_content = NULL, *target_uri;
HashTable *ah0, *ah1;
HashPosition hp0, hp1;
zval **hd;
zval *type_css;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 2, 1, &collection, &callback, &type);
PHALCON_INIT_VAR(output);
PHALCON_OBS_VAR(use_implicit_output);
phalcon_read_property_this_quick(&use_implicit_output, this_ptr, SL("_implicitOutput"), 3405432336UL, PH_NOISY_CC);
PHALCON_INIT_VAR(resources);
phalcon_call_method_key(resources, collection, "getresources", 2001784992UL);
PHALCON_INIT_VAR(filters);
phalcon_call_method_key(filters, collection, "getfilters", 2910616766UL);
PHALCON_INIT_VAR(prefix);
phalcon_call_method_key(prefix, collection, "getprefix", 2543805107UL);
PHALCON_INIT_VAR(type_css);
ZVAL_STRING(type_css, "css", 1);
if (Z_TYPE_P(filters) == IS_ARRAY) {
PHALCON_INIT_VAR(source_base_path);
PHALCON_INIT_VAR(target_base_path);
PHALCON_OBS_VAR(options);
phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC);
if (Z_TYPE_P(options) == IS_ARRAY) {
if (phalcon_array_isset_quick_string(options, SS("sourceBasePath"), 4090541534UL)) {
PHALCON_OBS_NVAR(source_base_path);
phalcon_array_fetch_quick_string(&source_base_path, options, SS("sourceBasePath"), 4090541534UL, PH_NOISY);
}
if (phalcon_array_isset_quick_string(options, SS("targetBasePath"), 2556086420UL)) {
PHALCON_OBS_NVAR(target_base_path);
phalcon_array_fetch_quick_string(&target_base_path, options, SS("targetBasePath"), 2556086420UL, PH_NOISY);
}
}
PHALCON_INIT_VAR(collection_source_path);
phalcon_call_method_key(collection_source_path, collection, "getsourcepath", 904752835UL);
if (PHALCON_IS_NOT_EMPTY(collection_source_path)) {
PHALCON_INIT_VAR(complete_source_path);
PHALCON_CONCAT_VV(complete_source_path, source_base_path, collection_source_path);
} else {
PHALCON_CPY_WRT(complete_source_path, source_base_path);
}
PHALCON_INIT_VAR(collection_target_path);
phalcon_call_method_key(collection_target_path, collection, "gettargetpath", 3143538297UL);
if (PHALCON_IS_NOT_EMPTY(collection_target_path)) {
PHALCON_INIT_VAR(complete_target_path);
PHALCON_CONCAT_VV(complete_target_path, target_base_path, collection_target_path);
} else {
PHALCON_CPY_WRT(complete_target_path, target_base_path);
}
PHALCON_INIT_VAR(filtered_joined_content);
PHALCON_INIT_VAR(join);
phalcon_call_method_key(join, collection, "getjoin", 4282196469UL);
if (zend_is_true(join)) {
if (PHALCON_IS_EMPTY(complete_target_path)) {
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (1)");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
return;
}
PHALCON_INIT_VAR(is_directory);
phalcon_is_dir(is_directory, complete_target_path TSRMLS_CC);
if (PHALCON_IS_TRUE(is_directory)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (2)");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
return;
}
}
}
phalcon_is_iterable(resources, &ah0, &hp0, 0, 0);
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HVALUE(resource);
PHALCON_INIT_NVAR(filter_needed);
ZVAL_FALSE(filter_needed);
if (!type) {
PHALCON_INIT_VAR(type);
phalcon_call_method_key(type, resource, "gettype", 4294422375UL);
}
PHALCON_INIT_NVAR(local);
phalcon_call_method_key(local, resource, "getlocal", 3951574576UL);
if (Z_TYPE_P(filters) == IS_ARRAY) {
if (zend_is_true(join)) {
if (zend_is_true(local)) {
PHALCON_INIT_NVAR(source_path);
phalcon_call_method_p1_key(source_path, resource, "getrealsourcepath", 1163474055UL, complete_source_path);
if (!zend_is_true(source_path)) {
PHALCON_INIT_NVAR(source_path);
phalcon_call_method_key(source_path, resource, "getpath", 4288820658UL);
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
return;
}
} else {
PHALCON_INIT_NVAR(source_path);
phalcon_call_method_key(source_path, resource, "getpath", 4288820658UL);
PHALCON_INIT_NVAR(filter_needed);
ZVAL_TRUE(filter_needed);
}
PHALCON_INIT_NVAR(target_path);
phalcon_call_method_p1_key(target_path, resource, "getrealtargetpath", 3402259517UL, complete_target_path);
if (PHALCON_IS_EMPTY(target_path)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
return;
}
if (zend_is_true(local)) {
if (PHALCON_IS_EQUAL(target_path, source_path)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
return;
}
if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) {
if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) {
PHALCON_INIT_NVAR(filter_needed);
ZVAL_TRUE(filter_needed);
}
} else {
PHALCON_INIT_NVAR(filter_needed);
ZVAL_TRUE(filter_needed);
}
}
}
}
if (Z_TYPE_P(filters) != IS_ARRAY) {
PHALCON_INIT_NVAR(path);
phalcon_call_method_key(path, resource, "getrealtargeturi", 4137962752UL);
if (Z_TYPE_P(prefix) != IS_NULL) {
PHALCON_INIT_NVAR(prefixed_path);
PHALCON_CONCAT_VV(prefixed_path, prefix, path);
} else {
PHALCON_CPY_WRT(prefixed_path, path);
}
PHALCON_INIT_NVAR(attributes);
phalcon_call_method_key(attributes, resource, "getattributes", 1013165772UL);
PHALCON_INIT_NVAR(parameters);
array_init_size(parameters, 2);
if (Z_TYPE_P(attributes) == IS_ARRAY) {
phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE);
phalcon_array_append(&parameters, attributes, 0);
} else {
phalcon_array_append(&parameters, prefixed_path, 0);
}
phalcon_array_append(&parameters, local, 0);
PHALCON_INIT_NVAR(html);
PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters);
if (zend_is_true(use_implicit_output)) {
zend_print_zval(html, 0);
} else {
phalcon_concat_self(&output, html TSRMLS_CC);
}
zend_hash_move_forward_ex(ah0, &hp0);
continue;
}
if (zend_is_true(filter_needed)) {
PHALCON_INIT_NVAR(content);
phalcon_call_method_p1_key(content, resource, "getcontent", 3141446400UL, complete_source_path);
PHALCON_INIT_NVAR(must_filter);
phalcon_call_method_key(must_filter, resource, "getfilter", 2170608779UL);
if (zend_is_true(must_filter)) {
phalcon_is_iterable(filters, &ah1, &hp1, 0, 0);
while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
PHALCON_GET_HVALUE(filter);
if (Z_TYPE_P(filter) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Filter is invalid");
return;
}
PHALCON_INIT_NVAR(filtered_content);
phalcon_call_method_p1_key(filtered_content, filter, "filter", 2890214155UL, content);
PHALCON_CPY_WRT_CTOR(content, filtered_content);
zend_hash_move_forward_ex(ah1, &hp1);
}
if (zend_is_true(join)) {
if (PHALCON_IS_EQUAL(type, type_css)) {
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_INIT_NVAR(filtered_joined_content);
PHALCON_CONCAT_VS(filtered_joined_content, content, "");
} else {
PHALCON_SCONCAT_VS(filtered_joined_content, content, "");
}
} else {
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_INIT_NVAR(filtered_joined_content);
PHALCON_CONCAT_VS(filtered_joined_content, content, ";");
} else {
PHALCON_SCONCAT_VS(filtered_joined_content, content, ";");
}
}
}
} else {
if (zend_is_true(join)) {
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_CPY_WRT(filtered_joined_content, content);
} else {
phalcon_concat_self(&filtered_joined_content, content TSRMLS_CC);
}
} else {
PHALCON_CPY_WRT(filtered_content, content);
}
}
if (!zend_is_true(join)) {
phalcon_file_put_contents(NULL, target_path, filtered_content TSRMLS_CC);
}
}
if (!zend_is_true(join)) {
PHALCON_INIT_NVAR(path);
phalcon_call_method_key(path, resource, "getrealtargeturi", 4137962752UL);
if (Z_TYPE_P(prefix) != IS_NULL) {
PHALCON_INIT_NVAR(prefixed_path);
PHALCON_CONCAT_VV(prefixed_path, prefix, path);
} else {
PHALCON_CPY_WRT(prefixed_path, path);
}
PHALCON_INIT_NVAR(attributes);
phalcon_call_method_key(attributes, resource, "getattributes", 1013165772UL);
PHALCON_INIT_NVAR(local);
ZVAL_TRUE(local);
PHALCON_INIT_NVAR(parameters);
array_init_size(parameters, 2);
if (Z_TYPE_P(attributes) == IS_ARRAY) {
phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE);
phalcon_array_append(&parameters, attributes, 0);
} else {
phalcon_array_append(&parameters, prefixed_path, 0);
}
phalcon_array_append(&parameters, local, 0);
PHALCON_INIT_NVAR(html);
PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters);
if (zend_is_true(use_implicit_output)) {
zend_print_zval(html, 0);
} else {
phalcon_concat_self(&output, html TSRMLS_CC);
}
}
zend_hash_move_forward_ex(ah0, &hp0);
}
if (Z_TYPE_P(filters) == IS_ARRAY) {
if (zend_is_true(join)) {
phalcon_file_put_contents(NULL, complete_target_path, filtered_joined_content TSRMLS_CC);
PHALCON_INIT_VAR(target_uri);
phalcon_call_method_key(target_uri, collection, "gettargeturi", 876359612UL);
if (Z_TYPE_P(prefix) != IS_NULL) {
PHALCON_INIT_NVAR(prefixed_path);
PHALCON_CONCAT_VV(prefixed_path, prefix, target_uri);
} else {
PHALCON_CPY_WRT(prefixed_path, target_uri);
}
PHALCON_INIT_NVAR(attributes);
phalcon_call_method_key(attributes, collection, "getattributes", 1013165772UL);
PHALCON_INIT_NVAR(local);
phalcon_call_method_key(local, collection, "gettargetlocal", 516995031UL);
PHALCON_INIT_NVAR(parameters);
array_init_size(parameters, 2);
if (Z_TYPE_P(attributes) == IS_ARRAY) {
phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE);
phalcon_array_append(&parameters, attributes, 0);
} else {
phalcon_array_append(&parameters, prefixed_path, 0);
}
phalcon_array_append(&parameters, local, 0);
PHALCON_INIT_NVAR(html);
PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters);
if (zend_is_true(use_implicit_output)) {
zend_print_zval(html, 0);
} else {
phalcon_concat_self(&output, html TSRMLS_CC);
}
}
}
RETURN_CCTOR(output);
}
static PHP_METHOD(Phalcon_Assets_Manager, outputCss){
zval *collection_name = NULL, *collection = NULL, *callback, *type = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &collection_name);
if (!collection_name || PHALCON_IS_EMPTY(collection_name)) {
PHALCON_INIT_VAR(collection);
phalcon_call_method_key(collection, this_ptr, "getcss", 4034032270UL);
} else {
PHALCON_INIT_NVAR(collection);
phalcon_call_method_p1_key(collection, this_ptr, "get", 2090288933UL, collection_name);
}
PHALCON_INIT_VAR(callback);
array_init_size(callback, 2);
add_next_index_stringl(callback, SL("Phalcon\\Tag"), 1);
add_next_index_stringl(callback, SL("stylesheetLink"), 1);
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "css", 1);
phalcon_return_call_method_p3(this_ptr, "output", collection, callback, type);
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Assets_Manager, outputJs){
zval *collection_name = NULL, *collection = NULL, *callback, *type = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &collection_name);
if (!collection_name) {
collection_name = PHALCON_GLOBAL(z_null);
}
PHALCON_INIT_VAR(collection);
if (PHALCON_IS_EMPTY(collection_name)) {
phalcon_call_method_key(collection, this_ptr, "getjs", 4287067682UL);
} else {
phalcon_call_method_p1_key(collection, this_ptr, "get", 2090288933UL, collection_name);
}
PHALCON_INIT_VAR(callback);
array_init_size(callback, 2);
add_next_index_stringl(callback, SL("Phalcon\\Tag"), 1);
add_next_index_stringl(callback, SL("javascriptInclude"), 1);
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "js", 1);
phalcon_return_call_method_p3(this_ptr, "output", collection, callback, type);
PHALCON_MM_RESTORE();
}
zend_class_entry *phalcon_assets_resource_ce;
static PHP_METHOD(Phalcon_Assets_Resource, __construct);
static PHP_METHOD(Phalcon_Assets_Resource, setType);
static PHP_METHOD(Phalcon_Assets_Resource, getType);
static PHP_METHOD(Phalcon_Assets_Resource, setPath);
static PHP_METHOD(Phalcon_Assets_Resource, getPath);
static PHP_METHOD(Phalcon_Assets_Resource, setLocal);
static PHP_METHOD(Phalcon_Assets_Resource, getLocal);
static PHP_METHOD(Phalcon_Assets_Resource, setFilter);
static PHP_METHOD(Phalcon_Assets_Resource, getFilter);
static PHP_METHOD(Phalcon_Assets_Resource, setAttributes);
static PHP_METHOD(Phalcon_Assets_Resource, getAttributes);
static PHP_METHOD(Phalcon_Assets_Resource, setTargetUri);
static PHP_METHOD(Phalcon_Assets_Resource, getTargetUri);
static PHP_METHOD(Phalcon_Assets_Resource, setSourcePath);
static PHP_METHOD(Phalcon_Assets_Resource, getSourcePath);
static PHP_METHOD(Phalcon_Assets_Resource, setTargetPath);
static PHP_METHOD(Phalcon_Assets_Resource, getTargetPath);
static PHP_METHOD(Phalcon_Assets_Resource, getContent);
static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetUri);
static PHP_METHOD(Phalcon_Assets_Resource, getRealSourcePath);
static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetPath);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource___construct, 0, 0, 2)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, local)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_settype, 0, 0, 1)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_setpath, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_setlocal, 0, 0, 1)
ZEND_ARG_INFO(0, local)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_setfilter, 0, 0, 1)
ZEND_ARG_INFO(0, filter)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_setattributes, 0, 0, 1)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_settargeturi, 0, 0, 1)
ZEND_ARG_INFO(0, targetUri)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_setsourcepath, 0, 0, 1)
ZEND_ARG_INFO(0, sourcePath)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_settargetpath, 0, 0, 1)
ZEND_ARG_INFO(0, targetPath)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_getcontent, 0, 0, 0)
ZEND_ARG_INFO(0, basePath)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_getrealsourcepath, 0, 0, 0)
ZEND_ARG_INFO(0, basePath)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_getrealtargetpath, 0, 0, 0)
ZEND_ARG_INFO(0, basePath)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_resource_method_entry[] = {
PHP_ME(Phalcon_Assets_Resource, __construct, arginfo_phalcon_assets_resource___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Assets_Resource, setType, arginfo_phalcon_assets_resource_settype, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getType, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, setPath, arginfo_phalcon_assets_resource_setpath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getPath, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, setLocal, arginfo_phalcon_assets_resource_setlocal, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getLocal, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, setFilter, arginfo_phalcon_assets_resource_setfilter, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getFilter, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, setAttributes, arginfo_phalcon_assets_resource_setattributes, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getAttributes, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, setTargetUri, arginfo_phalcon_assets_resource_settargeturi, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getTargetUri, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, setSourcePath, arginfo_phalcon_assets_resource_setsourcepath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getSourcePath, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, setTargetPath, arginfo_phalcon_assets_resource_settargetpath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getTargetPath, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getContent, arginfo_phalcon_assets_resource_getcontent, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getRealTargetUri, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getRealSourcePath, arginfo_phalcon_assets_resource_getrealsourcepath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Resource, getRealTargetPath, arginfo_phalcon_assets_resource_getrealtargetpath, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Resource){
PHALCON_REGISTER_CLASS(Phalcon\\Assets, Resource, assets_resource, phalcon_assets_resource_method_entry, 0);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_path"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_local"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_filter"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_sourcePath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_targetPath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_resource_ce, SL("_targetUri"), ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Resource, __construct){
zval *type, *path, *local = NULL, *filter = NULL, *attributes = NULL;
phalcon_fetch_params(0, 2, 3, &type, &path, &local, &filter, &attributes);
if (!local) {
local = PHALCON_GLOBAL(z_true);
}
if (!filter) {
filter = PHALCON_GLOBAL(z_true);
}
if (!attributes) {
attributes = PHALCON_GLOBAL(z_null);
}
phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC);
if (Z_TYPE_P(attributes) == IS_ARRAY) {
phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC);
}
}
static PHP_METHOD(Phalcon_Assets_Resource, setType){
zval *type;
phalcon_fetch_params(0, 1, 0, &type);
phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getType){
RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, setPath){
zval *path;
phalcon_fetch_params(0, 1, 0, &path);
phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getPath){
RETURN_MEMBER_QUICK(this_ptr, "_path", 3986357393UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, setLocal){
zval *local;
phalcon_fetch_params(0, 1, 0, &local);
phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getLocal){
RETURN_MEMBER_QUICK(this_ptr, "_local", 2560221423UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, setFilter){
zval *filter;
phalcon_fetch_params(0, 1, 0, &filter);
phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getFilter){
RETURN_MEMBER_QUICK(this_ptr, "_filter", 3500594986UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, setAttributes){
zval *attributes;
phalcon_fetch_params(0, 1, 0, &attributes);
phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getAttributes){
RETURN_MEMBER_QUICK(this_ptr, "_attributes", 1565778155UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, setTargetUri){
zval *target_uri;
phalcon_fetch_params(0, 1, 0, &target_uri);
phalcon_update_property_this_quick(this_ptr, SL("_targetUri"), target_uri, 2193460699UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getTargetUri){
RETURN_MEMBER_QUICK(this_ptr, "_targetUri", 2193460699UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, setSourcePath){
zval *source_path;
phalcon_fetch_params(0, 1, 0, &source_path);
phalcon_update_property_this_quick(this_ptr, SL("_sourcePath"), source_path, 1419415746UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getSourcePath){
RETURN_MEMBER_QUICK(this_ptr, "_targetPath", 3658201208UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, setTargetPath){
zval *target_path;
phalcon_fetch_params(0, 1, 0, &target_path);
phalcon_update_property_this_quick(this_ptr, SL("_targetPath"), target_path, 3658201208UL TSRMLS_CC);
RETURN_THISW();
}
static PHP_METHOD(Phalcon_Assets_Resource, getTargetPath){
RETURN_MEMBER_QUICK(this_ptr, "_sourcePath", 1419415746UL);
}
static PHP_METHOD(Phalcon_Assets_Resource, getContent){
zval *base_path = NULL, *source_path = NULL, *complete_path;
zval *local, *exception_message = NULL;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &base_path);
if (!base_path) {
base_path = PHALCON_GLOBAL(z_null);
}
PHALCON_OBS_VAR(source_path);
phalcon_read_property_this_quick(&source_path, this_ptr, SL("_sourcePath"), 1419415746UL, PH_NOISY_CC);
if (PHALCON_IS_EMPTY(source_path)) {
PHALCON_OBS_NVAR(source_path);
phalcon_read_property_this_quick(&source_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC);
}
PHALCON_INIT_VAR(complete_path);
PHALCON_CONCAT_VV(complete_path, base_path, source_path);
PHALCON_OBS_VAR(local);
phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC);
if (zend_is_true(local)) {
if (phalcon_file_exists(complete_path TSRMLS_CC) == FAILURE) {
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be loaded");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
return;
}
}
phalcon_file_get_contents(return_value, complete_path TSRMLS_CC);
if (PHALCON_IS_FALSE(return_value)) {
PHALCON_INIT_NVAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be read");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
return;
}
PHALCON_MM_RESTORE();
}
static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetUri){
zval *target_uri;
target_uri = phalcon_fetch_nproperty_this(this_ptr, SL("_targetUri"), PH_NOISY_CC);
if (PHALCON_IS_EMPTY(target_uri)) {
target_uri = phalcon_fetch_nproperty_this(this_ptr, SL("_path"), PH_NOISY_CC);
}
RETURN_ZVAL(target_uri, 1, 0);
}
static PHP_METHOD(Phalcon_Assets_Resource, getRealSourcePath){
zval *base_path = NULL, *source_path = NULL, *local, *complete_path;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &base_path);
if (!base_path) {
base_path = PHALCON_GLOBAL(z_null);
}
PHALCON_OBS_VAR(source_path);
phalcon_read_property_this_quick(&source_path, this_ptr, SL("_sourcePath"), 1419415746UL, PH_NOISY_CC);
if (PHALCON_IS_EMPTY(source_path)) {
PHALCON_OBS_NVAR(source_path);
phalcon_read_property_this_quick(&source_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC);
}
PHALCON_OBS_VAR(local);
phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC);
if (zend_is_true(local)) {
PHALCON_INIT_VAR(complete_path);
PHALCON_CONCAT_VV(complete_path, base_path, source_path);
phalcon_realpath(return_value, complete_path TSRMLS_CC);
RETURN_MM();
}
RETURN_CCTOR(source_path);
}
static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetPath){
zval *base_path = NULL, *target_path = NULL, *local, *complete_path;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 0, 1, &base_path);
if (!base_path) {
base_path = PHALCON_GLOBAL(z_null);
}
PHALCON_OBS_VAR(target_path);
phalcon_read_property_this_quick(&target_path, this_ptr, SL("_targetPath"), 3658201208UL, PH_NOISY_CC);
if (PHALCON_IS_EMPTY(target_path)) {
PHALCON_OBS_NVAR(target_path);
phalcon_read_property_this_quick(&target_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC);
}
PHALCON_OBS_VAR(local);
phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC);
if (zend_is_true(local)) {
PHALCON_INIT_VAR(complete_path);
PHALCON_CONCAT_VV(complete_path, base_path, target_path);
if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) {
phalcon_realpath(return_value, complete_path TSRMLS_CC);
RETURN_MM();
}
RETURN_CTOR(complete_path);
}
RETURN_CCTOR(target_path);
}
zend_class_entry *phalcon_assets_filters_cssmin_ce;
static PHP_METHOD(Phalcon_Assets_Filters_Cssmin, filter);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_filters_cssmin_filter, 0, 0, 1)
ZEND_ARG_INFO(0, content)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_filters_cssmin_method_entry[] = {
PHP_ME(Phalcon_Assets_Filters_Cssmin, filter, arginfo_phalcon_assets_filters_cssmin_filter, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Filters_Cssmin){
PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, Cssmin, assets_filters_cssmin, phalcon_assets_filters_cssmin_method_entry, 0);
zend_class_implements(phalcon_assets_filters_cssmin_ce TSRMLS_CC, 1, phalcon_assets_filterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Filters_Cssmin, filter){
zval *content;
phalcon_fetch_params(0, 1, 0, &content);
if (phalcon_cssmin(return_value, content TSRMLS_CC) == FAILURE) {
return;
}
}
/* cssmin.c
Copyright (c) 2010 (www.ryanday.org)
w3c css spec: http://www.w3.org/TR/CSS2/syndata.html
this parser makes no attempt to understand css as such it does not interpret css to spec.
** cannot handle nested { blocks but will ignore aditional { in parens ()
** no in quote detection for ( or }
function get, peek and general lookahead structure taken from..
jsmin.c
Copyright (c) 2002 Douglas Crockford (www.crockford.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <ext/standard/php_smart_str.h>
#define STATE_FREE 1
#define STATE_ATRULE 2
#define STATE_SELECTOR 3
#define STATE_BLOCK 4
#define STATE_DECLARATION 5
#define STATE_COMMENT 6
typedef struct _cssmin_parser {
int tmp_state;
int state;
int last_state;
int in_paren;
zval *style;
zval **error;
smart_str *minified;
int style_pointer;
} cssmin_parser;
/* get -- return the next character from stdin. Watch out for lookahead. If
the character is a control character, translate it to a space or
linefeed.
*/
static char cssmin_peek(cssmin_parser *parser){
char ch;
if (parser->style_pointer < Z_STRLEN_P(parser->style)) {
ch = Z_STRVAL_P(parser->style)[parser->style_pointer];
return ch;
}
return EOF;
}
static char cssmin_back_peek(cssmin_parser *parser){
char ch;
if (parser->style_pointer > 1) {
ch = Z_STRVAL_P(parser->style)[parser->style_pointer - 1];
return ch;
}
return EOF;
}
/* machine
*/
static int phalcon_cssmin_machine(cssmin_parser *parser, unsigned char c TSRMLS_DC){
unsigned char p;
if (parser->state != STATE_COMMENT) {
if (c == '/' && cssmin_peek(parser) == '*') {
parser->tmp_state = parser->state;
parser->state = STATE_COMMENT;
}
}
switch (parser->state) {
case STATE_FREE:
if (c == ' ' && c == '\t' && c == '\n' && c == '\r') {
c = 0;
} else if (c == '@'){
parser->state = STATE_ATRULE;
break;
} else if(c > 0){
//fprintf(stdout,"one to 3 - %c %i",c,c);
parser->state = STATE_SELECTOR;
}
/* no break */
case STATE_SELECTOR:
if (c == '{') {
parser->state = STATE_BLOCK;
} else {
if(c == '\n' || c == '\r') {
c = 0;
} else {
if(c == '@'){
parser->state = STATE_ATRULE;
} else {
if ((c == ' ' || c == '\t')) {
p = cssmin_peek(parser);
if (p == '{' || p == '\t' || p == ' ' || p == '>' || p == ',') {
c = 0;
} else {
p = cssmin_back_peek(parser);
if (p == ',' || p == '>' || p == ':') {
c = 0;
} else {
c = ' ';
}
}
}
}
}
}
break;
case STATE_ATRULE:
/* support
@import etc.
@font-face{
*/
if (c == '\r' || c == '\n' || c == ';') {
c = ';';
parser->state = STATE_FREE;
} else {
if(c == '{') {
parser->state = STATE_BLOCK;
}
}
break;
case STATE_BLOCK:
if (c == ' ' || c == '\t' || c == '\n' || c == '\r' ) {
c = 0;
break;
} else {
if (c == '}') {
parser->state = STATE_FREE;
//fprintf(stdout,"closing bracket found in block\n");
break;
} else {
parser->state = STATE_DECLARATION;
}
}
/* no break */
case STATE_DECLARATION:
if (c == '(') {
parser->in_paren = 1;
}
if (parser->in_paren == 0) {
if (c == ';') {
parser->state = STATE_BLOCK;
if (cssmin_peek(parser) == '}') {
c = 0;
}
} else if (c == '}') {
parser->state = STATE_FREE;
} else {
if (c == '\n' || c == '\r') {
c = 0;
} else {
if (c == ' ' || c == '\t') {
p = cssmin_peek(parser);
if (p == ' ' || p == '\t') {
c = 0;
} else {
c = ' ';
}
}
}
}
} else {
if (c == ')') {
parser->in_paren = 0;
}
}
break;
case STATE_COMMENT:
if (c == '*' && cssmin_peek(parser) == '/'){
parser->style_pointer += 2;
parser->state = parser->tmp_state;
}
c = 0;
break;
}
return c;
}
static int phalcon_cssmin_internal(zval *return_value, zval *style, zval **error TSRMLS_DC) {
int i;
unsigned char c;
cssmin_parser parser;
smart_str minified = {0};
parser.tmp_state = 0;
parser.state = 1;
parser.last_state = 1;
parser.in_paren = 0;
parser.style = style;
parser.error = error;
parser.minified = &minified;
for (i = 0; i < Z_STRLEN_P(style); i++) {
parser.style_pointer = i + 1;
c = phalcon_cssmin_machine(&parser, Z_STRVAL_P(style)[i] TSRMLS_CC);
if (c != 0) {
smart_str_appendc(parser.minified, c);
}
i = parser.style_pointer - 1;
}
smart_str_0(&minified);
if (minified.len) {
ZVAL_STRINGL(return_value, minified.c, minified.len, 0);
} else {
ZVAL_STRING(return_value, "", 1);
}
return SUCCESS;
}
/* cssmin -- minify the css
removes comments
removes newlines and line feeds keeping
removes last semicolon from last property
*/
static int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC) {
zval *error = NULL;
PHALCON_MM_GROW();
ZVAL_NULL(return_value);
if (Z_TYPE_P(style) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Style must be a string");
return FAILURE;
}
if (phalcon_cssmin_internal(return_value, style, &error TSRMLS_CC) == FAILURE) {
if (Z_TYPE_P(error) == IS_STRING) {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, Z_STRVAL_P(error));
} else {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Unknown error");
}
return FAILURE;
}
PHALCON_MM_RESTORE();
return SUCCESS;
}
zend_class_entry *phalcon_assets_filters_jsmin_ce;
static PHP_METHOD(Phalcon_Assets_Filters_Jsmin, filter);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_filters_jsmin_filter, 0, 0, 1)
ZEND_ARG_INFO(0, content)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_filters_jsmin_method_entry[] = {
PHP_ME(Phalcon_Assets_Filters_Jsmin, filter, arginfo_phalcon_assets_filters_jsmin_filter, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Filters_Jsmin){
PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, Jsmin, assets_filters_jsmin, phalcon_assets_filters_jsmin_method_entry, 0);
zend_class_implements(phalcon_assets_filters_jsmin_ce TSRMLS_CC, 1, phalcon_assets_filterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Filters_Jsmin, filter){
zval *content;
phalcon_fetch_params(0, 1, 0, &content);
if (phalcon_jsmin(return_value, content TSRMLS_CC) == FAILURE) {
return;
}
}
/* jsmin.c
2013-03-29
Copyright (c) 2002 Douglas Crockford (www.crockford.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <ext/standard/php_smart_str.h>
#define JSMIN_ACTION_OUTPUT_NEXT 1
#define JSMIN_ACTION_NEXT_DELETE 2
#define JSMIN_ACTION_NEXT 3
typedef struct _jsmin_parser {
zval *script;
zval **error;
int script_pointer;
int inside_string;
smart_str *minified;
unsigned char theA;
unsigned char theB;
unsigned char theC;
unsigned char theX;
unsigned char theY;
} jsmin_parser;
static void jsmin_error(jsmin_parser *parser, char* s, int s_length TSRMLS_DC) {
PHALCON_INIT_VAR(*parser->error);
ZVAL_STRINGL(*parser->error, s, s_length, 1);
}
/* isAlphanum -- return true if the character is a letter, digit, underscore,
dollar sign, or non-ASCII character.
*/
static int jsmin_isAlphanum(int c) {
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' || c > 126);
}
/* get -- return the next character from stdin. Watch out for lookahead. If
the character is a control character, translate it to a space or
linefeed.
*/
static unsigned char jsmin_peek(jsmin_parser *parser){
unsigned char ch;
if (parser->script_pointer < Z_STRLEN_P(parser->script)) {
ch = Z_STRVAL_P(parser->script)[parser->script_pointer];
return ch;
}
return '\0';
}
static unsigned char jsmin_get(jsmin_parser *parser) {
unsigned char c;
if (parser->script_pointer < Z_STRLEN_P(parser->script)) {
c = Z_STRVAL_P(parser->script)[parser->script_pointer];
parser->script_pointer++;
} else {
c = '\0';
}
parser->theC = c;
if (parser->inside_string == 1) {
if (c >= ' ' || c == '\n' || c == '\t' || c == '\0') {
return c;
}
} else {
if (c >= ' ' || c == '\n' || c == '\0') {
return c;
}
}
if (c == '\r') {
return '\n';
}
return ' ';
}
/* next -- get the next character, excluding comments. peek() is used to see
if a '/' is followed by a '/' or '*'.
*/
static int jsmin_next(jsmin_parser *parser TSRMLS_DC) {
unsigned char c = jsmin_get(parser);
if (c == '/') {
switch (jsmin_peek(parser)) {
case '/':
for (;;) {
c = jsmin_get(parser);
if (c <= '\n') {
break;
}
}
break;
case '*':
jsmin_get(parser);
while (c != ' ') {
switch (jsmin_get(parser)) {
case '*':
if (jsmin_peek(parser) == '/') {
jsmin_get(parser);
c = ' ';
}
break;
case '\0':
jsmin_error(parser, SL("Unterminated comment.") TSRMLS_CC);
return FAILURE;
}
}
break;
}
}
parser->theY = parser->theX;
parser->theX = c;
return c;
}
/* action -- do something! What you do is determined by the argument:
1 Output A. Copy B to A. Get the next B.
2 Copy B to A. Get the next B. (Delete A).
3 Get the next B. (Delete B).
action treats a string as a single character. Wow!
action recognizes a regular expression if it is preceded by ( or , or =.
*/
static int jsmin_action(jsmin_parser *parser, unsigned char d TSRMLS_DC) {
switch (d) {
case JSMIN_ACTION_OUTPUT_NEXT:
smart_str_appendc(parser->minified, parser->theA);
if (
(parser->theY == '\n' || parser->theY == ' ') &&
(parser->theA == '+' || parser->theA == '-' || parser->theA == '*' || parser->theA == '/') &&
(parser->theB == '+' || parser->theB == '-' || parser->theB == '*' || parser->theB == '/')
) {
smart_str_appendc(parser->minified, parser->theY);
}
/* no break */
case JSMIN_ACTION_NEXT_DELETE:
parser->theA = parser->theB;
if (parser->theA == '\'' || parser->theA == '"' || parser->theA == '`') {
parser->inside_string = 1;
for (;;) {
smart_str_appendc(parser->minified, parser->theA);
parser->theA = jsmin_get(parser);
if (parser->theA == parser->theB) {
break;
}
if (parser->theA == '\\') {
smart_str_appendc(parser->minified, parser->theA);
parser->theA = jsmin_get(parser);
}
if (parser->theA == '\0') {
jsmin_error(parser, SL("Unterminated string literal.") TSRMLS_CC);
return FAILURE;
}
}
parser->inside_string = 0;
}
/* no break */
case JSMIN_ACTION_NEXT:
parser->theB = jsmin_next(parser TSRMLS_CC);
if (*parser->error != NULL) {
return FAILURE;
}
if (parser->theB == '/' && (
parser->theA == '(' || parser->theA == ',' || parser->theA == '=' || parser->theA == ':' ||
parser->theA == '[' || parser->theA == '!' || parser->theA == '&' || parser->theA == '|' ||
parser->theA == '?' || parser->theA == '+' || parser->theA == '-' || parser->theA == '~' ||
parser->theA == '*' || parser->theA == '/' || parser->theA == '{' || parser->theA == '\n'
)) {
smart_str_appendc(parser->minified, parser->theA);
if (parser->theA == '/' || parser->theA == '*') {
smart_str_appendc(parser->minified, ' ');
}
smart_str_appendc(parser->minified, parser->theB);
for (;;) {
parser->theA = jsmin_get(parser);
if (parser->theA == '[') {
for (;;) {
smart_str_appendc(parser->minified, parser->theA);
parser->theA = jsmin_get(parser);
if (parser->theA == ']') {
break;
}
if (parser->theA == '\\') {
smart_str_appendc(parser->minified, parser->theA);
parser->theA = jsmin_get(parser);
}
if (parser->theA == '\0') {
jsmin_error(parser, SL("Unterminated set in Regular Expression literal.") TSRMLS_CC);
return FAILURE;
}
}
} else {
if (parser->theA == '/') {
switch (jsmin_peek(parser)) {
case '/':
case '*':
jsmin_error(parser, SL("Unterminated set in Regular Expression literal.") TSRMLS_CC);
return FAILURE;
}
break;
} else {
if (parser->theA == '\\') {
smart_str_appendc(parser->minified, parser->theA);
parser->theA = jsmin_get(parser);
}
}
}
if (parser->theA == '\0') {
jsmin_error(parser, SL("Unterminated Regular Expression literal.") TSRMLS_CC);
return FAILURE;
}
smart_str_appendc(parser->minified, parser->theA);
}
parser->theB = jsmin_next(parser TSRMLS_CC);
if (*parser->error != NULL) {
return FAILURE;
}
}
}
return SUCCESS;
}
/* jsmin -- Copy the input to the output, deleting the characters which are
insignificant to JavaScript. Comments will be removed. Tabs will be
replaced with spaces. Carriage returns will be replaced with linefeeds.
Most spaces and linefeeds will be removed.
*/
static int phalcon_jsmin_internal(zval *return_value, zval *script, zval **error TSRMLS_DC) {
jsmin_parser parser;
smart_str minified = {0};
int status = SUCCESS;
parser.theA = '\n';
parser.theX = '\0';
parser.theY = '\0';
parser.script = script;
parser.error = error;
parser.script_pointer = 0;
parser.inside_string = 0;
parser.minified = &minified;
if (jsmin_action(&parser, JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) {
return FAILURE;
}
while (parser.theA != '\0') {
if (status == FAILURE) {
break;
}
switch (parser.theA) {
case ' ':
if (jsmin_action(&parser, jsmin_isAlphanum(parser.theB) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT_DELETE TSRMLS_CC)) {
status = FAILURE;
break;
}
break;
case '\n':
switch (parser.theB) {
case '{':
case '[':
case '(':
case '+':
case '-':
case '!':
case '~':
if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) {
status = FAILURE;
break;
}
break;
case ' ':
if (jsmin_action(&parser, JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) {
status = FAILURE;
break;
}
break;
default:
if (jsmin_action(&parser, jsmin_isAlphanum(parser.theB) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT_DELETE TSRMLS_CC) == FAILURE) {
status = FAILURE;
break;
}
}
break;
default:
switch (parser.theB) {
case ' ':
if (jsmin_action(&parser, jsmin_isAlphanum(parser.theA) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) {
status = FAILURE;
break;
}
break;
case '\n':
switch (parser.theA) {
case '}':
case ']':
case ')':
case '+':
case '-':
case '"':
case '\'':
case '`':
if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) {
status = FAILURE;
break;
}
break;
default:
if (jsmin_action(&parser, jsmin_isAlphanum(parser.theA) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) {
status = FAILURE;
break;
}
}
break;
default:
if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) {
status = FAILURE;
break;
}
break;
}
}
}
if (status == FAILURE) {
smart_str_free(&minified);
return FAILURE;
}
smart_str_0(&minified);
if (minified.len) {
ZVAL_STRINGL(return_value, minified.c, minified.len, 0);
} else {
ZVAL_STRING(return_value, "", 1);
}
return SUCCESS;
}
static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) {
zval *error = NULL;
PHALCON_MM_GROW();
ZVAL_NULL(return_value);
if (Z_TYPE_P(script) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Script must be a string");
return FAILURE;
}
if (phalcon_jsmin_internal(return_value, script, &error TSRMLS_CC) == FAILURE){
if (Z_TYPE_P(error) == IS_STRING) {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, Z_STRVAL_P(error));
} else {
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Unknown error");
}
return FAILURE;
}
PHALCON_MM_RESTORE();
return SUCCESS;
}
zend_class_entry *phalcon_assets_filters_none_ce;
static PHP_METHOD(Phalcon_Assets_Filters_None, filter);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_filters_none_filter, 0, 0, 1)
ZEND_ARG_INFO(0, content)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_filters_none_method_entry[] = {
PHP_ME(Phalcon_Assets_Filters_None, filter, arginfo_phalcon_assets_filters_none_filter, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Filters_None){
PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, None, assets_filters_none, phalcon_assets_filters_none_method_entry, 0);
zend_class_implements(phalcon_assets_filters_none_ce TSRMLS_CC, 1, phalcon_assets_filterinterface_ce);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Filters_None, filter){
zval *content;
phalcon_fetch_params(0, 1, 0, &content);
RETURN_CTORW(content);
}
zend_class_entry *phalcon_assets_resource_css_ce;
static PHP_METHOD(Phalcon_Assets_Resource_Css, __construct);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_css___construct, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, local)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_resource_css_method_entry[] = {
PHP_ME(Phalcon_Assets_Resource_Css, __construct, arginfo_phalcon_assets_resource_css___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Resource_Css){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets\\Resource, Css, assets_resource_css, phalcon_assets_resource_ce, phalcon_assets_resource_css_method_entry, 0);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Resource_Css, __construct){
zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes);
PHALCON_ALLOC_GHOST_ZVAL(type);
ZVAL_STRING(type, "css", 1);
phalcon_call_parent_p5_noret(
this_ptr,
phalcon_assets_resource_css_ce, "__construct",
type, path,
(local ? local : PHALCON_GLOBAL(z_true)),
(filter ? filter : PHALCON_GLOBAL(z_true)),
(attributes ? attributes : PHALCON_GLOBAL(z_null))
);
PHALCON_MM_RESTORE();
}
zend_class_entry *phalcon_assets_resource_js_ce;
static PHP_METHOD(Phalcon_Assets_Resource_Js, __construct);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_resource_js___construct, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, local)
ZEND_ARG_INFO(0, filter)
ZEND_ARG_INFO(0, attributes)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_assets_resource_js_method_entry[] = {
PHP_ME(Phalcon_Assets_Resource_Js, __construct, arginfo_phalcon_assets_resource_js___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Assets_Resource_Js){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets\\Resource, Js, assets_resource_js, phalcon_assets_resource_ce, phalcon_assets_resource_js_method_entry, 0);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Assets_Resource_Js, __construct){
zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes);
PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "js", 1);
phalcon_call_parent_p5_noret(
this_ptr,
phalcon_assets_resource_js_ce, "__construct",
type, path,
(local ? local : PHALCON_GLOBAL(z_true)),
(filter ? filter : PHALCON_GLOBAL(z_true)),
(attributes ? attributes : PHALCON_GLOBAL(z_null))
);
PHALCON_MM_RESTORE();
}
zend_class_entry *phalcon_cache_backend_ce;
static PHP_METHOD(Phalcon_Cache_Backend, __construct);
static PHP_METHOD(Phalcon_Cache_Backend, start);
static PHP_METHOD(Phalcon_Cache_Backend, stop);
static PHP_METHOD(Phalcon_Cache_Backend, getFrontend);
static PHP_METHOD(Phalcon_Cache_Backend, getOptions);
static PHP_METHOD(Phalcon_Cache_Backend, isFresh);
static PHP_METHOD(Phalcon_Cache_Backend, isStarted);
static PHP_METHOD(Phalcon_Cache_Backend, setLastKey);
static PHP_METHOD(Phalcon_Cache_Backend, getLastKey);
static PHP_METHOD(Phalcon_Cache_Backend, getLifetime);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_cache_backend___construct, 0, 0, 1)
ZEND_ARG_INFO(0, frontend)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
static const zend_function_entry phalcon_cache_backend_method_entry[] = {
PHP_ME(Phalcon_Cache_Backend, __construct, arginfo_phalcon_cache_backend___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Cache_Backend, start, arginfo_phalcon_cache_backendinterface_start, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, stop, arginfo_phalcon_cache_backendinterface_stop, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, getFrontend, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, getOptions, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, isFresh, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, isStarted, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, setLastKey, arginfo_phalcon_cache_backendinterface_setlastkey, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, getLastKey, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Cache_Backend, getLifetime, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Cache_Backend){
PHALCON_REGISTER_CLASS(Phalcon\\Cache, Backend, cache_backend, phalcon_cache_backend_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
zend_declare_property_null(phalcon_cache_backend_ce, SL("_frontend"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_cache_backend_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_cache_backend_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_cache_backend_ce, SL("_lastKey"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_cache_backend_ce, SL("_lastLifetime"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_cache_backend_ce, SL("_fresh"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_cache_backend_ce, SL("_started"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
static PHP_METHOD(Phalcon_Cache_Backend, __construct){
zval *frontend, *options = NULL, *prefix;
phalcon_fetch_params(0, 1, 1, &frontend, &options);
PHALCON_VERIFY_INTERFACE_EX(frontend, phalcon_cache_frontendinterface_ce, phalcon_cache_exception_ce, 0);
if (options) {
if (phalcon_array_isset_string_fetch(&prefix, options, SS("prefix"))) {
phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC);
}
phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC);
}
phalcon_update_property_this_quick(this_ptr, SL("_frontend"), frontend, 3187914628UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Cache_Backend, start){
zval *key_name, *lifetime = NULL, *fresh = NULL;
zval *frontend;
PHALCON_MM_GROW();
phalcon_fetch_params(1, 1, 1, &key_name, &lifetime);
if (!lifetime) {
lifetime = PHALCON_GLOBAL(z_null);
}
phalcon_return_call_method_p2(this_ptr, "get", key_name, lifetime);
if ((return_value_ptr && Z_TYPE_PP(return_value_ptr) == IS_NULL) || (!return_value_ptr && Z_TYPE_P(return_value) == IS_NULL)) {
fresh = PHALCON_GLOBAL(z_true);
frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY_CC);
phalcon_call_method_key(NULL, frontend, "start", 478839859UL);
} else {
fresh = PHALCON_GLOBAL(z_false);
}
phalcon_update_property_this_quick(this_ptr, SL("_fresh"), fresh, 2329058172UL TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_started"), PHALCON_GLOBAL(z_true) TSRMLS_CC);
if (Z_TYPE_P(lifetime) != IS_NULL) {
phalcon_update_property_this_quick(this_ptr, SL("_lastLifetime"), lifetime, 3936785351UL TSRMLS_CC);
}
RETURN_MM();
}
static PHP_METHOD(Phalcon_Cache_Backend, stop){
zval *stop_buffer = NULL, *frontend;
phalcon_fetch_params(0, 0, 1, &stop_buffer);
if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) {
PHALCON_MM_GROW();
frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY_CC);
phalcon_call_method_key(NULL, frontend, "stop", 274826411UL);
PHALCON_MM_RESTORE();
}
phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Cache_Backend, getFrontend){
RETURN_MEMBER_QUICK(this_ptr, "_frontend", 3187914628UL);
}
static PHP_METHOD(Phalcon_Cache_Backend, getOptions){
RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL);
}
static PHP_METHOD(Phalcon_Cache_Backend, isFresh){
RETURN_MEMBER_QUICK(this_ptr, "_fresh", 2329058172UL);
}
static PHP_METHOD(Phalcon_Cache_Backend, isStarted){
RETURN_MEMBER_QUICK(this_ptr, "_started", 433407867UL);
}
static PHP_METHOD(Phalcon_Cache_Backend, setLastKey){
zval *last_key;
phalcon_fetch_params(0, 1, 0, &last_key);
phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), last_key, 394299009UL TSRMLS_CC);
}
static PHP_METHOD(Phalcon_Cache_Backend, getLastKey){
RETURN_MEMBER_QUICK(this_ptr, "_lastKey", 394299009UL);
}
static PHP_METHOD(Phalcon_Cache_Backend, getLifetime){
RETURN_MEMBER_QUICK(this_ptr, "_lastLifetime", 3936785351UL);
}
zend_class_entry *phalcon_cache_backendinterface_ce;
static const zend_function_entry phalcon_cache_backendinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, start, arginfo_phalcon_cache_backendinterface_start)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, stop, arginfo_phalcon_cache_backendinterface_stop)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, getFrontend, NULL)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, getOptions, NULL)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, isFresh, NULL)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, isStarted, NULL)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, setLastKey, arginfo_phalcon_cache_backendinterface_setlastkey)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, getLastKey, NULL)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, get, arginfo_phalcon_cache_backendinterface_get)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, save, arginfo_phalcon_cache_backendinterface_save)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, delete, arginfo_phalcon_cache_backendinterface_delete)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, queryKeys, arginfo_phalcon_cache_backendinterface_querykeys)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, exists, arginfo_phalcon_cache_backendinterface_exists)
PHP_ABSTRACT_ME(Phalcon_Cache_BackendInterface, flush, NULL)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Cache_BackendInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Cache, BackendInterface, cache_backendinterface, phalcon_cache_backendinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_cache_exception_ce;
PHALCON_INIT_CLASS(Phalcon_Cache_Exception){
PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache, Exception, cache_exception, phalcon_exception_ce, NULL, 0);
return SUCCESS;
}
zend_class_entry *phalcon_cache_frontendinterface_ce;
static const zend_function_entry phalcon_cache_frontendinterface_method_entry[] = {
PHP_ABSTRACT_ME(Phalcon_Cache_FrontendInterface, getLifetime, arginfo_phalcon_cache_frontendinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Cache_FrontendInterface, isBuffering, arginfo_phalcon_cache_frontendinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Cache_FrontendInterface, start, arginfo_phalcon_cache_frontendinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Cache_FrontendInterface, getContent, arginfo_phalcon_cache_frontendinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Cache_FrontendInterface, stop, arginfo_phalcon_cache_frontendinterface_empty)
PHP_ABSTRACT_ME(Phalcon_Cache_FrontendInterface, beforeStore, arginfo_phalcon_cache_frontendinterface_beforestore)
PHP_ABSTRACT_ME(Phalcon_Cache_FrontendInterface, afterRetrieve, arginfo_phalcon_cache_frontendinterface_afterretrieve)
PHP_FE_END
};
PHALCON_INIT_CLASS(Phalcon_Cache_FrontendInterface){
PHALCON_REGISTER_INTERFACE(Phalcon\\Cache, FrontendInterface, cache_frontendinterface, phalcon_cache_frontendinterface_method_entry);
return SUCCESS;
}
zend_class_entry *phalcon_cache_multiple_ce;
static PHP_METHOD(Phalcon_Cache_M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment