Make calling ocs/v1.php/config work
This commit is contained in:
parent
180bd69dbb
commit
7a24f0cd8d
4 changed files with 41 additions and 8 deletions
17
lib/api.php
17
lib/api.php
|
@ -43,7 +43,8 @@ class OC_API {
|
|||
$name = str_replace(array('/', '{', '}'), '_', $name);
|
||||
if(!isset(self::$actions[$name])){
|
||||
OC::$router->create($name, $url.'.{_format}')
|
||||
->defaults(array('_format'=>'xml'))
|
||||
->defaults(array('_format' => 'xml'))
|
||||
->requirements(array('_format' => 'xml|json'))
|
||||
->action('OC_API', 'call');
|
||||
self::$actions[$name] = array();
|
||||
}
|
||||
|
@ -55,7 +56,7 @@ class OC_API {
|
|||
* @param array $parameters
|
||||
*/
|
||||
public static function call($parameters){
|
||||
$name = $parameters['_name'];
|
||||
$name = $parameters['_route'];
|
||||
// Loop through registered actions
|
||||
foreach(self::$actions[$name] as $action){
|
||||
$app = $action['app'];
|
||||
|
@ -107,8 +108,14 @@ class OC_API {
|
|||
* @param int|array $response the response
|
||||
* @param string $format the format xml|json
|
||||
*/
|
||||
private function respond($response, $format='json'){
|
||||
// TODO respond in the correct format
|
||||
private static function respond($response, $format='json'){
|
||||
if ($format == 'json') {
|
||||
echo json_encode($response);
|
||||
} else if ($format == 'xml') {
|
||||
// TODO array to xml
|
||||
} else {
|
||||
var_dump($format, $response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ class OC_App{
|
|||
* @param string $appid the id of the app to check
|
||||
* @return bool
|
||||
*/
|
||||
public function isShipped($appid){
|
||||
public static function isShipped($appid){
|
||||
$info = self::getAppInfo($appid);
|
||||
if(isset($info['shipped']) && $info['shipped']=='true'){
|
||||
return true;
|
||||
|
|
18
lib/ocs.php
18
lib/ocs.php
|
@ -251,6 +251,24 @@ class OC_OCS {
|
|||
exit();
|
||||
}
|
||||
|
||||
public static function notFound() {
|
||||
if($_SERVER['REQUEST_METHOD'] == 'GET') {
|
||||
$method='get';
|
||||
}elseif($_SERVER['REQUEST_METHOD'] == 'PUT') {
|
||||
$method='put';
|
||||
parse_str(file_get_contents("php://input"),$put_vars);
|
||||
}elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$method='post';
|
||||
}else{
|
||||
echo('internal server error: method not supported');
|
||||
exit();
|
||||
}
|
||||
$format = self::readData($method, 'format', 'text', '');
|
||||
$txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
|
||||
$txt.=OC_OCS::getDebugOutput();
|
||||
echo(OC_OCS::generateXml($format,'failed',999,$txt));
|
||||
}
|
||||
|
||||
/**
|
||||
* generated some debug information to make it easier to find faild API calls
|
||||
* @return debug data string
|
||||
|
|
12
ocs/v1.php
12
ocs/v1.php
|
@ -22,5 +22,13 @@
|
|||
*/
|
||||
|
||||
require_once('../lib/base.php');
|
||||
@ob_clean();
|
||||
OC_OCS::handle();
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
|
||||
OC::$router->useCollection('ocs');
|
||||
OC::$router->loadRoutes();
|
||||
|
||||
try {
|
||||
OC::$router->match($_SERVER['PATH_INFO']);
|
||||
} catch (ResourceNotFoundException $e) {
|
||||
OC_OCS::notFound();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue