Skip to content

Commit b20dc9a

Browse files
committed
Added stub.php;
Made extrasetup.php use installed files as opposed to archived ones; Made packagexmlsetup.php use $oompatible conditionally.
1 parent 7baa83c commit b20dc9a

File tree

4 files changed

+125
-77
lines changed

4 files changed

+125
-77
lines changed

RELEASE-1.0.0b3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Bug fixes on edge cases, and some API changes
22

3-
* Persistent connections are now properly supported. Added a new Registry class to facilitate this.
3+
* (GH #6) Persistent connections are now properly supported. Added a new Registry class to facilitate this.
44
* The second and third argument of Request::__construct() have been swapped.
55
* At Request::__construct(), a backslash can now be escaped in an argument value, and arguments can be spread across multiple lines.
66
* Client::getStreamResponses() and Client::setStreamResponses() are now Client::isStreamingResponses() and Client::setStreamingResponses(), respectively.

extrasetup.php

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,28 @@
11
<?php
22
$extrafiles = array();
33

4-
foreach (
5-
array(
6-
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'PEAR2_Net_Transmitter.git',
7-
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'PEAR2_Cache_SHM.git'
8-
) as $packageRoot
9-
) {
10-
$pkg = new \Pyrus\Package(
11-
$packageRoot . DIRECTORY_SEPARATOR . 'package.xml'
12-
);
13-
foreach (array('tests', 'docs') as $folder) {
4+
$phpDir = Pyrus\Config::current()->php_dir . DIRECTORY_SEPARATOR;
5+
$packages = array('PEAR2/Autoload', 'PEAR2/Cache/SHM', 'PEAR2/Net/Transmitter');
6+
7+
foreach ($packages as $pkg) {
8+
$prefix = $phpDir . $pkg;
9+
10+
if (is_dir($prefix)) {
1411
foreach (
1512
new RecursiveIteratorIterator(
1613
new RecursiveDirectoryIterator(
17-
$packageRoot . DIRECTORY_SEPARATOR . $folder,
14+
$prefix,
1815
RecursiveDirectoryIterator::UNIX_PATHS
1916
),
2017
RecursiveIteratorIterator::LEAVES_ONLY
2118
) as $path
2219
) {
23-
unset($pkg->files[$path->getPathname()]);
20+
$pathname = $path->getPathname();
21+
$extrafiles['src/' . $pathname] = $pathname;
2422
}
2523
}
26-
$extrafiles[] = $pkg;
27-
}
28-
29-
//$transmitterPackage
30-
// = new \Pyrus\Package(
31-
// __DIR__ . DIRECTORY_SEPARATOR
32-
// . '../PEAR2_Net_Transmitter.git/package.xml'
33-
// );
34-
//unset($transmitterPackage->files['docs/docblox.xml']);
35-
//unset($transmitterPackage->files['docs/doxygen.ini']);
36-
//
37-
//unset($transmitterPackage->files['tests/ClientTest.php']);
38-
//unset($transmitterPackage->files['tests/ServerTest.php']);
39-
//unset($transmitterPackage->files['tests/UnconnectedTest.php']);
40-
//unset($transmitterPackage->files['tests/bootstrap.php']);
41-
//unset($transmitterPackage->files['tests/phpunit.xml']);
42-
//unset($transmitterPackage->files['tests/secondaryPeer.xml']);
43-
//unset($transmitterPackage->files['tests/secondaryPeer.bat']);
44-
//
45-
//$shmPackage
46-
// = new \Pyrus\Package(
47-
// __DIR__ . DIRECTORY_SEPARATOR
48-
// . '../PEAR2_Cache_SHM.git/package.xml'
49-
// );
50-
//unset($shmPackage->files['docs/phpdoc.dist.xml']);
51-
//unset($shmPackage->files['docs/doxygen.ini']);
52-
//
53-
//unset($shmPackage->files['tests/bootstrap.php']);
54-
//unset($shmPackage->files['tests/phpunit.xml']);
55-
//
56-
//$extrafiles = array($transmitterPackage, $shmPackage);
24+
25+
if (is_file($prefix . '.php')) {
26+
$extrafiles['src/' . $pkg . '.php'] = $prefix . '.php';
27+
}
28+
}

packagexmlsetup.php

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
)
3939
);
4040

41-
$compatible->license = $package->license;
42-
4341
$package->files['tests/bootstrap.php'] = array_merge_recursive(
4442
$package->files['tests/bootstrap.php']->getArrayCopy(), $srcDirTask,
4543
array(
@@ -73,39 +71,43 @@
7371
)
7472
)
7573
);
76-
77-
$compatible->files[
78-
"test/{$package->channel}/{$package->name}/bootstrap.php"
79-
] = array_merge_recursive(
80-
$compatible->files[
74+
$hasCompatible = isset($compatible);
75+
if ($hasCompatible) {
76+
$compatible->license = $package->license;
77+
$compatible->files[
8178
"test/{$package->channel}/{$package->name}/bootstrap.php"
82-
]->getArrayCopy(), $srcDirTask
83-
);
79+
] = array_merge_recursive(
80+
$compatible->files[
81+
"test/{$package->channel}/{$package->name}/bootstrap.php"
82+
]->getArrayCopy(), $srcDirTask
83+
);
8484

85-
$compatible->files["doc/{$package->channel}/{$package->name}/phpdoc.dist.xml"]
86-
= array_merge_recursive(
87-
$compatible->files[
85+
$compatible->files[
8886
"doc/{$package->channel}/{$package->name}/phpdoc.dist.xml"
89-
]->getArrayCopy(), $srcDirTask
90-
);
87+
] = array_merge_recursive(
88+
$compatible->files[
89+
"doc/{$package->channel}/{$package->name}/phpdoc.dist.xml"
90+
]->getArrayCopy(), $srcDirTask
91+
);
9192

92-
$compatible->files["doc/{$package->channel}/{$package->name}/doxygen.ini"]
93-
= array_merge_recursive(
94-
$compatible->files[
95-
"doc/{$package->channel}/{$package->name}/doxygen.ini"
96-
]->getArrayCopy(), $srcDirTask,
97-
array(
98-
'tasks:replace' => array(
99-
array(
100-
'attribs' => array(
101-
'from' => 'GIT: $Id$',
102-
'to' => 'version',
103-
'type' => 'package-info'
93+
$compatible->files["doc/{$package->channel}/{$package->name}/doxygen.ini"]
94+
= array_merge_recursive(
95+
$compatible->files[
96+
"doc/{$package->channel}/{$package->name}/doxygen.ini"
97+
]->getArrayCopy(), $srcDirTask,
98+
array(
99+
'tasks:replace' => array(
100+
array(
101+
'attribs' => array(
102+
'from' => 'GIT: $Id$',
103+
'to' => 'version',
104+
'type' => 'package-info'
105+
)
104106
)
105107
)
106108
)
107-
)
108-
);
109+
);
110+
}
109111

110112
$oldCwd = getcwd();
111113
chdir(__DIR__);
@@ -123,10 +125,12 @@
123125
$package->files[$filename]->getArrayCopy(), $srcFileTasks
124126
);
125127

126-
$compatibleFilename = str_replace('src/', 'php/', $filename);
127-
$compatible->files[$compatibleFilename] = array_merge_recursive(
128-
$compatible->files[$compatibleFilename]->getArrayCopy(),
129-
$srcFileTasks
130-
);
128+
if ($hasCompatible) {
129+
$compatibleFilename = str_replace('src/', 'php/', $filename);
130+
$compatible->files[$compatibleFilename] = array_merge_recursive(
131+
$compatible->files[$compatibleFilename]->getArrayCopy(),
132+
$srcFileTasks
133+
);
134+
}
131135
}
132136
chdir($oldCwd);

stub.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
if (count(get_included_files()) > 1) {
3+
Phar::mapPhar();
4+
$autoloder = 'phar://' . __FILE__ . DIRECTORY_SEPARATOR . 'src'
5+
. DIRECTORY_SEPARATOR . 'PEAR2' . DIRECTORY_SEPARATOR . 'Autoload.php';
6+
if (is_file($autoloder)) {
7+
include_once $autoloder;
8+
}
9+
} else {
10+
$isNotCli = PHP_SAPI !== 'cli';
11+
if ($isNotCli) {
12+
header('Content-Type: text/plain;charset=UTF-8');
13+
}
14+
echo "PEAR2_Net_RouterOS @PACKAGE_VERSION@\n";
15+
16+
if (version_compare(phpversion(), '5.3.0', '<')) {
17+
echo "\nThis package requires PHP 5.3.0 or later.";
18+
exit(1);
19+
}
20+
21+
$missing_extensions = array();
22+
foreach (array('phar', 'spl', 'pcre') as $ext) {
23+
if (!extension_loaded($ext)) {
24+
$missing_extensions[] = $ext;
25+
}
26+
}
27+
if ($missing_extensions) {
28+
echo "\nYou must compile PHP with the following extensions enabled:\n",
29+
implode(', ', $missing_extensions), "\n",
30+
"or install the necessary extensions for your distribution.\n";
31+
exit(1);
32+
}
33+
34+
if (!in_array('phar', $missing_extensions)) {
35+
$phar = new Phar(__FILE__);
36+
$sig = $phar->getSignature();
37+
echo "{$sig['hash_type']} hash: {$sig['hash']}\n\n";
38+
}
39+
40+
if (function_exists('stream_socket_client')) {
41+
echo <<<HEREDOC
42+
The stream_socket_client() function is enabled.\n
43+
If you can't connect to RouterOS (SocketException with code 100), this means one
44+
of the following:\n
45+
1. You haven't enabled the API service at RouterOS or you've enabled it on a
46+
different TCP port. Make sure that the "api" service at "/ip services" is
47+
enabled, and with that same TCP port (8728 by default).\n
48+
2. You've mistyped the IP and/or port. Check the IP and port you've specified
49+
are the one you intended.\n
50+
3. The router is not reachable from your web server. Try to reach the router
51+
from the web server by other means (e.g. Winbox, ping) using the same IP, and if
52+
you're unable to reach it, check your network's settings.\n
53+
2. Your web server is configured to forbid that outgoing connection. If you're
54+
the web server administrator, check your firewall's settings. If you're on a
55+
hosting plan... Typically, shared hosts block all outgoing connections, but it's
56+
also possible that only connections to that port are blocked. Try to connect to
57+
a host on a popular port (21, 80, etc.), and if successful, change the API
58+
service port to that port. If the connection fails even then, ask your host to
59+
configure their firewall so as to allow you to make outgoing connections to the
60+
ip:port you've set the API service on.
61+
HEREDOC;
62+
} else {
63+
echo <<<HEREDOC
64+
WARNING: stream_socket_client() is disabled. Without it, you won't be able to
65+
connect to any RouterOS host. Enable it in php.ini, or ask your host to enable
66+
it for you.
67+
HEREDOC;
68+
}
69+
70+
}
71+
72+
__HALT_COMPILER();

0 commit comments

Comments
 (0)