Browse Source

init

tags/v1.0.0
Robin Thoni 7 years ago
commit
32e2c65f72

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+/vendor
2
+/.idea

+ 16
- 0
README.md View File

@@ -0,0 +1,16 @@
1
+# Luticate 2
2
+
3
+## Docker
4
+
5
+```shell
6
+projectName=myproject
7
+apiLocation="/var/${projectName}"
8
+httpPort=8080
9
+wsPort=8180
10
+
11
+imageName="${projectName}"-luticate2-image
12
+containerName="${projectName}"-luticate2-container
13
+cd docker
14
+docker build -t "${tag}" 
15
+docker run -d -v "${apiLocation}":/var/www -p ${httpPort}:80 -p ${wsPort}:81 --name="${containerName}" "${imageName}"
16
+```

+ 33
- 0
app/Business/MiscBusiness.php View File

@@ -0,0 +1,33 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 10:04 PM
7
+ */
8
+
9
+namespace App\Business;
10
+
11
+use App\DataAccess\MiscDataAccess;
12
+
13
+class MiscBusiness
14
+{
15
+    protected static function getDataAccess()
16
+    {
17
+        return new MiscDataAccess();
18
+    }
19
+
20
+    public static function getConfig()
21
+    {
22
+        $data = static::getDataAccess()->getConfigWebPage();
23
+
24
+        $needle = "window.transitOptions =";
25
+        $pos = strpos($data, $needle);
26
+        $data = substr($data, $pos + strlen($needle));
27
+
28
+        $pos = strpos($data, "</script");
29
+        $data = substr($data, 0, $pos);
30
+
31
+        return json_decode($data, true);
32
+    }
33
+}

+ 24
- 0
app/Business/RoutesBusiness.php View File

@@ -0,0 +1,24 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 8:58 PM
7
+ */
8
+
9
+namespace App\Business;
10
+
11
+use App\DataAccess\RoutesDataAccess;
12
+
13
+class RoutesBusiness
14
+{
15
+    protected static function getDataAccess()
16
+    {
17
+        return new RoutesDataAccess();
18
+    }
19
+
20
+    public static function getAll()
21
+    {
22
+        return static::getDataAccess()->getAll();
23
+    }
24
+}

+ 64
- 0
app/Business/StopsBusiness.php View File

@@ -0,0 +1,64 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 8:58 PM
7
+ */
8
+
9
+namespace App\Business;
10
+
11
+
12
+use App\DataAccess\StopsDataAccess;
13
+use App\Dbo\StopsDbo;
14
+use Luticate\Utils\Dbo\LuPaginatedDbo;
15
+
16
+class StopsBusiness
17
+{
18
+    protected static function getDataAccess()
19
+    {
20
+        return new StopsDataAccess();
21
+    }
22
+
23
+    public static function getStopDboById(array $dbos, string $id)
24
+    {
25
+        /**
26
+         * @var $dbos StopsDbo[]
27
+         */
28
+        foreach ($dbos as $dbo) {
29
+            if ($dbo->getId() == $id) {
30
+                return $dbo;
31
+            }
32
+        }
33
+        return null;
34
+    }
35
+
36
+    public static function mergeStringArray(array $array1, array $array2)
37
+    {
38
+        foreach ($array2 as $e) {
39
+            if (!in_array($e, $array1)) {
40
+                $array1[] = $e;
41
+            }
42
+        }
43
+        return $array1;
44
+    }
45
+
46
+    public static function getAll()
47
+    {
48
+        $config = MiscBusiness::getConfig();
49
+        $dbos = [];
50
+        foreach ($config["scheduleTypes"] as $scheduleType) {
51
+            $scheduleDbos = static::getDataAccess()->getAll($scheduleType["resourceId"], $scheduleType["type"]);
52
+            foreach ($scheduleDbos as $scheduleDbo) {
53
+                $dbo = static::getStopDboById($dbos, $scheduleDbo->getId());
54
+                if (is_null($dbo)) {
55
+                    $dbos[] = $scheduleDbo;
56
+                }
57
+                else {
58
+                    $dbo->setRoutes(static::mergeStringArray($dbo->getRoutes(), $dbo->getRoutes()));
59
+                }
60
+            }
61
+        }
62
+        return new LuPaginatedDbo(count($dbos), $dbos);
63
+    }
64
+}

+ 30
- 0
app/Controller/RoutesController.php View File

@@ -0,0 +1,30 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 8:59 PM
7
+ */
8
+
9
+namespace App\Controller;
10
+
11
+use App\Business\RoutesBusiness;
12
+use Luticate\Utils\Controller\LuController;
13
+use Luticate\Utils\Dbo\LuPaginatedDbo;
14
+
15
+class RoutesController extends LuController
16
+{
17
+    protected function getBusiness()
18
+    {
19
+        return new RoutesBusiness();
20
+    }
21
+
22
+    /**
23
+     * Get all routes, without any pagination
24
+     * @return LuPaginatedDbo
25
+     */
26
+    public function getAll()
27
+    {
28
+        return static::getBusiness()->getAll();
29
+    }
30
+}

+ 30
- 0
app/Controller/StopsController.php View File

@@ -0,0 +1,30 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 8:59 PM
7
+ */
8
+
9
+namespace App\Controller;
10
+
11
+use App\Business\StopsBusiness;
12
+use Luticate\Utils\Controller\LuController;
13
+use Luticate\Utils\Dbo\LuPaginatedDbo;
14
+
15
+class StopsController extends LuController
16
+{
17
+    protected function getBusiness()
18
+    {
19
+        return new StopsBusiness();
20
+    }
21
+
22
+    /**
23
+     * Get all stops, without any pagination
24
+     * @return LuPaginatedDbo
25
+     */
26
+    public function getAll()
27
+    {
28
+        return static::getBusiness()->getAll();
29
+    }
30
+}

+ 25
- 0
app/DataAccess/MiscDataAccess.php View File

@@ -0,0 +1,25 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 10:04 PM
7
+ */
8
+
9
+namespace App\DataAccess;
10
+
11
+
12
+use GuzzleHttp\Client;
13
+use Luticate\Utils\Controller\LuticateApplication;
14
+
15
+class MiscDataAccess
16
+{
17
+    public static function getConfigWebPage()
18
+    {
19
+        $client = new Client();
20
+        $configWebPage = LuticateApplication::getInstance()->getSetting("API_CONFIG_WEBPAGE");
21
+        $response = $client->request("GET", $configWebPage);
22
+        $data = (string)$response->getBody();
23
+        return $data;
24
+    }
25
+}

+ 23
- 0
app/DataAccess/RoutesDataAccess.php View File

@@ -0,0 +1,23 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 8:57 PM
7
+ */
8
+
9
+namespace App\DataAccess;
10
+
11
+use GuzzleHttp\Client;
12
+use Luticate\Utils\Controller\LuticateApplication;
13
+use Luticate\Utils\Dbo\LuPaginatedDbo;
14
+
15
+class RoutesDataAccess
16
+{
17
+    public static function getAll()
18
+    {
19
+        $client = new Client();
20
+        $response = $client->request("GET", LuticateApplication::getInstance()->getSetting("API_ENTRYPOINT") . "");
21
+        return new LuPaginatedDbo();
22
+    }
23
+}

+ 41
- 0
app/DataAccess/StopsDataAccess.php View File

@@ -0,0 +1,41 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 8:57 PM
7
+ */
8
+
9
+namespace App\DataAccess;
10
+
11
+
12
+use App\Business\MiscBusiness;
13
+use App\Dbo\StopsDbo;
14
+use GuzzleHttp\Client;
15
+use Luticate\Utils\Controller\LuticateApplication;
16
+use Luticate\Utils\Dbo\LuPaginatedDbo;
17
+
18
+class StopsDataAccess
19
+{
20
+    public static function getAll(string $resourceId, string $type)
21
+    {
22
+        $client = new Client();
23
+        $entrypoint = LuticateApplication::getInstance()->getSetting("API_ENTRYPOINT");
24
+        $response = $client->request("GET", $entrypoint . "transit/${resourceId}/${type}/stops.json");
25
+        $data = json_decode($response->getBody(), true);
26
+        /**
27
+         * @var $dbos StopsDbo[]
28
+         */
29
+        $dbos = [];
30
+        foreach ($data["features"] as $stop) {
31
+            $dbo = new StopsDbo();
32
+            $dbo->setId($stop["id"]);
33
+            $dbo->setName($stop["properties"]["name"]);
34
+            $dbo->setPosX($stop["geometry"]["coordinates"][0]);
35
+            $dbo->setPosY($stop["geometry"]["coordinates"][1]);
36
+            $dbo->setRoutes($stop["properties"]["route_ids"]);
37
+            $dbos[] = $dbo;
38
+        }
39
+        return $dbos;
40
+    }
41
+}

+ 121
- 0
app/Dbo/StopsDbo.php View File

@@ -0,0 +1,121 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 9:46 PM
7
+ */
8
+
9
+namespace App\Dbo;
10
+
11
+
12
+use Luticate\Utils\Dbo\LuDbo;
13
+
14
+class StopsDbo extends LuDbo
15
+{
16
+    /**
17
+     * @var $_name string
18
+     */
19
+    protected $_name;
20
+
21
+    /**
22
+     * @var $_id string
23
+     */
24
+    protected $_id;
25
+
26
+    /**
27
+     * @var $_posX float
28
+     */
29
+    protected $_posX;
30
+
31
+    /**
32
+     * @var $_posY float
33
+     */
34
+    protected $_posY;
35
+
36
+    /**
37
+     * @var $_routes string[]
38
+     */
39
+    protected $_routes;
40
+
41
+    /**
42
+     * @return string
43
+     */
44
+    public function getName(): string
45
+    {
46
+        return $this->_name;
47
+    }
48
+
49
+    /**
50
+     * @param string $name
51
+     */
52
+    public function setName(string $name)
53
+    {
54
+        $this->_name = $name;
55
+    }
56
+
57
+    /**
58
+     * @return string
59
+     */
60
+    public function getId(): string
61
+    {
62
+        return $this->_id;
63
+    }
64
+
65
+    /**
66
+     * @param string $id
67
+     */
68
+    public function setId(string $id)
69
+    {
70
+        $this->_id = $id;
71
+    }
72
+
73
+    /**
74
+     * @return float
75
+     */
76
+    public function getPosX(): float
77
+    {
78
+        return $this->_posX;
79
+    }
80
+
81
+    /**
82
+     * @param float $posX
83
+     */
84
+    public function setPosX(float $posX)
85
+    {
86
+        $this->_posX = $posX;
87
+    }
88
+
89
+    /**
90
+     * @return float
91
+     */
92
+    public function getPosY(): float
93
+    {
94
+        return $this->_posY;
95
+    }
96
+
97
+    /**
98
+     * @param float $posY
99
+     */
100
+    public function setPosY(float $posY)
101
+    {
102
+        $this->_posY = $posY;
103
+    }
104
+
105
+    /**
106
+     * @return \string[]
107
+     */
108
+    public function getRoutes(): array
109
+    {
110
+        return $this->_routes;
111
+    }
112
+
113
+    /**
114
+     * @param \string[] $routes
115
+     */
116
+    public function setRoutes(array $routes)
117
+    {
118
+        $this->_routes = $routes;
119
+    }
120
+
121
+}

+ 7
- 0
app/Http/http.php View File

@@ -0,0 +1,7 @@
1
+<?php
2
+
3
+namespace App\Http;
4
+
5
+$app = require_once __DIR__ . "/../bootstrap.php";
6
+
7
+$app->runHttp();

+ 0
- 0
app/Middleware/.gitkeep View File


+ 25
- 0
app/Middleware/Test2Middleware.php View File

@@ -0,0 +1,25 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 6/5/16
6
+ * Time: 5:56 PM
7
+ */
8
+
9
+namespace App\Middleware;
10
+
11
+use Luticate\Utils\Dbo\LuRouteDbo;
12
+use Luticate\Utils\Middleware\LuAbstractMiddleware;
13
+
14
+class Test2Middleware implements LuAbstractMiddleware
15
+{
16
+    public function onBefore($_parameters)
17
+    {
18
+        return $_parameters;
19
+    }
20
+
21
+    public function onAfter($_result)
22
+    {
23
+        return $_result;
24
+    }
25
+}

+ 25
- 0
app/Middleware/TestMiddleware.php View File

@@ -0,0 +1,25 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 6/5/16
6
+ * Time: 5:56 PM
7
+ */
8
+
9
+namespace App\Middleware;
10
+
11
+use Luticate\Utils\Dbo\LuRouteDbo;
12
+use Luticate\Utils\Middleware\LuAbstractMiddleware;
13
+
14
+class TestMiddleware implements LuAbstractMiddleware
15
+{
16
+    public function onBefore($_parameters)
17
+    {
18
+        return $_parameters;
19
+    }
20
+
21
+    public function onAfter($_result)
22
+    {
23
+        return $_result;
24
+    }
25
+}

+ 7
- 0
app/WebSocket/websocket.php View File

@@ -0,0 +1,7 @@
1
+<?php
2
+
3
+namespace App\WebSocket;
4
+
5
+$app = require_once __DIR__ . "/../bootstrap.php";
6
+
7
+$app->runWs();

+ 15
- 0
app/bootstrap.php View File

@@ -0,0 +1,15 @@
1
+<?php
2
+use Luticate\Utils\Controller\LuticateApplication;
3
+
4
+require_once __DIR__ . '/../vendor/autoload.php';
5
+
6
+$json = file_get_contents(__DIR__ . '/../config.json');
7
+$config = json_decode($json, true);
8
+
9
+$app = new LuticateApplication($config);
10
+
11
+$app->setVersion(1.0);
12
+
13
+$app->setupRoutes();
14
+
15
+return $app;

+ 15
- 0
app/routes.php View File

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+/**
4
+ * @var $route \Luticate\Utils\Controller\LuRoute
5
+ */
6
+$route = $app->getRouter();
7
+
8
+//$route->addMiddleware(['middleware' => 'App\Middleware\TestMiddleware', "parameters" => ["test" => "lol"]]);
9
+
10
+//$route->get("/{test}", "Test", "test", ["permissions" => ["LU_PERMISSION"], "test2" => "lol2_"],
11
+//    [['middleware' => 'App\Middleware\Test2Middleware', "parameters" => ["test2" => "lol2"]]]);
12
+
13
+$route->get("/routes", "Routes", "getAll");
14
+
15
+$route->get("/stops", "Stops", "getAll");

+ 29
- 0
composer.json View File

@@ -0,0 +1,29 @@
1
+{
2
+    "name": "luticate/luticate",
3
+    "description": "The Luticate Framework.",
4
+    "keywords": ["framework", "luticate"],
5
+    "license": "MIT",
6
+    "type": "project",
7
+    "repositories": [{
8
+        "type": "vcs",
9
+        "url":  "https://git.rthoni.com/luticate/api-utils.git"
10
+    }],
11
+    "require": {
12
+        "php": ">=5.5.9",
13
+        "luticate/utils": "dev-develop"
14
+    },
15
+    "require-dev": {
16
+        "phpunit/phpunit": "~4.0"
17
+    },
18
+    "autoload": {
19
+        "psr-4": {
20
+            "App\\": "app/"
21
+        }
22
+    },
23
+    "autoload-dev": {
24
+        "classmap": [
25
+            "tests/"
26
+        ]
27
+    },
28
+    "minimum-stability": "dev"
29
+}

+ 2548
- 0
composer.lock
File diff suppressed because it is too large
View File


+ 13
- 0
config.json View File

@@ -0,0 +1,13 @@
1
+{
2
+  "logs": "storage/logs/luticate.log",
3
+  "websocket": {
4
+    "address": "0.0.0.0",
5
+    "port": 8180
6
+  },
7
+  "databases": [
8
+  ],
9
+  "settings": {
10
+    "API_ENTRYPOINT": "http://horaires.sts.saguenay.ca/api/",
11
+    "API_CONFIG_WEBPAGE": "http://horaires.sts.saguenay.ca/"
12
+  }
13
+}

+ 144
- 0
docker/Dockerfile View File

@@ -0,0 +1,144 @@
1
+FROM debian:jessie
2
+
3
+MAINTAINER Robin Thoni <robin@rthoni.com>
4
+
5
+# Build php
6
+# ======================================================================================================================
7
+
8
+ENV PHPIZE_DEPS \
9
+            autoconf \
10
+            file \
11
+            g++ \
12
+            gcc \
13
+            libc-dev \
14
+            make \
15
+            pkg-config \
16
+            re2c
17
+RUN apt-get update \
18
+        && apt-get install -y \
19
+		    $PHPIZE_DEPS \
20
+		    ca-certificates \
21
+		    curl \
22
+		    libedit2 \
23
+		    libsqlite3-0 \
24
+		    libxml2 \
25
+	        --no-install-recommends \
26
+	    && rm -r /var/lib/apt/lists/*
27
+
28
+ENV PHP_INI_DIR /etc/php7.0
29
+RUN mkdir -p $PHP_INI_DIR/conf.d
30
+
31
+RUN apt-get update \
32
+        && apt-get install -y apache2-bin apache2.2-common --no-install-recommends \
33
+        && rm -rf /var/lib/apt/lists/*
34
+
35
+RUN rm -rf /var/www/html \
36
+        && mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html \
37
+        && chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html
38
+
39
+RUN a2dismod mpm_event \
40
+        && a2enmod mpm_prefork
41
+
42
+RUN mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.dist \
43
+        && rm /etc/apache2/conf-enabled/* /etc/apache2/sites-enabled/*
44
+COPY apache2.conf /etc/apache2/apache2.conf
45
+
46
+ENV PHP_EXTRA_BUILD_DEPS apache2-dev
47
+ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --enable-maintainer-zts --enable-pthreads
48
+
49
+ENV GPG_KEYS 1A4E8B7277C42E53DBA9C7B9BCAA30EA9C0D5763
50
+
51
+ENV PHP_VERSION 7.0.7
52
+ENV PHP_FILENAME php-7.0.7.tar.xz
53
+ENV PHP_SHA256 9cc64a7459242c79c10e79d74feaf5bae3541f604966ceb600c3d2e8f5fe4794
54
+
55
+RUN set -xe \
56
+        && buildDeps=" \
57
+            $PHP_EXTRA_BUILD_DEPS \
58
+            libcurl4-openssl-dev \
59
+            libedit-dev \
60
+            libsqlite3-dev \
61
+            libssl-dev \
62
+            libxml2-dev \
63
+            xz-utils \
64
+        " \
65
+        && apt-get update \
66
+        && apt-get install -y $buildDeps --no-install-recommends \
67
+        && rm -rf /var/lib/apt/lists/* \
68
+        && curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
69
+        && echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
70
+        && curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
71
+        && export GNUPGHOME="$(mktemp -d)" \
72
+        && for key in $GPG_KEYS; do \
73
+            gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
74
+            done \
75
+        && gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
76
+        && rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \
77
+        && mkdir -p /usr/src/php \
78
+        && tar -xf "$PHP_FILENAME" -C /usr/src/php --strip-components=1 \
79
+        && rm "$PHP_FILENAME" \
80
+        && cd /usr/src/php \
81
+        && ./configure \
82
+            --with-config-file-path="$PHP_INI_DIR" \
83
+            --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
84
+            $PHP_EXTRA_CONFIGURE_ARGS \
85
+            --disable-cgi \
86
+            --enable-mysqlnd \
87
+            --enable-mbstring \
88
+            --with-curl \
89
+            --with-libedit \
90
+            --with-openssl \
91
+            --with-zlib \
92
+        && make -j"$(nproc)" \
93
+        && make install \
94
+        && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
95
+        && make clean \
96
+        && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps
97
+
98
+RUN ln -sf /dev/stdout /var/log/apache2/access.log \
99
+        && ln -sf /dev/stderr /var/log/apache2/error.log \
100
+        && ln -sf /dev/stdout /var/log/websocket.log \
101
+        && ln -sf /dev/stderr /var/log/websocket.err \
102
+        && a2enmod rewrite \
103
+        && rm -rf /var/www/* \
104
+        && chown -R www-data:www-data /var/www
105
+
106
+RUN pecl install pthreads
107
+
108
+# Install Composer
109
+# ======================================================================================================================
110
+RUN curl https://getcomposer.org/composer.phar -o /usr/local/bin/composer \
111
+        && chmod +x /usr/local/bin/composer
112
+
113
+RUN apt-get update \
114
+        && apt-get install -y git unzip --no-install-recommends \
115
+        && rm -rf /var/lib/apt/lists/*
116
+
117
+# Add pdo and db drivers
118
+# ======================================================================================================================
119
+
120
+COPY docker-php-ext-* /usr/local/bin/
121
+
122
+RUN buildDeps="libpq-dev libzip-dev " \
123
+        && apt-get update \
124
+        && apt-get install -y $buildDeps --no-install-recommends \
125
+        && rm -rf /var/lib/apt/lists/* \
126
+        && docker-php-ext-install pdo pdo_pgsql pgsql
127
+
128
+# Install PHP config files
129
+# ======================================================================================================================
130
+
131
+COPY php-cli.ini "${PHP_INI_DIR}"/
132
+COPY php-apache.ini "${PHP_INI_DIR}"/php-apache2handler.ini
133
+
134
+# Run everything
135
+# ======================================================================================================================
136
+
137
+COPY run.sh /usr/local/bin/
138
+
139
+WORKDIR /var/www
140
+
141
+EXPOSE 8180
142
+EXPOSE 80
143
+VOLUME ["/var/www"]
144
+CMD ["run.sh"]

+ 59
- 0
docker/apache2.conf View File

@@ -0,0 +1,59 @@
1
+# see http://sources.debian.net/src/apache2/2.4.10-1/debian/config-dir/apache2.conf
2
+
3
+Mutex file:/var/lock/apache2 default
4
+PidFile /var/run/apache2/apache2.pid
5
+Timeout 300
6
+KeepAlive On
7
+MaxKeepAliveRequests 100
8
+KeepAliveTimeout 5
9
+User www-data
10
+Group www-data
11
+HostnameLookups Off
12
+ErrorLog /var/log/apache2/error.log
13
+LogLevel warn
14
+
15
+IncludeOptional mods-enabled/*.load
16
+IncludeOptional mods-enabled/*.conf
17
+
18
+# ports.conf
19
+Listen 80
20
+<IfModule ssl_module>
21
+    Listen 443
22
+</IfModule>
23
+<IfModule mod_gnutls.c>
24
+    Listen 443
25
+</IfModule>
26
+
27
+DocumentRoot "/var/www/public/"
28
+
29
+<Directory />
30
+    Options FollowSymLinks
31
+    AllowOverride None
32
+    Require all denied
33
+</Directory>
34
+
35
+<Directory /var/www/public/>
36
+    Options FollowSymLinks
37
+    AllowOverride All
38
+    Require all granted
39
+</Directory>
40
+
41
+
42
+
43
+LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
44
+LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
45
+LogFormat "%h %l %u %t \"%r\" %>s %O" common
46
+LogFormat "%{Referer}i -> %U" referer
47
+LogFormat "%{User-agent}i" agent
48
+
49
+CustomLog /var/log/apache2/access.log combined
50
+
51
+<FilesMatch \.php$>
52
+    SetHandler application/x-httpd-php
53
+</FilesMatch>
54
+
55
+# Multiple DirectoryIndex directives within the same context will add
56
+# to the list of resources to look for rather than replace
57
+# https://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex
58
+DirectoryIndex disabled
59
+DirectoryIndex index.php

+ 19
- 0
docker/docker-php-ext-configure View File

@@ -0,0 +1,19 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+ext="$1"
5
+extDir="/usr/src/php/ext/$ext"
6
+if [ -z "$ext" ] || ! [ -d "$extDir" ]; then
7
+	echo >&2 "usage: $0 ext-name [configure flags]"
8
+	echo >&2 "   ie: $0 gd --with-jpeg-dir=/usr/local/something"
9
+	echo >&2
10
+	echo >&2 'Possible values for ext-name:'
11
+	echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
12
+	exit 1
13
+fi
14
+shift
15
+
16
+set -x
17
+cd "$extDir"
18
+phpize
19
+./configure "$@"

+ 83
- 0
docker/docker-php-ext-enable View File

@@ -0,0 +1,83 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+cd "$(php -r 'echo ini_get("extension_dir");')"
5
+
6
+usage() {
7
+	echo "usage: $0 [options] module-name [module-name ...]"
8
+	echo "   ie: $0 gd mysqli"
9
+	echo "       $0 pdo pdo_mysql"
10
+	echo "       $0 --ini-name 0-apc.ini apcu apc"
11
+	echo
12
+	echo 'Possible values for module-name:'
13
+	echo $(find -maxdepth 1 -type f -name '*.so' -exec basename '{}' ';' | sort)
14
+}
15
+
16
+opts="$(getopt -o 'h?' --long 'help,ini-name:' -- "$@" || { usage >&2 && false; })"
17
+eval set -- "$opts"
18
+
19
+iniName=
20
+while true; do
21
+	flag="$1"
22
+	shift
23
+	case "$flag" in
24
+		--help|-h|'-?') usage && exit 0 ;;
25
+		--ini-name) iniName="$1" && shift ;;
26
+		--) break ;;
27
+		*)
28
+			{
29
+				echo "error: unknown flag: $flag"
30
+				usage
31
+			} >&2
32
+			exit 1
33
+			;;
34
+	esac
35
+done
36
+
37
+modules=
38
+for module; do
39
+	if [ -z "$module" ]; then
40
+		continue
41
+	fi
42
+	if [ -f "$module.so" ] && ! [ -f "$module" ]; then
43
+		# allow ".so" to be optional
44
+		module="$module.so"
45
+	fi
46
+	if ! [ -f "$module" ]; then
47
+		echo >&2 "error: $(readlink -f "$module") does not exist"
48
+		echo >&2
49
+		usage >&2
50
+		exit 1
51
+	fi
52
+	modules="$modules $module"
53
+done
54
+
55
+if [ -z "$modules" ]; then
56
+	usage >&2
57
+	exit 1
58
+fi
59
+
60
+for module in $modules; do
61
+	if nm -g "$module" | grep -q ' zend_extension_entry$'; then
62
+		# https://wiki.php.net/internals/extensions#loading_zend_extensions
63
+		line="zend_extension=$(readlink -f "$module")"
64
+	else
65
+		line="extension=$module"
66
+	fi
67
+
68
+	ext="$(basename "$module")"
69
+	ext="${ext%.*}"
70
+	if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then
71
+		# this isn't perfect, but it's better than nothing
72
+		# (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache')
73
+		echo >&2
74
+		echo >&2 "warning: $ext ($module) is already loaded!"
75
+		echo >&2
76
+		continue
77
+	fi
78
+
79
+	ini="${PHP_INI_DIR}/conf.d/${iniName:-"docker-php-ext-$ext.ini"}"
80
+	if ! grep -q "$line" "$ini" 2>/dev/null; then
81
+		echo "$line" >> "$ini"
82
+	fi
83
+done

+ 79
- 0
docker/docker-php-ext-install View File

@@ -0,0 +1,79 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+cd /usr/src/php/ext
5
+
6
+usage() {
7
+	echo "usage: $0 [-jN] ext-name [ext-name ...]"
8
+	echo "   ie: $0 gd mysqli"
9
+	echo "       $0 pdo pdo_mysql"
10
+	echo "       $0 -j5 gd mbstring mysqli pdo pdo_mysql shmop"
11
+	echo
12
+	echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure'
13
+	echo
14
+	echo 'Possible values for ext-name:'
15
+	echo $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
16
+}
17
+
18
+opts="$(getopt -o 'h?j:' --long 'help,jobs:' -- "$@" || { usage >&2 && false; })"
19
+eval set -- "$opts"
20
+
21
+j=1
22
+while true; do
23
+	flag="$1"
24
+	shift
25
+	case "$flag" in
26
+		--help|-h|'-?') usage && exit 0 ;;
27
+		--jobs|-j) j="$1" && shift ;;
28
+		--) break ;;
29
+		*)
30
+			{
31
+				echo "error: unknown flag: $flag"
32
+				usage
33
+			} >&2
34
+			exit 1
35
+			;;
36
+	esac
37
+done
38
+
39
+exts=
40
+for ext; do
41
+	if [ -z "$ext" ]; then
42
+		continue
43
+	fi
44
+	if [ ! -d "$ext" ]; then
45
+		echo >&2 "error: $(pwd -P)/$ext does not exist"
46
+		echo >&2
47
+		usage >&2
48
+		exit 1
49
+	fi
50
+	exts="$exts $ext"
51
+done
52
+
53
+if [ -z "$exts" ]; then
54
+	usage >&2
55
+	exit 1
56
+fi
57
+
58
+if [ -e /lib/apk/db/installed ] && [ -n "$PHPIZE_DEPS" ]; then
59
+	apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS
60
+fi
61
+
62
+for ext in $exts; do
63
+	(
64
+		cd "$ext"
65
+		[ -e Makefile ] || docker-php-ext-configure "$ext"
66
+		make -j"$j"
67
+		make -j"$j" install
68
+		find modules \
69
+			-maxdepth 1 \
70
+			-name '*.so' \
71
+			-exec basename '{}' ';' \
72
+				| xargs -r docker-php-ext-enable
73
+		make -j"$j" clean
74
+	)
75
+done
76
+
77
+if [ -e /lib/apk/db/installed ] && [ -n "$PHPIZE_DEPS" ]; then
78
+	apk del .phpize-deps
79
+fi

+ 1
- 0
docker/php-apache.ini View File

@@ -0,0 +1 @@
1
+[PHP]

+ 2
- 0
docker/php-cli.ini View File

@@ -0,0 +1,2 @@
1
+[PHP]
2
+extension=pthreads.so

+ 6
- 0
docker/run.sh View File

@@ -0,0 +1,6 @@
1
+#!/bin/bash
2
+
3
+php -c /etc/php/cli /var/www/app/WebSocket/websocket.php >/var/log/websocket.log 2>/var/log/websocket.err &
4
+
5
+rm -f /run/apache2/apache2.pid
6
+exec /usr/sbin/apache2ctl -D FOREGROUND

+ 25
- 0
phpunit.xml View File

@@ -0,0 +1,25 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<phpunit backupGlobals="false"
3
+         backupStaticAttributes="false"
4
+         bootstrap="app/bootstrap.php"
5
+         colors="true"
6
+         convertErrorsToExceptions="true"
7
+         convertNoticesToExceptions="true"
8
+         convertWarningsToExceptions="true"
9
+         processIsolation="false"
10
+         stopOnFailure="false"
11
+         syntaxCheck="false">
12
+    <testsuites>
13
+        <testsuite name="Application Test Suite">
14
+            <directory>./tests/</directory>
15
+        </testsuite>
16
+    </testsuites>
17
+    <filter>
18
+        <whitelist>
19
+            <directory suffix=".php">app/</directory>
20
+        </whitelist>
21
+    </filter>
22
+    <php>
23
+        <env name="APP_ENV" value="testing"/>
24
+    </php>
25
+</phpunit>

+ 12
- 0
public/.htaccess View File

@@ -0,0 +1,12 @@
1
+RewriteEngine On
2
+
3
+# Redirect Trailing Slashes
4
+RewriteRule ^(.*)/$ /$1 [L]
5
+
6
+# Redirect Root
7
+RewriteRule ^$ api.php [L]
8
+
9
+# Handle API Requests
10
+RewriteCond %{REQUEST_FILENAME} !-d
11
+RewriteCond %{REQUEST_FILENAME} !-f
12
+RewriteRule ^ api.php [L]

+ 2
- 0
public/api.php View File

@@ -0,0 +1,2 @@
1
+<?php
2
+require_once "../app/Http/http.php";

+ 2
- 0
storage/logs/.gitignore View File

@@ -0,0 +1,2 @@
1
+*
2
+!.gitignore

Loading…
Cancel
Save