-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.php
More file actions
44 lines (32 loc) · 1.11 KB
/
Copy pathcmd.php
File metadata and controls
44 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require 'vendor/autoload.php';
use Parentheses\Parentheses;
use Parentheses\InvalidArgumentException;
class ConsoleException extends \Exception
{
}
try {
if (empty($argv[1])) {
throw new ConsoleException('Please enter file path');
}
if (! file_exists($argv[1])) {
throw new ConsoleException('File "' . $argv[1] . '" not exists');
}
if (! is_file($argv[1])) {
throw new ConsoleException($argv[1] . ' is not a file');
}
if (! is_readable($argv[1])) {
throw new ConsoleException($argv[1] . ' file is not readable');
}
$string = file_get_contents($argv[1]);
$Parentheses = new Parentheses($string);
if ($Parentheses->isBalanced()) {
print 'File string have balanced parentheses' . PHP_EOL;
} else {
print 'File string have not balances parentheses' . PHP_EOL;
}
} catch (ConsoleException $e) {
print 'File error: ' . $e->getMessage() . PHP_EOL;
} catch (\Parentheses\Exception\InvalidArgumentException $e) {
print 'File string error: ' . $e->getMessage() . PHP_EOL;
}