定制 ohseesoftware/caddy-config-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ohseesoftware/caddy-config-php

Composer 安装命令:

composer require ohseesoftware/caddy-config-php

包简介

Caddy v2 API helper library.

README 文档

README

Caddy v2 API helper for PHP.

Current Release Build Status Badge Coverage Status Maintainability Score Downloads MIT License

Caddy v2 allows you to update your Caddy configuration via a JSON API. This package is a simple helper library to update parts of your configuration.

Functionality for updating all aspects of the configuration will be added over time.

Usage

To get started, create an instance of OhSeeSoftware\CaddyConfig\Client, ensuring to pass your Caddy network address as the first argument:

$client = new OhSeeSoftware\CaddyConfig\Client('localhost:2019');

From there, you can use the $client instance to make API requests to your Caddy instance.

The idea behind the wrapper is that you can have a Client singleton class, and then use the $client->request() method to create new Request instances. You should create a new Request instance per HTTP request you send to your Caddy server.

API Methods

Client

__constructor()

Creates a new instance of the Client class.

Arguments:

setCaddyHost()

Allows you to change the Caddy host after creating the Client instance.

Arguments:

request()

Returns a new Request instance which you use to make configuration requests.

No arguments.

Request

Use the Request class to compose your request to send to Caddy. Here's an example of how you can add a new host to a server:

$client = new OhSeeSoftware\CaddyConfig\Client('localhost:2019');
$client->request()
  ->http()
  ->server('srv0')
  ->route(0)
  ->match(0)
  ->addHost('example.com');

__constructor()

Creates a new instance of the Request class.

Arguments:

addHost()

Sends a request to Caddy to add the given host.

Arguments:

  • $host - string: The host to add.

Returns:

  • Response - The response from Caddy wrapped in a Response instance.

http()

Adds the http path, "/apps/http", to the request URI.

No arguments.

Returns:

  • Request - The request instance (allows chaining).

server()

Adds the server path, "/servers/{server}", to the request URI.

Arguments:

  • $server - string: The name of the server to target.

Returns:

  • Request - The request instance (allows chaining).

route()

Adds the route path, "/routes/{routeIndex}", to the request URI.

Arguments:

  • $routeIndex - int: The route to target.

Returns:

  • Request - The request instance (allows chaining).

match()

Adds the match path, "/match/{matchIndex}", to the request URI.

Arguments:

  • $matchIndex - int: The match to target.

Returns:

  • Request - The request instance (allows chaining).

sendRequest()

Sends the built request to the Caddy server.

Arguments:

  • $method - string: The method for the request.
  • $body - array|nuullable: The request body to send to Caddy.

Returns:

  • Response - A new instance of a Response instance.

Response

__constructor()

Creates a new instance of the Response class.

Arguments:

  • $response - ResponseInterface: Instance of a ResponseInterface (created by Guzzle).

getBody()

Returns the response body as a string.

No arguments.

isSuccessful()

Returns a boolean indicating if the request was successful. Status codes of 200 or 201 are considered successful, everything else is not.

No arguments.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 132
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固