| @ -0,0 +1,2 @@ | |||
| /vendor/ | |||
| composer.lock | |||
| @ -0,0 +1,13 @@ | |||
| default: install | |||
| clean: | |||
| @rm -rf vendor | |||
| @rm composer.lock | |||
| install: | |||
| composer install | |||
| run: | |||
| ./bin/drudge $(ARGS) | |||
| .PHONY: clean install default | |||
| @ -0,0 +1,28 @@ | |||
| drudge | |||
| ====== | |||
| A web server written in PHP. | |||
| A work in progress | |||
| # License | |||
| ``` | |||
| The MIT License (MIT) Copyright (c) 2012 Brett Langdon <brett@blangdon.com> | |||
| Permission is hereby granted, free of charge, to any person obtaining a copy | |||
| of this software and associated documentation files (the "Software"), to deal | |||
| in the Software without restriction, including without limitation the rights to | |||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |||
| of the Software, and to permit persons to whom the Software is furnished to do | |||
| so, subject to the following conditions: | |||
| The above copyright notice and this permission notice shall be included in all | |||
| copies or substantial portions of the Software. | |||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||
| INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |||
| PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |||
| HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||
| CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||
| OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
| ``` | |||
| @ -0,0 +1,35 @@ | |||
| #!/usr/bin/env php | |||
| <?php | |||
| $root = dirname(__dir__); | |||
| require implode(DIRECTORY_SEPARATOR, array($root, 'vendor', 'autoload.php')); | |||
| $doc = <<<DOC | |||
| Drudge | |||
| Usage: | |||
| drudge [--host <host>] [--port <port>] <script> | |||
| Options: | |||
| --help Show this help message | |||
| --version Show version information | |||
| -h --host <host> Host to bind to [default: 0.0.0.0] | |||
| -p --port <port> Port to bin to [default: 80] | |||
| DOC; | |||
| $handler = new Docopt\Handler( | |||
| array( | |||
| 'version' => 'Drudge 0.1.0', | |||
| 'help' => true, | |||
| ) | |||
| ); | |||
| $args = $handler->handle($doc); | |||
| $params = array( | |||
| 'host' => $args['--host'] || '0.0.0.0', | |||
| 'port' => intval($args['--port']) || 80, | |||
| ); | |||
| $handler = require realpath($args['<script>']); | |||
| $server = new Brettlangdon\Drudge\Server($params, $handler); | |||
| $server->run(); | |||
| @ -0,0 +1,35 @@ | |||
| { | |||
| "name": "brettlangdon/drudge", | |||
| "description": "A simple PHP web server", | |||
| "version": "0.1.0", | |||
| "license": "MIT", | |||
| "homepage": "https://github.com/brettlangdon/drudge", | |||
| "keywords": [ | |||
| "web", | |||
| "http", | |||
| "server" | |||
| ], | |||
| "authors": [ | |||
| { | |||
| "name": "brettlangdon", | |||
| "email": "brett@blangdon.com", | |||
| "homepage": "http://brett.is/" | |||
| } | |||
| ], | |||
| "support": { | |||
| "issues": "https://github.com/brettlangdon/drudge/issues", | |||
| "source": "https://github.com/brettlangdon/drudge" | |||
| }, | |||
| "require": { | |||
| "ext-uv": "*", | |||
| "docopt/docopt": ">=0.6.0" | |||
| }, | |||
| "bin": [ | |||
| "bin/drudge" | |||
| ], | |||
| "autoload": { | |||
| "psr-0": { | |||
| "Brettlangdon\\Drudge\\": "src/" | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,38 @@ | |||
| <?php | |||
| namespace Brettlangdon\Drudge; | |||
| class Server{ | |||
| protected $host = '0.0.0.0'; | |||
| protected $port = 80; | |||
| protected $handler = NULL; | |||
| private $server = NULL; | |||
| public function __construct($params, $handler){ | |||
| if(!is_array($params)){ | |||
| throw new InvalidArgumentException('Brettlangdon\\Drudge\\Server requires param 1 to be an array'); | |||
| } | |||
| if(!is_callable($handler)){ | |||
| throw new InvalidArgumentException('Brettlangdon\\Drudge\\Server requires param 2 to be a callable'); | |||
| } | |||
| if(array_key_exists('host', $params)){ | |||
| $this->host = $params['host']; | |||
| } | |||
| if(array_key_exists('port', $params)){ | |||
| $this->port = intval($params['port']); | |||
| } | |||
| $this->handler = $handler; | |||
| } | |||
| public function run(){ | |||
| } | |||
| public function __destruct(){ | |||
| } | |||
| } | |||