forked from ringcentral/ringcentral-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-phar.php
115 lines (78 loc) · 2.86 KB
/
create-phar.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
use Symfony\Component\Config\Definition\Exception\Exception;
exec('rm -rf ' . __DIR__ . '/dist/phar');
@mkdir('./dist/phar');
@unlink('./dist/ringcentral.phar');
@unlink('./dist/phar/composer.json');
@unlink('./dist/phar/composer.lock');
$phar = new Phar(
'./dist/ringcentral.phar',
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
'ringcentral.phar'
);
function listDir($root, $path, $phar)
{
//print 'Entering ' . $root . $path . PHP_EOL;
$it = new DirectoryIterator($root . $path);
foreach ($it as $fileinfo) {
$filename = $fileinfo->getFilename();
if ($fileinfo->isDot() ||
stristr($filename, 'Test.php') ||
stristr($filename, '.git') ||
stristr($filename, 'manual_tests') ||
stristr($filename, 'tests') ||
stristr($filename, 'demo') ||
stristr($filename, 'dist') ||
stristr($filename, 'docs')
) {
continue;
} elseif ($fileinfo->isDir()) {
listDir($root, $path . '/' . $filename, $phar);
} else {
$key = ($path ? $path . '/' : '') . $filename;
$phar[$key] = file_get_contents($root . $path . '/' . $fileinfo->getFilename());
//print ' ' . $key . ' -> ' . $path . '/' . $filename . PHP_EOL;
}
}
}
$json = array(
'type' => 'project',
'minimum-stability' => 'dev',
'require' => array(
'ringcentral/ringcentral-php' => 'dev-master'
)
);
if (!empty($argv) && in_array('develop', $argv)) {
$json['require']['ringcentral/ringcentral-php'] = 'dev-develop';
}
if (!empty($argv) && in_array('local', $argv)) {
$json['repositories'] = array(
array(
'url' => __DIR__,
'type' => 'vcs'
)
);
}
print 'Composer config:' . PHP_EOL;
print_r($json);
print PHP_EOL . PHP_EOL;
file_put_contents('./dist/phar/composer.json', json_encode($json));
exec('cd ' . __DIR__ . '/dist/phar && composer install --prefer-source --no-interaction --no-dev');
listDir(__DIR__ . '/dist/phar/vendor', '', $phar);
$phar->setStub($phar->createDefaultStub("autoload.php"));
/////
require('./dist/ringcentral.phar');
try {
if (!file_exists('demo/_credentials.php')) {
print 'Connection check skipped.';
exit;
}
$credentials = require('demo/_credentials.php');
$sdk = new RingCentral\SDK\SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server']);
$sdk->platform()->login($credentials['username'], $credentials['extension'], $credentials['password']);
$t = $sdk->platform()->get('/restapi/v1.0');
print 'Connected to API server ' . $t->json()->uri . ', version ' . $t->json()->versionString . PHP_EOL;
} catch (Exception $e) {
print 'Error while connecting using PHAR: ' . $e->getMessage();
exit(1);
}