<?php
use Laminas\Http\Client as HttpClient;
use Laminas\Json\Json;
use Laminas\Mvc\MvcEvent;
use Laminas\ServiceManager\ServiceLocatorInterface as ServiceLocator;
use Laminas\Loader\AutoloaderFactory;
use Laminas\Http\Client\Adapter\Curl;
define('BASE_PATH', __DIR__);
// setup autoloading
set_include_path(BASE_PATH);
include 'vendor/laminas/laminas-loader/src/AutoloaderFactory.php';
$config = [
'Laminas\Loader\StandardAutoloader' => [
'namespaces' => array(
'Laminas\\Http' => BASE_PATH . '/vendor/laminas/laminas-http/src',
'Laminas\\Http\\Client\\Adapter' => BASE_PATH . '/vendor/laminas/laminas-http/src/Client/Adapter',
'Laminas\\Loader' => BASE_PATH . '/vendor/laminas/laminas-loader/src',
'Laminas\\Stdlib' => BASE_PATH . '/vendor/laminas/laminas-stdlib/src',
'Laminas\\Uri' => BASE_PATH . '/vendor/laminas/laminas-uri/src',
'Laminas\\Validator' => BASE_PATH . '/vendor/laminas/laminas-validator/src',
'Laminas\\Escaper' => BASE_PATH . '/vendor/laminas/laminas-escaper/src',
)
]
];
\Laminas\Loader\AutoloaderFactory::factory($config);
// config is needed for parameters among other things
if (!file_exists('jiraconfig.php')) {
echo "Cannot find the test config file 'jiraconfig.php'\n";
return;
}
$config = include 'jiraconfig.php';
if (!array_key_exists('jira', $config)) {
echo "Cannot find the 'jira' configuration block in the jiraconfig.php file.\n";
return;
}
$jconfig = $config['jira'];
$jconfig['host'] = rtrim($jconfig['host'], '/');
if ($jconfig['host'] && strpos(strtolower($jconfig['host']), 'http') !== 0) {
$jconfig['host'] = 'http://' . $jconfig['host'];
}
echo "JIRA host: ", $jconfig['host'], "\n";
$url = $jconfig['host'] . '/rest/api/latest/project' ;
$client = new HttpClient;
$client->setUri($url)
->setHeaders(array('Content-Type' => 'application/json'))
->setMethod('get');
$options = $config + array('http_client_options' => array());
$options = (array) $options['http_client_options'];
if (isset($options['hosts'][$client->getUri()->getHost()])) {
$options = (array) $options['hosts'][$client->getUri()->getHost()] + $options;
}
unset($options['hosts']);
$client->setOptions($options);
if ($jconfig['user']) {
$client->setAuth($jconfig['user'], $jconfig['password']);
}
echo 'Making request to ', $url, "\n" ;
try {
$response = $client->dispatch($client->getRequest());
echo " Status code: ", $response->getStatusCode(), " ", $response->getReasonPhrase(), "\n";
if ( $response->isSuccess()) {
$projects = json_decode($response->getBody(), true) ;
echo "JIRA Projects returned: ", count($projects), "\n";
foreach($projects as $proj) {
echo " ",$proj['key'];
}
echo " \n";
} else {
echo "Failed!\n";
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
echo $e;
echo "\n";
}
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #1 | 27438 | Joel Brown |
New jiratest2020.php for Swarm 2020 release. The different scripts correspond to the Zend framework used by Swarm. <=2018: zend 2 2019: zend 3 2020: laminas Update README to match the script names. |