pstaender/silverstripe-serve

连接PHP开发服务器到SilverStripe

2.2.0 2019-03-29 03:50 UTC

This package is auto-updated.

Last update: 2024-09-15 13:03:58 UTC


README

一个简单的开发任务,用于启动SilverStripe应用的开发服务器。

入门指南

$ composer require silverstripe/serve
$ framework/sake dev/build flush=1
$ vendor/bin/serve

这将启动服务器,地址为 http://localhost:8080

你可以覆盖主机/端口

$ vendor/bin/serve --host 127.0.0.1 --port 8000

包括引导文件

引导文件参数允许你在composer加载后(包括Silverstripe的Constants.php)但在main.php加载前包含一个自定义的PHP文件。

这可以用于各种目的,但主要用例是引入在当前执行会话中通常不会由SilverStripe包含的任何占位代码和配置,例如测试占位代码。

$ vendor/bin/serve --bootstrap-file tests/serve-bootstrap.php

作为库使用

你还可以将serve用作库,从其他工具(如测试套件)启动SilverStripe服务器

假设BASE_PATH已定义,你可以这样使用

use SilverStripe\Serve\ServerFactory;

$factory = new ServerFactory();

$server = $factory->launchServer([
    'host' => 'localhost',
    'preferredPort' => 3000,
]);

// Print the contents of the homepage
echo file_get_contents($server->getURL());

// Stop the server when you're done with it
$server->stop();

如果BASE_PATH未定义,例如如果你不是运行SapphireTest,你可以为工厂构造函数提供一个替代路径

$factory = new ServerFactory(realpath(__DIR__ . '/../'));

launchServer允许传递以下选项给它

  • host: 要监听的主机,默认为0.0.0.0
  • preferredPort: 优先端口。如果此端口不可用,将使用下一个最高端口
  • bootstrapFile: 引导文件,如上所述