getName() . ' doesn\'t have a __constructor() function. Please provide one.');
}
/**
* Return Class name, useful when a list of installed plugins is need
*
* @return string
*/
public function getName(): string
{
return get_class($this);
}
static function setTsStartLoad()
{
self::$timeLoadStart = round(microtime(true) * 1000);
}
public function __destruct()
{
global $f3, $frameworkUtils;
if ($f3->get('DEBUG') > 2) {
$timeEnd = round(microtime(true) * 1000);
$totalMS = $timeEnd - self::$timeLoadStart;
$className = get_called_class();
$frameworkUtils->getLogger()->write("Class $className loaded in {$totalMS}ms", 'd/m/Y H:i:s');
}
}
/**
* Return default version for plugins that doesn't have one
*
* @return string
*/
public function getVersion(): string
{
return '1.0';
}
/**
* Add URL routing to the Route chain
*
* @param array|string $pattern
* @param string $handler
*/
public function AddRoute($pattern, string $handler)
{
global $f3;
$f3->route($pattern, $handler, 0); // TTL 60s
}
/**
* Add menu to application for the plugin, if another menu with same $menuName is present, the last added has priority on other.
*
* @param string $menuName Name of menu to add
* @param array $options the struct of OMLink Menu
*
*
* [
* 'menu_name' => 'Bind',
* 'url' => '/bind',
* 'isDisabled' => false
* ]
*/
public function AddMenuItem(string $menuName, array $options)
{
global $f3;
$defaults = [
'url' => '',
'isDisabled' => false,
'image' => '',
'permissionName' => null,
'order' => 99999
];
$newMenu = array_merge($defaults, $options);
$globalMenuUpdated = $f3->get('GLOBALMENU');
$globalMenuUpdated[$menuName] = $newMenu;
// If user logged check permission
$user = User::Restore();
if (!$user->dry()) {
$hasMenuPermissionRequirements = !is_null($newMenu['permissionName']);
if (!$hasMenuPermissionRequirements || ($hasMenuPermissionRequirements && $user->hasPermission($newMenu['permissionName']))) {
$f3->set('GLOBALMENU', $globalMenuUpdated);
}
}
}
}