This repository was archived by the owner on May 23, 2020. It is now read-only.
forked from allegro/php-protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotoc-php.php
More file actions
55 lines (45 loc) · 1.31 KB
/
protoc-php.php
File metadata and controls
55 lines (45 loc) · 1.31 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
45
46
47
48
49
50
51
52
53
54
55
<?php
require 'ProtobufCompiler/ProtobufParser.php';
if (!debug_backtrace()) {
if (!class_exists('\ProtobufMessage')) {
echo $argv[0] .
' requires protobuf extension installed to run' .
PHP_EOL;
exit(1);
}
$optionError = false;
$useNamespaces = false;
$iterator = new \RegexIterator(new \ArrayIterator($argv), '/^-/');
foreach ($iterator as $key => $value) {
switch ($value) {
case '-n' :
case '--use-namespaces' :
$useNamespaces = true;
break;
default :
$optionError = true;
break;
}
array_splice($argv, $key, 1);
}
if ($optionError || count($argv) != 2) {
printf('USAGE: %s [OPTIONS] PROTO_FILE' . PHP_EOL, $argv[0]);
printf(' -n, --use-namespaces Use native PHP namespaces' . PHP_EOL);
exit(1);
}
$parser = new ProtobufParser($useNamespaces);
$file = $argv[1];
if (!file_exists($file)) {
printf($file . ' does not exist' . PHP_EOL);
exit(1);
}
if (!is_file($file)) {
printf($file . ' is not a file' . PHP_EOL);
exit(1);
}
try {
$parser->parse($file);
} catch (Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}