Skip to content

Commit

Permalink
Use autoload from composer
Browse files Browse the repository at this point in the history
  • Loading branch information
frost-nzcr4 committed Sep 11, 2016
1 parent 6be7223 commit 1df9620
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 54 deletions.
26 changes: 26 additions & 0 deletions examples/_bootstrap.php
@@ -0,0 +1,26 @@
<?php
/**
* Bootstrap for examples.
*/

error_reporting(E_ALL | E_STRICT);

if (PHP_SAPI !== 'cli') {
echo 'Warning: script should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

foreach (array(
dirname(__FILE__) . '/../../autoload.php',
dirname(__FILE__) . '/../vendor/autoload.php',
dirname(__FILE__) . '/vendor/autoload.php'
) as $file) {
if (file_exists($file)) {
require $file;
break;
}
}
unset($file);
6 changes: 3 additions & 3 deletions examples/curl.php
Expand Up @@ -36,14 +36,14 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc < 2) {
echo "Usage: $argv[0] url\n";
echo "Usage: $argv[0] url".PHP_EOL;
exit;
}

require_once 'jaxl.php';
JAXLLogger::$level = JAXLLogger::DEBUG;
require_once JAXL_CWD.'/http/http_client.php';

$request = new HTTPClient($argv[1]);
$request->start();
7 changes: 4 additions & 3 deletions examples/echo_bosh_bot.php
Expand Up @@ -36,15 +36,16 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc < 3) {
echo "Usage: $argv[0] jid pass\n";
echo "Usage: $argv[0] jid pass".PHP_EOL;
exit;
}

//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array(
// (required) credentials
'jid' => $argv[1],
Expand Down Expand Up @@ -103,4 +104,4 @@
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
echo "done".PHP_EOL;
7 changes: 4 additions & 3 deletions examples/echo_bot.php
Expand Up @@ -36,19 +36,20 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

// Run as:
// php examples/echo_bot.php root@localhost password
// php examples/echo_bot.php root@localhost password DIGEST-MD5
// php examples/echo_bot.php localhost "" ANONYMOUS
if ($argc < 3) {
echo "Usage: $argv[0] jid pass auth_type\n";
echo "Usage: $argv[0] jid pass auth_type".PHP_EOL;
exit;
}

//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array(
// (required) credentials
'jid' => $argv[1],
Expand Down Expand Up @@ -144,4 +145,4 @@
'--with-debug-shell' => true,
'--with-unix-sock' => true
));
echo "done\n";
echo "done".PHP_EOL;
7 changes: 4 additions & 3 deletions examples/echo_component_bot.php
Expand Up @@ -36,15 +36,16 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc != 5) {
echo "Usage: $argv[0] jid pass host port\n";
echo "Usage: $argv[0] jid pass host port".PHP_EOL;
exit;
}

//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$comp = new JAXL(array(
// (required) component host and secret
'jid' => $argv[1],
Expand Down Expand Up @@ -95,4 +96,4 @@
// finally start configured xmpp stream
//
$comp->start();
echo "done\n";
echo "done".PHP_EOL;
6 changes: 3 additions & 3 deletions examples/echo_http_server.php
Expand Up @@ -36,16 +36,16 @@
*
*/

// include and configure logger
require_once 'jaxl.php';
require dirname(__FILE__) . '/_bootstrap.php';

// configure logger
JAXLLogger::$level = JAXLLogger::INFO;

// print usage notice and parse addr/port parameters if passed
_colorize("Usage: $argv[0] port (default: 9699)", JAXLLogger::NOTICE);
$port = ($argc == 2 ? $argv[1] : 9699);

// initialize http server
require_once JAXL_CWD.'/http/http_server.php';
$http = new HTTPServer($port);

// catch all incoming requests here
Expand Down
7 changes: 4 additions & 3 deletions examples/echo_unix_sock_server.php
Expand Up @@ -36,12 +36,13 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc < 2) {
echo "Usage: $argv[0] /path/to/server.sock\n";
echo "Usage: $argv[0] /path/to/server.sock".PHP_EOL;
exit;
}

require_once 'jaxl.php';
JAXLLogger::$level = JAXLLogger::INFO;

$server = null;
Expand All @@ -59,4 +60,4 @@ function on_request($client, $raw)
$server = new JAXLSocketServer('unix://'.$argv[1], null, 'on_request');

JAXLLoop::run();
echo "done\n";
echo "done".PHP_EOL;
5 changes: 3 additions & 2 deletions examples/http_bind.php
Expand Up @@ -36,6 +36,8 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if (!isset($_GET['jid']) || !isset($_GET['pass'])) {
echo "invalid input";
exit;
Expand All @@ -44,7 +46,6 @@
//
// initialize JAXL object with initial config
//
require_once '../jaxl.php';
$client = new JAXL(array(
'jid' => $_GET['jid'],
'pass' => $_GET['pass'],
Expand All @@ -61,4 +62,4 @@
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
echo "done".PHP_EOL;
6 changes: 3 additions & 3 deletions examples/http_pre_bind.php
Expand Up @@ -36,6 +36,8 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

// http pre bind php script
$body = file_get_contents("php://input");
$body = new SimpleXMLElement($body);
Expand All @@ -53,8 +55,6 @@
//
// initialize JAXL object with initial config
//
require_once '../jaxl.php';

$to = (string)$attrs['to'];
$rid = (int)$attrs['rid'];
$wait = (int)$attrs['wait'];
Expand Down Expand Up @@ -96,4 +96,4 @@
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
echo "done".PHP_EOL;
6 changes: 3 additions & 3 deletions examples/http_rest_server.php
Expand Up @@ -36,16 +36,16 @@
*
*/

// include and configure logger
require_once 'jaxl.php';
require dirname(__FILE__) . '/_bootstrap.php';

// configure logger
JAXLLogger::$level = JAXLLogger::INFO;

// print usage notice and parse addr/port parameters if passed
_colorize("Usage: $argv[0] port (default: 9699)", JAXLLogger::NOTICE);
$port = ($argc == 2 ? $argv[1] : 9699);

// initialize http server
require_once JAXL_CWD.'/http/http_server.php';
$http = new HTTPServer($port);

// callback method for dispatch rule (see below)
Expand Down
7 changes: 4 additions & 3 deletions examples/muc_log_bot.php
Expand Up @@ -36,15 +36,16 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc < 5) {
echo "Usage: $argv[0] host jid pass room@service.domain.tld nickname\n";
echo "Usage: $argv[0] host jid pass room@service.domain.tld nickname".PHP_EOL;
exit;
}

//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array(
// (required) credentials
'jid' => $argv[2],
Expand Down Expand Up @@ -143,4 +144,4 @@
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
echo "done".PHP_EOL;
7 changes: 3 additions & 4 deletions examples/multi_client.php
Expand Up @@ -36,6 +36,8 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

// input multiple account credentials
$accounts = array();
$add_new = true;
Expand All @@ -47,9 +49,6 @@
$add_new = $next == 'y' ? true : false;
}

// setup jaxl
require_once 'jaxl.php';

//
// common callbacks
//
Expand Down Expand Up @@ -127,4 +126,4 @@ function on_disconnect($client)

// start core loop
JAXLLoop::run();
echo "done\n";
echo "done".PHP_EOL;
10 changes: 4 additions & 6 deletions examples/pipes.php
Expand Up @@ -36,12 +36,10 @@
*
*/

// include and configure logger
require_once 'jaxl.php';
JAXLLogger::$level = JAXLLogger::INFO;
require dirname(__FILE__) . '/_bootstrap.php';

// include jaxl pipes
require_once JAXL_CWD.'/core/jaxl_pipe.php';
// configure logger
JAXLLogger::$level = JAXLLogger::INFO;

// initialize
$pipe_name = getmypid();
Expand All @@ -54,4 +52,4 @@
});

JAXLLoop::run();
echo "done\n";
echo "done".PHP_EOL;
7 changes: 4 additions & 3 deletions examples/publisher.php
Expand Up @@ -36,15 +36,16 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc < 3) {
echo "Usage: $argv[0] jid pass\n";
echo "Usage: $argv[0] jid pass".PHP_EOL;
exit;
}

//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array(
'jid' => $argv[1],
'pass' => $argv[2],
Expand Down Expand Up @@ -98,4 +99,4 @@
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
echo "done".PHP_EOL;
7 changes: 4 additions & 3 deletions examples/register_user.php
Expand Up @@ -36,15 +36,16 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc < 2) {
echo "Usage: $argv[0] domain\n";
echo "Usage: $argv[0] domain".PHP_EOL;
exit;
}

//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array(
'jid' => $argv[1],
'log_level' => JAXLLogger::DEBUG
Expand Down Expand Up @@ -164,4 +165,4 @@ function wait_for_register_form($event, $args)
$client->start();
}

echo "done\n";
echo "done".PHP_EOL;
7 changes: 4 additions & 3 deletions examples/subscriber.php
Expand Up @@ -36,15 +36,16 @@
*
*/

require dirname(__FILE__) . '/_bootstrap.php';

if ($argc < 3) {
echo "Usage: $argv[0] jid pass\n";
echo "Usage: $argv[0] jid pass".PHP_EOL;
exit;
}

//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array(
'jid' => $argv[1],
'pass' => $argv[2],
Expand Down Expand Up @@ -93,4 +94,4 @@
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
echo "done".PHP_EOL;

0 comments on commit 1df9620

Please sign in to comment.