Skip to content

Commit

Permalink
Add home page to test site. Add autoload sandbox directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdietz committed Mar 12, 2015
1 parent 381310a commit a2f6bc1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ workspace.xml
# Vagrant
.vagrant/

# Vagrant site's document root.
# Vagrant sandbox site files.
/htdocs/
/autoload/
10 changes: 9 additions & 1 deletion vagrant/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<?php

print "Hello, world!";
use pjdietz\WellRESTed\Router;

$loader = require_once __DIR__. "/../vendor/autoload.php";
$loader->addPsr4("", __DIR__ . "/../vagrant/src");
$loader->addPsr4("", __DIR__ . "/../autoload");

$router = new Router();
$router->add("/", "\\WellRESTedDev\\RootHandler");
$router->respond();
9 changes: 7 additions & 2 deletions vagrant/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ fi

# Create the document and symlinks.
if [ ! -d /vagrant/htdocs ] ; then
mkdir /vagrant/htdocs 2&> /dev/null
mkdir /vagrant/htdocs
fi
if [ ! -h /vagrant/htdocs/docs ] ; then
ln -s /vagrant/docs/build/html /vagrant/htdocs/docs
fi
if [ ! -h /vagrant/htdocs/coverage ] ; then
ln -s /vagrant/report /vagrant/htdocs/coverage
fi
cp /vagrant/vagrant/index.php /vagrant/htdocs/index.php
if [ ! -f /vagrant/htdocs/index.php ] ; then
cp /vagrant/vagrant/index.php /vagrant/htdocs/index.php
fi
if [ ! -d /vagrant/autoload ] ; then
mkdir /vagrant/autoload
fi

# Install Composer dependencies
composer --working-dir=/vagrant install
Expand Down
50 changes: 50 additions & 0 deletions vagrant/src/WellRESTedDev/RootHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace WellRESTedDev;

use pjdietz\WellRESTed\Interfaces\HandlerInterface;
use pjdietz\WellRESTed\Interfaces\RequestInterface;
use pjdietz\WellRESTed\Interfaces\ResponseInterface;
use pjdietz\WellRESTed\Response;

class RootHandler implements HandlerInterface
{
/**
* Return the handled response.
*
* @param RequestInterface $request The request to respond to.
* @param array|null $args Optional additional arguments.
* @return ResponseInterface The handled response.
*/
public function getResponse(RequestInterface $request, array $args = null)
{
$view = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>WellRESTed</title>
</head>
<body>
<h1>Welcome to the WellRESTed Test Site</h1>
<ul>
<li>View <a href="/docs/">Documentatation</a></li>
<li>View <a href="/coverage/">Code Coverage Report</a></li>
</ul>
<p>Run <code>vagrant ssh</code>, then:</p>
<dl>
<dt>To run unit tests</dt>
<dd><code>vendor/bin/phpunit</code></dd>
<dt>To generate documentation</dt>
<dd><code>make html -C docs</code></dd>
</dl>
<p>Use this site as a sandbox. Modify the router <code>/htdocs/index.php</code> however you like.</p>
<p>Any classes you create inside <code>/autoload</code> will be autoloaded with a PSR-4 autoloader.</p>
</body>
</html>
HTML;
$response = new Response(200);
$response->setBody($view);
return $response;
}
}

0 comments on commit a2f6bc1

Please sign in to comment.