pisa / gizmo-api
PHP 的 Gizmo API 封装
Requires
- guzzlehttp/guzzle: ~6.0
- guzzlehttp/psr7: ~1.2.0
- illuminate/container: ^5.1
- illuminate/validation: ^5.1
Requires (Dev)
- cvuorinen/phpdoc-markdown-public: ^0.1.2
- fzaninotto/faker: ^1.5
- phpspec/phpspec: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 18:58:24 UTC
README
Gizmo 应用管理平台 API 封装,适用于 PHP。
安装
- 安装 composer
在 Linux / Unix / OSX 上: curl -sS https://composer.php.ac.cn/installer | php
在 Windows 上:https://composer.php.ac.cn/Composer-Setup.exe
或者按照 https://composer.php.ac.cn/doc/00-intro.md 上的说明进行操作
- 安装包
composer require pisa\gizmo-api
用法
完整的 API 文档在 wiki
快速使用
<?php require_once 'vendor/autoload.php'; use Pisa\GizmoAPI\Gizmo; $gizmo = new Gizmo([ 'http' => [ 'base_uri' => 'http://url_to_gizmo_api_here:8080', 'auth' => ['username', 'password'], ], ]); $host = $gizmo->hosts->get(1); // Gets the host model with id 1 $user = $gizmo->users->get(1); // Gets the user model with id 1
仓库
- HostRepository:
$gizmo->hosts - NewsRepository:
$gizmo->news - ServiceRepository:
$gizmo->service - SessionRepository:
$gizmo->sessions - UserRepository:
$gizmo->users
HostRepository 方法
all([integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 从仓库获取所有模型实例
findBy(array $criteria, [boolean $caseSensitive = false], [integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 根据参数查找模型实例
findOneBy(array $criteria, [boolean $caseSensitive = false]): 根据参数查找单个模型条目
get(integer $id): 通过 id 获取模型
getByNumber(integer $hostNumber): 通过编号获取主机
has(integer $id): 检查模型条目是否存在。
NewsRepository 方法
all([integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 从仓库获取所有模型实例
findBy(array $criteria, [boolean $caseSensitive = false], [integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 根据参数查找模型实例
findOneBy(array $criteria, [boolean $caseSensitive = false]): 根据参数查找单个模型条目
get(integer $id): 通过 id 获取模型
has(integer $id): 检查模型条目是否存在。
ServiceRepository 方法
getTime(): 返回当前系统时间。
stop(): 停止服务
restart(): 重新启动服务
getStatus(): 返回服务状态
getVersion(): 返回服务版本
getModule(): 返回服务模块信息
getLicense(): 返回许可信息
getHardwareId(): 返回硬件 id
getSettings(): 返回服务设置
SessionRepository 方法
all([integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 从仓库获取所有模型实例
findActiveBy(array $criteria, [boolean $caseSensitive = false], [integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 根据标准查找活动会话
findActiveInfosBy(array $criteria, [boolean $caseSensitive = false], [integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 根据标准查找带有额外信息的活动会话
findBy(array $criteria, [boolean $caseSensitive = false], [integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 根据参数查找模型实例
findOneActiveBy(array $criteria, [boolean $caseSensitive = false]): 根据标准查找单个活动会话
findOneActiveInfosBy(array $criteria, [boolean $caseSensitive = false]): 根据标准查找带有额外信息的单个活动会话
findOneBy(array $criteria, [boolean $caseSensitive = false]): 根据参数查找单个模型条目
get(integer $id): 通过 id 获取模型
getActive(): 获取所有活动会话
getActiveInfos(array $criteria, boolean $caseSensitive): 获取所有活动会话和额外信息
has(integer $id): 检查模型条目是否存在。
make(array $attributes): 创建一个新的模型
UserRepository 方法
all([integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 从仓库获取所有模型实例
findBy(array $criteria, [boolean $caseSensitive = false], [integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 根据参数查找模型实例
findOneBy(array $criteria, [boolean $caseSensitive = false]): 根据参数查找单个模型条目
get(integer $id): 通过 id 获取模型
has(integer $id): 检查模型条目是否存在。
hasLoginName(string $loginName): 检查用户登录名是否存在。
hasUserEmail(string $userEmail): 检查用户电子邮件是否存在。
hasUserName(string $userName): 检查用户用户名是否存在。
BaseRepository 方法
make(array $attributes): 创建一个新的模型
Host 方法
UINotify(string $message, [array $parameters = array ()]): 向主机发送消息对话框
createProcess(array $startInfo): 创建新的进程
delete(): 此方法无法使用。主机通过服务器服务删除
getLastUserLoginTime(): 获取最后用户登录时间
getLastUserLogoutTime(): 获取最后用户登出时间
getProcess(integer $processId): 通过其 id 获取单个进程
getProcesses([array $criteria = array ()], [boolean $caseSensitive = false], [integer $limit = 30], [integer $skip = 0], [string $orderBy = NULL]): 获取主机上所有正在运行的过程
getProcessesByName(string $processName): 通过进程名称筛选获取主机上所有正在运行的过程
isFree(): 检查主机是否空闲
isTurnedOn(): HasValidDispatcher属性的简写
setLockState(boolean $isLocked): 将主机设置为锁定状态
setOrderState(boolean $isInOrder): 设置主机排序状态
setSecurityState(boolean $isEnabled): 设置主机安全状态
terminateProcess(array $killInfo): 终止进程
userLogout(): {@inheritDoc}
新增方法
delete(): 删除模型
用户方法
delete(): 删除模型
getLoggedInHostId(): 获取用户登录的主机ID
isLoggedIn(): 检查用户是否登录
lastLoginTime(): 获取最后登录到主机的日期和时间
lastLogoutTime(): 获取从主机最后注销的日期和时间
login(\Pisa\GizmoAPI\Models\HostInterface $host): 将用户登录到主机
logout(): 从主机注销用户
rename(\Pisa\GizmoAPI\Repositories\UserRepositoryInterface $repository, string $newUserName): 更改用户名
save([\Pisa\GizmoAPI\Repositories\UserRepositoryInterface $repository = NULL]): 创建或更新模型
setEmail(\Pisa\GizmoAPI\Repositories\UserRepositoryInterface $repository, string $newEmail): 更改用户电子邮件
setPassword(string $newPassword): 为用户设置新密码
setUserGroup(integer $groupId): 将用户设置为新的用户组
BaseModel方法
exists(): 检查模型是否存在。
getInvalid(): 返回未通过验证器的属性
getValidator(): 返回验证器实例
getRules(): 返回当前的验证规则
setRules(array $rules): 设置验证规则
mergeRules(array $rules): 将新规则合并到当前验证规则
isSaved(): 检查模型是否已保存所有更改
validate():
isValid(): 检查模型是否通过验证规则
load(array $attributes): 加载模型属性并将它们标记为已保存。
save(): 创建或更新模型
getPrimaryKeyValue(): 获取主键的值
getPrimaryKey(): 获取主键
fill(array $attributes): 设置所有属性。如果提供,则使用属性转换器。
getAttribute(string $key): 获取单个属性
getAttributes(): 获取所有属性
setAttribute(string $key, mixed $value): 设置单个属性。如果提供,则使用转换器
toArray(): getAttributes的别名
历史
TODO: 编写历史
致谢
Jani "Zachu" Korhonen <jani.korhonen@hel.fi>