/** * Set all the render params * *<code> * $this->view->setVars(array('products' => $products)); *</code> * * @param array $params * @param boolean $merge * @return Phalcon\Mvc\View\Simple */ PHP_METHOD(Phalcon_Mvc_View_Simple, setVars){ zval *params, *merge = NULL, *view_params, *merged_params = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, ¶ms, &merge); if (!merge) { PHALCON_INIT_VAR(merge); ZVAL_BOOL(merge, 1); } if (Z_TYPE_P(params) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The render parameters must be an array"); return; } if (zend_is_true(merge)) { PHALCON_OBS_VAR(view_params); phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); 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); } phalcon_update_property_this(this_ptr, SL("_viewParams"), merged_params TSRMLS_CC); } else { phalcon_update_property_this(this_ptr, SL("_viewParams"), params TSRMLS_CC); } RETURN_THIS(); }
/** * Adds a group of validators * * @param Phalcon\Validation\ValidatorInterface[] * @return Phalcon\Forms\ElementInterface */ PHP_METHOD(Phalcon_Forms_Element, addValidators){ zval *validators, *merge = NULL, *current_validators; zval *merged_validators = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &validators, &merge); if (!merge) { PHALCON_INIT_VAR(merge); ZVAL_BOOL(merge, 1); } if (Z_TYPE_P(validators) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The validators parameter must be an array"); return; } if (zend_is_true(merge)) { PHALCON_OBS_VAR(current_validators); phalcon_read_property_this(¤t_validators, this_ptr, SL("_validators"), PH_NOISY_CC); if (Z_TYPE_P(current_validators) == IS_ARRAY) { PHALCON_INIT_VAR(merged_validators); phalcon_fast_array_merge(merged_validators, ¤t_validators, &validators TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_validators, validators); } phalcon_update_property_this(this_ptr, SL("_validators"), merged_validators TSRMLS_CC); } RETURN_THIS(); }
/** * Register an array of modules present in the jsonrpc * *<code> * $this->registerModules(array( * 'frontend' => array( * 'className' => 'Multiple\Frontend\Module', * 'path' => '../apps/frontend/Module.php' * ), * 'backend' => array( * 'className' => 'Multiple\Backend\Module', * 'path' => '../apps/backend/Module.php' * ) * )); *</code> * * @param array $modules * @param boolean $merge * @param Phalcon\Mvc\JsonRpc */ PHP_METHOD(Phalcon_Mvc_JsonRpc, registerModules){ zval *modules, *merge = NULL, *registered_modules, *merged_modules = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &modules, &merge); if (!merge) { merge = &PHALCON_GLOBAL(z_false); } if (Z_TYPE_P(modules) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "Modules must be an Array"); return; } if (PHALCON_IS_FALSE(merge)) { phalcon_update_property_this(getThis(), SL("_modules"), modules); } else { registered_modules = phalcon_read_property(getThis(), SL("_modules"), PH_NOISY); if (Z_TYPE_P(registered_modules) == IS_ARRAY) { PHALCON_INIT_VAR(merged_modules); phalcon_fast_array_merge(merged_modules, registered_modules, modules); } else { PHALCON_CPY_WRT(merged_modules, modules); } phalcon_update_property_this(getThis(), SL("_modules"), merged_modules); } RETURN_THIS(); }
/** * Register an array of modules present in the application * *<code> * $this->registerModules(array( * 'frontend' => array( * 'className' => 'Multiple\Frontend\Module', * 'path' => '../apps/frontend/Module.php' * ), * 'backend' => array( * 'className' => 'Multiple\Backend\Module', * 'path' => '../apps/backend/Module.php' * ) * )); *</code> * * @param array $modules * @param boolean $merge * @param Phalcon\Mvc\Application */ PHP_METHOD(Phalcon_Mvc_Application, registerModules){ zval *modules, *merge = NULL, *registered_modules, *merged_modules = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &modules, &merge); if (!merge) { merge = PHALCON_GLOBAL(z_false); } if (Z_TYPE_P(modules) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Modules must be an Array"); return; } if (PHALCON_IS_FALSE(merge)) { phalcon_update_property_this(this_ptr, SL("_modules"), modules TSRMLS_CC); } else { PHALCON_OBS_VAR(registered_modules); phalcon_read_property_this(®istered_modules, this_ptr, SL("_modules"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(registered_modules) == IS_ARRAY) { PHALCON_INIT_VAR(merged_modules); phalcon_fast_array_merge(merged_modules, ®istered_modules, &modules TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_modules, modules); } phalcon_update_property_this(this_ptr, SL("_modules"), merged_modules TSRMLS_CC); } RETURN_THIS(); }
/** * Gets a variable from the $_REQUEST superglobal applying filters if needed. * If no parameters are given the $_REQUEST superglobal is returned * *<code> * //Returns value from $_REQUEST["user_email"] without sanitizing * $userEmail = $request->get("user_email"); * * //Returns value from $_REQUEST["user_email"] with sanitizing * $userEmail = $request->get("user_email", "email"); *</code> * * @param string $name * @param string|array $filters * @param mixed $defaultValue * @param boolean $notAllowEmpty * @param boolean $noRecursive * @return mixed */ PHP_METHOD(Phalcon_Http_Request, get) { zval *name = NULL, *filters = NULL, *default_value = NULL, *not_allow_empty = NULL, *norecursive = NULL, *request; zval put = {}, merged = {}; phalcon_fetch_params(0, 0, 5, &name, &filters, &default_value, ¬_allow_empty, &norecursive); if (!name) { name = &PHALCON_GLOBAL(z_null); } if (!filters) { filters = &PHALCON_GLOBAL(z_null); } if (!default_value) { default_value = &PHALCON_GLOBAL(z_null); } if (!not_allow_empty) { not_allow_empty = &PHALCON_GLOBAL(z_false); } if (!norecursive) { norecursive = &PHALCON_GLOBAL(z_false); } request = phalcon_get_global_str(SL("_REQUEST")); PHALCON_CALL_METHODW(&put, getThis(), "getput"); phalcon_fast_array_merge(&merged, request, &put); PHALCON_RETURN_CALL_SELFW("_get", &merged, name, filters, default_value, not_allow_empty, norecursive); }
/** * Adds a route applying the common attributes * * @param string $patten * @param array $paths * @param array $httpMethods * @return Phalcon\Mvc\Router\Route */ PHP_METHOD(Phalcon_Mvc_Router_Group, _addRoute){ zval *pattern, *paths = NULL, *http_methods = NULL, *prefix, *prefix_pattern; zval *default_paths, *merged_paths = NULL, *route; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); if (!paths) { PHALCON_INIT_VAR(paths); } if (!http_methods) { PHALCON_INIT_VAR(http_methods); } PHALCON_OBS_VAR(prefix); phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC); /** * Add the prefix to the pattern */ PHALCON_INIT_VAR(prefix_pattern); PHALCON_CONCAT_VV(prefix_pattern, prefix, pattern); PHALCON_OBS_VAR(default_paths); phalcon_read_property_this(&default_paths, this_ptr, SL("_paths"), PH_NOISY_CC); /** * Check if the paths need to be merged with current paths */ if (Z_TYPE_P(default_paths) == IS_ARRAY) { if (Z_TYPE_P(paths) == IS_ARRAY) { /** * Merge the paths with the default paths */ PHALCON_INIT_VAR(merged_paths); phalcon_fast_array_merge(merged_paths, &default_paths, &paths TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_paths, default_paths); } } else { PHALCON_CPY_WRT(merged_paths, paths); } /** * Every route is internally stored as a Phalcon\Mvc\Router\Route */ PHALCON_INIT_VAR(route); object_init_ex(route, phalcon_mvc_router_route_ce); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(route, "__construct", prefix_pattern, merged_paths, http_methods); phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC); RETURN_CTOR(route); }
/** * Adds a join to the query * *<code> * $criteria->join('Robots'); * $criteria->join('Robots', 'r.id = RobotsParts.robots_id'); * $criteria->join('Robots', 'r.id = RobotsParts.robots_id', 'r'); * $criteria->join('Robots', 'r.id = RobotsParts.robots_id', 'r', 'LEFT'); *</code> * * @param string $model * @param string $conditions * @param string $alias * @param string $type * @return Phalcon\Mvc\Model\CriteriaInterface */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ zval *model, *conditions = NULL, *alias = NULL, *type = NULL, *new_join, *params; zval *current_joins, *merged_joins = NULL, *new_join_array = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 3, &model, &conditions, &alias, &type); if (!conditions) { conditions = PHALCON_GLOBAL(z_null); } if (!alias) { alias = PHALCON_GLOBAL(z_null); } if (!type) { type = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(new_join); array_init_size(new_join, 4); phalcon_array_append(&new_join, model, 0); phalcon_array_append(&new_join, conditions, 0); phalcon_array_append(&new_join, alias, 0); phalcon_array_append(&new_join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_string(params, SS("joins"))) { PHALCON_INIT_VAR(new_join_array); array_init_size(new_join_array, 1); phalcon_array_append(&new_join_array, new_join, 0); PHALCON_OBS_VAR(current_joins); phalcon_array_fetch_string(¤t_joins, params, SL("joins"), PH_NOISY); if (Z_TYPE_P(current_joins) == IS_ARRAY) { PHALCON_INIT_VAR(merged_joins); phalcon_fast_array_merge(merged_joins, ¤t_joins, &new_join_array TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_joins, new_join_array); } } else { PHALCON_INIT_NVAR(merged_joins); array_init_size(merged_joins, 1); phalcon_array_append(&merged_joins, new_join, 0); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); RETURN_THIS(); }
/** * Adds a RIGHT join to the query * *<code> * $criteria->rightJoin('Robots', 'r.id = RobotsParts.robots_id', 'r'); *</code> * * @param string $model * @param string $conditions * @param string $alias * @return Phalcon\Mvc\Model\Query\Builder */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, rightJoin){ zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; zval *current_joins, *merged_joins = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); if (!conditions) { PHALCON_INIT_VAR(conditions); } if (!alias) { PHALCON_INIT_VAR(alias); } PHALCON_INIT_VAR(type); ZVAL_STRING(type, "RIGHT", 1); PHALCON_INIT_VAR(join); array_init_size(join, 4); phalcon_array_append(&join, model, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&join, conditions, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&join, alias, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&join, type, PH_SEPARATE TSRMLS_CC); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); if (phalcon_array_isset_string(params, SS("joins"))) { PHALCON_OBS_VAR(current_joins); phalcon_array_fetch_string(¤t_joins, params, SL("joins"), PH_NOISY_CC); if (Z_TYPE_P(current_joins) == IS_ARRAY) { PHALCON_INIT_VAR(merged_joins); phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_joins, join); } } else { PHALCON_INIT_NVAR(merged_joins); array_init_size(merged_joins, 1); phalcon_array_append(&merged_joins, join, PH_SEPARATE TSRMLS_CC); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); RETURN_THIS(); }
/** * Merge modules with the existing ones * *<code> * $application->addModules(array( * 'admin' => array( * 'className' => 'Multiple\Admin\Module', * 'path' => '../apps/admin/Module.php' * ) * )); *</code> * * @param array $modules */ PHP_METHOD(Phalcon_CLI_Console, addModules){ zval *modules, *original_modules, register_modules = {}; phalcon_fetch_params(0, 1, 0, &modules); if (Z_TYPE_P(modules) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Modules must be an Array"); return; } original_modules = phalcon_read_property(getThis(), SL("_modules"), PH_NOISY); phalcon_fast_array_merge(®ister_modules, modules, original_modules); phalcon_update_property_this(getThis(), SL("_modules"), ®ister_modules); }
/** * Merge modules with the existing ones * *<code> * $application->addModules(array( * 'admin' => array( * 'className' => 'Multiple\Admin\Module', * 'path' => '../apps/admin/Module.php' * ) * )); *</code> * * @param array $modules */ PHP_METHOD(Phalcon_CLI_Console, addModules){ zval *modules, *original_modules, *register_modules; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &modules); if (Z_TYPE_P(modules) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "Modules must be an Array"); return; } PHALCON_OBS_VAR(original_modules); phalcon_read_property_this(&original_modules, this_ptr, SL("_modules"), PH_NOISY_CC); PHALCON_INIT_VAR(register_modules); phalcon_fast_array_merge(register_modules, &modules, &original_modules TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_modules"), register_modules TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Set styles for vars type */ PHP_METHOD(Phalcon_Debug_Dump, setStyles){ zval *styles, *default_styles, *new_styles; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &styles); if (Z_TYPE_P(styles) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_debug_exception_ce, "The styles must be an array"); return; } default_styles = phalcon_fetch_nproperty_this(this_ptr, SL("_styles"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(new_styles); phalcon_fast_array_merge(new_styles, &default_styles, &styles TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_styles"), new_styles TSRMLS_CC); RETURN_THIS(); }
/** * Appends a condition to the current conditions using an OR operator * * @param string $conditions * @param array $bindParams * @param array $bindTypes * @return Phalcon\Mvc\Model\Criteria */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, orWhere){ zval *conditions, *bind_params = NULL, *bind_types = NULL; zval *params = NULL, *current_conditions, *new_conditions = NULL; zval *current_bind_params, *merged_params = NULL; zval *current_bind_types, *merged_params_types = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); if (!bind_params) { PHALCON_INIT_VAR(bind_params); } if (!bind_types) { PHALCON_INIT_VAR(bind_types); } if (Z_TYPE_P(conditions) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Conditions must be string"); return; } PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); if (phalcon_array_isset_string(params, SS("conditions"))) { PHALCON_OBS_VAR(current_conditions); phalcon_array_fetch_string(¤t_conditions, params, SL("conditions"), PH_NOISY_CC); PHALCON_INIT_VAR(new_conditions); PHALCON_CONCAT_SVSVS(new_conditions, "(", current_conditions, ") OR (", conditions, ")"); } else { PHALCON_CPY_WRT(new_conditions, conditions); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), new_conditions TSRMLS_CC); /** * Update or merge existing bound parameters */ if (Z_TYPE_P(bind_params) == IS_ARRAY) { PHALCON_OBS_NVAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); if (phalcon_array_isset_string(params, SS("bind"))) { PHALCON_OBS_VAR(current_bind_params); phalcon_array_fetch_string(¤t_bind_params, params, SL("bind"), PH_NOISY_CC); PHALCON_INIT_VAR(merged_params); phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params, bind_params); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), merged_params TSRMLS_CC); } /** * Update or merge existing bind types parameters */ if (Z_TYPE_P(bind_types) == IS_ARRAY) { PHALCON_OBS_NVAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); if (phalcon_array_isset_string(params, SS("bindTypes"))) { PHALCON_OBS_VAR(current_bind_types); phalcon_array_fetch_string(¤t_bind_types, params, SL("bindTypes"), PH_NOISY_CC); PHALCON_INIT_VAR(merged_params_types); phalcon_fast_array_merge(merged_params_types, ¤t_bind_types, &bind_types TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params_types, bind_types); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), merged_params_types TSRMLS_CC); } RETURN_THIS(); }
/** * Returns an array of prepared attributes for Phalcon\Tag helpers * according to the element's parameters * * @param array $attributes * @param boolean $useChecked * @return array */ PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ zval *attributes = NULL, *use_checked = NULL, *name, *widget_attributes = NULL; zval *default_attributes, *merged_attributes = NULL; zval *value, *current_value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &attributes, &use_checked); if (!attributes) { PHALCON_INIT_VAR(attributes); } if (!use_checked) { PHALCON_INIT_VAR(use_checked); ZVAL_BOOL(use_checked, 0); } PHALCON_OBS_VAR(name); phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); /** * Create an array of parameters */ if (Z_TYPE_P(attributes) != IS_ARRAY) { PHALCON_INIT_VAR(widget_attributes); array_init(widget_attributes); } else { PHALCON_CPY_WRT(widget_attributes, attributes); } phalcon_array_update_long(&widget_attributes, 0, &name, PH_COPY | PH_SEPARATE TSRMLS_CC); /** * Merge passed parameters with default ones */ PHALCON_OBS_VAR(default_attributes); phalcon_read_property_this(&default_attributes, this_ptr, SL("_attributes"), PH_NOISY_CC); if (Z_TYPE_P(default_attributes) == IS_ARRAY) { PHALCON_INIT_VAR(merged_attributes); phalcon_fast_array_merge(merged_attributes, &default_attributes, &widget_attributes TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_attributes, widget_attributes); } /** * Get the current element's value */ PHALCON_INIT_VAR(value); phalcon_call_method(value, this_ptr, "getvalue"); /** * If the widget has a value set it as default value */ if (Z_TYPE_P(value) != IS_NULL) { if (zend_is_true(use_checked)) { /** * Check if the element already has a default value, compare it with the one in the * attributes, if they are the same mark the element as checked */ if (phalcon_array_isset_string(merged_attributes, SS("value"))) { PHALCON_OBS_VAR(current_value); phalcon_array_fetch_string(¤t_value, merged_attributes, SL("value"), PH_NOISY_CC); if (PHALCON_IS_EQUAL(current_value, value)) { phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } } else { /** * Evaluate the current value and mark the check as checked */ if (zend_is_true(value)) { phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } phalcon_array_update_string(&merged_attributes, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } else { phalcon_array_update_string(&merged_attributes, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } RETURN_CCTOR(merged_attributes); }
/** * Renders a partial view * * <code> * //Show a partial inside another view * $this->partial('shared/footer'); * </code> * * <code> * //Show a partial inside another view with parameters * $this->partial('shared/footer', array('content' => $html)); * </code> * * @param string $partialPath * @param array $params */ PHP_METHOD(Phalcon_Mvc_View_Simple, partial){ zval *partial_path, *params = NULL, *view_params = NULL, *merged_params = NULL; zval *content; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); if (!params) { PHALCON_INIT_VAR(params); } /** * Start ouput buffering */ phalcon_ob_start(TSRMLS_C); /** * If the developer pass an array of variables we create a new virtual symbol table */ if (Z_TYPE_P(params) == IS_ARRAY) { PHALCON_OBS_VAR(view_params); phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); /** * Merge or assign the new params as parameters */ 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); } /** * Create a virtual symbol table */ phalcon_create_symbol_table(TSRMLS_C); } else { PHALCON_CPY_WRT(merged_params, params); } /** * Call engine render, this checks in every registered engine for the partial */ phalcon_call_method_p2_noret(this_ptr, "_internalrender", partial_path, merged_params); /** * Now we need to restore the original view parameters */ if (view_params != NULL) { /** * Restore the original view params */ phalcon_update_property_this(this_ptr, SL("_viewParams"), view_params TSRMLS_CC); } phalcon_ob_end_clean(TSRMLS_C); PHALCON_OBS_VAR(content); phalcon_read_property_this(&content, this_ptr, SL("_content"), PH_NOISY_CC); /** * Content is output to the parent view */ zend_print_zval(content, 0); PHALCON_MM_RESTORE(); }
/** * 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); }
/** * Adds a route applying the common attributes * * @param string $pattern * @param array $paths * @param array $httpMethods * @return Phalcon\Mvc\Router\Route */ PHP_METHOD(Phalcon_Mvc_Router_Group, _addRoute){ zval *pattern, *paths = NULL, *http_methods = NULL, prefix = {}, prefix_pattern = {}, default_paths = {}, merged_paths = {}; phalcon_fetch_params(0, 1, 2, &pattern, &paths, &http_methods); PHALCON_ENSURE_IS_STRING(pattern); if (!paths) { paths = &PHALCON_GLOBAL(z_null); } if (!http_methods) { http_methods = &PHALCON_GLOBAL(z_null); } phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY); if (Z_TYPE(prefix) != IS_STRING) { convert_to_string_ex(&prefix); } /** * Add the prefix to the pattern */ { const char *s_pattern = Z_STRVAL_P(pattern); /* NUL-terminated */ const char *s_prefix = Z_STRVAL(prefix); /* NUL-terminated */ int pattern_len = Z_STRLEN_P(pattern); int prefix_len = Z_STRLEN(prefix); if (prefix_len && *s_pattern == '/' && s_prefix[prefix_len-1] == '/') { char *new_pattern = safe_emalloc(prefix_len - 1 /* slash */ + 1 /* \0 */, 1, pattern_len); memcpy(new_pattern, s_prefix, prefix_len - 1); memcpy(new_pattern + prefix_len - 1, s_pattern, pattern_len + 1); ZVAL_STRINGL(&prefix_pattern, new_pattern, prefix_len + pattern_len - 1); } else { PHALCON_CONCAT_VV(&prefix_pattern, &prefix, pattern); } } phalcon_read_property(&default_paths, getThis(), SL("_paths"), PH_NOISY); /** * Check if the paths need to be merged with current paths */ if (Z_TYPE(default_paths) == IS_ARRAY && Z_TYPE_P(paths) == IS_ARRAY) { /** * Merge the paths with the default paths */ phalcon_fast_array_merge(&merged_paths, &default_paths, paths); } else { PHALCON_CPY_WRT(&merged_paths, paths); } /** * Every route is internally stored as a Phalcon\Mvc\Router\Route */ object_init_ex(return_value, phalcon_mvc_router_route_ce); PHALCON_CALL_METHODW(NULL, return_value, "__construct", &prefix_pattern, &merged_paths, http_methods); PHALCON_CALL_METHODW(NULL, return_value, "setgroup", getThis()); phalcon_update_property_array_append(getThis(), SL("_routes"), return_value); }