Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> This project tries to cover some PHP features in a simple MVC structure with minimum installed composer packages. Then developers can use packages for specific requirements. Please add your ideas in Discussions, ask features or report bugs in issues.

🚧 WIP: gRPC server _(gRPC client not completed yet, and gRPC server is under working, so be careful about the bugs in gRPC)_
🚧 WIP: gRPC server _(gRPC client not completed yet, and gRPC server is under working, so be careful about the bugs in gRPC)_

💡 TODO: WebSocket

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"files": [
"env.php",
"src/migrations.php",
"src/routes.php"
"src/routes.php",
"src/grpc_route.php"
],
"classmap": [
"src/"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
version: '3.1'

services:
php-mvc-server:
php-mvc-app-server:
image: nginx:alpine
container_name: php-mvc-server
container_name: php-mvc-app-server
volumes:
- ./:/var/www
- ./docker/nginx:/etc/nginx/conf.d/
- ./docker/nginx_http1:/etc/nginx/conf.d/
ports:
- '8080:80'
networks:
- php-mvc-network

php-mvc-grpc-server:
image: nginx:alpine
container_name: php-mvc-grpc-server
volumes:
- ./:/var/www
- ./docker/nginx_http2:/etc/nginx/conf.d/
ports:
- '8585:80'
networks:
- php-mvc-network

php-mvc-app:
build:
context: .
Expand Down
8 changes: 3 additions & 5 deletions docker/nginx/default.conf → docker/nginx_http1/default.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
server {
listen 80;
client_max_body_size 108M;
access_log /var/log/nginx/application.access.log;
access_log /var/log/nginx/app.access.log;
error_log /var/log/nginx/app.error.log;
index index.php;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;

# try to serve file directly, fallback to index.php
# Try to serve file directly, fallback to index.php
location / {
try_files $uri /index.php$is_args$args;
gzip_static on;
Expand All @@ -21,5 +20,4 @@ server {
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
fastcgi_param PATH_INFO $fastcgi_path_info;
}

}
11 changes: 11 additions & 0 deletions docker/nginx_http2/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
listen 80 http2;
client_max_body_size 108M;
access_log /var/log/nginx/grpc.access.log;
error_log /var/log/nginx/grpc.error.log;

# Listening for unencrypted gRPC traffic on port 80 and forwarding requests to the server on port 50051
location / {
grpc_pass grpc://localhost:50051;
}
}
10 changes: 6 additions & 4 deletions src/App/HandleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ public static function upload(
}
imagecopyresampled($newImage, $oldImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

$target2 = $target1 . $baseName . '.' . $fileExtension;
imagejpeg($newImage, $target2, 100);
$overlayImage = imagecreatefrompng($overlay);
imagecopyresampled($newImage, $overlayImage, 0, 0, 0, 0, $overlayWidth, $overlayHeight, $overlayWidth, $overlayHeight);
$target2 = $target . $baseName . '.' . $fileExtension;
if (!empty($overlay)) {
imagejpeg($newImage, $target2, 100);
$overlayImage = imagecreatefrompng($overlay);
imagecopyresampled($newImage, $overlayImage, 0, 0, 0, 0, $overlayWidth, $overlayHeight, $overlayWidth, $overlayHeight);
}
imagejpeg($newImage, $target2, $compressRate);

unlink($target1);
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/API/BlogGrpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BlogGrpcController implements BlogInterface
*
* @param string $host
*/
public function __construct(string $host)
public function __construct(string $host = 'localhost:50051')
{
$this->client = new BlogClient($host, ['credentials' => ChannelCredentials::createDefault()]);
}
Expand Down
12 changes: 8 additions & 4 deletions src/Models/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ public static function verify(object $request): bool
!is_null(Database::fetch())
&& !is_null(Database::fetch()['user_token'])
&& $request->user_token == Database::fetch()['user_token']
&& setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS))
) {
Database::query("UPDATE users SET verified = :verified WHERE email = :email");
Database::bind([
':verified' => 1,
':email' => $request->email,
]);

if (Database::execute()) return true;
if (Database::execute()) {
setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS));
return true;
}
}
return false;
}
Expand Down Expand Up @@ -111,8 +113,10 @@ public static function login(object $request): bool
&& password_verify($request->password, Database::fetch()['password'])
&& !is_null(Database::fetch()['user_token'])
&& Database::fetch()['verified']
&& setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS))
) return true;
) {
setcookie('loggedin', base64_encode($request->email), time() + (86400 * COOKIE_DAYS));
return true;
}
return false;
}

Expand Down
6 changes: 6 additions & 0 deletions src/grpc_route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$server = new \Grpc\RpcServer([]);
$server->addHttp2Port('localhost:50051');
$server->handle(new \Controllers\API\BlogGrpcController());
$server->run();
2 changes: 1 addition & 1 deletion src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Router::get('/logout', 'AuthController@logout');

/**
* API routes
* RESTful API routes
*/
Router::get('/api/blog', 'API\BlogController@index');
Router::get('/api/blog/(:any)', 'API\BlogController@show');
Expand Down