/** * Returns a complete resultset as an array, if the resultset has a big number of rows * it could consume more memory than currently it does. * * @return array */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, toArray){ zval *records, *valid = NULL, *current = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(records); array_init(records); PHALCON_CALL_METHOD_NORETURN(this_ptr, "rewind"); while (1) { PHALCON_INIT_NVAR(r0); PHALCON_CALL_METHOD(r0, this_ptr, "valid"); PHALCON_CPY_WRT(valid, r0); if (PHALCON_IS_NOT_FALSE(valid)) { } else { break; } PHALCON_INIT_NVAR(current); PHALCON_CALL_METHOD(current, this_ptr, "current"); phalcon_array_append(&records, current, PH_SEPARATE TSRMLS_CC); PHALCON_CALL_METHOD_NORETURN(this_ptr, "next"); } RETURN_CTOR(records); }
/** * Serializing a resultset will dump all related rows into a big array * * @return string */ PHP_METHOD(Phalcon_Model_Resultset, serialize){ zval *records = NULL; zval *a0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(records, a0); PHALCON_CALL_METHOD_NORETURN(this_ptr, "rewind", PHALCON_NO_CHECK); ws_fd08_1: PHALCON_INIT_VAR(r0); PHALCON_CALL_METHOD(r0, this_ptr, "valid", PHALCON_NO_CHECK); if (Z_TYPE_P(r0) != IS_BOOL || (Z_TYPE_P(r0) == IS_BOOL && !Z_BVAL_P(r0))) { goto we_fd08_1; } PHALCON_INIT_VAR(r1); PHALCON_CALL_METHOD(r1, this_ptr, "current", PHALCON_NO_CHECK); phalcon_array_append(&records, r1, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_CALL_METHOD_NORETURN(this_ptr, "next", PHALCON_NO_CHECK); goto ws_fd08_1; we_fd08_1: PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_FUNC_PARAMS_1(r2, "serialize", records, 0x057); PHALCON_RETURN_DZVAL(r2); }
/** * Appends an array of messages to the group * *<code> * $messages->appendMessages($messagesArray); *</code> * * @param Phalcon\Validation\MessageInterface[] $messages */ PHP_METHOD(Phalcon_Validation_Message_Group, appendMessages){ zval *messages, *current_messages, *final_messages = NULL; zval *message = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &messages) == FAILURE) { RETURN_MM_NULL(); } if (Z_TYPE_P(messages) != IS_ARRAY) { if (Z_TYPE_P(messages) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The messages must be array or object"); return; } } PHALCON_OBS_VAR(current_messages); phalcon_read_property(¤t_messages, this_ptr, SL("_messages"), PH_NOISY_CC); if (Z_TYPE_P(messages) == IS_ARRAY) { /** * An array of messages is simply merged into the current one */ if (Z_TYPE_P(current_messages) == IS_ARRAY) { PHALCON_INIT_VAR(final_messages); PHALCON_CALL_FUNC_PARAMS_2(final_messages, "array_merge", current_messages, messages); } else { PHALCON_CPY_WRT(final_messages, messages); } phalcon_update_property_zval(this_ptr, SL("_messages"), final_messages TSRMLS_CC); } else { /** * A group of messages is iterated and appended one-by-one to the current list */ PHALCON_CALL_METHOD_NORETURN(messages, "rewind"); while (1) { PHALCON_INIT_NVAR(r0); PHALCON_CALL_METHOD(r0, messages, "valid"); if (PHALCON_IS_NOT_FALSE(r0)) { } else { break; } PHALCON_INIT_NVAR(message); PHALCON_CALL_METHOD(message, messages, "current"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "appendmessage", message); PHALCON_CALL_METHOD_NORETURN(messages, "next"); } } PHALCON_MM_RESTORE(); }
/** * Returns the messages generated in the validation * * @param boolean $byItemName * @return array */ PHP_METHOD(Phalcon_Forms_Form, getMessages){ zval *by_item_name = NULL, *messages, *group = NULL, *element_messages = NULL; zval *element = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &by_item_name) == FAILURE) { RETURN_MM_NULL(); } if (!by_item_name) { PHALCON_INIT_VAR(by_item_name); ZVAL_BOOL(by_item_name, 0); } PHALCON_OBS_VAR(messages); phalcon_read_property(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); if (zend_is_true(by_item_name)) { if (Z_TYPE_P(messages) != IS_ARRAY) { PHALCON_INIT_VAR(group); object_init_ex(group, phalcon_validation_message_group_ce); PHALCON_CALL_METHOD_NORETURN(group, "__construct"); RETURN_CTOR(group); } RETURN_CCTOR(messages); } PHALCON_INIT_NVAR(group); object_init_ex(group, phalcon_validation_message_group_ce); PHALCON_CALL_METHOD_NORETURN(group, "__construct"); if (!phalcon_is_iterable(messages, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(element, ah0, hp0); PHALCON_GET_FOREACH_VALUE(element_messages); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(group, "appendmessages", element_messages); zend_hash_move_forward_ex(ah0, &hp0); } RETURN_CTOR(group); }
/** * Checks whether a model has a hasOne relation with another model * * @param string $modelName * @param string $modelRelation * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasOne){ zval *model_name = NULL, *model_relation = NULL, *initialized = NULL; zval *model = NULL, *has_one = NULL; zval *r0 = NULL; int eval_int; zend_class_entry *ce0, *ce1; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &model_name, &model_relation) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(initialized); phalcon_read_property(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); eval_int = phalcon_array_isset(initialized, model_name); if (!eval_int) { ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); } eval_int = phalcon_array_isset(initialized, model_relation); if (!eval_int) { ce1 = phalcon_fetch_class(model_relation TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce1); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); } PHALCON_INIT_VAR(has_one); phalcon_read_property(&has_one, this_ptr, SL("_hasOne"), PH_NOISY_CC); eval_int = phalcon_array_isset(has_one, model_name); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch(&r0, has_one, model_name, PH_NOISY_CC); eval_int = phalcon_array_isset(r0, model_relation); if (eval_int) { PHALCON_MM_RESTORE(); RETURN_TRUE; } } PHALCON_MM_RESTORE(); RETURN_FALSE; }
/** * Isset property * * @param string $property * @return boolean */ PHP_METHOD(Phalcon_Session_Bag, __isset){ zval *property, *initalized, *data; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &property) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(initalized); phalcon_read_property(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); if (PHALCON_IS_FALSE(initalized)) { PHALCON_CALL_METHOD_NORETURN(this_ptr, "initialize", PH_NO_CHECK); } PHALCON_INIT_VAR(data); phalcon_read_property(&data, this_ptr, SL("_data"), PH_NOISY_CC); eval_int = phalcon_array_isset(data, property); if (eval_int) { PHALCON_MM_RESTORE(); RETURN_TRUE; } PHALCON_MM_RESTORE(); RETURN_FALSE; }
/** * Phalcon\Forms\Form constructor * * @param object $entity */ PHP_METHOD(Phalcon_Forms_Form, __construct){ zval *entity = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &entity) == FAILURE) { RETURN_MM_NULL(); } if (!entity) { PHALCON_INIT_VAR(entity); } if (Z_TYPE_P(entity) != IS_NULL) { if (Z_TYPE_P(entity) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The base entity is not valid"); return; } phalcon_update_property_zval(this_ptr, SL("_entity"), entity TSRMLS_CC); } /** * Check for an 'initialize' method and call it */ if (phalcon_method_exists_ex(this_ptr, SS("initialize") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_NORETURN(this_ptr, "initialize"); } PHALCON_MM_RESTORE(); }
/** * Returns the messages generated by * * @return Phalcon\Validation\Message\Group[] */ PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ zval *name, *messages, *element_messages, *group; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(messages); phalcon_read_property(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); if (phalcon_array_isset(messages, name)) { PHALCON_OBS_VAR(element_messages); phalcon_array_fetch(&element_messages, messages, name, PH_NOISY_CC); RETURN_CCTOR(element_messages); } PHALCON_INIT_VAR(group); object_init_ex(group, phalcon_validation_message_group_ce); PHALCON_CALL_METHOD_NORETURN(group, "__construct"); RETURN_CTOR(group); }
/** * Restores the state of a Phalcon\Annotations\Reflection variable export * * @return array $data */ PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){ zval *data, *reflection_data, *reflection = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) { RETURN_MM_NULL(); } if (Z_TYPE_P(data) == IS_ARRAY) { /** * Check for a '_reflectionData' in the array to build the Reflection */ if (phalcon_array_isset_string(data, SS("_reflectionData"))) { PHALCON_OBS_VAR(reflection_data); phalcon_array_fetch_string(&reflection_data, data, SL("_reflectionData"), PH_NOISY_CC); PHALCON_INIT_VAR(reflection); object_init_ex(reflection, phalcon_annotations_reflection_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(reflection, "__construct", reflection_data); RETURN_CTOR(reflection); } } PHALCON_INIT_NVAR(reflection); object_init_ex(reflection, phalcon_annotations_reflection_ce); PHALCON_CALL_METHOD_NORETURN(reflection, "__construct"); RETURN_CTOR(reflection); }
/** * Sets a value in the session bag * *<code> * $user->set('name', 'Kimbra'); *</code> * * @param string $property * @param string $value */ PHP_METHOD(Phalcon_Session_Bag, set){ zval *property, *value, *initalized, *name, *data; zval *session; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &property, &value) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(initalized); phalcon_read_property(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); if (PHALCON_IS_FALSE(initalized)) { PHALCON_CALL_METHOD_NORETURN(this_ptr, "initialize"); } phalcon_update_property_array(this_ptr, SL("_data"), property, value TSRMLS_CC); PHALCON_OBS_VAR(name); phalcon_read_property(&name, this_ptr, SL("_name"), PH_NOISY_CC); PHALCON_OBS_VAR(data); phalcon_read_property(&data, this_ptr, SL("_data"), PH_NOISY_CC); PHALCON_OBS_VAR(session); phalcon_read_property(&session, this_ptr, SL("_session"), PH_NOISY_CC); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(session, "set", name, data); PHALCON_MM_RESTORE(); }
/** * Gets the views part manager * * @return Phalcon_View */ PHP_METHOD(Phalcon_Controller_Front, getViewComponent){ zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL; zval *i0 = NULL; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_view", sizeof("_view")-1, PHALCON_NOISY TSRMLS_CC); if (!zend_is_true(t0)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_view_ce); PHALCON_CALL_METHOD_NORETURN(i0, "__construct", PHALCON_CHECK); phalcon_update_property_zval(this_ptr, "_view", strlen("_view"), i0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_view", sizeof("_view")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_viewsDir", sizeof("_viewsDir")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(t1, "setviewsdir", t2, PHALCON_NO_CHECK); } PHALCON_ALLOC_ZVAL_MM(t3); phalcon_read_property(&t3, this_ptr, "_view", sizeof("_view")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_RETURN_CHECK_CTOR(t3); }
/** * Loads a model throwing an exception if it doesn't exist * * @return Phalcon\Mvc\Model */ PHP_METHOD(Phalcon_Mvc_Model_Manager, load){ zval *model_name, *model, *exception_message; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &model_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (phalcon_class_exists(model_name TSRMLS_CC)) { ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); RETURN_CTOR(model); } PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "The model '", model_name, "' could not be loaded"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; }
/** * Starts a cache. The $keyname allows to identify the created fragment * * @param int|string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend, start){ zval *key_name, *lifetime = NULL, *existing_cache, *fresh = NULL; zval *frontend; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); if (!lifetime) { PHALCON_INIT_VAR(lifetime); } /** * Get the cache content verifying if it was expired */ PHALCON_INIT_VAR(existing_cache); PHALCON_CALL_METHOD_PARAMS_2(existing_cache, this_ptr, "get", key_name, lifetime); if (Z_TYPE_P(existing_cache) == IS_NULL) { PHALCON_INIT_VAR(fresh); ZVAL_BOOL(fresh, 1); PHALCON_OBS_VAR(frontend); phalcon_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); PHALCON_CALL_METHOD_NORETURN(frontend, "start"); } else { PHALCON_INIT_NVAR(fresh); ZVAL_BOOL(fresh, 0); } phalcon_update_property_this(this_ptr, SL("_fresh"), fresh TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); RETURN_CCTOR(existing_cache); }
/** * Loads a model throwing an exception if it doesn't exist * * @return Phalcon\Mvc\Model */ PHP_METHOD(Phalcon_Mvc_Model_Manager, load){ zval *model_name = NULL, *model_exists = NULL, *model = NULL, *exception_message = NULL; zval *exception = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &model_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(model_exists); PHALCON_CALL_FUNC_PARAMS_1(model_exists, "class_exists", model_name); if (zend_is_true(model_exists)) { ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); RETURN_CTOR(model); } PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "The model '", model_name, "' could not be loaded"); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_model_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; }
/** * Restore a Phalcon\Http\Response\Headers object * * @return Phalcon\Http\Response\Headers */ PHP_METHOD(Phalcon_Http_Response_Headers, __set_state){ zval *data, *headers, *data_headers, *value = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(headers); object_init_ex(headers, phalcon_http_response_headers_ce); PHALCON_CALL_METHOD_NORETURN(headers, "__construct", PH_CHECK); eval_int = phalcon_array_isset_string(data, SS("_headers")); if (eval_int) { PHALCON_INIT_VAR(data_headers); phalcon_array_fetch_string(&data_headers, data, SL("_headers"), PH_NOISY_CC); if (!phalcon_valid_foreach(data_headers TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(data_headers); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(headers, "set", key, value, PH_NO_CHECK); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: if(0){} } RETURN_CTOR(headers); }
/** * Returns the annotations found in a specific property * * @param string $className * @param string $propertyName * @return Phalcon\Annotations\Collection */ PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){ zval *class_name, *property_name, *class_annotations; zval *properties, *property = NULL, *name = NULL, *collection; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &class_name, &property_name); /** * Get the full annotations from the class */ PHALCON_INIT_VAR(class_annotations); PHALCON_CALL_METHOD_PARAMS_1(class_annotations, this_ptr, "get", class_name); /** * A valid annotations reflection is an object */ if (Z_TYPE_P(class_annotations) == IS_OBJECT) { PHALCON_INIT_VAR(properties); PHALCON_CALL_METHOD(properties, class_annotations, "getpropertyannotations"); if (Z_TYPE_P(properties) == IS_ARRAY) { if (!phalcon_is_iterable(properties, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(name, ah0, hp0); PHALCON_GET_FOREACH_VALUE(property); if (PHALCON_IS_EQUAL(name, property_name)) { RETURN_CCTOR(property); } zend_hash_move_forward_ex(ah0, &hp0); } } } /** * Returns a collection anyways */ PHALCON_INIT_VAR(collection); object_init_ex(collection, phalcon_annotations_collection_ce); PHALCON_CALL_METHOD_NORETURN(collection, "__construct"); RETURN_CTOR(collection); }
/** * Serializing a resultset will dump all related rows into a big array * * @return string */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, serialize){ zval *type = NULL, *result = NULL, *records = NULL, *row_count = NULL, *model = NULL; zval *cache = NULL, *data = NULL, *serialized = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(type); phalcon_read_property(&type, this_ptr, SL("_type"), PH_NOISY_CC); if (zend_is_true(type)) { PHALCON_INIT_VAR(result); phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC); if (PHALCON_IS_NOT_FALSE(result)) { PHALCON_CALL_METHOD_NORETURN(result, "execute", PH_NO_CHECK); PHALCON_INIT_VAR(records); PHALCON_CALL_METHOD(records, result, "fetchall", PH_NO_CHECK); } else { PHALCON_INIT_VAR(records); array_init(records); } } else { PHALCON_INIT_VAR(records); phalcon_read_property(&records, this_ptr, SL("_rows"), PH_NOISY_CC); if (Z_TYPE_P(records) == IS_NULL) { PHALCON_INIT_VAR(result); phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC); if (PHALCON_IS_NOT_FALSE(result)) { PHALCON_INIT_VAR(records); PHALCON_CALL_METHOD(records, result, "fetchall", PH_NO_CHECK); PHALCON_INIT_VAR(row_count); phalcon_fast_count(row_count, records TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_rows"), row_count TSRMLS_CC); } } } PHALCON_INIT_VAR(model); phalcon_read_property(&model, this_ptr, SL("_model"), PH_NOISY_CC); PHALCON_INIT_VAR(cache); phalcon_read_property(&cache, this_ptr, SL("_cache"), PH_NOISY_CC); PHALCON_INIT_VAR(data); array_init(data); phalcon_array_update_string(&data, SL("model"), &model, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&data, SL("cache"), &cache, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&data, SL("rows"), &records, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(serialized); PHALCON_CALL_FUNC_PARAMS_1(serialized, "serialize", data); RETURN_CCTOR(serialized); }
/** * Resets all the stablished headers * * @return Phalcon\Http\ResponseInterface */ PHP_METHOD(Phalcon_Http_Response, resetHeaders){ zval *headers; PHALCON_MM_GROW(); PHALCON_INIT_VAR(headers); PHALCON_CALL_METHOD(headers, this_ptr, "getheaders"); PHALCON_CALL_METHOD_NORETURN(headers, "reset"); RETURN_THIS(); }
/** * Starts a cache. The $keyname allow to identify the created fragment * * @param int|string $keyName * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend, start){ zval *key_name = NULL, *backend = NULL, *front_end = NULL, *prefixed_key = NULL; zval *existing_cache = NULL, *fresh = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &key_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_backendOptions"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(backend, t0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_frontendObject"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(front_end, t1); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_prefix"), PHALCON_NOISY TSRMLS_CC); PHALCON_CONCAT_VV(r0, t2, key_name); PHALCON_CPY_WRT(prefixed_key, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD_PARAMS_1(r1, this_ptr, "get", prefixed_key, PHALCON_NO_CHECK); PHALCON_CPY_WRT(existing_cache, r1); PHALCON_INIT_VAR(t3); ZVAL_NULL(t3); PHALCON_ALLOC_ZVAL_MM(r2); is_equal_function(r2, existing_cache, t3 TSRMLS_CC); if (zend_is_true(r2)) { PHALCON_INIT_VAR(fresh); ZVAL_BOOL(fresh, 1); PHALCON_CALL_METHOD_NORETURN(front_end, "start", PHALCON_NO_CHECK); } else { PHALCON_INIT_VAR(fresh); ZVAL_BOOL(fresh, 0); } phalcon_update_property_zval(this_ptr, SL("_fresh"), fresh TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); RETURN_CHECK_CTOR(existing_cache); }
/** * Prints out HTTP response to the client * * @return Phalcon\Http\ResponseInterface */ PHP_METHOD(Phalcon_Http_Response, send){ zval *sent, *headers, *cookies, *content; PHALCON_MM_GROW(); PHALCON_OBS_VAR(sent); phalcon_read_property(&sent, this_ptr, SL("_sent"), PH_NOISY_CC); if (PHALCON_IS_FALSE(sent)) { /** * Sent headers */ PHALCON_OBS_VAR(headers); phalcon_read_property(&headers, this_ptr, SL("_headers"), PH_NOISY_CC); if (Z_TYPE_P(headers) != IS_NULL) { PHALCON_CALL_METHOD_NORETURN(headers, "send"); } PHALCON_OBS_VAR(cookies); phalcon_read_property(&cookies, this_ptr, SL("_cookies"), PH_NOISY_CC); if (Z_TYPE_P(cookies) != IS_NULL) { PHALCON_CALL_METHOD_NORETURN(cookies, "send"); } /** * Output the response body */ PHALCON_OBS_VAR(content); phalcon_read_property(&content, this_ptr, SL("_content"), PH_NOISY_CC); zend_print_zval(content, 0); phalcon_update_property_bool(this_ptr, SL("_sent"), 1 TSRMLS_CC); RETURN_THIS(); } PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "Response was already sent"); return; }
/** * Serializing a resultset will dump all related rows into a big array * * @return string */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, serialize){ zval *records, *valid = NULL, *current = NULL, *cache, *data, *serialized; zval *r0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(records); array_init(records); PHALCON_CALL_METHOD_NORETURN(this_ptr, "rewind", PH_NO_CHECK); ph_cycle_start_0: PHALCON_INIT_NVAR(r0); PHALCON_CALL_METHOD(r0, this_ptr, "valid", PH_NO_CHECK); PHALCON_CPY_WRT(valid, r0); if (PHALCON_IS_NOT_TRUE(valid)) { goto ph_cycle_end_0; } PHALCON_INIT_NVAR(current); PHALCON_CALL_METHOD(current, this_ptr, "current", PH_NO_CHECK); phalcon_array_append(&records, current, PH_SEPARATE TSRMLS_CC); PHALCON_CALL_METHOD_NORETURN(this_ptr, "next", PH_NO_CHECK); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_VAR(cache); phalcon_read_property(&cache, this_ptr, SL("_cache"), PH_NOISY_CC); PHALCON_INIT_VAR(data); array_init(data); phalcon_array_update_string(&data, SL("cache"), &cache, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&data, SL("rows"), &records, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(serialized); PHALCON_CALL_FUNC_PARAMS_1(serialized, "serialize", data); RETURN_CCTOR(serialized); }
/** * Serializing a resultset will dump all related rows into a big array * * @return string */ PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, serialize){ zval *records = NULL, *valid = NULL, *current = NULL, *cache = NULL, *data = NULL, *serialized = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(records); array_init(records); PHALCON_CALL_METHOD_NORETURN(this_ptr, "rewind", PH_NO_CHECK); ws_c3ae_0: PHALCON_INIT_VAR(r0); PHALCON_CALL_METHOD(r0, this_ptr, "valid", PH_NO_CHECK); PHALCON_CPY_WRT(valid, r0); if (Z_TYPE_P(valid) != IS_BOOL || (Z_TYPE_P(valid) == IS_BOOL && !Z_BVAL_P(valid))) { goto we_c3ae_0; } PHALCON_INIT_VAR(current); PHALCON_CALL_METHOD(current, this_ptr, "current", PH_NO_CHECK); phalcon_array_append(&records, current, PH_SEPARATE TSRMLS_CC); PHALCON_CALL_METHOD_NORETURN(this_ptr, "next", PH_NO_CHECK); goto ws_c3ae_0; we_c3ae_0: PHALCON_INIT_VAR(cache); phalcon_read_property(&cache, this_ptr, SL("_cache"), PH_NOISY_CC); PHALCON_INIT_VAR(data); array_init(data); phalcon_array_update_string(&data, SL("cache"), &cache, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&data, SL("rows"), &records, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(serialized); PHALCON_CALL_FUNC_PARAMS_1(serialized, "serialize", data); RETURN_CCTOR(serialized); }
/** * Moves internal resulset cursor to another position letting us to fetch a certain row * * @param int $number */ PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek) { zval *number = NULL, *n = NULL, *pdo_statement = NULL, *result = NULL; zval *r0 = NULL, *r1 = NULL; zval *t0 = NULL, *t1 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &number) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(number); PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, -1); PHALCON_ALLOC_ZVAL_MM(r0); mul_function(r0, t0, t1 TSRMLS_CC); PHALCON_CPY_WRT(n, r0); decrement_function(number); PHALCON_INIT_VAR(pdo_statement); phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); PHALCON_CALL_METHOD_NORETURN(pdo_statement, "execute", PH_NO_CHECK); ws_a5eb_0: PHALCON_INIT_VAR(r1); is_not_equal_function(r1, n, number TSRMLS_CC); if (!zend_is_true(r1)) { goto we_a5eb_0; } PHALCON_INIT_VAR(result); PHALCON_CALL_METHOD(result, pdo_statement, "fetch", PH_NO_CHECK); if (Z_TYPE_P(result) != IS_ARRAY) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE(n); increment_function(n); goto ws_a5eb_0; we_a5eb_0: if(0) {} PHALCON_MM_RESTORE(); }
/** * Sends headers to the client * * @return Phalcon\Http\ResponseInterface */ PHP_METHOD(Phalcon_Http_Response, sendHeaders){ zval *headers; PHALCON_MM_GROW(); PHALCON_OBS_VAR(headers); phalcon_read_property(&headers, this_ptr, SL("_headers"), PH_NOISY_CC); if (Z_TYPE_P(headers) != IS_NULL) { PHALCON_CALL_METHOD_NORETURN(headers, "send"); } RETURN_THIS(); }
/** * Sends cookies to the client * * @return Phalcon\Http\ResponseInterface */ PHP_METHOD(Phalcon_Http_Response, sendCookies){ zval *cookies; PHALCON_MM_GROW(); PHALCON_OBS_VAR(cookies); phalcon_read_property_this(&cookies, this_ptr, SL("_cookies"), PH_NOISY_CC); if (Z_TYPE_P(cookies) == IS_OBJECT) { PHALCON_CALL_METHOD_NORETURN(cookies, "send"); } RETURN_THIS(); }
/** * Phalcon\Db constructor * * @param stdClass $descriptor */ PHP_METHOD(Phalcon_Db, __construct){ zval *descriptor = NULL, *connection_consecutive = NULL; zval *next_consecutive = NULL, *dialect_type = NULL, *dialect_class = NULL; zval *dialect_object = NULL; zval *t0 = NULL; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_OBSERVE_VAR(connection_consecutive); phalcon_read_static_property(&connection_consecutive, SL("phalcon\\db"), SL("_connectionConsecutive") TSRMLS_CC); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_INIT_VAR(next_consecutive); phalcon_add_function(next_consecutive, connection_consecutive, t0 TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\db"), SL("_connectionConsecutive"), next_consecutive TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_connectionId"), connection_consecutive TSRMLS_CC); eval_int = phalcon_array_isset_string(descriptor, SL("dialectClass")+1); if (!eval_int) { PHALCON_INIT_VAR(dialect_type); phalcon_read_property(&dialect_type, this_ptr, SL("_dialectType"), PH_NOISY_CC); PHALCON_INIT_VAR(dialect_class); PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); } else { PHALCON_INIT_VAR(dialect_class); phalcon_array_fetch_string(&dialect_class, descriptor, SL("dialectClass"), PH_NOISY_CC); } ce0 = phalcon_fetch_class(dialect_class TSRMLS_CC); PHALCON_INIT_VAR(dialect_object); object_init_ex(dialect_object, ce0); PHALCON_CALL_METHOD_NORETURN(dialect_object, "__construct", PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_dialect"), dialect_object TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_descriptor"), descriptor TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Removes an access from a resource * * @param string $resourceName * @param mixed $accessList */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, dropResourceAccess){ zval *resource_name, *access_list, *access_name = NULL; zval *t0 = NULL, *t1 = NULL; zval *r0 = NULL, *r1 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &resource_name, &access_list) == FAILURE) { RETURN_MM_NULL(); } if (Z_TYPE_P(access_list) == IS_ARRAY) { if (!phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(access_name); PHALCON_OBS_NVAR(t0); phalcon_read_property(&t0, this_ptr, SL("_accessList"), PH_NOISY_CC); PHALCON_OBS_NVAR(r0); phalcon_array_fetch(&r0, t0, resource_name, PH_NOISY_CC); phalcon_array_unset(&r0, access_name, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } } else { if (zend_is_true(access_list)) { PHALCON_OBS_VAR(t1); phalcon_read_property(&t1, this_ptr, SL("_accessList"), PH_NOISY_CC); PHALCON_OBS_VAR(r1); phalcon_array_fetch(&r1, t1, resource_name, PH_NOISY_CC); phalcon_array_unset(&r1, access_list, PH_SEPARATE); } } PHALCON_CALL_METHOD_NORETURN(this_ptr, "_rebuildaccesslist"); PHALCON_MM_RESTORE(); }
/** * Gets Phalcon_Controller_Front singleton instance * * @return Phalcon_Controller_Front */ PHP_METHOD(Phalcon_Controller_Front, getInstance){ zval *instance = NULL; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(instance); phalcon_read_static_property(&instance, SL("phalcon\\controller\\front"), SL("_instance") TSRMLS_CC); if (!zend_is_true(instance)) { PHALCON_INIT_VAR(instance); object_init_ex(instance, phalcon_controller_front_ce); PHALCON_CALL_METHOD_NORETURN(instance, "__construct", PH_CHECK); phalcon_update_static_property(SL("phalcon\\controller\\front"), SL("_instance"), instance TSRMLS_CC); } RETURN_CCTOR(instance); }
/** * 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 = NULL, *frontend; zval *prefix, *prefixed_key, *cached_content; zval *content; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &key_name, &lifetime) == FAILURE) { RETURN_MM_NULL(); } if (!lifetime) { PHALCON_INIT_VAR(lifetime); } PHALCON_OBS_VAR(memcache); phalcon_read_property(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC); if (Z_TYPE_P(memcache) != IS_OBJECT) { PHALCON_CALL_METHOD_NORETURN(this_ptr, "_connect"); PHALCON_OBS_NVAR(memcache); phalcon_read_property(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC); } PHALCON_OBS_VAR(frontend); phalcon_read_property(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); PHALCON_OBS_VAR(prefix); phalcon_read_property(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC); PHALCON_INIT_VAR(prefixed_key); PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); phalcon_update_property_zval(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC); PHALCON_INIT_VAR(cached_content); PHALCON_CALL_METHOD_PARAMS_1(cached_content, memcache, "get", prefixed_key); if (PHALCON_IS_FALSE(cached_content)) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(content); PHALCON_CALL_METHOD_PARAMS_1(content, frontend, "afterretrieve", cached_content); RETURN_CCTOR(content); }
/** * Get first row in the resultset * * @return Phalcon_Model_Base */ PHP_METHOD(Phalcon_Model_Resultset, getFirst){ zval *r0 = NULL, *r1 = NULL; PHALCON_MM_GROW(); PHALCON_CALL_METHOD_NORETURN(this_ptr, "rewind", PHALCON_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, this_ptr, "valid", PHALCON_NO_CHECK); if (Z_TYPE_P(r0) != IS_BOOL || (Z_TYPE_P(r0) == IS_BOOL && Z_BVAL_P(r0))) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, this_ptr, "current", PHALCON_NO_CHECK); PHALCON_RETURN_DZVAL(r1); } PHALCON_MM_RESTORE(); RETURN_FALSE; }