The startup file is connected at the moment the hack is initialized. He is responsible for the preliminary settings of the hack and the preparation of handlers.
Configuration array
The hack initialization file should end with returning an array that contains the hack configuration: launch functions, delivery and ad networks handlers, scheduler tasks, API functions.
The keys of this array will be the names of the corresponding configurations. Values - arrays with a list of files, functions or settings. If the function or file is a single instance, you can use a string instead of an array.
Available keys:
init
- hack initialization function.api
- list of API application files.api-auth
- API functions authorization (always just an array).cron-1min
- list of files for scheduler, which is executed once a minute (quick tasks).cron-3min
- list of files for scheduler, which is executed once a 3 minutes (high duration tasks).cron-10min
- list of files for scheduler, which is executed once a 10 minutes (medium duration tasks).cron-1day
- list of files for scheduler, which is executed once a day (very long tasks)tpl
- overriding system templates.lib
- overriding system libraries.delivery
- handlers for delivery services.adv
- handlers for ad networks.
Return array example:
return [ 'init' => [ 'hack_proxy_init'], 'api' => [ 'proxy', 'wm' ], 'api-auth' => [ [ 'proxy', [ 'check', 'list', 'add', 'del' ], [ 'wm', 'getproxy' ] ], 'cron-3min' => [ 'checker' ], ];
Initialization function
Immediately after loading all modules, the system starts their initialization functions.
The task of the function is to prepare all the handlers that are used in the system. It is not recommended to perform any complex actions during initialization.
An example of an initialization function:
function hack_proxy_init( $core ) { $core->handle( 'modules', 'hack_proxy_route' ); $core->handle( 'menu', 'hack_proxy_menu' ); }
Handlers and filters
The filter and handler toolkit allows you to call functions and change some data on the fly.
A new handler is added by the handle
function:
$core->handle( $place, $function );
Where $place
is the place of the handler and $function
is the name of the function to be called.
Example:
$core->handle( 'modules', 'hack_proxy_route' );
There are many points in the system to which you can catch. Here are some of the more useful ones.:
modules
- place to install routing functions, executed before system routing.actions
- place for preparatory actions, executed right before modules handlers.menu
is a filter that prepares the navigation menu. Takes a menu as the second parameter and should return an augmented variant.newmenu
- menu post-processing filter. Runs on a pre-made menu array.header
- executed before displaying the top block of the site, after preparing the block.footer
- executed before the site footer is displayed, after the block is prepared.medialibs
- filter the list of libraries for loading files.
Check with technical support for the availability of the filter or handler you need. New filters can be added at your request, as appropriate.
Example of a finished start file
This is what the start file for a hack called proxy
would look like, which has several sections, an API with authorization, and scheduler tasks.
<?php // Startup function hack_proxy_init( $core ) { $core->handle( 'modules', 'hack_proxy_route' ); } // Routing function hack_proxy_route( $core ) { switch ( $core->app->div ) { case 'proxy-list': $core->hack->proxy->mod( 'listing', 'hack_proxy_list' ); case 'proxy-check': $core->hack->proxy->mod( 'listing', 'hack_proxy_check' ); case 'proxy-stats': $core->hack->proxy->mod( 'stats’, 'hack_proxy_stats' ); } } // Configuration return [ 'init' => [ 'hack_proxy_init'], 'api' => [ 'proxy' ], 'api-auth' => [ [ 'proxy', [ 'check', 'list', 'add', 'del' ], ], 'cron-3min' => [ 'checker' ], 'cron-1day' => [ 'stats' ], ];