-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 3 php-fpm, added validator for '()'
- Loading branch information
1 parent
edaa9e8
commit 0422267
Showing
7 changed files
with
73 additions
and
62 deletions.
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aleksandrdolgov\OtusPhp2023; | ||
|
||
use Exception; | ||
|
||
function validateString(string $string): bool { | ||
if (preg_match('/^(\((?1)*\))*$/', $string)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
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 (validateString($string)) { | ||
echo sprintf('Скобки в строке "<b>%s</b>" прошли валидацию', $string); | ||
} else { | ||
echo sprintf('Строка "<b>%s</b>" не прошла валидацию на скобки', $string); | ||
} | ||
} catch (Exception $exception) { | ||
header("HTTP/1.1 {$exception->getCode()} {$exception->getMessage()}"); | ||
} |