Hello,
I have added some more convenient features for developers if they wish to use them in this new version. There are still many more changes I will have to stage in the near future, but for now there are a few minor, interesting tweaks.
Database transaction support
You can now use the shorthand `db_transaction` with a closure to do a database transaction. However, make sure you convert all your tables to a transaction supported table (such as InnoDB) before hand:
$result = db_transaction(function () { db_query('DELETE FROM ?:orders WHERE 1 LIMIT 1'); throw new DeveloperException("Oh no, we encountered an error!"); return "We deleted the order and no exception occurred"; });
Fully qualified class names as hook handlers
Hook handlers just got a bit easier to manage with some changes in how hook handlers are resolved. You can now pass a FQCN as a valid hook handler when using the new object oriented style for your addons:
<?php namespace Tygh\Addons\Example; use Tygh\Core\ApplicationInterface; use Tygh\Core\BootstrapInterface; use Tygh\Core\HookHandlerProviderInterface; /** * Class Bootstrap * @package Tygh\Addons\Example */ class Bootstrap implements BootstrapInterface, HookHandlerProviderInterface { /** * @inheritDoc */ public function boot(ApplicationInterface $app): void { $app->register(new ServiceProvider()); } /** * @inheritDoc */ public function getHookHandlerMap(): array { return [ 'get_orders' => [ HookHandlers\OrdersHookHandler::class, 'onGetOrders', ], ]; } }
A new hook that allows you to log exceptions to e.g. Sentry
Like the title mentions, there is a new hook that now allows you to handle an exception before it is thrown by CsCart. You can take a look at `app/Tygh/Tools/ErrorHandler.php`.
/** * Allows to process a fatal exception. * * @param Throwable $exception The un-caught exception to be handled. */ fn_set_hook('error_handler_handle_exception', $exception);