[size=6]Common changes[/size][list]
[]REST API: “HTTP/1.1 204 No Content” status is now returned when DELETE request succeed by all API entities.
[]In development mode, JavaScript errors are now displayed at document body.
[]Smarty plugin array_to_fields was added. It converts given array to HTML hidden fields.
[]Smarty library is now required via Composer.
[]Storage type “statics” was renamed to “assets”. However, backward compatibility preserved. The storage type is set in config.local.php.
[]Custom PHP error handlers were implemented. They are being registered at new fn_init_error_handler() initializer function.
[list]
[]PHP fatal errors are now being caught — the “Service unavailable” page will appear in case of a fatal error in production mode.
[]PHP non-fatal errors, warnings and notices are being caught and properly formatted now (in development mode only and if xdebug extension is not installed).
[/list]
[/list]
[size=6]Hook changes[/size]
-fn_set_hook('create_seo_name_pre', $object_id, $object_type, $object_name, $index, $dispatch, $company_id, $lang_code);
+fn_set_hook('create_seo_name_pre', $object_id, $object_type, $object_name, $index, $dispatch, $company_id, $lang_code, $params);
-fn_set_hook('create_seo_name_post', $_object_name, $object_id, $object_type, $object_name, $index, $dispatch, $company_id, $lang_code);
+fn_set_hook('create_seo_name_post', $_object_name, $object_id, $object_type, $object_name, $index, $dispatch, $company_id, $lang_code, $params);
[size=6]Core functions[/size]
[size=5]Changed functions[/size][list]
[]fn_create_seo_name(): $params parameter added:
[list]
* $params['use_generated_paths_cache'] - Whether to cache fn_get_seo_parent_path() calls.
[]-function fn_create_seo_name($object_id, $object_type, $object_name, $index = 0, $dispatch = '', $company_id = '', $lang_code = CART_LANGUAGE, $create_redirect = false, $area = AREA)
+function fn_create_seo_name($object_id, $object_type, $object_name, $index = 0, $dispatch = '', $company_id = '', $lang_code = CART_LANGUAGE, $create_redirect = false, $area = AREA, $params = array())
[/list][]fn_get_seo_parent_path(): $use_caching parameter added. It indicates whether to cache results of path_function calls.
[list]
[]-function fn_get_seo_parent_path($object_id, $object_type, $company_id = 0)
+function fn_get_seo_parent_path($object_id, $object_type, $company_id = 0, $use_caching = true)
[/list][]fn_generate_seo_url_from_schema(): $company_id parameter added.
[list]
[]-function fn_generate_seo_url_from_schema($redirect_data, $full = true, $query_string = array())
+function fn_generate_seo_url_from_schema($redirect_data, $full = true, $query_string = array(), $company_id = null)
[/list][]fn_exim_parse_data(): $is_option parameter added.
[list]
[]-function fn_exim_parse_data($data, $variants_delimiter = ',', $features_delimiter = '///')
+function fn_exim_parse_data($data, $variants_delimiter = ',', $features_delimiter = '///', $is_option = false)
[/list][]fn_settings_actions_general_secure_storefront(): renamed to fn_settings_actions_security_secure_storefront().
[]fn_settings_actions_general_secure_admin(): renamed to fn_settings_actions_security_secure_admin().
[/list]
[size=5]New functions[/size][list]
[]fn_array_column($array, $column_key, $index_key = null): a polyfill for PHP 5.5 array_column function.
[]fn_get_runtime_company_id(): returns runtime company_id in any mode.
[]fn_clear_ob(): clears output buffers' contents.
[]fn_get_supported_image_format_variants(): returns list of supported image formats to be used as setting variants.
[]Tygh\Tools\ImageHelper class added.
[list]
[]ImageHelper::calculateTextSize($string, FontInterface $font) - Calculates size for bounding box of text written in given font.
[]ImageHelper::positionLayerOnCanvas(BoxInterface $canvas_size, BoxInterface $layer_size, $horizontal_position, $vertical_position, BoxInterface $padding = null) - Calculates coordinates of top left corner of layer that should be positioned on canvas using given vertical and horizontal positions.
[]ImageHelper::getSupportedFormats() - Returns image formats, supported by current image manipulation driver. The only formats that being checked are jpg, png and gif.
[/list][]fn_init_error_handler(): registers custom error handlers.
[]fn_init_imagine(): registers image manipulation library object at Application container.
[/list]
[size=5]Deprecated functions[/size]
Deprecated functions are still working, but will be removed in the next major release (CS-Cart 5.)[list]
[]fn_create_image_from_file()
[]fn_check_gd_formats(): use fn_get_supported_image_format_variants() instead.
[]fn_parse_rgb(): use Imagine\Image\Palette\RGB class instead.
[/list]
[size=6]Imagine[/size]
The Imagine library is used in CS-Cart 4.3.2 core for working with images instead of the self written solution. External interfaces for working with images stayed unchangable (fn_resize_image(), for example). But the Imagine class object is available in the Application container and can be used directly, if needed:
/** @var $imagine Imagine\Image\ImagineInterface **/
$imagine = Tygh::$app['image'];
$imagine->open('/path/to/large_image.jpg')
->thumbnail($size, $mode)
->save('/path/to/thumbnail.png');
More information about the Imagine library you can find here: http://imagine.readt…org/en/latest/.
The auto variant appeared in the $config['tweaks']['image_resize_lib'] setting. It is used by default. If this variant is set up, the driver used for images manipulation (Imagick/GD) is chosen automatically based on the php-imagick extension availability. In another words, if the php-imagick extension is installed on server, Imagick is used for working with images, in another case - GD will.
[size=6]Application[/size]
The new Tygh\Application functionality appeared in CS-Cart 4.3.2
The Application class object is created when initializing the core in the init.php file. After that it is available from every part of code:
// to get the Application object
Tygh::$app
If the object is needed to retrieve inside a file with the namespace, the call looks as follows:
// to get the Application object inside a file with the namespace
\Tygh::$app
Its single purpose at the moment is the IoC container that stores objects and factory anonimous functions for creating objects.
[size=5]IoC container[/size]
Earlier the Registry class stored objects. It was also used to store cache and other runtime-data.
// before
$smarty = Registry::get('view');
// now
$smarty = Tygh::$app['view'];
The main difference between the Application container and Registry class is the lazy objects initialization in the Application.
Objects stored in a container are called services. In most cases they are components of larger system that have their own area of responsibility. For example, sending e-mail messages or database connection, etc.
// register an object in a container using an anonymous factory function
Tygh::$app['foo'] = function($app) {
return new Tygh\Foo();
};
Tygh::$app['bar'] = function($app) {
return new Tygh\Bar($app['foo']);
};
// no object was created by this moment, they will be created on demand
// Application will return the anonymous factory function call result.
// Besides, the Tygh\Bar class constructor will get the result of calling another factory function.
$bar_instance = Tygh::$app['bar'];
// the line above equals the following code:
// $foo_instance = new Tygh\Foo();
// $bar_instance = new Tygh\Bar($foo_instance);
// if getting service from a container again, the same object is returned (a new one is not created).
var_dump($bar_instance === Tygh::$app['bar']); // true
// if we want a NEW object to be returned EACH TIME we get a service,
// we should wrap the anonymous factory function like this when initializing service:
Tygh::$app['cool_service'] = Tygh::$app->factory(function($app) {
return new Tygh\CoolService();
});
// these are different objects
$a = Tygh::$app['cool_service'];
$b = Tygh::$app['cool_service'];
$c = Tygh::$app['cool_service'];
// apart from the mentioned methods it is possible to simply put an object to a container,
// it is the behaviour Registry provided
Tygh::$app['my_object'] = new Tygh\MyClass();
Here you can read more about the advanced container usage: [url=“http://pimple.sensiolabs.org/.”]http://pimple.sensiolabs.org/.[/url]
[size=5]Backwards compatibility[/size]
For the backwards compatibility Registry redirects the api, crypt, view, ajax, and class_loader services calls to a container.
So, the code using Registry::get('view|ajax|crypt|api|class_loader') will function in the same manner without modifications.
Appllication was added to improve system architecture and testing its components.