pstaender / silverstripe-serve
连接PHP开发服务器到SilverStripe
2.2.0
2019-03-29 03:50 UTC
Requires
- php: ^5.6||^7.0
- silverstripe/framework: ^4
- symfony/process: ^3.0 || ^4.0
Requires (Dev)
- phpunit/phpunit: ^5.7
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: 引导文件,如上所述