function folder_loader($dir, $priorities, $excludes) { $retval = array(); $amqp_folders = scandir($dir, 1); foreach ($priorities as $priority) { for ($i = 0; $i < count($amqp_folders); $i++) { if (strpos(strtolower($amqp_folders[$i]), strtolower($priority)) !== FALSE) { $slice = array_slice($amqp_folders, $i, 1); unset($amqp_folders[$i]); array_unshift($amqp_folders, $slice[0]); } } } foreach ($amqp_folders as $amqp_folder) { if (strpos($amqp_folder, ".") === 0) { continue; } if (is_dir($dir . "/" . $amqp_folder)) { $retval = array_merge($retval, folder_loader($dir . "/" . $amqp_folder, $priorities, $excludes)); } else { $to_add = $dir . "/" . $amqp_folder; $found_exclude = False; foreach ($excludes as $exclude) { if (strpos($to_add, $exclude) !== False) { $found_exclude = True; } } if (!$found_exclude) { if (strpos($to_add, ".php") !== FALSE) { $retval[] = $to_add; } } } } return $retval; }
function connect() { if ($this->connected) { return true; } $failed = false; $this->debug = true; $includes = folder_loader("api/PhpAmqpLib", array("Channel", "Exception", "Abstract", "AMQPException", "AMQPProtocolException", "Interface", "AMQPConnection", "AMQPException", "AMQPStreamConnection", "AbstractConnection"), array("Tests")); foreach ($includes as $inc) { include_once $inc; } //use PhpAmqpLib\Connection\AMQPConnection; //use PhpAmqpLib\Message\AMQPMessage; //if (class_exists("PhpAmqpLib\Connection\AMQPConnection")) echo "YES"; //else echo "NO"; //echo "<pre>"; //$this->vhost=""; try { $conn = new PhpAmqpLib\Connection\AMQPConnection($this->host, $this->port, $this->auth1, $this->auth2, $this->vhost) or $failed = true; } catch (Exception $e) { echo htmlspecialchars($e); exit; } $this->messenger = $conn; return $this->connectcheck($failed); }