Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed May 19, 2016
0 parents commit 322ed81
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework
vendor
composer.lock
24 changes: 24 additions & 0 deletions _config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

$host = "localhost";

if (isset($_GET["host"])) {
$host = $_GET["host"];
}

define("SERVE_HOST", $host);

$port = "8080";

if (isset($_GET["port"])) {
$port = $_GET["port"];
}

define("SERVE_PORT", $port);

$root = realpath(__DIR__ . "/../");

define("SERVE_ROOT", $root);

global $_FILE_TO_URL_MAPPING;
$_FILE_TO_URL_MAPPING[$root] = "http://{$host}:{$port}";
44 changes: 44 additions & 0 deletions code/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace SilverStripe\Serve;

use BuildTask;
use SS_HTTPRequest;
use Symfony\Component\Process\PhpExecutableFinder;

class Task extends BuildTask
{
/**
* @var string
*/
protected $title = "Development Server";

/**
* @var string
*/
protected $description = "Connects the PHP development server to SilverStripe.";

/**
* @var bool
*/
protected $enabled = true;

/**
* @inheritdoc
*
* @param SS_HTTPRequest $request
*/
public function run($request)
{
$path = __DIR__;
$bin = (new PhpExecutableFinder)->find(false);

$root = SERVE_ROOT;
$host = SERVE_HOST;
$port = SERVE_PORT;

print "Server running at http://{$host}:{$port}\n";

passthru("'{$bin}' -S {$host}:{$port} -t '{$root}' '{$path}/server.php'");
}
}
14 changes: 14 additions & 0 deletions code/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$uri = urldecode(
parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)
);

if ($uri !== "/" && file_exists(__DIR__ . "/../../" . $uri)) {
return false;
}

$_GET["url"] = $uri;
$_REQUEST["url"] = $uri;

require_once __DIR__ . "/../../framework/main.php";
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "silverstripe/serve",
"description": "Connects the PHP development server to SilverStripe",
"type": "silverstripe-module",
"license": "MIT",
"require": {
"php": "^5.4",
"symfony/process": "^3.0",
"silverstripe/framework": "^3.2"
}
}
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SilverStripe Serve

A simple dev task, to start a development server for your SilverStripe app.

## Getting started

```sh
$ framework/sake dev/tasks/SilverStripe-Serve-Task
```

This will start the server at `http://localhost:8080`.

You can override the host/port:

```sh
$ framework/sake dev/tasks/SilverStripe-Serve-Task host=127.0.0.1 port=8000
```

0 comments on commit 322ed81

Please sign in to comment.