Skip to content

Instantly share code, notes, and snippets.

@shoma
Created February 29, 2016 03:21
Show Gist options
  • Save shoma/25e28d85d3d0eb24eb45 to your computer and use it in GitHub Desktop.
Save shoma/25e28d85d3d0eb24eb45 to your computer and use it in GitHub Desktop.
A patch to run DietCube on Google Compute Engine
diff -uprN orig/vendor/dietcube/dietcube/src/Application.php gce/vendor/dietcube/dietcube/src/Application.php
--- orig/vendor/dietcube/dietcube/src/Application.php 2016-01-29 13:08:52.000000000 +0900
+++ gce/vendor/dietcube/dietcube/src/Application.php 2016-02-25 19:36:22.315706094 +0900
@@ -71,7 +71,7 @@ abstract class Application
{
$server = $container['global.server']->get();
$this->host = $server['HTTP_HOST'];
- $this->port = $server['SERVER_PORT'];
+ $this->port = isset($server['SERVER_PORT']) ? $server['SERVER_PORT'] : 80;
$this->protocol = (($this->port == '443' || (isset($server['X_FORWARDED_PROTO']) && $server['X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http');
$this->path = parse_url($server['REQUEST_URI'])['path'];
$this->url = $this->protocol . '://' . $this->host;
diff -uprN orig/vendor/dietcube/dietcube/src/Dispatcher.php gce/vendor/dietcube/dietcube/src/Dispatcher.php
--- orig/vendor/dietcube/dietcube/src/Dispatcher.php 2016-01-29 13:08:52.000000000 +0900
+++ gce/vendor/dietcube/dietcube/src/Dispatcher.php 2016-02-25 19:14:53.164020471 +0900
@@ -16,6 +16,7 @@ use Dietcube\Exception\HttpNotFoundExcep
use Dietcube\Exception\HttpMethodNotAllowedException;
use Dietcube\Exception\HttpErrorException;
use Dietcube\Twig\DietcubeExtension;
+use Monolog\Handler\SyslogHandler;
use Pimple\Container;
use FastRoute\Dispatcher as RouteDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -90,17 +92,7 @@ class Dispatcher
{
$logger = new Logger('app');
$logger->pushProcessor(new PsrLogMessageProcessor);
-
- if (is_writable($path) || is_writable(dirname($path))) {
- $logger->pushHandler(new StreamHandler($path, $level));
- } else {
- if ($this->app->isDebug()) {
- throw new DCException("Log path '{$path}' is not writable. Make sure your logger.path of config.");
- }
- $logger->pushHandler(new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, $level));
- $logger->warning("Log path '{$path}' is not writable. Make sure your logger.path of config.");
- $logger->warning("error_log() is used for application logger instead at this time.");
- }
+ $logger->pushHandler(new SyslogHandler('intranet', LOG_USER, $level));
return $logger;
}
diff -uprN orig/vendor/dietcube/dietcube/src/Response.php gce/vendor/dietcube/dietcube/src/Response.php
--- orig/vendor/dietcube/dietcube/src/Response.php 2016-01-29 13:08:52.000000000 +0900
+++ gce/vendor/dietcube/dietcube/src/Response.php 2016-02-25 19:20:50.400776459 +0900
@@ -14,7 +14,7 @@ class Response
use LoggerAwareTrait;
/** @const array Map of standard HTTP status code/reason phrases */
- const PHRASES = [
+ public static function PHRASES() { return [
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
@@ -73,7 +73,7 @@ class Response
507 => 'Insufficient Storage',
508 => 'Loop Detected',
511 => 'Network Authentication Required',
- ];
+ ];}
/** @var null|string */
protected $reason_phrase = '';
@@ -99,7 +99,8 @@ class Response
*/
public function setStatusCode($status_code)
{
- if (null === self::PHRASES[$this->status_code]) {
+ $phrases = self::PHRASES();
+ if (null === $phrases[$this->status_code]) {
throw new \InvalidArgumentException("Invalid status code '{$this->status_code}'");
}
@@ -137,8 +138,9 @@ class Response
return $this;
}
- if (null !== self::PHRASES[$this->status_code]) {
- $this->reason_phrase = self::PHRASES[$this->status_code];
+ $phrases = self::PHRASES();
+ if (null !== $phrases[$this->status_code]) {
+ $this->reason_phrase = $phrases[$this->status_code];
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment