tigron/skeleton-container-control

与远程容器的通信

v1.0.3 2022-05-11 14:55 UTC

This package is auto-updated.

Last update: 2024-08-26 18:06:59 UTC


README

描述

这个库允许与远程服务器进行通信。远程服务器需要安装 skeleton-container 包。

安装

通过 composer 安装

composer require tigron/skeleton-container-control

如何做

初始化服务目录

\Skeleton\Container\Control\Config::$service_dir = $some_very_cool_directory;

以下 skeleton 控制台命令将可用

container
 container:deprovision  Deprovision a service from a container
 container:info         Get info of a paired container
 container:list         List all paired containers
 container:pair         Pair with a new container
 container:provision    Provision a container with a new service
 container:rename       Rename a container
 container:unpair       Unpair from a container
service
 service:diff           Show differences between the local and remote service, if any
 service:list           List all known services

要创建服务,在服务目录中创建如下目录结构

service_name
├── lib 	                # Libraries needed for this service
└── module                  # Contains the module for the service

在模块目录中,至少应添加一个文件:index.php。该模块将处理所有传入的请求。它是一个应该从 'Service_Module' 继承的类

这是一个非常基本的模块示例

<?php
/**
 * Dummy module
 *
 * @author Christophe Gosiau <christophe@tigron.be>
 * @author Gerry Demaret <gerry@tigron.be>
 */

class Web_Module_Index extends Service_Module {

    /**
     * Handle call1
     *
     * @access public
     * @param array $data
     */
    public function handle_call1($data) {
    }
}

部署后,远程服务器可以响应 call1。要发起调用,请使用以下命令

$container = \Skeleton\Container\Control\Container::get_by_name('my_remote_container');
$service = \Skeleton\Container\Control\Service::get_by_name('dummy');
$container_service = $container->get_container_service($service);
$data = [
    'param1' => 'this is a test',
    'param2' => 'This is another test'
];
$container_service->call1($data);

默认情况下,服务以 '生产' 模式运行。这意味着调用将由 Web_Module_Index 处理。为了测试目的,环境可以修改为 '调试'。这样做后,调用将由 Web_Module_Debug 处理。这是可选的,但强烈建议这样做。创建服务时,请确保生产调用和调试调用都可用。要启用调试模式,请执行以下调用

$container = \Skeleton\Container\Control\Container::get_by_name('my_remote_container');
$service = \Skeleton\Container\Control\Service::get_by_name('dummy');
$container_service = $container->get_container_service($service);
$container_service->set_environment('debug');
$data = [
    'param1' => 'this is a test',
    'param2' => 'This is another test'
];
$container_service->call1($data);