/** * 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_noret(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); phalcon_call_method_noret(this_ptr, "next"); } RETURN_CTOR(records); }
/** * Listen for uncaught exceptions and unsilent notices or warnings * * @param boolean $exceptions * @param boolean $lowSeverity * @return Phalcon\Debug */ PHP_METHOD(Phalcon_Debug, listen){ zval *exceptions = NULL, *low_severity = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &exceptions, &low_severity); if (!exceptions) { PHALCON_INIT_VAR(exceptions); ZVAL_BOOL(exceptions, 1); } if (!low_severity) { PHALCON_INIT_VAR(low_severity); ZVAL_BOOL(low_severity, 0); } if (zend_is_true(exceptions)) { phalcon_call_method_noret(this_ptr, "listenexceptions"); } if (zend_is_true(low_severity)) { phalcon_call_method_noret(this_ptr, "listenlowseverity"); } RETURN_THIS(); }
/** * Prints out HTTP response to the client * * @return Phalcon\Http\ResponseInterface */ PHP_METHOD(Phalcon_Http_Response, send){ zval *sent, *headers, *cookies, *content, *file; PHALCON_MM_GROW(); PHALCON_OBS_VAR(sent); phalcon_read_property_this(&sent, this_ptr, SL("_sent"), PH_NOISY_CC); if (PHALCON_IS_FALSE(sent)) { /** * Send headers */ PHALCON_OBS_VAR(headers); phalcon_read_property_this(&headers, this_ptr, SL("_headers"), PH_NOISY_CC); if (Z_TYPE_P(headers) == IS_OBJECT) { phalcon_call_method_noret(headers, "send"); } 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_noret(cookies, "send"); } /** * Output the response body */ PHALCON_OBS_VAR(content); phalcon_read_property_this(&content, this_ptr, SL("_content"), PH_NOISY_CC); if (Z_STRLEN_P(content)) { zend_print_zval(content, 0); } else { PHALCON_OBS_VAR(file); phalcon_read_property_this(&file, this_ptr, SL("_file"), PH_NOISY_CC); if (Z_STRLEN_P(file)) { php_stream *stream; stream = php_stream_open_wrapper(Z_STRVAL_P(file), "rb", REPORT_ERRORS, NULL); if (stream != NULL) { php_stream_passthru(stream); php_stream_close(stream); } } } 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; }
/** * Rollbacks active transactions within the manager * Collect will remove transaction from the manager * * @param boolean $collect */ PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollback){ zval *collect = NULL, *transactions, *transaction = NULL, *connection = NULL; zval *is_under_transaction = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &collect); if (!collect) { PHALCON_INIT_VAR(collect); ZVAL_BOOL(collect, 1); } PHALCON_OBS_VAR(transactions); phalcon_read_property_this(&transactions, this_ptr, SL("_transactions"), PH_NOISY_CC); if (Z_TYPE_P(transactions) == IS_ARRAY) { phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(transaction); PHALCON_INIT_NVAR(connection); phalcon_call_method(connection, transaction, "getconnection"); PHALCON_INIT_NVAR(is_under_transaction); phalcon_call_method(is_under_transaction, connection, "isundertransaction"); if (zend_is_true(is_under_transaction)) { phalcon_call_method_noret(connection, "rollback"); phalcon_call_method_noret(connection, "close"); } if (zend_is_true(collect)) { phalcon_call_method_p1_noret(this_ptr, "_collecttransaction", transaction); } zend_hash_move_forward_ex(ah0, &hp0); } } PHALCON_MM_RESTORE(); }
/** * Get first row in the resultset * * @return Phalcon\Mvc\ModelInterface */ PHP_METHOD(Phalcon_Mvc_Model_Resultset, getFirst){ zval *pointer, *current = NULL, *valid; PHALCON_MM_GROW(); /** * Check if the last record returned is the current requested */ PHALCON_OBS_VAR(pointer); phalcon_read_property_this(&pointer, this_ptr, SL("_pointer"), PH_NOISY_CC); if (PHALCON_IS_LONG(pointer, 0)) { PHALCON_INIT_VAR(current); phalcon_call_method(current, this_ptr, "current"); RETURN_CCTOR(current); } /** * Otherwise re-execute the statement */ phalcon_call_method_noret(this_ptr, "rewind"); PHALCON_INIT_VAR(valid); phalcon_call_method(valid, this_ptr, "valid"); if (PHALCON_IS_NOT_FALSE(valid)) { PHALCON_INIT_NVAR(current); phalcon_call_method(current, this_ptr, "current"); RETURN_CCTOR(current); } RETURN_MM_FALSE; }
/** * Removes a property from the internal bag * *<code> * $user->remove('name'); *</code> * * @param string $property * @return boolean */ PHP_METHOD(Phalcon_Session_Bag, remove){ zval *property, *data = NULL, *name, *session; zval *initialized; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &property); PHALCON_OBS_VAR(initialized); phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); if (PHALCON_IS_FALSE(initialized)) { phalcon_call_method_noret(this_ptr, "initialize"); } PHALCON_OBS_VAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); if (phalcon_array_isset(data, property)) { phalcon_unset_property_array(this_ptr, SL("_data"), property TSRMLS_CC); PHALCON_OBS_NVAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); PHALCON_OBS_VAR(name); phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); PHALCON_OBS_VAR(session); phalcon_read_property_this(&session, this_ptr, SL("_session"), PH_NOISY_CC); phalcon_call_method_p2_noret(session, "set", name, data); RETURN_MM_TRUE; } RETURN_MM_FALSE; }
/** * 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(); phalcon_fetch_params(1, 1, 0, &data); 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_p1_noret(reflection, "__construct", reflection_data); RETURN_CTOR(reflection); } } PHALCON_INIT_NVAR(reflection); object_init_ex(reflection, phalcon_annotations_reflection_ce); phalcon_call_method_noret(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(); phalcon_fetch_params(1, 2, 0, &property, &value); PHALCON_OBS_VAR(initalized); phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); if (PHALCON_IS_FALSE(initalized)) { phalcon_call_method_noret(this_ptr, "initialize"); } phalcon_update_property_array(this_ptr, SL("_data"), property, value TSRMLS_CC); PHALCON_OBS_VAR(name); phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); PHALCON_OBS_VAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); PHALCON_OBS_VAR(session); phalcon_read_property_this(&session, this_ptr, SL("_session"), PH_NOISY_CC); phalcon_call_method_p2_noret(session, "set", name, data); PHALCON_MM_RESTORE(); }
/** * Phalcon\Validation constructor * * @param array $validators */ PHP_METHOD(Phalcon_Validation, __construct){ zval *validators = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &validators); if (!validators) { PHALCON_INIT_VAR(validators); } if (Z_TYPE_P(validators) != IS_NULL) { if (Z_TYPE_P(validators) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Validators must be an array"); return; } phalcon_update_property_this(this_ptr, SL("_validators"), validators TSRMLS_CC); } /** * Check for an 'initialize' method */ if (phalcon_method_exists_ex(this_ptr, SS("initialize") TSRMLS_CC) == SUCCESS) { phalcon_call_method_noret(this_ptr, "initialize"); } PHALCON_MM_RESTORE(); }
/** * Rollbacks active transactions within the manager * */ PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollbackPendent){ PHALCON_MM_GROW(); phalcon_call_method_noret(this_ptr, "rollback"); PHALCON_MM_RESTORE(); }
/** * 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_noret(headers, "reset"); 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_noret(cookies, "send"); } RETURN_THIS(); }
/** * Returns the internal formatter * * @return Phalcon\Logger\Formatter\Line */ PHP_METHOD(Phalcon_Logger_Adapter_File, getFormatter){ zval *formatter = NULL; PHALCON_MM_GROW(); PHALCON_OBS_VAR(formatter); phalcon_read_property_this(&formatter, this_ptr, SL("_formatter"), PH_NOISY_CC); if (Z_TYPE_P(formatter) != IS_OBJECT) { PHALCON_INIT_NVAR(formatter); object_init_ex(formatter, phalcon_logger_formatter_line_ce); phalcon_call_method_noret(formatter, "__construct"); phalcon_update_property_this(this_ptr, SL("_formatter"), formatter TSRMLS_CC); } RETURN_CCTOR(formatter); }
/** * Create internal connection to memcached */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, _connect){ zval *options, *memcache, *host, *port, *persistent; zval *success; zend_class_entry *ce0; PHALCON_MM_GROW(); PHALCON_OBS_VAR(options); phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); ce0 = zend_fetch_class(SL("Memcache"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(memcache); object_init_ex(memcache, ce0); if (phalcon_has_constructor(memcache TSRMLS_CC)) { phalcon_call_method_noret(memcache, "__construct"); } PHALCON_OBS_VAR(host); phalcon_array_fetch_string(&host, options, SL("host"), PH_NOISY); PHALCON_OBS_VAR(port); phalcon_array_fetch_string(&port, options, SL("port"), PH_NOISY); PHALCON_OBS_VAR(persistent); phalcon_array_fetch_string(&persistent, options, SL("persistent"), PH_NOISY); PHALCON_INIT_VAR(success); if (zend_is_true(persistent)) { phalcon_call_method_p2(success, memcache, "pconnect", host, port); } else { phalcon_call_method_p2(success, memcache, "connect", host, port); } if (!zend_is_true(success)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cannot connect to Memcached server"); return; } phalcon_update_property_this(this_ptr, SL("_memcache"), memcache TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * 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; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); if (!lifetime) { PHALCON_INIT_VAR(lifetime); } PHALCON_OBS_VAR(memcache); phalcon_read_property_this(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC); if (Z_TYPE_P(memcache) != IS_OBJECT) { phalcon_call_method_noret(this_ptr, "_connect"); PHALCON_OBS_NVAR(memcache); phalcon_read_property_this(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC); } PHALCON_OBS_VAR(frontend); phalcon_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); PHALCON_OBS_VAR(prefix); phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_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_INIT_VAR(cached_content); phalcon_call_method_p1(cached_content, memcache, "get", prefixed_key); if (PHALCON_IS_FALSE(cached_content)) { RETURN_MM_NULL(); } phalcon_call_method_p1(return_value, frontend, "afterretrieve", cached_content); RETURN_MM(); }
/** * Destroyes the session bag * *<code> * $user->destroy(); *</code> */ PHP_METHOD(Phalcon_Session_Bag, destroy){ zval *initalized, *name, *session; PHALCON_MM_GROW(); PHALCON_OBS_VAR(initalized); phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); if (PHALCON_IS_FALSE(initalized)) { phalcon_call_method_noret(this_ptr, "initialize"); } PHALCON_OBS_VAR(name); phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); PHALCON_OBS_VAR(session); phalcon_read_property_this(&session, this_ptr, SL("_session"), PH_NOISY_CC); phalcon_call_method_p1_noret(session, "remove", name); PHALCON_MM_RESTORE(); }
/** * Appends a message to the internal message list * * @param Phalcon\Validation\Message $message * @return Phalcon\Forms\ElementInterface */ PHP_METHOD(Phalcon_Forms_Element, appendMessage){ zval *message, *messages = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &message); PHALCON_OBS_VAR(messages); phalcon_read_property_this(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); if (Z_TYPE_P(messages) != IS_OBJECT) { PHALCON_INIT_NVAR(messages); object_init_ex(messages, phalcon_validation_message_group_ce); phalcon_call_method_noret(messages, "__construct"); phalcon_update_property_this(this_ptr, SL("_messages"), messages TSRMLS_CC); } phalcon_call_method_p1_noret(messages, "appendmessage", message); RETURN_THIS(); }
/** * Check whether a property is defined in the internal bag * *<code> * var_dump($user->has('name')); *</code> * * @param string $property * @return boolean */ PHP_METHOD(Phalcon_Session_Bag, has){ zval *property, *initalized, *data; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &property); PHALCON_OBS_VAR(initalized); phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); if (PHALCON_IS_FALSE(initalized)) { phalcon_call_method_noret(this_ptr, "initialize"); } PHALCON_OBS_VAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); if (phalcon_array_isset(data, property)) { RETURN_MM_TRUE; } RETURN_MM_FALSE; }
/** * Initializes the internal handler, calling functions on it * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call) { zval *method, *arguments, *handler = NULL, *definition; zval *call_handler, *result; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &method, &arguments); PHALCON_OBS_VAR(handler); phalcon_read_property_this(&handler, this_ptr, SL("_handler"), PH_NOISY_CC); if (Z_TYPE_P(handler) != IS_OBJECT) { PHALCON_OBS_VAR(definition); phalcon_read_property_this(&definition, this_ptr, SL("_definition"), PH_NOISY_CC); ce0 = phalcon_fetch_class(definition TSRMLS_CC); PHALCON_INIT_NVAR(handler); object_init_ex(handler, ce0); if (phalcon_has_constructor(handler TSRMLS_CC)) { phalcon_call_method_noret(handler, "__construct"); } phalcon_update_property_this(this_ptr, SL("_handler"), handler TSRMLS_CC); } PHALCON_INIT_VAR(call_handler); array_init_size(call_handler, 2); phalcon_array_append(&call_handler, handler, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&call_handler, method, PH_SEPARATE TSRMLS_CC); /** * Call the handler */ PHALCON_INIT_VAR(result); PHALCON_CALL_USER_FUNC_ARRAY(result, call_handler, arguments); RETURN_CCTOR(result); }
/** * Obtains a value from the session bag optionally setting a default value * *<code> * echo $user->get('name', 'Kimbra'); *</code> * * @param string $property * @param string $defaultValue * @return mixed */ PHP_METHOD(Phalcon_Session_Bag, get){ zval *property, *default_value = NULL, *initalized; zval *data, *value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &property, &default_value); if (!default_value) { PHALCON_INIT_VAR(default_value); } /** * Check first if the bag is initialized */ PHALCON_OBS_VAR(initalized); phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); if (PHALCON_IS_FALSE(initalized)) { phalcon_call_method_noret(this_ptr, "initialize"); } /** * Retrieve the data */ PHALCON_OBS_VAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); if (phalcon_array_isset(data, property)) { PHALCON_OBS_VAR(value); phalcon_array_fetch(&value, data, property, PH_NOISY); if (PHALCON_IS_NOT_EMPTY(value)) { RETURN_CCTOR(value); } } RETURN_CCTOR(default_value); }
/** * Returns the messages that belongs to the element * The element needs to be attached to a form * * @return Phalcon\Validation\Message\Group */ PHP_METHOD(Phalcon_Forms_Element, getMessages){ zval *messages = NULL; PHALCON_MM_GROW(); /** * Get the related form */ PHALCON_OBS_VAR(messages); phalcon_read_property_this(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); if (Z_TYPE_P(messages) == IS_OBJECT) { RETURN_CCTOR(messages); } PHALCON_INIT_NVAR(messages); object_init_ex(messages, phalcon_validation_message_group_ce); phalcon_call_method_noret(messages, "__construct"); phalcon_update_property_this(this_ptr, SL("_messages"), messages TSRMLS_CC); RETURN_CCTOR(messages); }
/** * Renders a view * * @param string $path * @param array $params * @return string */ PHP_METHOD(Phalcon_Mvc_View_Simple, render){ zval *path, *params = NULL, *cache, *is_started = NULL, *key = NULL, *lifetime = NULL; zval *cache_options, *content = NULL, *view_params; zval *merged_params = NULL, *is_fresh; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &path, ¶ms); if (!params) { PHALCON_INIT_VAR(params); } /** * Create/Get a cache */ PHALCON_INIT_VAR(cache); phalcon_call_method(cache, this_ptr, "getcache"); if (Z_TYPE_P(cache) == IS_OBJECT) { /** * Check if the cache is started, the first time a cache is started we start the * cache */ PHALCON_INIT_VAR(is_started); phalcon_call_method(is_started, cache, "isstarted"); if (PHALCON_IS_FALSE(is_started)) { PHALCON_INIT_VAR(key); PHALCON_INIT_VAR(lifetime); PHALCON_OBS_VAR(cache_options); phalcon_read_property_this(&cache_options, this_ptr, SL("_cacheOptions"), PH_NOISY_CC); /** * Check if the user has defined a different options to the default */ if (Z_TYPE_P(cache_options) == IS_ARRAY) { if (phalcon_array_isset_string(cache_options, SS("key"))) { PHALCON_OBS_NVAR(key); phalcon_array_fetch_string(&key, cache_options, SL("key"), PH_NOISY); } if (phalcon_array_isset_string(cache_options, SS("lifetime"))) { PHALCON_OBS_NVAR(lifetime); phalcon_array_fetch_string(&lifetime, cache_options, SL("lifetime"), PH_NOISY); } } /** * If a cache key is not set we create one using a md5 */ if (Z_TYPE_P(key) == IS_NULL) { PHALCON_INIT_NVAR(key); phalcon_md5(key, path); } /** * We start the cache using the key set */ PHALCON_INIT_VAR(content); phalcon_call_method_p2(content, cache, "start", key, lifetime); if (Z_TYPE_P(content) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_content"), content TSRMLS_CC); RETURN_CCTOR(content); } } } /** * Create a virtual symbol table */ phalcon_create_symbol_table(TSRMLS_C); phalcon_ob_start(TSRMLS_C); PHALCON_OBS_VAR(view_params); phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); /** * Merge parameters */ if (Z_TYPE_P(params) == IS_ARRAY) { if (Z_TYPE_P(view_params) == IS_ARRAY) { PHALCON_INIT_VAR(merged_params); phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params, params); } } else { PHALCON_CPY_WRT(merged_params, view_params); } /** * internalRender is also reused by partials */ phalcon_call_method_p2_noret(this_ptr, "_internalrender", path, merged_params); /** * Store the data in output into the cache */ if (Z_TYPE_P(cache) == IS_OBJECT) { PHALCON_INIT_NVAR(is_started); phalcon_call_method(is_started, cache, "isstarted"); if (PHALCON_IS_TRUE(is_started)) { PHALCON_INIT_VAR(is_fresh); phalcon_call_method(is_fresh, cache, "isfresh"); if (PHALCON_IS_TRUE(is_fresh)) { phalcon_call_method_noret(cache, "save"); } else { phalcon_call_method_noret(cache, "stop"); } } else { phalcon_call_method_noret(cache, "stop"); } } phalcon_ob_end_clean(TSRMLS_C); PHALCON_OBS_NVAR(content); phalcon_read_property_this(&content, this_ptr, SL("_content"), PH_NOISY_CC); RETURN_CCTOR(content); }
/** * 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 *last_key = NULL, *prefix, *frontend, *cached_content = NULL; zval *prepared_content, *ttl = NULL, *success, *is_buffering; zval *options, *special_key, *keys = NULL, *zero; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name) { PHALCON_INIT_VAR(key_name); } if (!content) { PHALCON_INIT_VAR(content); } if (!lifetime) { PHALCON_INIT_VAR(lifetime); } else { PHALCON_SEPARATE_PARAM(lifetime); } if (!stop_buffer) { PHALCON_INIT_VAR(stop_buffer); ZVAL_BOOL(stop_buffer, 1); } if (Z_TYPE_P(key_name) == IS_NULL) { PHALCON_OBS_VAR(last_key); phalcon_read_property_this(&last_key, this_ptr, SL("_lastKey"), PH_NOISY_CC); } else { PHALCON_OBS_VAR(prefix); phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC); PHALCON_INIT_NVAR(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; } PHALCON_OBS_VAR(frontend); phalcon_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); if (Z_TYPE_P(content) == IS_NULL) { PHALCON_INIT_VAR(cached_content); phalcon_call_method(cached_content, frontend, "getcontent"); } else { PHALCON_CPY_WRT(cached_content, content); } PHALCON_INIT_VAR(prepared_content); phalcon_call_method_p1(prepared_content, frontend, "beforestore", cached_content); /** * Take the lifetime from the frontend or read it from the set in start() */ if (Z_TYPE_P(lifetime) == IS_NULL) { PHALCON_OBS_NVAR(lifetime); phalcon_read_property_this(&lifetime, this_ptr, SL("_lastLifetime"), PH_NOISY_CC); if (Z_TYPE_P(lifetime) == IS_NULL) { PHALCON_INIT_VAR(ttl); phalcon_call_method(ttl, frontend, "getlifetime"); } else { PHALCON_CPY_WRT(ttl, lifetime); } } else { PHALCON_CPY_WRT(ttl, lifetime); } /** * Call xcache_set in the PHP userland since most of the time it isn't available at * compile time */ PHALCON_INIT_VAR(success); phalcon_call_func_p3(success, "xcache_set", last_key, prepared_content, ttl); PHALCON_INIT_VAR(is_buffering); phalcon_call_method(is_buffering, frontend, "isbuffering"); if (PHALCON_IS_TRUE(stop_buffer)) { phalcon_call_method_noret(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); /** * xcache_set() could fail because of Out of Memory condition. I don't think it is * appropriate to throw an exception here (like * Phalcon\Cache\Backend\Memcache::save() does): first, to be consistent with * Phalcon\Cache\Backend\Apc::save(), second, because xCache is usually given much * less RAM than memcached */ if (zend_is_true(success)) { PHALCON_OBS_VAR(options); phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); PHALCON_OBS_VAR(special_key); phalcon_array_fetch_string(&special_key, options, SL("statsKey"), PH_NOISY_CC); /** * xcache_list() is available only to the administrator (unless XCache was * patched). We have to update the list of the stored keys. */ PHALCON_INIT_VAR(keys); phalcon_call_func_p1(keys, "xcache_get", special_key); if (Z_TYPE_P(keys) != IS_ARRAY) { PHALCON_INIT_NVAR(keys); array_init(keys); } if (!zend_is_true(keys)) { phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } } PHALCON_MM_RESTORE(); }
/** * Internal handler to call a queue of events * * @param \SplPriorityQueue $queue * @param Phalcon\Events\Event $event * @return mixed */ PHP_METHOD(Phalcon_Events_Manager, fireQueue){ zval *queue, *event, *status = NULL, *arguments = NULL, *event_name; zval *source, *data, *cancelable, *collect, *iterator; zval *handler = NULL, *is_stopped = NULL; zval *r0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &queue, &event); if (unlikely(Z_TYPE_P(queue) != IS_ARRAY)) { if (Z_TYPE_P(queue) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The SplPriorityQueue is not valid"); return; } } if (unlikely(Z_TYPE_P(event) != IS_OBJECT)) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event is not valid"); return; } PHALCON_INIT_VAR(status); PHALCON_INIT_VAR(arguments); /** * Get the event type */ PHALCON_INIT_VAR(event_name); phalcon_call_method(event_name, event, "gettype"); if (unlikely(Z_TYPE_P(event_name) != IS_STRING)) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event type not valid"); return; } /** * Get the object who triggered the event */ PHALCON_INIT_VAR(source); phalcon_call_method(source, event, "getsource"); /** * Get extra data passed to the event */ PHALCON_INIT_VAR(data); phalcon_call_method(data, event, "getdata"); /** * Tell if the event is cancelable */ PHALCON_INIT_VAR(cancelable); phalcon_call_method(cancelable, event, "getcancelable"); /** * Responses need to be traced? */ PHALCON_OBS_VAR(collect); phalcon_read_property_this(&collect, this_ptr, SL("_collect"), PH_NOISY_CC); if (Z_TYPE_P(queue) == IS_OBJECT) { /** * We need to clone the queue before iterate over it */ PHALCON_INIT_VAR(iterator); if (phalcon_clone(iterator, queue TSRMLS_CC) == FAILURE) { return; } /** * Move the queue to the top */ phalcon_call_method_noret(iterator, "top"); while (1) { PHALCON_INIT_NVAR(r0); phalcon_call_method(r0, iterator, "valid"); if (zend_is_true(r0)) { } else { break; } /** * Get the current data */ PHALCON_INIT_NVAR(handler); phalcon_call_method(handler, iterator, "current"); /** * Only handler objects are valid */ if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { /** * Check if the event is a closure */ if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { /** * Create the closure arguments */ if (Z_TYPE_P(arguments) == IS_NULL) { PHALCON_INIT_NVAR(arguments); array_init_size(arguments, 3); phalcon_array_append(&arguments, event, PH_SEPARATE); phalcon_array_append(&arguments, source, PH_SEPARATE); phalcon_array_append(&arguments, data, PH_SEPARATE); } /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); /** * Trace the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } else { /** * Check if the listener has implemented an event with the same name */ if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); /** * Collect the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } } } /** * Move the queue to the next handler */ phalcon_call_method_noret(iterator, "next"); } } else { phalcon_is_iterable(queue, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(handler); /** * Only handler objects are valid */ if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { /** * Check if the event is a closure */ if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { /** * Create the closure arguments */ if (Z_TYPE_P(arguments) == IS_NULL) { PHALCON_INIT_NVAR(arguments); array_init_size(arguments, 3); phalcon_array_append(&arguments, event, PH_SEPARATE); phalcon_array_append(&arguments, source, PH_SEPARATE); phalcon_array_append(&arguments, data, PH_SEPARATE); } /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); /** * Trace the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } else { /** * Check if the listener has implemented an event with the same name */ if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); /** * Collect the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } } } zend_hash_move_forward_ex(ah0, &hp0); } } RETURN_CCTOR(status); }
/** * Attach a listener to the events manager * * @param string $eventType * @param object|callable $handler * @param int $priority */ PHP_METHOD(Phalcon_Events_Manager, attach){ zval *event_type, *handler, *priority = NULL, *events = NULL; zval *enable_priorities, *priority_queue = NULL; zval *mode; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &event_type, &handler, &priority); if (!priority) { PHALCON_INIT_VAR(priority); ZVAL_LONG(priority, 100); } if (unlikely(Z_TYPE_P(event_type) != IS_STRING)) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event type must be a string"); return; } if (unlikely(Z_TYPE_P(handler) != IS_OBJECT)) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event handler must be an Object"); return; } PHALCON_OBS_VAR(events); phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); if (Z_TYPE_P(events) != IS_ARRAY) { PHALCON_INIT_NVAR(events); array_init(events); } if (!phalcon_array_isset(events, event_type)) { PHALCON_OBS_VAR(enable_priorities); phalcon_read_property_this(&enable_priorities, this_ptr, SL("_enablePriorities"), PH_NOISY_CC); if (zend_is_true(enable_priorities)) { /** * Create a SplPriorityQueue to store the events with priorities */ PHALCON_INIT_VAR(priority_queue); object_init_ex(priority_queue, spl_ce_SplPriorityQueue); if (phalcon_has_constructor(priority_queue TSRMLS_CC)) { phalcon_call_method_noret(priority_queue, "__construct"); } /** * Extract only the Data */ PHALCON_INIT_VAR(mode); ZVAL_LONG(mode, 1); /** * Set extraction flags */ phalcon_call_method_p1_noret(priority_queue, "setextractflags", mode); /** * Append the events to the queue */ phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); phalcon_update_property_this(this_ptr, SL("_events"), events TSRMLS_CC); } else { PHALCON_INIT_NVAR(priority_queue); array_init(priority_queue); } } else { /** * Get the current SplPriorityQueue */ PHALCON_OBS_NVAR(priority_queue); phalcon_array_fetch(&priority_queue, events, event_type, PH_NOISY); } /** * Insert the handler in the queue */ if (unlikely(Z_TYPE_P(priority_queue) == IS_OBJECT)) { phalcon_call_method_p2_noret(priority_queue, "insert", handler, priority); } else { phalcon_array_append(&priority_queue, handler, PH_SEPARATE); /** * Append the events to the queue */ phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); phalcon_update_property_this(this_ptr, SL("_events"), events TSRMLS_CC); } PHALCON_MM_RESTORE(); }
/** * Validate a set of data according to a set of rules * * @param array|object $data * @param object $entity * @return Phalcon\Validation\Message\Group */ PHP_METHOD(Phalcon_Validation, validate){ zval *data = NULL, *entity = NULL, *validators, *messages = NULL, *status = NULL; zval *cancel_on_fail, *scope = NULL, *attribute = NULL, *validator = NULL; zval *must_cancel = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &data, &entity); if (!data) { PHALCON_INIT_VAR(data); } if (!entity) { PHALCON_INIT_VAR(entity); } PHALCON_OBS_VAR(validators); phalcon_read_property_this(&validators, this_ptr, SL("_validators"), PH_NOISY_CC); if (Z_TYPE_P(validators) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There are no validators to validate"); return; } /** * Clear pre-calculated values */ phalcon_update_property_null(this_ptr, SL("_values") TSRMLS_CC); /** * Implicitly creates a Phalcon\Validation\Message\Group object */ PHALCON_INIT_VAR(messages); object_init_ex(messages, phalcon_validation_message_group_ce); phalcon_call_method_noret(messages, "__construct"); /** * Validation classes can implement the 'beforeValidation' callback */ if (phalcon_method_exists_ex(this_ptr, SS("beforevalidation") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(status); phalcon_call_method_p3(status, this_ptr, "beforevalidation", data, entity, messages); if (PHALCON_IS_FALSE(status)) { RETURN_CCTOR(status); } } phalcon_update_property_this(this_ptr, SL("_messages"), messages TSRMLS_CC); if (Z_TYPE_P(data) == IS_ARRAY) { phalcon_update_property_this(this_ptr, SL("_data"), data TSRMLS_CC); } else { if (Z_TYPE_P(data) == IS_OBJECT) { phalcon_update_property_this(this_ptr, SL("_data"), data TSRMLS_CC); } } PHALCON_INIT_VAR(cancel_on_fail); ZVAL_STRING(cancel_on_fail, "cancelOnFail", 1); phalcon_is_iterable(validators, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(scope); if (Z_TYPE_P(scope) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator scope is not valid"); return; } PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, scope, 0, PH_NOISY_CC); PHALCON_OBS_NVAR(validator); phalcon_array_fetch_long(&validator, scope, 1, PH_NOISY_CC); if (Z_TYPE_P(validator) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "One of the validators is not valid"); return; } PHALCON_INIT_NVAR(status); phalcon_call_method_p2(status, validator, "validate", this_ptr, attribute); /** * Check if the validation must be canceled if this validator fails */ if (PHALCON_IS_FALSE(status)) { PHALCON_INIT_NVAR(must_cancel); phalcon_call_method_p1(must_cancel, validator, "getoption", cancel_on_fail); if (zend_is_true(must_cancel)) { break; } } zend_hash_move_forward_ex(ah0, &hp0); } /** * Get the messages generated by the validators */ PHALCON_OBS_NVAR(messages); phalcon_read_property_this(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); if (phalcon_method_exists_ex(this_ptr, SS("aftervalidation") TSRMLS_CC) == SUCCESS) { phalcon_call_method_p3_noret(this_ptr, "aftervalidation", data, entity, messages); } RETURN_CCTOR(messages); }
/** * Handle the command-line arguments. * * * <code> * $arguments = array( * 'task' => 'taskname', * 'action' => 'action', * 'params' => array('parameter1', 'parameter2') * ); * $console->handle($arguments); * </code> * * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_CLI_Console, handle){ zval *arguments = NULL, *dependency_injector, *events_manager; zval *service = NULL, *router, *module_name, *event_name = NULL; zval *status = NULL, *modules, *exception_msg = NULL, *module; zval *path, *class_name = NULL, *module_object, *task_name; zval *action_name, *params, *dispatcher, *task; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &arguments); if (!arguments) { PHALCON_INIT_VAR(arguments); array_init(arguments); } PHALCON_OBS_VAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "A dependency injection object is required to access internal services"); return; } PHALCON_OBS_VAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); PHALCON_INIT_VAR(service); ZVAL_STRING(service, "router", 1); PHALCON_INIT_VAR(router); phalcon_call_method_p1(router, dependency_injector, "getshared", service); phalcon_call_method_p1_noret(router, "handle", arguments); PHALCON_INIT_VAR(module_name); phalcon_call_method(module_name, router, "getmodulename"); if (zend_is_true(module_name)) { if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "console:beforeStartModule", 1); PHALCON_INIT_VAR(status); phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, module_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } PHALCON_OBS_VAR(modules); phalcon_read_property_this(&modules, this_ptr, SL("_modules"), PH_NOISY_CC); if (!phalcon_array_isset(modules, module_name)) { PHALCON_INIT_VAR(exception_msg); PHALCON_CONCAT_SVS(exception_msg, "Module '", module_name, "' isn't registered in the console container"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cli_console_exception_ce, exception_msg); return; } PHALCON_OBS_VAR(module); phalcon_array_fetch(&module, modules, module_name, PH_NOISY); if (Z_TYPE_P(module) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "Invalid module definition path"); return; } if (phalcon_array_isset_string(module, SS("path"))) { PHALCON_OBS_VAR(path); phalcon_array_fetch_string(&path, module, SL("path"), PH_NOISY); if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { if (phalcon_require(path TSRMLS_CC) == FAILURE) { return; } } else { PHALCON_INIT_NVAR(exception_msg); PHALCON_CONCAT_SVS(exception_msg, "Module definition path '", path, "\" doesn't exist"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cli_console_exception_ce, exception_msg); return; } } if (phalcon_array_isset_string(module, SS("className"))) { PHALCON_OBS_VAR(class_name); phalcon_array_fetch_string(&class_name, module, SL("className"), PH_NOISY); } else { PHALCON_INIT_NVAR(class_name); ZVAL_STRING(class_name, "Module", 1); } PHALCON_INIT_VAR(module_object); phalcon_call_method_p1(module_object, dependency_injector, "get", class_name); phalcon_call_method_noret(module_object, "registerautoloaders"); phalcon_call_method_p1_noret(module_object, "registerservices", dependency_injector); if (Z_TYPE_P(events_manager) == IS_OBJECT) { phalcon_update_property_this(this_ptr, SL("_moduleObject"), module_object TSRMLS_CC); PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "console:afterStartModule", 1); PHALCON_INIT_NVAR(status); phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, module_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } } PHALCON_INIT_VAR(task_name); phalcon_call_method(task_name, router, "gettaskname"); PHALCON_INIT_VAR(action_name); phalcon_call_method(action_name, router, "getactionname"); PHALCON_INIT_VAR(params); phalcon_call_method(params, router, "getparams"); PHALCON_INIT_NVAR(service); ZVAL_STRING(service, "dispatcher", 1); PHALCON_INIT_VAR(dispatcher); phalcon_call_method_p1(dispatcher, dependency_injector, "getshared", service); PHALCON_VERIFY_INTERFACE(dispatcher, phalcon_dispatcherinterface_ce); phalcon_call_method_p1_noret(dispatcher, "settaskname", task_name); phalcon_call_method_p1_noret(dispatcher, "setactionname", action_name); phalcon_call_method_p1_noret(dispatcher, "setparams", params); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "console:beforeHandleTask", 1); PHALCON_INIT_NVAR(status); phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, dispatcher); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } PHALCON_INIT_VAR(task); phalcon_call_method(task, dispatcher, "dispatch"); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "console:afterHandleTask", 1); phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, task); } RETURN_CCTOR(task); }
/** * Executes a prepared statement binding. This function uses integer indexes starting from zero * *<code> * $statement = $db->prepare('SELECT * FROM robots WHERE name = :name'); * $result = $connection->executePrepared($statement, array('name' => 'Voltron')); *</code> * * @param \PDOStatement $statement * @param array $placeholders * @param array $dataTypes * @return \PDOStatement */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared){ zval *statement = NULL, *placeholders = NULL, *data_types = NULL; zval *one, *value = NULL, *wildcard = NULL, *parameter = NULL, *type = NULL, *cast_value = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &statement, &placeholders, &data_types) == FAILURE) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); if (!phalcon_is_iterable_ex(placeholders, &ah0, &hp0, 0, 0)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(wildcard, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(wildcard) == IS_LONG) { PHALCON_INIT_NVAR(parameter); phalcon_add_function(parameter, wildcard, one TSRMLS_CC); } else { if (Z_TYPE_P(wildcard) == IS_STRING) { PHALCON_CPY_WRT(parameter, wildcard); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind parameter"); return; } } if (Z_TYPE_P(data_types) == IS_ARRAY) { if (likely(phalcon_array_isset(data_types, wildcard))) { /** * The bind type is double so we try to get the double value */ PHALCON_OBS_NVAR(type); phalcon_array_fetch(&type, data_types, wildcard, PH_NOISY); if (phalcon_compare_strict_long(type, 32 TSRMLS_CC)) { PHALCON_INIT_NVAR(cast_value); phalcon_cast(cast_value, value, IS_DOUBLE); PHALCON_INIT_NVAR(type); ZVAL_LONG(type, 1024); } else { PHALCON_CPY_WRT(cast_value, value); } /** * 1024 is ignore the bind type */ Z_SET_ISREF_P(cast_value); if (phalcon_compare_strict_long(type, 1024 TSRMLS_CC)) { phalcon_call_method_p2_noret(statement, "bindparam", parameter, cast_value); } else { phalcon_call_method_p3_noret(statement, "bindparam", parameter, cast_value, type); } Z_UNSET_ISREF_P(cast_value); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind type parameter"); return; } } else { Z_SET_ISREF_P(value); phalcon_call_method_p2_noret(statement, "bindparam", parameter, value); Z_UNSET_ISREF_P(value); } zend_hash_move_forward_ex(ah0, &hp0); } phalcon_call_method_noret(statement, "execute"); RETURN_CCTOR(statement); }
/** * Returns the cookie's value * * @param string|array $filters * @param string $defaultValue * @return mixed */ PHP_METHOD(Phalcon_Http_Cookie, getValue){ zval *filters = NULL, *default_value = NULL, *restored, *dependency_injector = NULL; zval *readed, *name, *_COOKIE, *value = NULL, *encryption; zval *service = NULL, *crypt, *decrypted_value = NULL, *filter = NULL; zval *sanitized_value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &filters, &default_value); if (!filters) { PHALCON_INIT_VAR(filters); } if (!default_value) { PHALCON_INIT_VAR(default_value); } PHALCON_OBS_VAR(restored); phalcon_read_property_this(&restored, this_ptr, SL("_restored"), PH_NOISY_CC); if (!zend_is_true(restored)) { phalcon_call_method_noret(this_ptr, "restore"); } PHALCON_INIT_VAR(dependency_injector); PHALCON_OBS_VAR(readed); phalcon_read_property_this(&readed, this_ptr, SL("_readed"), PH_NOISY_CC); if (PHALCON_IS_FALSE(readed)) { PHALCON_OBS_VAR(name); phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); phalcon_get_global(&_COOKIE, SS("_COOKIE") TSRMLS_CC); if (phalcon_array_isset(_COOKIE, name)) { PHALCON_OBS_VAR(value); phalcon_array_fetch(&value, _COOKIE, name, PH_NOISY); PHALCON_OBS_VAR(encryption); phalcon_read_property_this(&encryption, this_ptr, SL("_useEncryption"), PH_NOISY_CC); if (zend_is_true(encryption)) { PHALCON_OBS_NVAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "crypt", 1); PHALCON_INIT_VAR(crypt); phalcon_call_method_p1(crypt, dependency_injector, "getshared", service); /** * Decrypt the value also decoding it with base64 */ PHALCON_INIT_VAR(decrypted_value); phalcon_call_method_p1(decrypted_value, crypt, "decryptbase64", value); } else { PHALCON_CPY_WRT(decrypted_value, value); } /** * Update the decrypted value */ phalcon_update_property_this(this_ptr, SL("_value"), decrypted_value TSRMLS_CC); if (Z_TYPE_P(filters) != IS_NULL) { PHALCON_OBS_VAR(filter); phalcon_read_property_this(&filter, this_ptr, SL("_filter"), PH_NOISY_CC); if (Z_TYPE_P(filter) != IS_OBJECT) { if (Z_TYPE_P(dependency_injector) == IS_NULL) { PHALCON_OBS_NVAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } } PHALCON_INIT_NVAR(service); ZVAL_STRING(service, "filter", 1); PHALCON_INIT_NVAR(filter); phalcon_call_method_p1(filter, dependency_injector, "getshared", service); phalcon_update_property_this(this_ptr, SL("_filter"), filter TSRMLS_CC); } PHALCON_INIT_VAR(sanitized_value); phalcon_call_method_p2(sanitized_value, filter, "sanitize", decrypted_value, filters); RETURN_CCTOR(sanitized_value); } /** * Return the value without filtering */ RETURN_CCTOR(decrypted_value); } RETURN_CCTOR(default_value); } PHALCON_OBS_NVAR(value); phalcon_read_property_this(&value, this_ptr, SL("_value"), PH_NOISY_CC); RETURN_CCTOR(value); }
/** * Builds a Phalcon\Mvc\Model\Criteria based on an input array like $_POST * * @param Phalcon\DiInterface $dependencyInjector * @param string $modelName * @param array $data * @return static */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ zval *dependency_injector, *model_name, *data; zval *conditions, *service, *meta_data, *model; zval *data_types, *bind, *value = NULL, *field = NULL, *type = NULL, *condition = NULL; zval *value_pattern = NULL, *criteria, *join_conditions; HashTable *ah0; HashPosition hp0; zval **hd; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &dependency_injector, &model_name, &data); if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array"); return; } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); return; } PHALCON_INIT_VAR(conditions); array_init(conditions); if (phalcon_fast_count_ev(data TSRMLS_CC)) { PHALCON_INIT_VAR(service); ZVAL_STRING(service, "modelsMetadata", 1); PHALCON_INIT_VAR(meta_data); phalcon_call_method_p1(meta_data, dependency_injector, "getshared", service); ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); if (phalcon_has_constructor(model TSRMLS_CC)) { phalcon_call_method_noret(model, "__construct"); } PHALCON_INIT_VAR(data_types); phalcon_call_method_p1(data_types, meta_data, "getdatatypes", model); PHALCON_INIT_VAR(bind); array_init(bind); /** * We look for attributes in the array passed as data */ phalcon_is_iterable(data, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(field, ah0, hp0); PHALCON_GET_HVALUE(value); if (phalcon_array_isset(data_types, field)) { if (Z_TYPE_P(value) != IS_NULL) { if (!PHALCON_IS_STRING(value, "")) { PHALCON_OBS_NVAR(type); phalcon_array_fetch(&type, data_types, field, PH_NOISY_CC); if (PHALCON_IS_LONG(type, 2)) { /** * For varchar types we use LIKE operator */ PHALCON_INIT_NVAR(condition); PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":"); PHALCON_INIT_NVAR(value_pattern); PHALCON_CONCAT_SVS(value_pattern, "%", value, "%"); phalcon_array_update_zval(&bind, field, &value_pattern, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { /** * For the rest of data types we use a plain = operator */ PHALCON_INIT_NVAR(condition); PHALCON_CONCAT_VSVS(condition, field, "=:", field, ":"); phalcon_array_update_zval(&bind, field, &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); } } } zend_hash_move_forward_ex(ah0, &hp0); } } /** * Create an object instance and pass the paramaters to it */ PHALCON_INIT_VAR(criteria); object_init_ex(criteria, phalcon_mvc_model_criteria_ce); if (phalcon_fast_count_ev(conditions TSRMLS_CC)) { PHALCON_INIT_VAR(join_conditions); phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); phalcon_call_method_p1_noret(criteria, "where", join_conditions); phalcon_call_method_p1_noret(criteria, "bind", bind); } RETURN_CTOR(criteria); }