当前位置: 首页>>代码示例>>PHP>>正文


PHP Api::output方法代码示例

本文整理汇总了PHP中Api::output方法的典型用法代码示例。如果您正苦于以下问题:PHP Api::output方法的具体用法?PHP Api::output怎么用?PHP Api::output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Api的用法示例。


在下文中一共展示了Api::output方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testOutputXml

 /**
  * @covers Api::output
  * @runInSeparateProcess
  */
 public function testOutputXml()
 {
     //set method for use in CLI
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $this->object = new Api('xml', array('GET'));
     $dummy = '<object></object>';
     ob_start();
     $this->object->output(200, $dummy);
     $output = ob_get_contents();
     ob_end_clean();
     $this->assertEquals($dummy, $output, 'Output should be a XML string');
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestIncomplete('xdebug_get_headers function does not exist; can not check Content-type');
         return;
     }
     $headers = xdebug_get_headers();
     $this->assertContains('Content-type: application/xml; charset=UTF-8', $headers, 'Output should include a content-type header');
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:22,代码来源:ApiTest.php

示例2: Api

 * @version 1.0.0
 *
 * @api
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Artist.php';
$api = new Api('json', ['GET', 'DELETE', 'PUT']);
switch ($api->method) {
    case 'GET':
        //returns the artist
        if (!$api->checkAuth()) {
            //User not authentified/authorized
            return;
        }
        if (!$api->checkParameterExists('id', $id)) {
            $api->output(400, 'Artist identifier must be provided');
            //artist was not provided, return an error
            return;
        }
        $artist = new Artist();
        if (!$artist->populate(['id' => $id])) {
            $api->output(404, 'Artist not found');
            //indicate the artist was not found
            return;
        }
        $artist->getTracks();
        $api->output(200, $artist->structureData());
        break;
    case 'DELETE':
        //delete artist and all his tracks
        if (!$api->checkAuth()) {
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:artist.php

示例3: Api

 *
 * Provides system configuration informations and a way to update it
 *
 * @version 1.0.0
 *
 * @api
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Artist.php';
$api = new Api('json', ['GET', 'PUT']);
if (!$api->checkAuth()) {
    //User not authentified/authorized
    return;
}
if (!$api->checkScope('admin')) {
    $api->output(403, 'Admin scope is required for the system administration API');
    //current user has no admin scope, return forbidden
    return;
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Configuration.php';
$configuration = new Configuration();
switch ($api->method) {
    case 'GET':
        //returns the settings configuration
        $api->output(200, $configuration->query());
        break;
    case 'PUT':
        //update setting
        if (!$api->checkParameterExists('key', $key)) {
            $api->output(400, '`Key` must be provided in path');
            //Key was not provided, return an error
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:setting.php

示例4: Api

 * @version 1.0.0
 *
 * @api
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Configuration.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Track.php';
$api = new Api('json', ['GET']);
switch ($api->method) {
    case 'GET':
        //returns the folders
        if (!$api->checkAuth()) {
            //User not authentified/authorized
            return false;
        }
        if (!$api->checkScope('admin')) {
            $api->output(403, 'Admin scope is required for listing folders');
            //current user has no admin scope, return forbidden
            return;
        }
        $library = new Tracks();
        $configuration = new Configuration();
        $library->getFolders($configuration->get('filesPath'));
        if (count($library->folders) == 0) {
            $api->output(204);
            //end the process
            return;
        }
        $api->output(200, $library->folders);
        break;
}
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:folder.php

示例5: Api

<?php

/**
 * Authenticate user and create a token.
 *
 * Provides a token required for others API call
 *
 * @version 1.0.0
 *
 * @api
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/User.php';
$api = new Api('json', ['POST']);
switch ($api->method) {
    case 'POST':
        if (!$api->checkParameterExists('login', $login) || !$api->checkParameterExists('password', $password)) {
            $api->output(400, 'Both login and password must be provided');
            //login or password was not provided
            return;
        }
        $user = new User();
        if (!$user->checkCredentials($login, $password)) {
            $api->output(401, 'Invalid credentials');
            header('WWW-Authenticate: Bearer realm="WMP"');
            //invalid credentials
            return;
        }
        $api->output(201, $api->generateToken($user->getProfile()));
        break;
}
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:token.php

示例6: Api

 * @version 1.1.0
 *
 * @api
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
$api = new Api('json', ['POST', 'GET', 'DELETE', 'PUT', 'PATCH']);
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Playlist.php';
switch ($api->method) {
    case 'GET':
        //querying a user playlist
        if (!$api->checkAuth()) {
            //User not authentified/authorized
            return false;
        }
        if (!$api->checkParameterExists('userId', $userId)) {
            $api->output(400, 'User identifier must be provided');
            //user was not provided, return an error
            return;
        }
        $userId = intval($userId);
        if ($api->requesterId !== $userId) {
            $api->output(403, 'Playlist can be queried by its owner only');
            //indicate the requester is not the playlist owner and is not allowed to get it
            return;
        }
        $playlist = new Playlist($userId);
        $playlist->populate();
        if (count($playlist->tracks) === 0) {
            $api->output(204, null);
            //user's playlist is empty
            return;
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:playlist.php

示例7: Api

 * Provides access to MusicBrainz API
 *
 * @version 1.0.0
 *
 * @api
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
$api = new Api('json', ['GET']);
switch ($api->method) {
    case 'GET':
        if (!$api->checkAuth()) {
            //User not authentified/authorized
            return;
        }
        if (!$api->checkParameterExists('type', $type)) {
            $api->output(400, '`Type` value (albums or artists) must be provided in path');
            //Type was not provided, return an error
            return;
        }
        require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/MusicBrainz.php';
        $musicBrainz = new MusicBrainz();
        switch ($type) {
            case 'artist':
                if (!$api->checkParameterExists('name', $artistName)) {
                    $api->output(400, 'A `name` parameter must be provided in query string for requesting artists');
                    //Type was not provided, return an error
                    return;
                }
                $result = $musicBrainz->searchArtistByName($artistName);
                if (!$result) {
                    $api->output(400, 'Error: ' . $musicBrainz->errorMessage);
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:musicBrainz.php

示例8: Api

 * @api
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Configuration.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/User.php';
$api = new Api('json', ['GET', 'PUT', 'POST']);
switch ($api->method) {
    case 'GET':
        if (!$api->checkAuth()) {
            //User not authentified/authorized
            return;
        }
        if (!$api->checkParameterExists('id', $id)) {
            //without 'id' parameter, users list is requested, check if current user is granted
            if (!$api->checkScope('admin')) {
                $api->output(403, 'Admin scope is required for listing users');
                //current user has no admin scope, return forbidden
                return;
            }
            //returns all users
            $user = new User();
            $rawUsers = $user->getAllUsers();
            if ($rawUsers === false) {
                $api->output(500, 'Error while querying');
                //return an internal error
                return;
            }
            $users = array();
            foreach ($rawUsers as $user) {
                array_push($users, $user->getProfile());
            }
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:user.php

示例9: header

 */
//manage cache browser: no response needed
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
    header('Last-Modified: ' . $_SERVER['HTTP_IF_MODIFIED_SINCE'], true, 304);
    return;
}
//get token parameter
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Api.php';
$api = new Api('base64', ['GET']);
if (!$api->checkAuth()) {
    //User not authentified/authorized
    return;
}
//get id parameter
if (!$api->checkParameterExists('track', $trackId)) {
    $api->output(400, 'Track identifier must be sent');
    //Track identifier not provided
    return;
}
//get file information
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Track.php';
$track = new Track($trackId);
$filename = $track->getFile();
if ($filename === false) {
    $api->output(404, 'Track not found');
    //indicate the track was not found
    return;
}
//manage cache browser
header('Cache-Control: private, max-age=604800, pre-check=604800');
header('Pragma: private');
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:track.php


注:本文中的Api::output方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。