-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hw4 #94
Open
Rustyam
wants to merge
2
commits into
RMulyukov/main
Choose a base branch
from
RMulyukov/hw4
base: RMulyukov/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
hw4 #94
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rmulyukov\Hw4; | ||
|
||
final class BracesChecker | ||
{ | ||
private array $braces = []; | ||
|
||
public function check(string $braces): bool | ||
{ | ||
if (empty($braces)) { | ||
return false; | ||
} | ||
|
||
for ($i = 0; $i < strlen($braces); $i++) { | ||
if (!$this->handle($braces[$i])) { | ||
return false; | ||
} | ||
} | ||
return !$this->hasBraces(); | ||
} | ||
|
||
private function handle(string $brace): bool | ||
{ | ||
if ($brace === ')') { | ||
return $this->removeBrace(); | ||
} | ||
$this->addBrace(); | ||
return true; | ||
} | ||
|
||
private function removeBrace(): bool | ||
{ | ||
if (!$this->hasBraces()) { | ||
return false; | ||
} | ||
array_pop($this->braces); | ||
return true; | ||
} | ||
|
||
private function addBrace(): void | ||
{ | ||
$this->braces[] = ')'; | ||
} | ||
|
||
private function hasBraces(): bool | ||
{ | ||
return count($this->braces) > 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rmulyukov\Hw4; | ||
|
||
final readonly class Request | ||
{ | ||
private array $post; | ||
|
||
public function __construct() | ||
{ | ||
$this->post = $_POST; | ||
} | ||
|
||
public function get(string $key, string $default = ''): string | ||
{ | ||
$value = $this->post[$key] ?? null; | ||
return is_string($value) ? $value : $default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rmulyukov\Hw4; | ||
|
||
final class Response | ||
{ | ||
private string $message; | ||
private string $header; | ||
|
||
public function __construct(bool $success) | ||
{ | ||
if ($success) { | ||
$this->initSuccess(); | ||
} else { | ||
$this->initError(); | ||
} | ||
} | ||
|
||
public function send(): string | ||
{ | ||
header($this->header); | ||
return $this->message; | ||
} | ||
|
||
private function initSuccess(): void | ||
{ | ||
$this->header = 'HTTP/1.1 200 OK'; | ||
$this->message = 'OK'; | ||
} | ||
|
||
private function initError(): void | ||
{ | ||
$this->header = 'HTTP/1.1 400 Bad request'; | ||
$this->message = 'Incorrect string'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "rmulyukov/hw4", | ||
"type": "project", | ||
"authors": [ | ||
{ | ||
"name": "Mulyukov Rustyam" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Rmulyukov\\Hw4\\": "app/" | ||
} | ||
}, | ||
"config": { | ||
"platform": { | ||
"php": "8.2" | ||
} | ||
}, | ||
"require": { | ||
"php":"^8.2", | ||
"ext-memcache": "*" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rmulyukov\Hw4\BracesChecker; | ||
use Rmulyukov\Hw4\Request; | ||
use Rmulyukov\Hw4\Response; | ||
|
||
require_once "../vendor/autoload.php"; | ||
|
||
$string = (new Request())->get('string'); | ||
$isCorrectString = (new BracesChecker())->check($string); | ||
echo (new Response($isCorrectString))->send(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
version: '3.9' | ||
|
||
services: | ||
nginx-proxy: | ||
container_name: proxy-hw4 | ||
hostname: proxy-hw4 | ||
build: | ||
context: ./docker | ||
dockerfile: proxy-nginx/Dockerfile | ||
ports: | ||
- "8080:80" | ||
networks: | ||
- hw4-network | ||
|
||
nginx-balancer1: | ||
container_name: balancer1-hw4 | ||
hostname: balancer1-hw4 | ||
build: | ||
context: ./docker | ||
dockerfile: balancer-nginx/Dockerfile | ||
volumes: | ||
- ./app:/hw4/app | ||
networks: | ||
- hw4-network | ||
|
||
nginx-balancer2: | ||
container_name: balancer2-hw4 | ||
hostname: balancer2-hw4 | ||
build: | ||
context: ./docker | ||
dockerfile: balancer-nginx/Dockerfile | ||
volumes: | ||
- ./app:/hw4/app | ||
networks: | ||
- hw4-network | ||
|
||
php1: | ||
container_name: php1-hw4 | ||
hostname: php1-hw4 | ||
build: | ||
context: ./docker | ||
dockerfile: php/Dockerfile | ||
volumes: | ||
- ./app:/hw4/app | ||
networks: | ||
- hw4-network | ||
|
||
php2: | ||
container_name: php2-hw4 | ||
hostname: php2-hw4 | ||
build: | ||
context: ./docker | ||
dockerfile: php/Dockerfile | ||
volumes: | ||
- ./app:/hw4/app | ||
networks: | ||
- hw4-network | ||
|
||
memcache: | ||
container_name: memcache-hw4 | ||
hostname: memcache-hw4 | ||
image: memcached:1.6.23-alpine | ||
networks: | ||
- hw4-network | ||
|
||
networks: | ||
hw4-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM nginx:1.25.0-alpine | ||
|
||
COPY ./balancer-nginx/conf.d /etc/nginx/conf.d | ||
|
||
WORKDIR /hw4/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
upstream php { | ||
server php1-hw4:9000; | ||
server php2-hw4:9000; | ||
} | ||
|
||
server { | ||
index index.php; | ||
root /hw4/app/public; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.php?$query_string; | ||
} | ||
|
||
location ~ \.php$ { | ||
try_files $uri =404; | ||
fastcgi_split_path_info ^(.+\.php)(/.+)$; | ||
fastcgi_pass php; | ||
fastcgi_index index.php; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
include fastcgi_params; | ||
} | ||
|
||
location ~/\.ht { | ||
deny all; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM php:8.2-fpm-alpine | ||
|
||
RUN apk update && apk add --no-cache --virtual .build-temp-deps \ | ||
autoconf make gcc g++ zlib-dev \ | ||
&& apk update && apk add --no-cache libmemcached-dev \ | ||
#memcache | ||
&& pecl install memcache \ | ||
&& docker-php-ext-enable memcache \ | ||
#composer | ||
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --quiet \ | ||
&& rm -rf /root/.composer/cache \ | ||
&& apk del --no-cache -f .build-temp-deps | ||
|
||
COPY ./php/conf.d /usr/local/etc/php/conf.d | ||
|
||
WORKDIR /hw4/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
session.save_handler = memcached | ||
session.save_path = "memcached:11211" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM nginx:1.25.0-alpine | ||
|
||
COPY ./proxy-nginx/conf.d /etc/nginx/conf.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
upstream nginx-balancers { | ||
least_conn; | ||
server balancer1-hw4:80; | ||
server balancer2-hw4:80; | ||
} | ||
|
||
server { | ||
listen 80; | ||
|
||
location / { | ||
proxy_pass http://nginx-balancers; | ||
} | ||
|
||
location ~/\.ht { | ||
deny all; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем нам тут устанавливать внутреннее значения сообщения?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в задании написано
• если строка корректна, то пользователю возвращается ответ 200 OK, с информационным текстом, что всё хорошо;
• если строка некорректна, то пользователю возвращается ответ 400 Bad Request, с информационным текстом, что всё плохо.
$this->message
содержит этот информационный текстThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вопрос в том, что тут мы устанавливаем заголовок и записываем значение в message, чтобы потом его получить и напечатать. Не будет ли лучше сразу напечатать и всё?