1. Go to this page and download the library: Download rcs_us/php-git-server library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rcs_us / php-git-server example snippets
if (PHP_SAPI == "cli-server") {
// To help the built-in PHP dev server, check if the request was actually for
// something which should probably be served as a static file
$file = __DIR__ . $_SERVER['REQUEST_URI'];
if (is_file($file)) {
return false;
}
}
// Define source path ( built in PHP server doesn't like relative paths )
defined('SOURCE_PATH')
|| define('SOURCE_PATH', (getenv('SOURCE_PATH') ? getenv('SOURCE_PATH') : dirname(__DIR__)));
defined('REPOSITORY_PATH')
|| define('REPOSITORY_PATH', (getenv('REPOSITORY_PATH') ? getenv('REPOSITORY_PATH') : "/tmp/git-repositories"));
$loader = webdav');
$r->addRoute('MKCOL', '/{repository}.git/[{path:.+}]', 'webdav');
$r->addRoute('LOCK', '/{repository}.git/[{path:.+}]', 'webdav');
$r->addRoute('PUT', '/{repository}.git/[{path:.+}]', 'webdav');
$r->addRoute('UNLOCK', '/{repository}.git/[{path:.+}]', 'webdav');
$r->addRoute('GET', '/{repository}.git/[{path:.+}]', 'webdav');
$r->addRoute('MOVE', '/{repository}.git/[{path:.+}]', 'webdav');
});
// Fetch method and URI from somewhere
$httpMethod = $_SERVER['REQUEST_METHOD'];
$uri = $_SERVER['REQUEST_URI'];
// Strip query string (?foo=bar) and decode URI
if (false !== $pos = strpos($uri, '?')) {
$uri = substr($uri, 0, $pos);
}
$uri = rawurldecode($uri);
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
switch ($routeInfo[0]) {
case \FastRoute\Dispatcher::NOT_FOUND:
error_log("\FastRoute\Dispatcher::NOT_FOUND");
// ... 404 Not Found
break;
case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
error_log("\FastRoute\Dispatcher::METHOD_NOT_ALLOWED");
$allowedMethods = $routeInfo[1];
// ... 405 Method Not Allowed
break;
case \FastRoute\Dispatcher::FOUND:
error_log("\FastRoute\Dispatcher::FOUND");
$handler = $routeInfo[1];
$vars = $routeInfo[2];
// ... call $handler with $vars
// list($class, $method) = explode(":", $handler, 2);
// call_user_func_array(array(new $class, $method), $vars);
call_user_func(array($rcsGitServer, $handler), $vars);
break;
}
// So you can see the requests as they come in on the PHP built in server
if (PHP_SAPI == "cli-server") {
error_log($_SERVER["REQUEST_METHOD"] . "::" . $_SERVER["REQUEST_URI"]."\n");
}
php -S localhost:8888 -t public index.php
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.