-
Notifications
You must be signed in to change notification settings - Fork 0
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
Alex dolgov/hw5 #576
Open
DolgovAleksandr
wants to merge
8
commits into
main
Choose a base branch
from
AlexDolgov/hw5
base: 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
Alex dolgov/hw5 #576
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e5ccef
Init
DolgovAleksandr 9273f7c
Homework 1
DolgovAleksandr d66235a
Added whitespace for .gitignore
DolgovAleksandr ef73927
Added .env.dist and removed credentials from docker-compose.yaml
DolgovAleksandr edaa9e8
Added whitespace for .env.dist
DolgovAleksandr 0422267
Added 3 php-fpm, added validator for '()'
DolgovAleksandr 62f1bbb
Try
DolgovAleksandr f20f93a
Fix homework
DolgovAleksandr 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,5 @@ | ||
COMPOSE_FILE=docker/docker-compose.yaml:docker/docker-compose.yaml | ||
MYSQL_ROOT_PASSWORD= | ||
MYSQL_DATABASE= | ||
MYSQL_USER= | ||
MYSQL_PASSWORD= |
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 @@ | ||
.env | ||
vendor | ||
mysql-data | ||
.idea | ||
composer.lock |
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,12 @@ | ||
{ | ||
"name": "aleksandrdolgov/otus_php_2023", | ||
"type": "project", | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "src/" | ||
} | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "^3.7" | ||
} | ||
} |
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,90 @@ | ||
version: '3' | ||
|
||
services: | ||
nginx-root: | ||
image: nginx:stable-alpine | ||
container_name: nginx-root | ||
working_dir: /app | ||
ports: | ||
- "80:80" | ||
networks: | ||
- app-network | ||
volumes: | ||
- ../docker/nginx-root/application.local.conf:/etc/nginx/conf.d/application.local.conf | ||
|
||
nginx-child-1: | ||
image: nginx:stable-alpine | ||
container_name: nginx-child-1 | ||
working_dir: /app | ||
volumes: | ||
- ../docker/nginx-child/application.local.conf:/etc/nginx/conf.d/application.local.conf | ||
- ../app:/app | ||
networks: | ||
- app-network | ||
|
||
nginx-child-2: | ||
image: nginx:stable-alpine | ||
container_name: nginx-child-2 | ||
working_dir: /app | ||
volumes: | ||
- ../docker/nginx-child/application.local.conf:/etc/nginx/conf.d/application.local.conf | ||
- ..app:/app | ||
networks: | ||
- app-network | ||
|
||
nginx-child-3: | ||
image: nginx:stable-alpine | ||
container_name: nginx-child-3 | ||
working_dir: /app | ||
volumes: | ||
- ../docker/nginx-child/application.local.conf:/etc/nginx/conf.d/application.local.conf | ||
- ..app:/app | ||
networks: | ||
- app-network | ||
|
||
memcached: | ||
image: memcached:latest | ||
ports: | ||
- "11211:11211" | ||
container_name: app-memcached | ||
networks: | ||
- app-network | ||
|
||
php-fpm-1: | ||
build: | ||
context: ./.. | ||
dockerfile: docker/fpm/Dockerfile | ||
container_name: php-fpm-1 | ||
volumes: | ||
- ../:/app | ||
working_dir: /app | ||
networks: | ||
- app-network | ||
|
||
# second php-fpm | ||
php-fpm-2: | ||
build: | ||
context: ./.. | ||
dockerfile: docker/fpm/Dockerfile | ||
container_name: php-fpm-2 | ||
volumes: | ||
- ../:/app | ||
working_dir: /app | ||
networks: | ||
- app-network | ||
|
||
# third php-fpm | ||
php-fpm-3: | ||
build: | ||
context: ./.. | ||
dockerfile: docker/fpm/Dockerfile | ||
container_name: php-fpm-3 | ||
volumes: | ||
- ../:/app | ||
working_dir: /app | ||
networks: | ||
- app-network | ||
|
||
networks: | ||
app-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,36 @@ | ||
FROM php:8.2-fpm | ||
|
||
# ставим необходимые для нормальной работы модули | ||
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
libfreetype6-dev \ | ||
libjpeg62-turbo-dev \ | ||
libpng-dev \ | ||
libonig-dev \ | ||
libzip-dev \ | ||
libmemcached11 \ | ||
zlib1g-dev libssl-dev \ | ||
libmemcached-dev \ | ||
libmcrypt-dev \ | ||
&& pecl install mcrypt \ | ||
&& docker-php-ext-enable mcrypt \ | ||
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \ | ||
&& docker-php-ext-configure gd --with-freetype --with-jpeg \ | ||
&& docker-php-ext-install -j$(nproc) gd \ | ||
&& chmod +x /usr/local/bin/install-php-extensions \ | ||
&& install-php-extensions redis \ | ||
&& install-php-extensions @composer-2.2.0 \ | ||
&& install-php-extensions memcached | ||
|
||
COPY docker/fpm/php.ini /usr/local/etc/php/conf.d/php-custom.ini | ||
|
||
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer | ||
|
||
USER www-data:www-data | ||
|
||
COPY composer.json composer.json | ||
|
||
RUN composer install | ||
|
||
CMD ["php-fpm"] |
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 = memcache | ||
session.save_path = "tcp://memcache: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,11 @@ | ||
FROM nginx | ||
|
||
COPY ./application.local.conf /etc/nginx/conf.d/application.local.conf | ||
|
||
WORKDIR /app | ||
|
||
VOLUME /app | ||
|
||
EXPOSE 7878 | ||
|
||
#CMD ["nginx", "-g", "daemon off;"] |
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,25 @@ | ||
upstream backend { | ||
least_conn; | ||
server php-fpm-1:9000; | ||
server php-fpm-2:9000; | ||
server php-fpm-3:9000; | ||
} | ||
|
||
server { | ||
listen 80; | ||
|
||
root /app/public; | ||
index index.php index.html; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.php?$query_string; | ||
} | ||
|
||
# и наконец правило обращения к php-fpm | ||
location ~* .php$ { | ||
fastcgi_pass backend; | ||
try_files $uri = 404; | ||
include fastcgi_params; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
} | ||
} |
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,11 @@ | ||
#FROM nginx | ||
# | ||
#COPY ./application.local.conf /etc/nginx/conf.d/application.local.conf | ||
# | ||
#WORKDIR /app | ||
# | ||
#VOLUME /app | ||
# | ||
#EXPOSE 80 | ||
|
||
#CMD ["nginx", "-g", "daemon off;"] |
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,14 @@ | ||
upstream nginx-balancer{ | ||
server nginx-child-1:80; | ||
server nginx-child-2:80; | ||
server nginx-child-3:80; | ||
} | ||
|
||
server { | ||
listen 80; | ||
server_name application.local; | ||
|
||
location / { | ||
proxy_pass http://nginx-balancer; | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\AppValidator; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$app = new AppValidator(); | ||
$app->runApp(); |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
use App\Validators\BracketValidator; | ||
use Exception; | ||
|
||
class AppValidator | ||
{ | ||
public function runApp(): void | ||
{ | ||
try { | ||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { | ||
throw new Exception('Use POST method', 400); | ||
} | ||
|
||
$string = $_POST['string'] ?? ''; | ||
|
||
if (empty($string)) { | ||
throw new Exception('Send me not empty "string" param', 400); | ||
} | ||
|
||
if (BracketValidator::validateString($string)) { | ||
echo "<h1>This is " . $_SERVER['HOSTNAME'] . "</h1>"; | ||
echo sprintf('Валидация скобок в строке "<b>%s</b>" прошла успешно', $string); | ||
phpinfo(); | ||
} else { | ||
echo sprintf('Строка "<b>%s</b>" не прошла валидацию на скобки', $string); | ||
} | ||
} catch (Exception $exception) { | ||
header("HTTP/1.1 {$exception->getCode()} {$exception->getMessage()}"); | ||
} | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Validators; | ||
|
||
class BracketValidator | ||
{ | ||
public static function validateString(string $string): bool | ||
{ | ||
if (preg_match('/^(\((?1)*\))*$/', $string)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
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.
Можно просто
return preg_match('/^(\((?1)*\))*$/', $string)