Skip to content

Commit

Permalink
Standardize PHP Function Naming Convention
Browse files Browse the repository at this point in the history
  • Loading branch information
taufik-nurrohman committed Jun 9, 2020
1 parent b930ef5 commit e776284
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ GUI Extension for Mecha
Release Notes
-------------

### 2.3.1

- Improved function naming convention. PHP functions should conform to the snake-case naming convention (e.g. `a_b__c\d`).

### 2.3.0

- Moved from `Pjax` to `F3H`.
Expand Down
2 changes: 1 addition & 1 deletion panel/about.page
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Panel
description: GUI extension for Mecha.
author: Taufik Nurrohman
type: Markdown
version: 2.3.0
version: 2.3.1

use:
'.\lot\x\layout': 1
Expand Down
24 changes: 16 additions & 8 deletions panel/engine/f.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function button($in, $key) {
function field($in, $key) {
$tags = ['field', 'p'];
if (isset($in['type'])) {
$tags[] = \strtr(\p2f($in['type'], '-', '/'), ['/' => ':']);
$tags[] = \strtr($in['type'], '/', ':');
}
$id = $in['id'] ?? 'f:' . \dechex(\time());
$in[2]['id'] = $in[2]['id'] ?? \str_replace('f:', 'field:', $id);
Expand Down Expand Up @@ -93,7 +93,11 @@ function fields($in) {
continue;
}
$type = $v['type'] ?? null;
if (\function_exists($fn = \rtrim(__NAMESPACE__ . "\\" . \f2p(\strtr($type, '/', '.')), "\\"))) {
if ($type && \function_exists($fn = __NAMESPACE__ . "\\" . \strtr($type, [
'/' => "\\",
'-' => '_',
'.' => '__'
]))) {
if ('field/hidden' !== $type) {
$out[1] .= \call_user_func($fn, $v, $k);
} else {
Expand Down Expand Up @@ -567,7 +571,7 @@ function content($in, $key) {
$out[1] .= \_\lot\x\panel\h\content($in['content']);
}
$out[2] = \array_replace([
'class' => 'count:1 lot' . (isset($type) ? ' lot:' . \implode(' lot:', \step(\c2f($type))) : ""),
'class' => 'count:1 lot' . (isset($type) ? ' lot:' . \implode(' lot:', \step(\strtr($type, '/', '.'))) : ""),
'id' => $in['id'] ?? null
], $out[2]);
return new \HTML($out);
Expand All @@ -586,7 +590,7 @@ function lot($in, $key) {
$out[1] .= \_\lot\x\panel\h\lot($in['lot'], null, $count);
}
$out[2] = \array_replace([
'class' => 'count:' . $count . ' lot' . (isset($type) ? ' lot:' . \implode(' lot:', \step(\c2f($type))) : ""),
'class' => 'count:' . $count . ' lot' . (isset($type) ? ' lot:' . \implode(' lot:', \step(\strtr($type, '/', '.'))) : ""),
'id' => $in['id'] ?? null
], $out[2]);
return new \HTML($out);
Expand All @@ -602,11 +606,15 @@ function panel($in, $key) {
return "";
}
$out = "";
if ($type = isset($in['type']) ? \f2p(\strtr($in['type'], '/', '.')) : null) {
if (\function_exists($fn = \rtrim(__NAMESPACE__ . "\\panel\\" . $type, "\\"))) {
if ($type = isset($in['type']) ? \strtr($in['type'], [
'/' => "\\",
'-' => '_',
'.' => '__'
]) : null) {
if ($type && \function_exists($fn = __NAMESPACE__ . "\\panel\\" . $type)) {
$out .= \call_user_func($fn, $in, $key);
} else if (isset($in['content'])) {
if (\function_exists($fn = \rtrim(__NAMESPACE__ . "\\panel\\content\\" . $type, "\\"))) {
if ($type && \function_exists($fn = __NAMESPACE__ . "\\panel\\content\\" . $type)) {
$out .= \call_user_func($fn, $in, $key);
} else {
if (\defined("\\DEBUG") && \DEBUG) {
Expand All @@ -615,7 +623,7 @@ function panel($in, $key) {
$out .= \_\lot\x\panel\content($in, $key);
}
} else if (isset($in['lot'])) {
if (\function_exists($fn = \rtrim(__NAMESPACE__ . "\\panel\\lot\\" . $type, "\\"))) {
if ($type && \function_exists($fn = __NAMESPACE__ . "\\panel\\lot\\" . $type)) {
$out .= \call_user_func($fn, $in, $key);
} else {
if (\defined("\\DEBUG") && \DEBUG) {
Expand Down
8 changes: 4 additions & 4 deletions panel/engine/f/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ function date($in, $key) {
if (!isset($in['pattern'])) {
$in['pattern'] = "^[1-9]\\d{3,}-(0\\d|1[0-2])-(0\\d|[1-2]\\d|3[0-1])$";
}
return \_\lot\x\panel\field\dateTime($in, $key);
return \_\lot\x\panel\field\date_time($in, $key);
}

function dateTime($in, $key) {
function date_time($in, $key) {
if (!isset($in['alt'])) {
$in['alt'] = \date('Y-m-d H:i:s');
}
Expand Down Expand Up @@ -418,7 +418,7 @@ function time($in, $key) {
if (!isset($in['pattern'])) {
$in['pattern'] = "^([0-1]\\d|2[0-4])(:([0-5]\\d|60)){1,2}$";
}
$out = \_\lot\x\panel\field\dateTime($in, $key);
$out = \_\lot\x\panel\field\date_time($in, $key);
return $out;
}

Expand All @@ -440,7 +440,7 @@ function toggle($in, $key) {
return \_\lot\x\panel\field($out, $key);
}

function URL($in, $key) {
function u_r_l($in, $key) {
if (!isset($in['alt'])) {
$url = $GLOBALS['url'];
$in['alt'] = \S . $url->protocol . \S . $url->host . \S;
Expand Down
2 changes: 1 addition & 1 deletion panel/engine/f/h.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function p(&$lot, $prefix) {
// Add prefix to `type`
$type = $prefix . '/' . $type;
}
$v['type'] = $type;
$v['type'] = \trim($type, '/');
}
unset($v);
}
Expand Down

0 comments on commit e776284

Please sign in to comment.