Merge branch 'refactor-rest-api' of

https://github.com/EuskalMoneta/dolibarr into
EuskalMoneta-refactor-rest-api

Conflicts:
	htdocs/api/admin/explorer.php
This commit is contained in:
Laurent Destailleur
2016-07-27 14:06:14 +02:00
21 changed files with 2514 additions and 122 deletions

View File

@@ -104,17 +104,43 @@ foreach ($modulesdir as $dir)
{
while (($file_searched = readdir($handle_part))!==false)
{
// Support of the deprecated API.
if (is_readable($dir_part.$file_searched) && preg_match("/^api_deprecated_(.*)\.class\.php$/i",$file_searched,$reg))
{
$classname = ucwords($reg[1]).'Api';
require_once $dir_part.$file_searched;
if (class_exists($classname))
{
dol_syslog("Found deprecated API classname=".$classname);
$api->r->addAPIClass($classname, '');
}
}
elseif (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$reg))
{
$classname = ucwords($reg[1]);
require_once $dir_part.$file_searched;
if (class_exists($classname))
{
dol_syslog("Found API classname=".$classname);
$listofapis[] = $classname;
}
}
/*
if (is_readable($dir_part.$file_searched) && preg_match("/^(api_.*)\.class\.php$/i",$file_searched,$reg))
{
$classname=$reg[1];
$classname = str_replace('Api_','',ucwords($reg[1])).'Api';
//$classname = str_replace('Api_','',ucwords($reg[1]));
$classname = ucfirst($classname);
require_once $dir_part.$file_searched;
if (class_exists($classname))
{
dol_syslog("Found API classname=".$classname);
$api->r->addAPIClass($classname,'');
/*
require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/Routes.php';
$tmpclass = new ReflectionClass($classname);
@@ -125,8 +151,9 @@ foreach ($modulesdir as $dir)
}*/
//$listofapis[]=array('classname'=>$classname, 'fullpath'=>$file_searched);
}
}
/* }
}*/
}
}
}
@@ -135,8 +162,8 @@ foreach ($modulesdir as $dir)
}
}
$listofapis=Routes::toArray();
//var_dump($listofapis);
$listofapis=Routes::toArray(); // TODO api for "status" is lost here
//var_dump($listofapis);
@@ -166,6 +193,7 @@ print $langs->trans("ListOfAvailableAPIs").':<br>';
foreach($listofapis['v1'] as $key => $val)
{
if ($key == 'login') continue;
if ($key == 'index') continue;
if ($key)
{

View File

@@ -95,9 +95,23 @@ print '</tr>';
print '</table>';
print '<br><br>';
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
// Show message
$message='';
$url='<a href="'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword" target="_blank">'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword[&reset=1]</a>';
$message.=$langs->trans("UrlToGetKeyToUseAPIs").':<br>';
$message.=img_picto('','object_globe.png').' '.$url;
print $message;
print '<br>';
print '<br>';
// Explorer
print '<u>'.$langs->trans("ApiExporerIs").':</u><br>';
$url=DOL_MAIN_URL_ROOT.'/api/admin/explorer.php';
$url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";