Changes:
- added some documentation - added type-hints
This commit is contained in:
parent
97904ea7dd
commit
14bf72e4fe
6 changed files with 67 additions and 51 deletions
|
@ -47,7 +47,7 @@ function fbrowser_content(App $a)
|
|||
}
|
||||
|
||||
// Needed to match the correct template in a module that uses a different theme than the user/site/default
|
||||
$theme = Strings::sanitizeFilePathItem($_GET['theme'] ?? null);
|
||||
$theme = Strings::sanitizeFilePathItem($_GET['theme'] ?? '');
|
||||
if ($theme && is_file("view/theme/$theme/config.php")) {
|
||||
$a->setCurrentTheme($theme);
|
||||
}
|
||||
|
|
|
@ -116,8 +116,7 @@ HELP;
|
|||
/**
|
||||
* Lists plugins
|
||||
*
|
||||
* @return int Return code of this command
|
||||
*
|
||||
* @return int|bool Return code of this command, false on error (?)
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function list()
|
||||
|
@ -165,10 +164,9 @@ HELP;
|
|||
* Enables an addon
|
||||
*
|
||||
* @return int Return code of this command
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function enable()
|
||||
private function enable(): int
|
||||
{
|
||||
$addonname = $this->getArgument(1);
|
||||
|
||||
|
@ -190,10 +188,9 @@ HELP;
|
|||
* Disables an addon
|
||||
*
|
||||
* @return int Return code of this command
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function disable()
|
||||
private function disable(): int
|
||||
{
|
||||
$addonname = $this->getArgument(1);
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ class Addon
|
|||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function uninstall($addon)
|
||||
public static function uninstall(string $addon)
|
||||
{
|
||||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
|
@ -149,7 +149,7 @@ class Addon
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function install($addon)
|
||||
public static function install(string $addon): bool
|
||||
{
|
||||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
|
@ -185,6 +185,8 @@ class Addon
|
|||
|
||||
/**
|
||||
* reload all updated addons
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function reload()
|
||||
{
|
||||
|
@ -222,7 +224,7 @@ class Addon
|
|||
* @return array with the addon information
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getInfo($addon)
|
||||
public static function getInfo(string $addon): array
|
||||
{
|
||||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
|
@ -287,7 +289,7 @@ class Addon
|
|||
* @param string $addon
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEnabled($addon)
|
||||
public static function isEnabled(string $addon): bool
|
||||
{
|
||||
return in_array($addon, self::$addons);
|
||||
}
|
||||
|
@ -297,7 +299,7 @@ class Addon
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getEnabledList()
|
||||
public static function getEnabledList(): array
|
||||
{
|
||||
return self::$addons;
|
||||
}
|
||||
|
@ -308,7 +310,7 @@ class Addon
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getVisibleList()
|
||||
public static function getVisibleList(): array
|
||||
{
|
||||
$visible_addons = [];
|
||||
$stmt = DBA::select('addon', ['name'], ['hidden' => false, 'installed' => true]);
|
||||
|
|
|
@ -49,6 +49,8 @@ class Hook
|
|||
|
||||
/**
|
||||
* Load hooks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function loadHooks()
|
||||
{
|
||||
|
@ -69,8 +71,9 @@ class Hook
|
|||
* @param string $hook
|
||||
* @param string $file
|
||||
* @param string $function
|
||||
* @return void
|
||||
*/
|
||||
public static function add($hook, $file, $function)
|
||||
public static function add(string $hook, string $file, string $function)
|
||||
{
|
||||
if (!array_key_exists($hook, self::$hooks)) {
|
||||
self::$hooks[$hook] = [];
|
||||
|
@ -90,7 +93,7 @@ class Hook
|
|||
* @return mixed|bool
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function register($hook, $file, $function, $priority = 0)
|
||||
public static function register(string $hook, string $file, string $function, int $priority = 0)
|
||||
{
|
||||
$file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
|
||||
|
||||
|
@ -111,7 +114,7 @@ class Hook
|
|||
* @return boolean
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function unregister($hook, $file, $function)
|
||||
public static function unregister(string $hook, string $file, string $function): bool
|
||||
{
|
||||
$relative_file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
|
||||
|
||||
|
@ -120,8 +123,8 @@ class Hook
|
|||
self::delete($condition);
|
||||
|
||||
$condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
|
||||
$result = self::delete($condition);
|
||||
return $result;
|
||||
|
||||
return self::delete($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +133,7 @@ class Hook
|
|||
* @param string $name Name of the hook
|
||||
* @return array
|
||||
*/
|
||||
public static function getByName($name)
|
||||
public static function getByName(string $name): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
|
@ -149,9 +152,10 @@ class Hook
|
|||
* @param integer $priority of the hook
|
||||
* @param string $name of the hook to call
|
||||
* @param mixed $data to transmit to the callback handler
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function fork($priority, $name, $data = null)
|
||||
public static function fork(int $priority, string $name, $data = null)
|
||||
{
|
||||
if (array_key_exists($name, self::$hooks)) {
|
||||
foreach (self::$hooks[$name] as $hook) {
|
||||
|
@ -184,9 +188,10 @@ class Hook
|
|||
*
|
||||
* @param string $name of the hook to call
|
||||
* @param string|array &$data to transmit to the callback handler
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function callAll($name, &$data = null)
|
||||
public static function callAll(string $name, &$data = null)
|
||||
{
|
||||
if (array_key_exists($name, self::$hooks)) {
|
||||
foreach (self::$hooks[$name] as $hook) {
|
||||
|
@ -202,9 +207,10 @@ class Hook
|
|||
* @param string $name of the hook to call
|
||||
* @param array $hook Hook data
|
||||
* @param string|array &$data to transmit to the callback handler
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function callSingle(App $a, $name, $hook, &$data = null)
|
||||
public static function callSingle(App $a, string $name, array $hook, &$data = null)
|
||||
{
|
||||
// Don't run a theme's hook if the user isn't using the theme
|
||||
if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
|
||||
|
@ -229,7 +235,7 @@ class Hook
|
|||
* @param string $name Name of the addon
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isAddonApp($name)
|
||||
public static function isAddonApp(string $name): bool
|
||||
{
|
||||
$name = Strings::sanitizeFilePathItem($name);
|
||||
|
||||
|
@ -253,7 +259,7 @@ class Hook
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function delete(array $condition)
|
||||
public static function delete(array $condition): bool
|
||||
{
|
||||
$result = DBA::delete('hook', $condition);
|
||||
|
||||
|
@ -273,7 +279,7 @@ class Hook
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function insert(array $condition)
|
||||
private static function insert(array $condition): bool
|
||||
{
|
||||
$result = DBA::insert('hook', $condition);
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ class L10n
|
|||
private function setLangFromSession(IHandleSessions $session)
|
||||
{
|
||||
if ($session->get('language') !== $this->lang) {
|
||||
$this->loadTranslationTable($session->get('language'));
|
||||
$this->loadTranslationTable($session->get('language') ?? $this->lang);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,10 +140,10 @@ class L10n
|
|||
* Uses an App object shim since all the strings files refer to $a->strings
|
||||
*
|
||||
* @param string $lang language code to load
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function loadTranslationTable($lang)
|
||||
private function loadTranslationTable(string $lang)
|
||||
{
|
||||
$lang = Strings::sanitizeFilePathItem($lang);
|
||||
|
||||
|
@ -183,7 +183,7 @@ class L10n
|
|||
*
|
||||
* @return string The two-letter language code
|
||||
*/
|
||||
public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT)
|
||||
public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT): string
|
||||
{
|
||||
$lang_variable = $server['HTTP_ACCEPT_LANGUAGE'] ?? null;
|
||||
|
||||
|
@ -269,7 +269,7 @@ class L10n
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function t($s, ...$vars)
|
||||
public function t(array $s, ...$vars): string
|
||||
{
|
||||
if (empty($s)) {
|
||||
return '';
|
||||
|
@ -307,7 +307,7 @@ class L10n
|
|||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function tt(string $singular, string $plural, int $count)
|
||||
public function tt(string $singular, string $plural, int $count): string
|
||||
{
|
||||
$s = null;
|
||||
|
||||
|
@ -352,7 +352,7 @@ class L10n
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function stringPluralSelectDefault($n)
|
||||
private function stringPluralSelectDefault(int $n): bool
|
||||
{
|
||||
return $n != 1;
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ class L10n
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableLanguages()
|
||||
public static function getAvailableLanguages(): array
|
||||
{
|
||||
$langs = [];
|
||||
$strings_file_paths = glob('view/lang/*/strings.php');
|
||||
|
@ -391,10 +391,9 @@ class L10n
|
|||
* Translate days and months names.
|
||||
*
|
||||
* @param string $s String with day or month name.
|
||||
*
|
||||
* @return string Translated string.
|
||||
*/
|
||||
public function getDay($s)
|
||||
public function getDay(string $s): string
|
||||
{
|
||||
$ret = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
||||
[$this->t('Monday'), $this->t('Tuesday'), $this->t('Wednesday'), $this->t('Thursday'), $this->t('Friday'), $this->t('Saturday'), $this->t('Sunday')],
|
||||
|
@ -411,10 +410,9 @@ class L10n
|
|||
* Translate short days and months names.
|
||||
*
|
||||
* @param string $s String with short day or month name.
|
||||
*
|
||||
* @return string Translated string.
|
||||
*/
|
||||
public function getDayShort($s)
|
||||
public function getDayShort(string $s): string
|
||||
{
|
||||
$ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
||||
[$this->t('Mon'), $this->t('Tue'), $this->t('Wed'), $this->t('Thu'), $this->t('Fri'), $this->t('Sat'), $this->t('Sun')],
|
||||
|
@ -435,7 +433,7 @@ class L10n
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @hook poke_verbs pokes array
|
||||
*/
|
||||
public function getPokeVerbs()
|
||||
public function getPokeVerbs(): array
|
||||
{
|
||||
// index is present tense verb
|
||||
// value is array containing past tense verb, translation of present, translation of past
|
||||
|
@ -461,7 +459,7 @@ class L10n
|
|||
* @return static A new L10n instance
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function withLang(string $lang)
|
||||
public function withLang(string $lang): L10n
|
||||
{
|
||||
// Don't create a new instance for same language
|
||||
if ($lang === $this->lang) {
|
||||
|
|
|
@ -32,7 +32,7 @@ require_once 'boot.php';
|
|||
*/
|
||||
class Theme
|
||||
{
|
||||
public static function getAllowedList()
|
||||
public static function getAllowedList(): array
|
||||
{
|
||||
$allowed_themes_str = DI::config()->get('system', 'allowed_themes');
|
||||
$allowed_themes_raw = explode(',', str_replace(' ', '', $allowed_themes_str));
|
||||
|
@ -69,7 +69,7 @@ class Theme
|
|||
* @param string $theme the name of the theme
|
||||
* @return array
|
||||
*/
|
||||
public static function getInfo($theme)
|
||||
public static function getInfo(string $theme): array
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -133,7 +133,7 @@ class Theme
|
|||
* @return string
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function getScreenshot($theme)
|
||||
public static function getScreenshot(string $theme): string
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -146,7 +146,13 @@ class Theme
|
|||
return DI::baseUrl() . '/images/blank.png';
|
||||
}
|
||||
|
||||
public static function uninstall($theme)
|
||||
/**
|
||||
* Uninstalls given theme name
|
||||
*
|
||||
* @param string $theme Name of theme
|
||||
* @return bool true on success
|
||||
*/
|
||||
public static function uninstall(string $theme)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -167,10 +173,18 @@ class Theme
|
|||
if ($key !== false) {
|
||||
unset($allowed_themes[$key]);
|
||||
Theme::setAllowedList($allowed_themes);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function install($theme)
|
||||
/**
|
||||
* Installs given theme name
|
||||
*
|
||||
* @param string $theme Name of theme
|
||||
* @return bool true on success
|
||||
*/
|
||||
public static function install(string $theme): bool
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -208,7 +222,7 @@ class Theme
|
|||
* @return string Path to the file or empty string if the file isn't found
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPathForFile($file)
|
||||
public static function getPathForFile(string $file): string
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
|
@ -237,10 +251,9 @@ class Theme
|
|||
* Provide a sane default if nothing is chosen or the specified theme does not exist.
|
||||
*
|
||||
* @param string $theme Theme name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getStylesheetPath($theme)
|
||||
public static function getStylesheetPath(string $theme): string
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -263,10 +276,10 @@ class Theme
|
|||
/**
|
||||
* Returns the path of the provided theme
|
||||
*
|
||||
* @param $theme
|
||||
* @param string $theme Theme name
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getConfigFile($theme)
|
||||
public static function getConfigFile(string $theme)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -285,11 +298,11 @@ class Theme
|
|||
/**
|
||||
* Returns the background color of the provided theme if available.
|
||||
*
|
||||
* @param string $theme
|
||||
* @param string $theme Theme name
|
||||
* @param int|null $uid Current logged-in user id
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getBackgroundColor(string $theme, $uid = null)
|
||||
public static function getBackgroundColor(string $theme, int $uid = null)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
|
Loading…
Reference in a new issue