The main working file of the hack contains a class that is responsible for configuration parameters, loading modules and libraries, connecting templates, styles and scripts. The class can be extended with any additional functions.
Built-in class functions
Methods and fields of a class are accessed by calling:
$core->hack->hackname->funcname()
Instead of hackname
, the name of the class is indicated, instead of funcname
- the corresponding function or field.
$core->hack->(name)->conf[$field]
Array with hack config, use read only.
$core->hack->(name)->conf( $field, $val = null )
Returns or changes the configuration of the hack depending on the parameters:
- When called without parameters, returns the entire configuration array.
- When called with one parameter
$field
- returns the value of a specific field. - When called with
$field
and$val
parameters, sets the$field
field to$val
.< /li>
$core->hack->(name)->(library)
Loads and returns the corresponding hack library. The library is loaded and initialized once. Usage example:
$core->hack->proxy->checker->run( 123 );
$core->hach->(name)->mod( $name, $func = false )
Loads the module named $name
. If the function name $func
is passed, immediately executes the specified function. Convenient for implementing routing.
$core->hack->(name)->tpl( $part, $name )
Loads the $part
section template named $name
from the templates folder. The .tpl extension is not specified.
$core->hack->(name)->css( $name )
Includes a CSS file named $name
from the styles folder. The .css extension is not specified.
$core->hack->(name)->js( $name )
Includes a JS file named $name
from the scripts folder. The .js extension is not specified.
Main file syntax
The file main.php
is responsible for extending the main hack class. It should contain a class called hack_name
, where name
will be the name of the hack. The class must inherit from thehack
. For example:
class hack_proxy extends thehack { … }
Do not override the built-in class constructor and destructor, they are responsible for the work of internal functions. Use init
as a constructor, stop
as a destructor. Both functions have no parameters. For example:
class hack_proxy extends thehack { public function init() { // Constructor functionality } public function stop() { // Destructor functionality } }
If you don't plan to extend the hack's main class and use only built-in functions, you can remove the main.php
file from the folder manually.