/** * Sets a LIMIT clause, optionally a offset clause * *<code> * $builder->limit(100); * $builder->limit(100, 20); *</code> * * @param int $limit * @param int $offset * @return Phalcon\Mvc\Model\Query\Builder */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, limit){ zval *limit, *offset = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &limit, &offset) == FAILURE) { RETURN_MM_NULL(); } if (!offset) { PHALCON_INIT_VAR(offset); } if (phalcon_is_numeric(limit)) { phalcon_update_property_zval(this_ptr, SL("_limit"), limit TSRMLS_CC); } if (Z_TYPE_P(offset) != IS_NULL) { if (phalcon_is_numeric(offset)) { phalcon_update_property_zval(this_ptr, SL("_offset"), offset TSRMLS_CC); } } RETURN_THIS(); }
/** * Returns a cached content * * @param int|string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){ zval *key_name, *lifetime = NULL, *memcache, *frontend; zval *prefix, *prefixed_key, *cached_content = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); memcache = phalcon_fetch_nproperty_this(this_ptr, SL("_memcache"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(memcache) != IS_OBJECT) { memcache = NULL; PHALCON_CALL_METHOD(&memcache, this_ptr, "_connect"); } frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(prefixed_key); PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); phalcon_update_property_this(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC); PHALCON_CALL_METHOD(&cached_content, memcache, "get", prefixed_key); if (PHALCON_IS_FALSE(cached_content)) { RETURN_MM_NULL(); } if (phalcon_is_numeric(cached_content)) { RETURN_CCTOR(cached_content); } PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content); RETURN_MM(); }
/** * Returns a cached content * * @param int|string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){ zval *key_name, *lifetime = NULL, memcache = {}, frontend = {}, prefix = {}, prefixed_key = {}, cached_content = {}; phalcon_fetch_params(0, 1, 1, &key_name, &lifetime); phalcon_return_property(&memcache, getThis(), SL("_memcache")); if (Z_TYPE(memcache) != IS_OBJECT) { PHALCON_CALL_METHODW(&memcache, getThis(), "_connect"); } phalcon_return_property(&frontend, getThis(), SL("_frontend")); phalcon_return_property(&prefix, getThis(), SL("_prefix")); PHALCON_CONCAT_VV(&prefixed_key, &prefix, key_name); phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key); PHALCON_CALL_METHODW(&cached_content, &memcache, "get", &prefixed_key); if (PHALCON_IS_FALSE(&cached_content)) { RETURN_NULL(); } if (phalcon_is_numeric(&cached_content)) { RETURN_CTORW(&cached_content); } PHALCON_RETURN_CALL_METHOD(&frontend, "afterretrieve", &cached_content); }
/** * Returns a cached content * * @param string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Memory, get){ zval *key_name, *lifetime = NULL; zval *data, *cached_content, *frontend, *last_key; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); if (Z_TYPE_P(key_name) == IS_NULL) { last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC); } else { zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(last_key); PHALCON_CONCAT_VV(last_key, prefix, key_name); phalcon_update_property_this(this_ptr, SL("_lastKey"), last_key TSRMLS_CC); } data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&cached_content, data, last_key)) { if (Z_TYPE_P(cached_content) != IS_NULL) { if (phalcon_is_numeric(cached_content)) { RETVAL_ZVAL(cached_content, 1, 0); } else { frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content); } } } PHALCON_MM_RESTORE(); }
/** * Adds the limit parameter to the criteria * * @param int $limit * @param int $offset * @return Phalcon\Mvc\Model\Criteria */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, limit){ zval *limit, *offset = NULL, *limit_clause; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &limit, &offset); if (!offset) { PHALCON_INIT_VAR(offset); } if (!phalcon_is_numeric(limit)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Rows limit parameter must be integer"); return; } if (Z_TYPE_P(offset) == IS_NULL) { phalcon_update_property_array_string(this_ptr, SL("_params"), SS("limit"), limit TSRMLS_CC); } else { PHALCON_INIT_VAR(limit_clause); array_init_size(limit_clause, 2); phalcon_array_update_string(&limit_clause, SL("number"), &limit, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&limit_clause, SL("offset"), &offset, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_update_property_array_string(this_ptr, SL("_params"), SS("limit"), limit_clause TSRMLS_CC); } RETURN_THIS(); }
/** * Returns cached content * * @param string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, get){ zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; zval *cached_content = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); frontend = phalcon_read_property(getThis(), SL("_frontend"), PH_NOISY); prefix = phalcon_read_property(getThis(), SL("_prefix"), PH_NOISY); PHALCON_INIT_VAR(prefixed_key); PHALCON_CONCAT_SVV(prefixed_key, "_PHCX", prefix, key_name); phalcon_update_property_this(getThis(), SL("_lastKey"), prefixed_key); PHALCON_CALL_FUNCTION(&cached_content, "xcache_get", prefixed_key); if (Z_TYPE_P(cached_content) == IS_NULL) { RETURN_MM_NULL(); } if (phalcon_is_numeric(cached_content)) { RETURN_CCTOR(cached_content); } else { PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content); } RETURN_MM(); }
/** * Executes the validation * * @param string $value * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Numericality, valid){ zval *value; phalcon_fetch_params(0, 2, 0, &value); if (phalcon_is_numeric(value)) { RETURN_TRUE; } RETURN_FALSE; }
/** * Stores cached content into the backend and stops the frontend * * @param string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Memory, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *cached_content = NULL, *prepared_content = NULL, *is_buffering = NULL; zval *last_key, *frontend; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC); } else { zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(last_key); PHALCON_CONCAT_VV(last_key, prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHOD(&cached_content, frontend, "getcontent"); } else { cached_content = content; } if (phalcon_is_numeric(cached_content)) { phalcon_update_property_array(this_ptr, SL("_data"), last_key, cached_content TSRMLS_CC); } else { PHALCON_CALL_METHOD(&prepared_content, frontend, "beforestore", cached_content); phalcon_update_property_array(this_ptr, SL("_data"), last_key, prepared_content TSRMLS_CC); } PHALCON_CALL_METHOD(&is_buffering, frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHOD(NULL, frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Generates the SQL for LIMIT clause * *<code> * $sql = $dialect->limit('SELECT * FROM robots', 10); * echo $sql; // SELECT * FROM robots LIMIT 10 *</code> * * @param string $sqlQuery * @param int $number * @return string */ PHP_METHOD(Phalcon_Db_Dialect, limit){ zval *sql_query, *number, limit = {}; phalcon_fetch_params(0, 2, 0, &sql_query, &number); if (phalcon_is_numeric(number)) { ZVAL_LONG(&limit, phalcon_get_intval(number)); PHALCON_CONCAT_VSV(return_value, sql_query, " LIMIT ", &limit); return; } RETURN_CTORW(sql_query); }
/** * Sets a LIMIT clause, optionally a offset clause * *<code> * $builder->limit(100); * $builder->limit(100, 20); *</code> * * @param int $limit * @param int $offset * @return Phalcon\Mvc\Model\Query\Builder */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, limit){ zval *limit, *offset = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &limit, &offset); if (!offset) { PHALCON_INIT_VAR(offset); } if (phalcon_is_numeric(limit)) { phalcon_update_property_this(this_ptr, SL("_limit"), limit TSRMLS_CC); } if (Z_TYPE_P(offset) != IS_NULL) { if (phalcon_is_numeric(offset)) { phalcon_update_property_this(this_ptr, SL("_offset"), offset TSRMLS_CC); } } RETURN_THIS(); }
/** * Generates the SQL for LIMIT clause * *<code> * $sql = $dialect->limit('SELECT * FROM robots', 10); * echo $sql; // SELECT * FROM robots LIMIT 10 *</code> * * @param string $sqlQuery * @param int $number * @return string */ PHP_METHOD(Phalcon_Db_Dialect, limit){ zval *sql_query, *number, *limit; phalcon_fetch_params(1, 2, 0, &sql_query, &number); if (phalcon_is_numeric(number)) { PHALCON_MM_GROW(); PHALCON_INIT_VAR(limit); ZVAL_LONG(limit, phalcon_get_intval(number)); PHALCON_CONCAT_VSV(return_value, sql_query, " LIMIT ", limit); RETURN_MM(); } RETURN_ZVAL(sql_query, 1, 0); }
/** * Executes the validator * * @param Phalcon\Mvc\ModelInterface $record * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){ zval *record, *option = NULL, *field, *value, *message = NULL, *type; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &record); PHALCON_INIT_VAR(option); ZVAL_STRING(option, "field", 1); PHALCON_INIT_VAR(field); phalcon_call_method_p1(field, this_ptr, "getoption", option); if (Z_TYPE_P(field) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); return; } PHALCON_INIT_VAR(value); phalcon_call_method_p1(value, record, "readattribute", field); /** * Check if the value is numeric using is_numeric in the PHP userland */ if (!phalcon_is_numeric(value)) { /** * Check if the developer has defined a custom message */ PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "message", 1); PHALCON_INIT_VAR(message); phalcon_call_method_p1(message, this_ptr, "getoption", option); if (!zend_is_true(message)) { PHALCON_INIT_NVAR(message); PHALCON_CONCAT_SVS(message, "Value of field '", field, "' must be numeric"); } PHALCON_INIT_VAR(type); ZVAL_STRING(type, "Numericality", 1); phalcon_call_method_p3_noret(this_ptr, "appendmessage", message, field, type); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Returns a cached content * * @param int|string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Mongo, get){ zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; zval *collection = NULL, *conditions, *document = NULL, *time_condition; zval *cached_content; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(prefixed_key); PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); phalcon_update_property_this(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC); PHALCON_CALL_METHOD(&collection, this_ptr, "_getcollection"); PHALCON_INIT_VAR(conditions); array_init_size(conditions, 2); phalcon_array_update_string(&conditions, SL("key"), prefixed_key, PH_COPY); MAKE_STD_ZVAL(time_condition); array_init_size(time_condition, 1); add_assoc_long_ex(time_condition, SS("$gt"), (long int)time(NULL)); add_assoc_zval_ex(conditions, SS("time"), time_condition); PHALCON_CALL_METHOD(&document, collection, "findone", conditions); if (Z_TYPE_P(document) == IS_ARRAY) { if (likely(phalcon_array_isset_string_fetch(&cached_content, document, SS("data")))) { if (phalcon_is_numeric(cached_content)) { RETURN_CCTOR(cached_content); } else { PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content); RETURN_MM(); } } else { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache is corrupt"); return; } } else { RETURN_MM_NULL(); } }
/** * Generates the SQL for LIMIT clause * *<code> * $sql = $dialect->limit('SELECT * FROM robots', 10); * echo $sql; // SELECT * FROM robots LIMIT 10 *</code> * * @param string $sqlQuery * @param int $number * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, limit){ zval *sql_query, *number, *limit, *sql_limit; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_query, &number) == FAILURE) { RETURN_MM_NULL(); } if (phalcon_is_numeric(number)) { PHALCON_INIT_VAR(limit); ZVAL_LONG(limit, phalcon_get_intval(number)); PHALCON_INIT_VAR(sql_limit); PHALCON_CONCAT_VSV(sql_limit, sql_query, " LIMIT ", limit); RETURN_CTOR(sql_limit); } RETURN_CTOR(sql_query); }
/** * Returns cached content * * @param string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, get){ zval *key_name, *lifetime = NULL, frontend = {}, prefix = {}, prefixed_key = {}, cached_content = {}; phalcon_fetch_params(0, 1, 1, &key_name, &lifetime); phalcon_return_property(&frontend, getThis(), SL("_frontend")); phalcon_return_property(&prefix, getThis(), SL("_prefix")); PHALCON_CONCAT_SVV(&prefixed_key, "_PHCX", &prefix, key_name); phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key); PHALCON_CALL_FUNCTIONW(&cached_content, "xcache_get", &prefixed_key); if (Z_TYPE(cached_content) == IS_NULL) { RETURN_NULL(); } if (phalcon_is_numeric(&cached_content)) { RETURN_CTORW(&cached_content); } else { PHALCON_RETURN_CALL_METHODW(&frontend, "afterretrieve", &cached_content); } }
/** * Returns a cached content * * @param string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Apc, get) { zval *key_name, *lifetime = NULL, prefixed_key = {}, prefix = {}, frontend = {}, cached_content = {}; phalcon_fetch_params(0, 1, 1, &key_name, &lifetime); phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY); PHALCON_CONCAT_SVV(&prefixed_key, "_PHCA", &prefix, key_name); phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key); PHALCON_CALL_FUNCTIONW(&cached_content, "apc_fetch", &prefixed_key); if (PHALCON_IS_FALSE(&cached_content)) { RETURN_NULL(); } if (phalcon_is_numeric(&cached_content)) { RETURN_CTORW(&cached_content); } else { phalcon_read_property(&frontend, getThis(), SL("_frontend"), PH_NOISY); PHALCON_RETURN_CALL_METHODW(&frontend, "afterretrieve", &cached_content); } }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * <code>print_r($connection->describeColumns("posts")); ?></code> * * @param string $table * @param string $schema * @return Phalcon\Db\Column[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns) { zval *table, *schema = NULL, *columns, *dialect, *sql = NULL, *fetch_num; zval *describe = NULL, *old_column = NULL, *field = NULL, *definition = NULL; zval *column_size = NULL, *column_precision = NULL, *column_scale = NULL; zval *column_type = NULL, *attribute = NULL, *column_name = NULL; zval *column = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { schema = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(columns); array_init(columns); PHALCON_OBS_VAR(dialect); phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(&sql, dialect, "describecolumns", table, schema); /** * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_CALL_METHOD(&describe, this_ptr, "fetchall", sql, fetch_num); /** * 0:column_name, 1:data_type, 2:data_length, 3:data_precision, 4:data_scale, * 5:nullable, 6:constraint_type, 7:default, 8:position; */ PHALCON_INIT_VAR(old_column); phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(field); PHALCON_INIT_NVAR(definition); array_init_size(definition, 1); add_assoc_long_ex(definition, SS("bindType"), 2); PHALCON_OBS_NVAR(column_size); phalcon_array_fetch_long(&column_size, field, 2, PH_NOISY); PHALCON_OBS_NVAR(column_precision); phalcon_array_fetch_long(&column_precision, field, 3, PH_NOISY); PHALCON_OBS_NVAR(column_scale); phalcon_array_fetch_long(&column_scale, field, 4, PH_NOISY); PHALCON_OBS_NVAR(column_type); phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); /** * Check the column type to get the correct Phalcon type */ while (1) { /** * Integer */ if (phalcon_memnstr_str(column_type, SL("NUMBER"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_DECIMAL, PH_COPY); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_COPY); phalcon_array_update_string(&definition, SL("size"), column_precision, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_COPY); if (phalcon_is_numeric(column_precision)) { phalcon_array_update_string_long(&definition, SL("bytes"), Z_LVAL_P(column_precision) * 8, PH_COPY); } else { phalcon_array_update_string_long(&definition, SL("size"), 30, PH_COPY); phalcon_array_update_string_long(&definition, SL("bytes"), 80, PH_COPY); } if (phalcon_is_numeric(column_scale)) { phalcon_array_update_string(&definition, SL("scale"), column_scale, PH_COPY); } else { phalcon_array_update_string_long(&definition, SL("scale"), 6, PH_COPY); } break; } /** * Tinyint(1) is boolean */ if (phalcon_memnstr_str(column_type, SL("TINYINT(1)"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_BOOLEAN, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_COPY); break; } /** * Smallint/Bigint/Integers/Int are int */ if (phalcon_memnstr_str(column_type, SL("INTEGER"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_INTEGER, PH_COPY); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_COPY); phalcon_array_update_string(&definition, SL("size"), column_precision, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_COPY); phalcon_array_update_string_long(&definition, SL("bytes"), 32, PH_COPY); break; } /** * Float/Smallfloats/Decimals are float */ if (phalcon_memnstr_str(column_type, SL("FLOAT"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_FLOAT, PH_COPY); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_COPY); phalcon_array_update_string(&definition, SL("size"), column_size, PH_COPY); phalcon_array_update_string(&definition, SL("scale"), column_scale, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_COPY); break; } /** * Date */ if (phalcon_memnstr_str(column_type, SL("TIMESTAMP"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_DATE, PH_COPY); break; } /** * Text */ if (phalcon_memnstr_str(column_type, SL("RAW"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_TEXT, PH_COPY); break; } /** * Text */ if (phalcon_memnstr_str(column_type, SL("BLOB"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_TEXT, PH_COPY); break; } /** * Text */ if (phalcon_memnstr_str(column_type, SL("CLOB"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_TEXT, PH_COPY); break; } /** * Chars2 are string */ if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_VARCHAR, PH_COPY); phalcon_array_update_string(&definition, SL("size"), column_size, PH_COPY); break; } /** * Chars are chars */ if (phalcon_memnstr_str(column_type, SL("CHAR"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_CHAR, PH_COPY); phalcon_array_update_string(&definition, SL("size"), column_size, PH_COPY); break; } /** * Text are varchars */ if (phalcon_memnstr_str(column_type, SL("text"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_TEXT, PH_COPY); break; } /** * By default is string */ phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_VARCHAR, PH_COPY); break; } if (Z_TYPE_P(old_column) == IS_NULL) { phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_COPY); } else { phalcon_array_update_string(&definition, SL("after"), old_column, PH_COPY); } /** * Check if the field is primary key */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); if (PHALCON_IS_STRING(attribute, "P")) { phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_COPY); } /** * Check if the column allows null values */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); if (PHALCON_IS_STRING(attribute, "N")) { phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_COPY); } PHALCON_OBS_NVAR(column_name); phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); /** * If the column set the default values, get it */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 7, PH_NOISY); if (!PHALCON_IS_EMPTY(attribute)) { phalcon_array_update_string(&definition, SL("default"), attribute, PH_COPY); } /** * Create a Phalcon\Db\Column to abstract the column */ PHALCON_INIT_NVAR(column); object_init_ex(column, phalcon_db_column_ce); PHALCON_CALL_METHOD(NULL, column, "__construct", column_name, definition); phalcon_array_append(&columns, column, PH_COPY); PHALCON_CPY_WRT(old_column, column_name); zend_hash_move_forward_ex(ah0, &hp0); } RETURN_CTOR(columns); }
/** * Stores cached content into the XCache backend and stops the frontend * * @param string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL, cached_content = {}, keys = {}, last_key = {}, frontend = {}; zval prepared_content = {}, ttl = {}, success = {}, is_buffering = {}, prefix = {}, options = {}, special_key = {}; phalcon_fetch_params(0, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { phalcon_return_property(&last_key, getThis(), SL("_lastKey")); } else { phalcon_return_property(&prefix, getThis(), SL("_prefix")); PHALCON_CONCAT_SVV(&last_key, "_PHCX", &prefix, key_name); } if (!zend_is_true(&last_key)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "The cache must be started first"); return; } phalcon_return_property(&frontend, getThis(), SL("_frontend")); if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHODW(&cached_content, &frontend, "getcontent"); } else { PHALCON_CPY_WRT(&cached_content, content); } if (!phalcon_is_numeric(&cached_content)) { PHALCON_CALL_METHODW(&prepared_content, &frontend, "beforestore", &cached_content); } /** * Take the lifetime from the frontend or read it from the set in start() */ if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { phalcon_return_property(&ttl, getThis(), SL("_lastLifetime")); if (Z_TYPE(ttl) <= IS_NULL) { PHALCON_CALL_METHODW(&ttl, &frontend, "getlifetime"); } } else { PHALCON_CPY_WRT(&ttl, lifetime); } if (Z_TYPE(prepared_content) > IS_NULL) { PHALCON_CALL_FUNCTIONW(&success, "xcache_set", &last_key, &prepared_content, &ttl); } else { PHALCON_CALL_FUNCTIONW(&success, "xcache_set", &last_key, &cached_content, &ttl); } PHALCON_CALL_METHODW(&is_buffering, &frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHODW(NULL, &frontend, "stop"); } if (PHALCON_IS_TRUE(&is_buffering)) { zend_print_zval(&cached_content, 0); } phalcon_update_property_bool(getThis(), SL("_started"), 0); if (zend_is_true(&success)) { phalcon_return_property(&options, getThis(), SL("_options")); if (unlikely(!phalcon_array_isset_fetch_str(&special_key, &options, SL("statsKey")))) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); return; } /** * xcache_list() is available only to the administrator (unless XCache was * patched). We have to update the list of the stored keys. */ PHALCON_CALL_FUNCTIONW(&keys, "xcache_get", &special_key); if (Z_TYPE(keys) != IS_ARRAY) { array_init(&keys); } phalcon_array_update_zval(&keys, &last_key, &ttl, PH_COPY); PHALCON_CALL_FUNCTIONW(NULL, "xcache_set", &special_key, &keys, &PHALCON_GLOBAL(z_zero)); } }
/** * Executes the validator * * @param Phalcon\Mvc\ModelInterface $record * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){ zval *record, *option = NULL, *field = NULL, *value = NULL, *message = NULL; zval *type, *is_set_code = NULL, *code = NULL; zval *allow_empty = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &record); PHALCON_INIT_VAR(option); ZVAL_STRING(option, "field", 1); PHALCON_CALL_METHOD(&field, this_ptr, "getoption", option); if (Z_TYPE_P(field) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); return; } PHALCON_CALL_METHOD(&value, record, "readattribute", field); /* * Allow empty */ PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "allowEmpty", 1); PHALCON_CALL_METHOD(&allow_empty, this_ptr, "getoption", option); if (allow_empty && zend_is_true(allow_empty) && PHALCON_IS_EMPTY(value)) { RETURN_MM_TRUE; } /** * Check if the value is numeric using is_numeric in the PHP userland */ if (!phalcon_is_numeric(value)) { /** * Check if the developer has defined a custom message */ PHALCON_INIT_NVAR(option); PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_message); PHALCON_CALL_METHOD(&message, this_ptr, "getoption", option); if (!zend_is_true(message)) { PHALCON_INIT_NVAR(message); PHALCON_CONCAT_SVS(message, "Value of field '", field, "' must be numeric"); } PHALCON_INIT_VAR(type); ZVAL_STRING(type, "Numericality", 1); /* * Is code set */ PHALCON_INIT_NVAR(option); PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_code); PHALCON_CALL_METHOD(&is_set_code, this_ptr, "issetoption", option); if (zend_is_true(is_set_code)) { PHALCON_CALL_METHOD(&code, this_ptr, "getoption", option); } else { PHALCON_INIT_VAR(code); ZVAL_LONG(code, 0); } PHALCON_CALL_METHOD(NULL, this_ptr, "appendmessage", message, field, type, code); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Stores cached content into the APC backend and stops the frontend * * @param string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Apc, save) { zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL, prefix = {}, frontend = {}; zval last_key = {}, cached_content = {}, prepared_content = {}, last_lifetime = {}, ttl, is_buffering = {}; phalcon_fetch_params(0, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { phalcon_return_property(&last_key, getThis(), SL("_lastKey")); } else { phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY); PHALCON_CONCAT_SVV(&last_key, "_PHCA", &prefix, key_name); } if (!zend_is_true(&last_key)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "The cache must be started first"); return; } phalcon_read_property(&frontend, getThis(), SL("_frontend"), PH_NOISY); if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHODW(&cached_content, &frontend, "getcontent"); } else { PHALCON_CPY_WRT(&cached_content, content); } if (!phalcon_is_numeric(&cached_content)) { PHALCON_CALL_METHODW(&prepared_content, &frontend, "beforestore", &cached_content); } else { PHALCON_CPY_WRT(&prepared_content, &cached_content); } /** * Take the lifetime from the frontend or read it from the set in start() */ if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { phalcon_read_property(&last_lifetime, getThis(), SL("_lastLifetime"), PH_NOISY); if (Z_TYPE(last_lifetime) == IS_NULL) { PHALCON_CALL_METHODW(&ttl, &frontend, "getlifetime"); } else { PHALCON_CPY_WRT(&ttl, &last_lifetime); } } else { PHALCON_CPY_WRT(&ttl, lifetime); } /** * Call apc_store in the PHP userland since most of the time it isn't available at * compile time */ PHALCON_CALL_FUNCTIONW(NULL, "apc_store", &last_key, &prepared_content, &ttl); PHALCON_CALL_METHODW(&is_buffering, &frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHODW(NULL, &frontend, "stop"); } if (PHALCON_IS_TRUE(&is_buffering)) { zend_print_zval(&cached_content, 0); } phalcon_update_property_bool(getThis(), SL("_started"), 0); }
/** * Manually bind params to a SQL statement. This method requires an active connection to a database system * *<code> * $sql = $connection->bindParams('SELECT * FROM robots WHERE name = ?0', array('Bender')); * echo $sql; // SELECT * FROM robots WHERE name = 'Bender' *</code> * * @param string $sqlStatement * @param array $params * @return string */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, bindParams){ zval *sql_statement, *params, *sql = NULL, *pdo, *bind_value = NULL; zval *index = NULL, *value = NULL, *place_key = NULL, *replaced_sql = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_statement, ¶ms) == FAILURE) { RETURN_MM_NULL(); } if (Z_TYPE_P(params) == IS_ARRAY) { if (phalcon_fast_count_ev(params TSRMLS_CC)) { PHALCON_CPY_WRT(sql, sql_statement); PHALCON_OBS_VAR(pdo); phalcon_read_property(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(index, ah0, hp0); PHALCON_GET_FOREACH_VALUE(bind_value); if (phalcon_is_numeric(bind_value)) { PHALCON_CPY_WRT(value, bind_value); } else { if (Z_TYPE_P(bind_value) == IS_OBJECT) { PHALCON_INIT_NVAR(value); PHALCON_CALL_FUNC_PARAMS_1(value, "strval", bind_value); } else { PHALCON_INIT_NVAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, pdo, "quote", bind_value); } } /** * Handle long parameters as numeric placeholders: ?0, ?1 */ if (Z_TYPE_P(index) == IS_LONG) { PHALCON_INIT_NVAR(place_key); PHALCON_CONCAT_SV(place_key, "?", index); PHALCON_INIT_NVAR(replaced_sql); phalcon_fast_str_replace(replaced_sql, place_key, value, sql TSRMLS_CC); PHALCON_CPY_WRT(sql, replaced_sql); zend_hash_move_forward_ex(ah0, &hp0); continue; } /** * Handle long parameters as string placeholders: :name:, :other: */ if (Z_TYPE_P(index) == IS_STRING) { PHALCON_INIT_NVAR(place_key); PHALCON_CONCAT_SVS(place_key, ":", index, ":"); PHALCON_INIT_NVAR(replaced_sql); phalcon_fast_str_replace(replaced_sql, place_key, value, sql TSRMLS_CC); PHALCON_CPY_WRT(sql, replaced_sql); zend_hash_move_forward_ex(ah0, &hp0); continue; } /** * Unrecognized parameter type */ PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind parameter"); return; zend_hash_move_forward_ex(ah0, &hp0); } RETURN_CCTOR(sql); } } RETURN_CCTOR(sql_statement); }
/** * Returns a cached content * * @param int|string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_File, get){ zval *key_name, *lifetime = NULL; zval *options, *prefix, *prefixed_key, *cache_dir; zval *cache_file, *tmp = NULL; zval *modified_time; zval *cached_content, *exception_message; long int now, ttl, mtime, diff; int expired; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(prefixed_key); PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); phalcon_update_property_this(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC); if (unlikely(!phalcon_array_isset_string_fetch(&cache_dir, options, SS("cacheDir")))) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); return; } PHALCON_INIT_VAR(cache_file); PHALCON_CONCAT_VV(cache_file, cache_dir, prefixed_key); if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { zval *frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); /** * Check if the file has expired */ now = (long int)time(NULL); /** * Take the lifetime from the frontend or read it from the set in start() */ if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { zval *last_lifetime = phalcon_fetch_nproperty_this(this_ptr, SL("_lastLifetime"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(last_lifetime) == IS_NULL) { PHALCON_CALL_METHOD(&tmp, frontend, "getlifetime"); ttl = phalcon_get_intval(tmp); } else { ttl = phalcon_get_intval(last_lifetime); } } else { ttl = phalcon_get_intval(lifetime); } PHALCON_INIT_VAR(modified_time); phalcon_filemtime(modified_time, cache_file TSRMLS_CC); if (unlikely(Z_TYPE_P(modified_time) != IS_LONG)) { convert_to_long(modified_time); } mtime = Z_LVAL_P(modified_time); diff = now - ttl; expired = diff > mtime; /** * The content is only retrieved if the content has not expired */ if (!expired) { /** * Use file-get-contents to control that the openbase_dir can't be skipped */ PHALCON_INIT_VAR(cached_content); phalcon_file_get_contents(cached_content, cache_file TSRMLS_CC); if (PHALCON_IS_FALSE(cached_content)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Cache file ", cache_file, " could not be opened"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cache_exception_ce, exception_message); return; } if (phalcon_is_numeric(cached_content)) { RETURN_CCTOR(cached_content); } else { /** * Use the frontend to process the content of the cache */ PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content); } RETURN_MM(); } } RETURN_MM_NULL(); }
/** * Stores cached content into the file backend and stops the frontend * * @param int|string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_File, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *cache_file, *cached_content = NULL, *prepared_content = NULL, *status, *is_buffering = NULL; zval *last_key, *frontend, *options, *cache_dir; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC); } else { zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(last_key); PHALCON_CONCAT_VV(last_key, prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); if (unlikely(!phalcon_array_isset_string_fetch(&cache_dir, options, SS("cacheDir")))) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); return; } PHALCON_INIT_VAR(cache_file); PHALCON_CONCAT_VV(cache_file, cache_dir, last_key); if (!content || !zend_is_true(content)) { PHALCON_CALL_METHOD(&cached_content, frontend, "getcontent"); } else { cached_content = content; } PHALCON_CALL_METHOD(&prepared_content, frontend, "beforestore", cached_content); /** * We use file_put_contents to respect open-base-dir directive */ PHALCON_INIT_VAR(status); if (!phalcon_is_numeric(cached_content)) { phalcon_file_put_contents(status, cache_file, prepared_content TSRMLS_CC); } else { phalcon_file_put_contents(status, cache_file, cached_content TSRMLS_CC); } if (PHALCON_IS_FALSE(status)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cache directory is not writable"); return; } PHALCON_CALL_METHOD(&is_buffering, frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHOD(NULL, frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Stores cached content into the Memcached backend and stops the frontend * * @param int|string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL, last_key = {}, prefix = {}, cached_content = {}, prepared_content = {}, ttl = {}, flags = {}, success = {}; zval keys = {}, is_buffering = {}, frontend = {}, memcache = {}, options = {}, special_key = {}; phalcon_fetch_params(0, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { phalcon_return_property(&last_key, getThis(), SL("_lastKey")); } else { phalcon_return_property(&prefix, getThis(), SL("_prefix")); PHALCON_CONCAT_VV(&last_key, &prefix, key_name); } if (!zend_is_true(&last_key)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "The cache must be started first"); return; } phalcon_return_property(&frontend, getThis(), SL("_frontend")); /** * Check if a connection is created or make a new one */ phalcon_return_property(&memcache, getThis(), SL("_memcache")); if (Z_TYPE(memcache) != IS_OBJECT) { PHALCON_CALL_METHODW(&memcache, getThis(), "_connect"); } if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHODW(&cached_content, &frontend, "getcontent"); } else { PHALCON_CPY_WRT(&cached_content, content); } /** * Prepare the content in the frontend */ PHALCON_CALL_METHODW(&prepared_content, &frontend, "beforestore", &cached_content); if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { phalcon_return_property(&ttl, getThis(), SL("_lastLifetime")); if (Z_TYPE(ttl) == IS_NULL) { PHALCON_CALL_METHODW(&ttl, &frontend, "getlifetime"); } } else { PHALCON_CPY_WRT(&ttl, lifetime); } ZVAL_LONG(&flags, 0); /** * We store without flags */ if (phalcon_is_numeric(&cached_content)) { PHALCON_CALL_METHODW(&success, &memcache, "set", &last_key, &cached_content, &flags, &ttl); } else { PHALCON_CALL_METHODW(&success, &memcache, "set", &last_key, &prepared_content, &flags, &ttl); } if (!zend_is_true(&success)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "Failed to store data in memcached"); return; } phalcon_return_property(&options, getThis(), SL("_options")); if (unlikely(!phalcon_array_isset_fetch_str(&special_key, &options, SL("statsKey")))) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); return; } if (Z_TYPE(special_key) != IS_NULL) { /* Update the stats key */ PHALCON_CALL_METHODW(&keys, &memcache, "get", &special_key); if (Z_TYPE(keys) != IS_ARRAY) { array_init(&keys); } if (!phalcon_array_isset(&keys, &last_key)) { phalcon_array_update_zval(&keys, &last_key, &ttl, PH_COPY); PHALCON_CALL_METHODW(NULL, &memcache, "set", &special_key, &keys); } } PHALCON_CALL_METHODW(&is_buffering, &frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHODW(NULL, &frontend, "stop"); } if (PHALCON_IS_TRUE(&is_buffering)) { zend_print_zval(&cached_content, 0); } phalcon_update_property_bool(getThis(), SL("_started"), 0); }
/** * Returns a PHQL statement built based on the builder parameters * * @return string */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getPhql){ zval *dependency_injector = NULL, *models, *conditions = NULL; zval *one, *number_models, *invalid_condition; zval *model = NULL, *service_name, *meta_data, *model_instance; zval *no_primary = NULL, *primary_keys, *first_primary_key; zval *column_map = NULL, *attribute_field = NULL, *exception_message; zval *primary_key_condition, *phql, *columns; zval *selected_columns = NULL, *column = NULL, *alias = NULL, *aliased_column = NULL; zval *joined_columns = NULL, *selected_column = NULL, *selected_models; zval *selected_model = NULL, *joined_models, *joins; zval *join = NULL, *join_model = NULL, *join_conditions = NULL, *join_alias = NULL; zval *join_type = NULL, *group, *group_items, *group_item = NULL; zval *escaped_item = NULL, *joined_items = NULL, *having, *order; zval *order_items, *order_item = NULL, *limit, *number; zval *offset = NULL; HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; HashPosition hp0, hp1, hp2, hp3, hp4, hp5; zval **hd; zend_class_entry *ce0; PHALCON_MM_GROW(); PHALCON_OBS_VAR(dependency_injector); phalcon_read_property(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_INIT_NVAR(dependency_injector); PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); phalcon_update_property_zval(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); } PHALCON_OBS_VAR(models); phalcon_read_property(&models, this_ptr, SL("_models"), PH_NOISY_CC); if (Z_TYPE_P(models) == IS_ARRAY) { if (!phalcon_fast_count_ev(models TSRMLS_CC)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "At least one model is required to build the query"); return; } } else { if (!zend_is_true(models)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "At least one model is required to build the query"); return; } } PHALCON_OBS_VAR(conditions); phalcon_read_property(&conditions, this_ptr, SL("_conditions"), PH_NOISY_CC); if (phalcon_is_numeric(conditions)) { /** * If the conditions is a single numeric field. We internally create a condition * using the related primary key */ if (Z_TYPE_P(models) == IS_ARRAY) { PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(number_models); phalcon_fast_count(number_models, models TSRMLS_CC); PHALCON_INIT_VAR(invalid_condition); is_smaller_function(invalid_condition, one, number_models TSRMLS_CC); if (PHALCON_IS_TRUE(invalid_condition)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Cannot build the query. Invalid condition"); return; } PHALCON_OBS_VAR(model); phalcon_array_fetch_long(&model, models, 0, PH_NOISY_CC); } else { PHALCON_CPY_WRT(model, models); } PHALCON_INIT_VAR(service_name); ZVAL_STRING(service_name, "modelsMetadata", 1); /** * Get the models metadata service to obtain the column names, column map and * primary key */ PHALCON_INIT_VAR(meta_data); PHALCON_CALL_METHOD_PARAMS_1(meta_data, dependency_injector, "getshared", service_name); ce0 = phalcon_fetch_class(model TSRMLS_CC); PHALCON_INIT_VAR(model_instance); object_init_ex(model_instance, ce0); if (phalcon_has_constructor(model_instance TSRMLS_CC)) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(model_instance, "__construct", dependency_injector); } PHALCON_INIT_VAR(no_primary); ZVAL_BOOL(no_primary, 1); PHALCON_INIT_VAR(primary_keys); PHALCON_CALL_METHOD_PARAMS_1(primary_keys, meta_data, "getprimarykeyattributes", model_instance); if (phalcon_fast_count_ev(primary_keys TSRMLS_CC)) { if (phalcon_array_isset_long(primary_keys, 0)) { PHALCON_OBS_VAR(first_primary_key); phalcon_array_fetch_long(&first_primary_key, primary_keys, 0, PH_NOISY_CC); /** * The PHQL contains the renamed columns if available */ if (PHALCON_GLOBAL(orm).column_renaming) { PHALCON_INIT_VAR(column_map); PHALCON_CALL_METHOD_PARAMS_1(column_map, meta_data, "getcolumnmap", model_instance); } else { PHALCON_INIT_NVAR(column_map); } if (Z_TYPE_P(column_map) == IS_ARRAY) { if (phalcon_array_isset(column_map, first_primary_key)) { PHALCON_OBS_VAR(attribute_field); phalcon_array_fetch(&attribute_field, column_map, first_primary_key, PH_NOISY_CC); } else { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Column '", first_primary_key, "\" isn't part of the column map"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } } else { PHALCON_CPY_WRT(attribute_field, first_primary_key); } PHALCON_INIT_VAR(primary_key_condition); PHALCON_CONCAT_SVSVSV(primary_key_condition, "[", model, "].[", attribute_field, "] = ", conditions); PHALCON_CPY_WRT(conditions, primary_key_condition); ZVAL_BOOL(no_primary, 0); } } /** * A primary key is mandatory in these cases */ if (PHALCON_IS_TRUE(no_primary)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Source related to this model does not have a primary key defined"); return; } } PHALCON_INIT_VAR(phql); ZVAL_STRING(phql, "SELECT ", 1); PHALCON_OBS_VAR(columns); phalcon_read_property(&columns, this_ptr, SL("_columns"), PH_NOISY_CC); if (Z_TYPE_P(columns) != IS_NULL) { if (Z_TYPE_P(columns) == IS_ARRAY) { PHALCON_INIT_VAR(selected_columns); array_init(selected_columns); if (!phalcon_is_iterable(columns, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(alias, ah0, hp0); PHALCON_GET_FOREACH_VALUE(column); if (Z_TYPE_P(alias) == IS_LONG) { phalcon_array_append(&selected_columns, column, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_NVAR(aliased_column); PHALCON_CONCAT_VSV(aliased_column, column, " AS ", alias); phalcon_array_append(&selected_columns, aliased_column, PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(joined_columns); phalcon_fast_join_str(joined_columns, SL(", "), selected_columns TSRMLS_CC); phalcon_concat_self(&phql, joined_columns TSRMLS_CC); } else { phalcon_concat_self(&phql, columns TSRMLS_CC); } } else { if (Z_TYPE_P(models) == IS_ARRAY) { PHALCON_INIT_NVAR(selected_columns); array_init(selected_columns); if (!phalcon_is_iterable(models, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_KEY(alias, ah1, hp1); PHALCON_GET_FOREACH_VALUE(model); if (Z_TYPE_P(alias) == IS_LONG) { PHALCON_INIT_NVAR(selected_column); PHALCON_CONCAT_SVS(selected_column, "[", model, "].*"); } else { PHALCON_INIT_NVAR(selected_column); PHALCON_CONCAT_SVS(selected_column, "[", alias, "].*"); } phalcon_array_append(&selected_columns, selected_column, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); } PHALCON_INIT_NVAR(joined_columns); phalcon_fast_join_str(joined_columns, SL(", "), selected_columns TSRMLS_CC); phalcon_concat_self(&phql, joined_columns TSRMLS_CC); } else { PHALCON_SCONCAT_SVS(phql, "[", models, "].*"); } } /** * Join multiple models or use a single one if it is a string */ if (Z_TYPE_P(models) == IS_ARRAY) { PHALCON_INIT_VAR(selected_models); array_init(selected_models); if (!phalcon_is_iterable(models, &ah2, &hp2, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_FOREACH_KEY(alias, ah2, hp2); PHALCON_GET_FOREACH_VALUE(model); if (Z_TYPE_P(alias) == IS_STRING) { PHALCON_INIT_NVAR(selected_model); PHALCON_CONCAT_SVSVS(selected_model, "[", model, "] AS [", alias, "]"); } else { PHALCON_INIT_NVAR(selected_model); PHALCON_CONCAT_SVS(selected_model, "[", model, "]"); } phalcon_array_append(&selected_models, selected_model, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah2, &hp2); } PHALCON_INIT_VAR(joined_models); phalcon_fast_join_str(joined_models, SL(", "), selected_models TSRMLS_CC); PHALCON_SCONCAT_SV(phql, " FROM ", joined_models); } else { PHALCON_SCONCAT_SVS(phql, " FROM [", models, "]"); } /** * Check if joins were passed to the builders */ PHALCON_OBS_VAR(joins); phalcon_read_property(&joins, this_ptr, SL("_joins"), PH_NOISY_CC); if (Z_TYPE_P(joins) == IS_ARRAY) { if (!phalcon_is_iterable(joins, &ah3, &hp3, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(join); /** * The joined table is in the first place of the array */ PHALCON_OBS_NVAR(join_model); phalcon_array_fetch_long(&join_model, join, 0, PH_NOISY_CC); /** * The join conditions are in the second place of the array */ PHALCON_OBS_NVAR(join_conditions); phalcon_array_fetch_long(&join_conditions, join, 1, PH_NOISY_CC); /** * The join alias is in the second place of the array */ PHALCON_OBS_NVAR(join_alias); phalcon_array_fetch_long(&join_alias, join, 2, PH_NOISY_CC); /** * Join type */ PHALCON_OBS_NVAR(join_type); phalcon_array_fetch_long(&join_type, join, 3, PH_NOISY_CC); /** * Create the join according to the type */ if (zend_is_true(join_type)) { PHALCON_SCONCAT_VSVS(phql, join_type, " JOIN [", join_model, "]"); } else { PHALCON_SCONCAT_SVS(phql, " JOIN [", join_model, "]"); } /** * Alias comes first */ if (zend_is_true(join_alias)) { PHALCON_SCONCAT_SVS(phql, " AS [", join_alias, "]"); } /** * Conditions then */ if (zend_is_true(join_conditions)) { PHALCON_SCONCAT_SV(phql, " ON ", join_conditions); } zend_hash_move_forward_ex(ah3, &hp3); } } if (Z_TYPE_P(conditions) == IS_STRING) { PHALCON_SCONCAT_SV(phql, " WHERE ", conditions); } /** * Process group parameters */ PHALCON_OBS_VAR(group); phalcon_read_property(&group, this_ptr, SL("_group"), PH_NOISY_CC); if (Z_TYPE_P(group) != IS_NULL) { if (Z_TYPE_P(group) == IS_ARRAY) { PHALCON_INIT_VAR(group_items); array_init(group_items); if (!phalcon_is_iterable(group, &ah4, &hp4, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(group_item); if (phalcon_is_numeric(group_item)) { phalcon_array_append(&group_items, group_item, PH_SEPARATE TSRMLS_CC); } else { if (phalcon_memnstr_str(group_item, SL(".") TSRMLS_CC)) { phalcon_array_append(&group_items, group_item, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_NVAR(escaped_item); PHALCON_CONCAT_SVS(escaped_item, "[", group_item, "]"); phalcon_array_append(&group_items, escaped_item, PH_SEPARATE TSRMLS_CC); } } zend_hash_move_forward_ex(ah4, &hp4); } PHALCON_INIT_VAR(joined_items); phalcon_fast_join_str(joined_items, SL(", "), group_items TSRMLS_CC); PHALCON_SCONCAT_SV(phql, " GROUP BY ", joined_items); } else { if (phalcon_is_numeric(group)) { PHALCON_SCONCAT_SV(phql, " GROUP BY ", group); } else { if (phalcon_memnstr_str(group, SL(".") TSRMLS_CC)) { PHALCON_SCONCAT_SV(phql, " GROUP BY ", group); } else { PHALCON_SCONCAT_SVS(phql, " GROUP BY [", group, "]"); } } } PHALCON_OBS_VAR(having); phalcon_read_property(&having, this_ptr, SL("_having"), PH_NOISY_CC); if (Z_TYPE_P(having) != IS_NULL) { PHALCON_SCONCAT_SV(phql, " HAVING ", having); } } /** * Process order clause */ PHALCON_OBS_VAR(order); phalcon_read_property(&order, this_ptr, SL("_order"), PH_NOISY_CC); if (Z_TYPE_P(order) != IS_NULL) { if (Z_TYPE_P(order) == IS_ARRAY) { PHALCON_INIT_VAR(order_items); array_init(order_items); if (!phalcon_is_iterable(order, &ah5, &hp5, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(order_item); if (phalcon_is_numeric(order_item)) { phalcon_array_append(&order_items, order_item, PH_SEPARATE TSRMLS_CC); } else { if (phalcon_memnstr_str(order_item, SL(".") TSRMLS_CC)) { phalcon_array_append(&order_items, order_item, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_NVAR(escaped_item); PHALCON_CONCAT_SVS(escaped_item, "[", order_item, "]"); phalcon_array_append(&order_items, escaped_item, PH_SEPARATE TSRMLS_CC); } } zend_hash_move_forward_ex(ah5, &hp5); } PHALCON_INIT_NVAR(joined_items); phalcon_fast_join_str(joined_items, SL(", "), order_items TSRMLS_CC); PHALCON_SCONCAT_SV(phql, " ORDER BY ", joined_items); } else { PHALCON_SCONCAT_SV(phql, " ORDER BY ", order); } } /** * Process limit parameters */ PHALCON_OBS_VAR(limit); phalcon_read_property(&limit, this_ptr, SL("_limit"), PH_NOISY_CC); if (Z_TYPE_P(limit) != IS_NULL) { if (Z_TYPE_P(limit) == IS_ARRAY) { PHALCON_OBS_VAR(number); phalcon_array_fetch_string(&number, limit, SL("number"), PH_NOISY_CC); if (phalcon_array_isset_string(limit, SS("offset"))) { PHALCON_OBS_VAR(offset); phalcon_array_fetch_string(&offset, limit, SL("offset"), PH_NOISY_CC); if (phalcon_is_numeric(offset)) { PHALCON_SCONCAT_SVSV(phql, " LIMIT ", number, " OFFSET ", offset); } else { PHALCON_SCONCAT_SVS(phql, " LIMIT ", number, " OFFSET 0"); } } else { PHALCON_SCONCAT_SV(phql, " LIMIT ", number); } } else { if (phalcon_is_numeric(limit)) { PHALCON_SCONCAT_SV(phql, " LIMIT ", limit); PHALCON_OBS_NVAR(offset); phalcon_read_property(&offset, this_ptr, SL("_offset"), PH_NOISY_CC); if (Z_TYPE_P(offset) != IS_NULL) { if (phalcon_is_numeric(offset)) { PHALCON_SCONCAT_SV(phql, " OFFSET ", offset); } else { phalcon_concat_self_str(&phql, SL(" OFFSET 0") TSRMLS_CC); } } } } } RETURN_CTOR(phql); }
/** * Stores cached content into the Mongo backend and stops the frontend * * @param int|string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Mongo, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *last_key, *frontend, *cached_content = NULL; zval *prepared_content = NULL, *ttl = NULL, *collection = NULL, *timestamp; zval *conditions, *document = NULL, *data, *is_buffering = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC); } else { zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(last_key); PHALCON_CONCAT_VV(last_key, prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHOD(&cached_content, frontend, "getcontent"); } else { cached_content = content; } if (!phalcon_is_numeric(cached_content)) { PHALCON_CALL_METHOD(&prepared_content, frontend, "beforestore", cached_content); } if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { zval *tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_lastLifetime"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(tmp) == IS_NULL) { PHALCON_CALL_METHOD(&ttl, frontend, "getlifetime"); } else { ttl = tmp; } } else { ttl = lifetime; } PHALCON_CALL_METHOD(&collection, this_ptr, "_getcollection"); PHALCON_INIT_VAR(timestamp); ZVAL_LONG(timestamp, (long) time(NULL) + phalcon_get_intval(ttl)); PHALCON_INIT_VAR(conditions); array_init_size(conditions, 1); phalcon_array_update_string(&conditions, SL("key"), last_key, PH_COPY); PHALCON_CALL_METHOD(&document, collection, "findone", conditions); if (Z_TYPE_P(document) == IS_ARRAY) { phalcon_array_update_string(&document, SL("time"), timestamp, PH_COPY); if (prepared_content) { phalcon_array_update_string(&document, SL("data"), prepared_content, PH_COPY); } else { phalcon_array_update_string(&document, SL("data"), cached_content, PH_COPY); } PHALCON_CALL_METHOD(NULL, collection, "save", document); } else { PHALCON_INIT_VAR(data); array_init_size(data, 3); phalcon_array_update_string(&data, SL("key"), last_key, PH_COPY); phalcon_array_update_string(&data, SL("time"), timestamp, PH_COPY); if (prepared_content) { phalcon_array_update_string(&data, SL("data"), prepared_content, PH_COPY); } else { phalcon_array_update_string(&data, SL("data"), cached_content, PH_COPY); } PHALCON_CALL_METHOD(NULL, collection, "save", data); } PHALCON_CALL_METHOD(&is_buffering, frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHOD(NULL, frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Stores cached content into the Memcached backend and stops the frontend * * @param int|string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *cached_content = NULL, *prepared_content = NULL, *ttl = NULL, *flags, *success = NULL; zval *keys = NULL, *is_buffering = NULL; zval *last_key, *frontend, *memcache, *options, *special_key; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC); } else { zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(last_key); PHALCON_CONCAT_VV(last_key, prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); /** * Check if a connection is created or make a new one */ memcache = phalcon_fetch_nproperty_this(this_ptr, SL("_memcache"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(memcache) != IS_OBJECT) { memcache = NULL; PHALCON_CALL_METHOD(&memcache, this_ptr, "_connect"); } if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHOD(&cached_content, frontend, "getcontent"); } else { cached_content = content; } /** * Prepare the content in the frontend */ PHALCON_CALL_METHOD(&prepared_content, frontend, "beforestore", cached_content); if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { zval *tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_lastLifetime"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(tmp) == IS_NULL) { PHALCON_CALL_METHOD(&ttl, frontend, "getlifetime"); } else { ttl = tmp; } } else { ttl = lifetime; } PHALCON_INIT_VAR(flags); ZVAL_LONG(flags, 0); /** * We store without flags */ if (phalcon_is_numeric(cached_content)) { PHALCON_CALL_METHOD(&success, memcache, "set", last_key, cached_content, flags, ttl); } else { PHALCON_CALL_METHOD(&success, memcache, "set", last_key, prepared_content, flags, ttl); } if (!zend_is_true(success)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Failed to store data in memcached"); return; } options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); if (unlikely(!phalcon_array_isset_string_fetch(&special_key, options, SS("statsKey")))) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); return; } if (Z_TYPE_P(special_key) != IS_NULL) { /* Update the stats key */ PHALCON_CALL_METHOD(&keys, memcache, "get", special_key); if (Z_TYPE_P(keys) != IS_ARRAY) { PHALCON_INIT_NVAR(keys); array_init(keys); } if (!phalcon_array_isset(keys, last_key)) { phalcon_array_update_zval(&keys, last_key, ttl, PH_COPY); PHALCON_CALL_METHOD(NULL, memcache, "set", special_key, keys); } } PHALCON_CALL_METHOD(&is_buffering, frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHOD(NULL, frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * <code>print_r($connection->describeColumns("posts")); ?></code> * * @param string $table * @param string $schema * @return Phalcon\Db\Column[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns){ zval *table, *schema = NULL, *columns, *dialect, *sql = NULL, *fetch_num; zval *describe = NULL, *old_column = NULL, *field = NULL, *definition = NULL; zval *char_size = NULL, *numeric_size = NULL, *numeric_scale = NULL, *column_type = NULL; zval *attribute = NULL, *column_name = NULL, *column = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema || !zend_is_true(schema)) { schema = phalcon_fetch_nproperty_this(this_ptr, SL("_schema"), PH_NOISY TSRMLS_CC); } PHALCON_INIT_VAR(columns); array_init(columns); PHALCON_OBS_VAR(dialect); phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(&sql, dialect, "describecolumns", table, schema); /** * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); ZVAL_LONG(fetch_num, PDO_FETCH_NUM); PHALCON_CALL_METHOD(&describe, this_ptr, "fetchall", sql, fetch_num); /** * 0:name, 1:type, 2:size, 3:numeric size, 4:numeric scale, 5: null, 6: key, 7: extra, 8: position, 9: element type */ PHALCON_INIT_VAR(old_column); phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(field); PHALCON_INIT_NVAR(definition); array_init_size(definition, 1); add_assoc_long_ex(definition, SS("bindType"), 2); PHALCON_OBS_NVAR(char_size); phalcon_array_fetch_long(&char_size, field, 2, PH_NOISY); if (Z_TYPE_P(char_size) != IS_NULL) { convert_to_long(char_size); } PHALCON_OBS_NVAR(numeric_size); phalcon_array_fetch_long(&numeric_size, field, 3, PH_NOISY); if (phalcon_is_numeric(numeric_size)) { convert_to_long(numeric_size); } PHALCON_OBS_NVAR(numeric_scale); phalcon_array_fetch_long(&numeric_scale, field, 4, PH_NOISY); if (phalcon_is_numeric(numeric_scale)) { convert_to_long(numeric_scale); } PHALCON_OBS_NVAR(column_type); phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); /** * Check the column type to get the correct Phalcon type */ while (1) { /** * Tinyint(1) is boolean */ if (phalcon_memnstr_str(column_type, SL("smallint(1)"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_BOOLEAN, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_COPY); break; } /** * Smallint/Bigint/Integers/Int are int */ if (phalcon_memnstr_str(column_type, SL("int"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_INTEGER, PH_COPY); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_COPY); phalcon_array_update_string(&definition, SL("size"), numeric_size, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_COPY); break; } /** * Varchar */ if (phalcon_memnstr_str(column_type, SL("varying"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_VARCHAR, PH_COPY); phalcon_array_update_string(&definition, SL("size"), char_size, PH_COPY); break; } /** * Special type for datetime */ if (phalcon_memnstr_str(column_type, SL("date"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_DATE, PH_COPY); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_COPY); break; } /** * Numeric */ if (phalcon_memnstr_str(column_type, SL("numeric"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_DECIMAL, PH_COPY); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_COPY); if (phalcon_is_numeric(numeric_size)) { phalcon_array_update_string(&definition, SL("size"), numeric_size, PH_COPY); phalcon_array_update_string_long(&definition, SL("bytes"), Z_LVAL_P(numeric_size) * 8, PH_COPY); } else { phalcon_array_update_string_long(&definition, SL("size"), 30, PH_COPY); phalcon_array_update_string_long(&definition, SL("bytes"), 80, PH_COPY); } if (phalcon_is_numeric(numeric_scale)) { phalcon_array_update_string(&definition, SL("scale"), numeric_scale, PH_COPY); } else { phalcon_array_update_string_long(&definition, SL("scale"), 6, PH_COPY); } phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_COPY); break; } /** * Chars are chars */ if (phalcon_memnstr_str(column_type, SL("char"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_CHAR, PH_COPY); phalcon_array_update_string(&definition, SL("size"), char_size, PH_COPY); break; } /** * Date */ if (phalcon_memnstr_str(column_type, SL("timestamp"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_DATETIME, PH_COPY); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_COPY); break; } /** * Text are varchars */ if (phalcon_memnstr_str(column_type, SL("text"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_TEXT, PH_COPY); phalcon_array_update_string(&definition, SL("size"), char_size, PH_COPY); break; } /** * Float/Smallfloats/Decimals are float */ if (phalcon_memnstr_str(column_type, SL("float"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_FLOAT, PH_COPY); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_COPY); phalcon_array_update_string(&definition, SL("size"), numeric_size, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_COPY); break; } /** * Boolean */ if (phalcon_memnstr_str(column_type, SL("bool"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_BOOLEAN, PH_COPY); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_COPY); phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_COPY); break; } /** * UUID */ if (phalcon_memnstr_str(column_type, SL("uuid"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_CHAR, PH_COPY); phalcon_array_update_string_long(&definition, SL("size"), 36, PH_COPY); break; } /** * JSON */ if (phalcon_memnstr_str(column_type, SL("json"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_JSON, PH_COPY); phalcon_array_update_string(&definition, SL("size"), char_size, PH_COPY); break; } /** * ARRAY */ if (phalcon_memnstr_str(column_type, SL("ARRAY"))) { phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_ARRAY, PH_COPY); phalcon_array_update_string(&definition, SL("size"), char_size, PH_COPY); break; } /** * By default is string */ phalcon_array_update_string_long(&definition, SL("type"), PHALCON_DB_COLUMN_TYPE_OTHER, PH_COPY); break; } if (phalcon_memnstr_str(column_type, SL("unsigned"))) { phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_COPY); } if (Z_TYPE_P(old_column) == IS_NULL) { phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_COPY); } else { phalcon_array_update_string(&definition, SL("after"), old_column, PH_COPY); } /** * Check if the field is primary key */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); if (PHALCON_IS_STRING(attribute, "PRI")) { phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_COPY); } /** * Check if the column allows null values */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); if (PHALCON_IS_STRING(attribute, "NO")) { phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_COPY); } /** * Check if the column is auto increment */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 7, PH_NOISY); if (PHALCON_IS_STRING(attribute, "auto_increment")) { phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_COPY); } else if (!PHALCON_IS_EMPTY(attribute)) { phalcon_array_update_string(&definition, SL("default"), attribute, PH_COPY); } PHALCON_OBS_NVAR(column_name); phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); /** * Create a Phalcon\Db\Column to abstract the column */ PHALCON_INIT_NVAR(column); object_init_ex(column, phalcon_db_column_ce); PHALCON_CALL_METHOD(NULL, column, "__construct", column_name, definition); phalcon_array_append(&columns, column, PH_COPY); PHALCON_CPY_WRT(old_column, column_name); zend_hash_move_forward_ex(ah0, &hp0); } RETURN_CTOR(columns); }
/** * Stores cached content into the XCache backend and stops the frontend * * @param string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *cached_content = NULL, *keys = NULL, *last_key, *frontend; zval *prepared_content = NULL, *ttl = NULL, *success = NULL, *is_buffering = NULL; zval *prefix, *options, *special_key, *z_zero, *tmp; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { last_key = phalcon_read_property(getThis(), SL("_lastKey"), PH_NOISY); } else { prefix = phalcon_read_property(getThis(), SL("_prefix"), PH_NOISY); PHALCON_INIT_VAR(last_key); PHALCON_CONCAT_SVV(last_key, "_PHCX", prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } frontend = phalcon_read_property(getThis(), SL("_frontend"), PH_NOISY); if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHOD(&cached_content, frontend, "getcontent"); } else { cached_content = content; } if (!phalcon_is_numeric(cached_content)) { PHALCON_CALL_METHOD(&prepared_content, frontend, "beforestore", cached_content); } /** * Take the lifetime from the frontend or read it from the set in start() */ if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { tmp = phalcon_read_property(getThis(), SL("_lastLifetime"), PH_NOISY); if (Z_TYPE_P(tmp) == IS_NULL) { PHALCON_CALL_METHOD(&ttl, frontend, "getlifetime"); } else { ttl = tmp; } } else { ttl = lifetime; } if (!prepared_content) { PHALCON_CALL_FUNCTION(&success, "xcache_set", last_key, cached_content, ttl); } else { PHALCON_CALL_FUNCTION(&success, "xcache_set", last_key, prepared_content, ttl); } PHALCON_CALL_METHOD(&is_buffering, frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHOD(NULL, frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(getThis(), SL("_started"), 0); if (zend_is_true(success)) { options = phalcon_read_property(getThis(), SL("_options"), PH_NOISY); if (unlikely(!phalcon_array_isset_str_fetch(&special_key, options, SL("statsKey")))) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); return; } /** * xcache_list() is available only to the administrator (unless XCache was * patched). We have to update the list of the stored keys. */ PHALCON_CALL_FUNCTION(&keys, "xcache_get", special_key); if (Z_TYPE_P(keys) != IS_ARRAY) { PHALCON_INIT_NVAR(keys); array_init(keys); } z_zero = &PHALCON_GLOBAL(z_zero); phalcon_array_update_zval(keys, last_key, ttl, PH_COPY); PHALCON_CALL_FUNCTION(NULL, "xcache_set", special_key, keys, z_zero); } PHALCON_MM_RESTORE(); }
/** * Prepare an HTML string of information about a single variable. */ PHP_METHOD(Phalcon_Debug_Dump, output){ zval *variable, *name = NULL, *tab = NULL, *space, *tmp = NULL, *new_tab = NULL; zval *output = NULL, *str = NULL, *type = NULL, *style = NULL, *count = NULL, *key = NULL, *value = NULL, *replace_pairs = NULL; zval *class_name = NULL, *objects, *detailed = NULL, *properties = NULL, *methods = NULL, *method = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &variable, &name, &tab); if (!name) { name = PHALCON_GLOBAL(z_null); } else if (!PHALCON_IS_EMPTY(name)) { PHALCON_CONCAT_SVS(return_value, "var ", name, " "); } if (!tab) { tab = PHALCON_GLOBAL(z_one); } PHALCON_INIT_VAR(space); ZVAL_STRING(space, " ", 1); if (Z_TYPE_P(variable) == IS_ARRAY) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style =':style'>Array</b> (<span style =':style'>:count</span>) (\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "arr", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(count); ZVAL_LONG(count, phalcon_fast_count_int(variable TSRMLS_CC)); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":count"), count, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); phalcon_concat_self(&return_value, output TSRMLS_CC); phalcon_is_iterable(variable, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); phalcon_concat_self(&return_value, tmp TSRMLS_CC); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "[<span style=':style'>:key</span>] => ", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "arr", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":key"), key, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); phalcon_concat_self(&return_value, output TSRMLS_CC); if (PHALCON_IS_LONG(tab, 1) && !PHALCON_IS_EMPTY(name) && !phalcon_is_numeric(key) && PHALCON_IS_IDENTICAL(name, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } else { PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_SELF(&tmp, "output", value, PHALCON_GLOBAL(z_null), new_tab); PHALCON_SCONCAT_VS(return_value, tmp, "\n"); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); } else if (Z_TYPE_P(variable) == IS_OBJECT) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Object</b> :class", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":class"), class_name, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_INIT_NVAR(class_name); phalcon_get_parent_class(class_name, variable, 0 TSRMLS_CC); if (zend_is_true(class_name)) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, " <b style=':style'>extends</b> :parent", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":parent"), class_name, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } PHALCON_SCONCAT_STR(return_value, " (\n"); objects = phalcon_fetch_nproperty_this(this_ptr, SL("_objects"), PH_NOISY TSRMLS_CC); if (phalcon_fast_in_array(variable, objects TSRMLS_CC)) { PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, "[already listed]\n"); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, ")"); RETURN_MM(); } phalcon_update_property_array_append(this_ptr, SL("_objects"), variable TSRMLS_CC); detailed = phalcon_fetch_nproperty_this(this_ptr, SL("_detailed"), PH_NOISY TSRMLS_CC); PHALCON_INIT_NVAR(properties); phalcon_get_object_vars(properties, variable, !zend_is_true(detailed) TSRMLS_CC); phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "-><span style=':style'>:key</span> (<span style=':style'>:type</span>) = ", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":key"), key, PH_COPY); if (PHALCON_PROPERTY_IS_PUBLIC_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("public"), PH_COPY); } else if (PHALCON_PROPERTY_IS_PRIVATE_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("private"), PH_COPY); } else if (PHALCON_PROPERTY_IS_PROTECTED_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("protected"), PH_COPY); } PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_SELF(&tmp, "output", value, PHALCON_GLOBAL(z_null), new_tab); PHALCON_SCONCAT_VS(return_value, tmp, ")\n"); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(methods); phalcon_get_class_methods(methods, variable, !zend_is_true(detailed) TSRMLS_CC); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, ":class <b style=':style'>methods</b>: (<span style=':style'>:count</span>) (\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); PHALCON_INIT_NVAR(count); ZVAL_LONG(count, phalcon_fast_count_int(methods TSRMLS_CC)); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":class"), class_name, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":count"), count, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); phalcon_is_iterable(methods, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(method); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, new_tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "-><span style=':style'>:method</span>();\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":method"), method, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, "\n"); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, ")"); } else if (Z_TYPE_P(variable) == IS_LONG) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Integer</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "int", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_DOUBLE) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Float</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "float", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (phalcon_is_numeric_ex(variable)) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Numeric string</b> (<span style=':style'>:length</span>) \"<span style=':style'>:var</span>\"", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "num", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string_long(&replace_pairs, SL(":length"), Z_STRLEN_P(variable), PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_STRING) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>String</b> (<span style=':style'>:length</span>) \"<span style=':style'>:var</span>\"", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "str", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string_long(&replace_pairs, SL(":length"), Z_STRLEN_P(variable), PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_BOOL) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Boolean</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "bool", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); if (zend_is_true(variable)) { phalcon_array_update_string_string(&replace_pairs, SL(":var"), SL("TRUE") , PH_COPY); } else { phalcon_array_update_string_string(&replace_pairs, SL(":var"), SL("FALSE") , PH_COPY); } PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_NULL) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>NULL</b>", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "null", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "(<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "other", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } RETURN_MM(); }