Download the PHP package khs1994/example without Composer

On this page you can find all versions of the php package khs1994/example. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package example

Docker 化 PHP 项目最佳实践

完全使用 Docker 开发、部署 PHP 项目。本指南只是简单列出,具体内容请查看 文档

IDE

本页面以 PHPStorm 为例进行介绍。

如果你使用的是 VSCode 请参考 这里

Create PHP Application by Composer

GitHub stars PHP from Packagist GitHub (pre-)release StyleCI

微信订阅号

关注项目作者微信订阅号,接收项目最新动态

说明

初始化

准备

建立一个自己的 PHP 项目模板(即 composer 包类型为 project),里面包含了常用的文件的模板。

示例:https://github.com/khs1994-docker/php-demo

内置文件模板

Filename Description
.github/workflows GitHub Actions CI 工具
.gitattributes git 打包时排除文件(例如 测试代码)
.drone.yml Drone CI 工具
.editorconfig 定义文件格式规则(例如 缩进方式)
.pcit.yml PCIT CI 工具
.php_cs PHP 代码格式化工具
.doctum.php PHP 文档生成工具
.styleci.yml Style CI PHP 代码格式化 CI 工具

一、开发

环境(以下步骤缺一不可)

1. 新建 PHP 项目

使用自己的模板项目初始化 PHP 项目。

2. 新增 NGINX 配置

一个 PHP 项目, 一个 网址,一个 NGINX 子配置文件

参考示例配置文件在 config/nginx 新建 *.conf NGINX 配置文件

3. 启动 khs1994-docker/lnmp

4. 浏览器验证

浏览器打开页面出现 php 信息

5. PHPStorm 打开 PHP 项目

注意 打开的是 PHP 项目(避免文件层次过深,IDE 直接打开 PHP 项目),不是 khs1994-docker/lnmp

要配置 khs1994-docker/lnmp 建议使用另外的文本编辑器。

你可以通过设置 APP_ROOT 变量来实现 app 文件夹与 khs1994-docker/lnmp 并列。

6. CLI settings

由于 PHP 环境位于 Docker 中,必须进行额外的配置

生成 docker-compose.yml

如果使用 Docker Compose V2,请使用 PHPStorm 2021.3 及以上版本

PHPStorm 设置 -> PHP -> CLI Interpreter -> 点击后边三个点 -> 点击左上角 + 号 -> From Docker ... -> 选择 Docker Compose -> Configuration file(s) -> 选择 docker-compose.yml(khs1994-docker/lnmp项目根目录) -> Services -> 选择 workspace -> 点击 OK 确认

点击 ok 之后跳转的页面上 Additionl -> Debugger extension-> 填写 xdebug

具体请查看 https://github.com/khs1994-docker/lnmp/issues/260#issuecomment-373964173

再点击 ok 之后跳转到了 PHPStorm 设置-> PHP -> CLI Interpreter 这个页面

配置本地路径与容器内路径对应关系

这里的配置 PHPStorm 可能会自动生成,保证正确即可。

这里以 Windows 为例,其他系统同理(添加本机路径与容器路径对应关系即可)。

由于 Windows 与 Linux 路径表示方法不同,我们必须另外添加路径对应关系。配置本地项目与容器目录之间的路径对应关系。

假设本地项目目录位于 C:/Users/username/app/demo 对应的容器目录位于 /app/demo 假设本地项目目录位于 WSL2 \\wsl$\Ubuntu\app\demo 对应的容器目录位于 /app/demo

PHPStorm 设置 -> PHP -> Path mappings 添加一个条目 C:/Users/username/app/demo => /app/demo

7. 设置 Xdebug

请查看 https://github.com/khs1994-docker/lnmp/blob/master/docs/xdebug.md

8. 依赖管理 Composer

容器化 PHPer 常用命令请查看 https://github.com/khs1994-docker/lnmp/blob/master/docs/command.md

9. 编写 PHP 代码

10. 编写 PHPUnit 测试代码

11. 使用 PHPUnit 测试

在 PHPStorm 中使用

PHPStorm 设置 -> PHP ->Test Frameworks -> 左上角添加 -> PHPUnit by Remote Interpreter -> 选择第五步添加的 workspace -> 点击 OK -> PHPUnit Library -> 选择 Use Composer autoloader -> Path to script -> 点击右边刷新按钮即可自动识别,或者手动 填写 /app/PROJECT_NAME/vendor/autoload.php -> 点击 OK 确认

在测试函数名单击右键 run FunName 开始测试。

在 命令行 中使用

12. 本地测试构建 PHP 及 NGINX 镜像

此示例将 PHP 代码打入了镜像中,如果你选择将代码放入宿主机,那么无需进行此步骤。两种方法自行取舍。

关于代码放到哪里?代码放入宿主机,上线时需要在服务器 pull 代码(或者参考 git-sync 周期性监听 git 变化并克隆到本地)。代码放入镜像中,上线时直接拉取镜像之后启动容器,无需 pull 代码。

若将 PHP 项目打入镜像,镜像中严禁包含配置文件

Docker 镜像必须由 CI 服务器构建,而不是本地人工构建!

自行修改 .env docker-compose.yml 文件,保留所需的 PHP 版本,其他的注释

13. 将项目提交到 Git

CI/CD 服务搭建

CI/CD 可以到 khs1994-docker/ci 查看。

二、测试

CI/CD 服务器收到 Git Push 事件,进行代码测试

三、开发、测试循环

四、在 Kubernetes 中部署生产环境 (全自动)

可以在生产环境之前加一个 预上线 环境,这里省略。

1. git 添加 tag,并推送到远程仓库

2. CI/CD 服务器收到 Git Tag 事件,自动构建镜像并推送镜像到 Docker 仓库(代码在镜像中)

3. CI/CD 服务器中使用 Helmkustomize 在 k8s 集群更新服务(代码在镜像中)

4. 使用 daemonset 部署 gti-sync(代码不在镜像中)

每个节点 都拥有一份代码,这样就不用关心 pod 调度到哪个节点。

BUG


All versions of example with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.3
ext-curl Version *
ext-json Version *
ext-pdo Version *
pimple/pimple Version ~3.0
khs1994/curl Version ~18.06.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package khs1994/example contains the following files

Loading the files please wait ....