icuk/broadband-availability-php

将ICUK宽带可用性检查器集成到您的PHP应用程序中

v1.2 2024-01-08 15:03 UTC

This package is auto-updated.

Last update: 2024-09-06 14:20:15 UTC


README

Latest Build

将ICUK宽带可用性检查器集成到您的PHP应用程序中

安装

需要PECL mbstring、zip和ext-curl扩展

下载并解压缩最新版本

Windows

curl -o icuk-broadband-checker.tar.gz https://github.com/ICUK-Net/icuk-broadband-checker-php/releases/latest/download/icuk-broadband-checker.tar.gz
tar -xvf icuk-broadband-checker.tar.gz

Linux

wget https://github.com/ICUK-Net/icuk-broadband-checker-php/releases/latest/download/icuk-broadband-checker.tar.gz
tar -xvf icuk-broadband-checker.tar.gz

这就是安装可用性检查器所需的所有内容,如果失败,则尝试从以下源安装。此时,您应该阅读使用说明部分,该部分将向您展示如何配置库

使用Composer进行安装

下载composer.phar(如果尚未安装)

wget https://getcomposer.org.cn/download/latest-stable/composer.phar

创建一个包含以下数据的composer.json文件(如果您已经有一个composer.json文件,请添加require部分中的数据)

{
    "name": "root/html",
    "type": "project",
    "minimum-stability": "dev",
    "require": {
        "icuk/broadband-availability-php": "dev-master"
    }
}

安装所有依赖项

php composer.phar install

使用方法

api.php

此文件允许用户对宽带可用性API进行请求。您应该使用此格式,但用您的凭据替换凭据,并且您可以在之前使用自己的认证方法来防止对端点的未授权访问。

<?php
require __DIR__ . '/vendor/autoload.php';

// Add user authentication here!

echo json_encode(\Icuk\BroadbandAvailabilityPhp\BroadbandAvailabilityProxy::handle_api("ExampleAPIUsername", "ExampleAPIPassword123"));

index.php

这是一个非常简单的示例,展示了如何使用页面向用户提供宽带可用性检查器。api.php端点纯粹是示例,应仅是api.php文件所在路径。

render_styles行是可选的,您可以将自己的样式表应用于表格,还应注意,结果面板将在搜索之前不会出现。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Broadband Availability Example</title>
  <?php
    require __DIR__ . '/vendor/autoload.php';
    $ba = new \Icuk\BroadbandAvailabilityPhp\BroadbandAvailability("/api.php");
    $ba->render_scripts();
    $ba->render_styles();
  ?>
</head>
<body>
  <?php
    $ba->render_search();
    $ba->render_address_list();
    $ba->render_results();
  ?>
</body>
</html>

Example of what the above code should result in

编辑错误消息

要替换当可用性检查失败时发生的错误消息,您可以使用错误消息作为render_search的参数。

$ba->render_search("Example error message");

自定义样式

使用样式配置

您可以使用SearchStyleSettings和ResultsStyleSettings类来编辑搜索和结果模块的颜色方案。以下示例显示了如何使用它来使搜索按钮从红色渐变到绿色,并将结果字段的背景颜色设置为蓝色。

$style = new \Icuk\BroadbandAvailabilityPhp\SearchStyleSettings();
$rstyle = new \Icuk\BroadbandAvailabilityPhp\ResultsStyleSettings();
$astyle = new \Icuk\BroadbandAvailabilityPhp\AddressSelectStyleSettings();

$style->button_gradient_low = "#f00";
$style->button_gradient_high = "#00ff00";
$rstyle->head_background_colour = "rgb(0, 0, 255)";
$astyle->background_colour = "rgb(0, 255, 0)";

$ba->render_styles($style, $rstyle, $astyle);

Example of what the above code should result in

目前支持rgb、rgba、hex、hsl、hsla、CIELab和xyz颜色格式,而像"purple"或"darkgreen"这样的颜色名称是无效的。

ResultsStyleSettings属性

  • background_colour:结果表的背景颜色
  • head_background_colour:结果表头的背景颜色
  • left_background_colour:结果表左侧的背景颜色
  • seperators_colour:单元格之间的分隔符颜色
  • text_colour:结果的文本颜色
  • head_text_colour:结果表头的文本颜色
  • left_text_colour:结果表左侧的文本颜色
  • available_label_colour:可用标签的颜色
  • not_available_label_colour:不可用标签的颜色
  • available_text_colour:可用标签上的文本颜色
  • not_available_text_colour:不可用标签上的文本颜色
  • loading_circle_primary_colour:加载圆圈上的主颜色
  • loading_circle_secondary_colour:加载圆圈的静态背景颜色
  • hide_results:在搜索发生之前隐藏结果表的结果

SearchStyleSettings属性

  • button_gradient_low:渐变底部按钮的颜色
  • button_gradient_high:渐变顶部按钮的颜色
  • button_gradient_low_hover : 按钮在渐变底部悬停时的颜色
  • button_gradient_high_hover : 按钮在渐变顶部悬停时的颜色
  • button_text_colour : 按钮上文字的颜色
  • input_bg_colour : 输入框的背景颜色
  • input_text_colour : 输入框上文字的颜色
  • input_hover_fade_colour : 输入框选中时周围渐变的颜色
  • error_message_colour : 错误信息的颜色

AddressSelectStyleSettings 属性

  • background_colour : 地址表的背景颜色
  • head_background_colour:结果表头的背景颜色
  • filter_box_background_colour : 过滤/搜索框的背景颜色
  • address_text_colour : 单元格之间的分隔线的颜色
  • filter_box_text_colour : 过滤/搜索框中文字的颜色
  • head_text_colour : 地址表头部文字的颜色
  • nad_text_colour : 地址表中 NAD 文字的颜色
  • border_colour : 地址表边框的颜色
  • head_border_colour : 地址表头部边框的颜色
  • filter_box_border_colour : 过滤/搜索框边框的颜色
  • filter_box_hover_fade_colour : 过滤框按下时的颜色

自定义样式表

您可以通过相对简单的方式开发自己的样式表,因为每个模块的元素都很容易通过它们的 ID 进行识别,例如搜索中使用的按钮 ID 是 "broadband-availability-search-submit",而输入框使用的是 "broadband-availability-search-input"。您可以使用此库使用的样式模板 PHP 文件作为参考,文件链接如下:这里