return type tagging
This commit is contained in:
@@ -26,9 +26,9 @@ function main(): void {
|
|||||||
|
|
||||||
$pbdb = pull_db();
|
$pbdb = pull_db();
|
||||||
|
|
||||||
prepend_contact_list($pbdb);
|
|
||||||
blacklist_terms($pbdb);
|
blacklist_terms($pbdb);
|
||||||
filter_extensions($pbdb);
|
filter_extensions($pbdb);
|
||||||
|
prepend_contact_list($pbdb);
|
||||||
|
|
||||||
|
|
||||||
$mac_list = pull_mac_list();
|
$mac_list = pull_mac_list();
|
||||||
@@ -41,8 +41,8 @@ function main(): void {
|
|||||||
$file = $PROVISION_DIR . '/' . $mac . '-features.cfg';
|
$file = $PROVISION_DIR . '/' . $mac . '-features.cfg';
|
||||||
|
|
||||||
$xml = pull_xml_file($file);
|
$xml = pull_xml_file($file);
|
||||||
$attendant = remove_attendants($xml);
|
$attendants = remove_attendants($xml);
|
||||||
write_attendants($attendant, $pbdb);
|
write_attendants($attendants, $pbdb);
|
||||||
write_to_file($file, $xml);
|
write_to_file($file, $xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ function pull_db(): array {
|
|||||||
return $pbdb;
|
return $pbdb;
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter_extensions(&$pbdb) {
|
function filter_extensions(array &$pbdb): null {
|
||||||
global $LIST_FILTER_TYPE;
|
global $LIST_FILTER_TYPE;
|
||||||
|
|
||||||
if ($LIST_FILTER_TYPE == "whitelist") {
|
if ($LIST_FILTER_TYPE == "whitelist") {
|
||||||
@@ -91,7 +91,7 @@ function filter_extensions(&$pbdb) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function blacklist_terms(&$pbdb) {
|
function blacklist_terms(array &$pbdb): null {
|
||||||
global $BLACKLISTED_TERMS;
|
global $BLACKLISTED_TERMS;
|
||||||
|
|
||||||
$pbdb = array_values(array_filter($pbdb, function ($item) use ($BLACKLISTED_TERMS) {
|
$pbdb = array_values(array_filter($pbdb, function ($item) use ($BLACKLISTED_TERMS) {
|
||||||
@@ -110,7 +110,7 @@ function blacklist_terms(&$pbdb) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function whitelist_extension_filter(&$pbdb) {
|
function whitelist_extension_filter(array &$pbdb): null {
|
||||||
global $EXTENSION_FILTER_LIST;
|
global $EXTENSION_FILTER_LIST;
|
||||||
|
|
||||||
$allowed = array_fill_keys(
|
$allowed = array_fill_keys(
|
||||||
@@ -128,7 +128,7 @@ function whitelist_extension_filter(&$pbdb) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function blacklist_extension_filter(&$pbdb) {
|
function blacklist_extension_filter(array &$pbdb): null {
|
||||||
global $EXTENSION_FILTER_LIST;
|
global $EXTENSION_FILTER_LIST;
|
||||||
|
|
||||||
$blocked = array_fill_keys(
|
$blocked = array_fill_keys(
|
||||||
@@ -146,7 +146,7 @@ function blacklist_extension_filter(&$pbdb) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepend_contact_list(&$pbdb) {
|
function prepend_contact_list(array &$pbdb): null {
|
||||||
global $PREPEND_EXTENSIONS;
|
global $PREPEND_EXTENSIONS;
|
||||||
array_unshift($pbdb, ...$PREPEND_EXTENSIONS);
|
array_unshift($pbdb, ...$PREPEND_EXTENSIONS);
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ function pull_mac_list(): array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function read_config_json_file($path){
|
function read_config_json_file(string $path): array {
|
||||||
$json = file_get_contents($path);
|
$json = file_get_contents($path);
|
||||||
$data = json_decode($json, true);
|
$data = json_decode($json, true);
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ function read_config_json_file($path){
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_config_json($key) {
|
function read_config_json(string $key): array {
|
||||||
global $CONFIG;
|
global $CONFIG;
|
||||||
$value = $CONFIG[$key] ?? [];
|
$value = $CONFIG[$key] ?? [];
|
||||||
|
|
||||||
@@ -202,13 +202,13 @@ function read_config_json($key) {
|
|||||||
return array_values(array_filter($items, fn($v) => $v !== ''));
|
return array_values(array_filter($items, fn($v) => $v !== ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_config_json_string($key) {
|
function read_config_json_string(string $key): string {
|
||||||
global $CONFIG;
|
global $CONFIG;
|
||||||
$value = $CONFIG[$key] ?? '';
|
$value = $CONFIG[$key] ?? '';
|
||||||
return strtolower(trim((string)$value));
|
return strtolower(trim((string)$value));
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_config_json_object_list($key) {
|
function read_config_json_object_list(string $key): array {
|
||||||
global $CONFIG;
|
global $CONFIG;
|
||||||
$value = $CONFIG[$key] ?? [];
|
$value = $CONFIG[$key] ?? [];
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ function read_config_json_object_list($key) {
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pull_xml_file($file): DOMDocument {
|
function pull_xml_file(string $file): DOMDocument {
|
||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
$file = '/tftpboot/000000000000-features.cfg';
|
$file = '/tftpboot/000000000000-features.cfg';
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ function pull_xml_file($file): DOMDocument {
|
|||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_attendants($xml): DOMElement {
|
function remove_attendants(DOMDocument $xml): DOMElement {
|
||||||
$xpath = new DOMXPath($xml);
|
$xpath = new DOMXPath($xml);
|
||||||
$attendantNodes = $xpath->query('/polycomConfig/attendant');
|
$attendantNodes = $xpath->query('/polycomConfig/attendant');
|
||||||
if ($attendantNodes->length === 0) {
|
if ($attendantNodes->length === 0) {
|
||||||
@@ -282,7 +282,7 @@ function remove_attendants($xml): DOMElement {
|
|||||||
return $attendant;
|
return $attendant;
|
||||||
}
|
}
|
||||||
|
|
||||||
function write_attendants($attendant, $pbdb): void {
|
function write_attendants(DOMElement $attendant, array $pbdb): void {
|
||||||
$index = 1;
|
$index = 1;
|
||||||
foreach ($pbdb as $r) {
|
foreach ($pbdb as $r) {
|
||||||
$label = trim((string)($r['name'] ?? ''));
|
$label = trim((string)($r['name'] ?? ''));
|
||||||
@@ -297,7 +297,7 @@ function write_attendants($attendant, $pbdb): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function write_to_file($file, $xml): void {
|
function write_to_file(string $file, DOMDocument $xml): void {
|
||||||
global $PROVISION_DIR;
|
global $PROVISION_DIR;
|
||||||
if (!is_dir($PROVISION_DIR)) {
|
if (!is_dir($PROVISION_DIR)) {
|
||||||
fwrite(STDERR, "Provisioning directory not found: $PROVISION_DIR\n");
|
fwrite(STDERR, "Provisioning directory not found: $PROVISION_DIR\n");
|
||||||
@@ -325,7 +325,7 @@ function write_to_file($file, $xml): void {
|
|||||||
echo "Wrote $file \n";
|
echo "Wrote $file \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function notify($pbdb): void {
|
function notify(array $pbdb): void {
|
||||||
$notified = 0;
|
$notified = 0;
|
||||||
foreach ($pbdb as $r) {
|
foreach ($pbdb as $r) {
|
||||||
$ext = trim((string)$r['extension']);
|
$ext = trim((string)$r['extension']);
|
||||||
|
|||||||
Reference in New Issue
Block a user