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


PHP Api::checkScope方法代码示例

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


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

示例1: testCheckScope

 /**
  * @covers Api::checkScope
  */
 public function testCheckScope()
 {
     $this->assertFalse($this->object->checkScope('user'), 'Unknown user should not have "user" in scope');
     $this->object->requesterId = 1;
     $this->assertTrue($this->object->checkScope('user'), 'User should have "user" in scope');
     $this->assertFalse($this->object->checkScope('xxx'), 'User should not have "xxx" in scope');
     $this->object->requesterId = 99;
     $this->assertFalse($this->object->checkScope('user'), 'Unknown user should not have "user" in scope');
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:12,代码来源:ApiTest.php

示例2: Artist

     $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()) {
         //User not authentified/authorized
         return;
     }
     if (!$api->checkScope('admin')) {
         $api->output(403, 'Admin scope is required for deleting artist');
         //indicate the requester do not have the required scope for deleting artist
         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($id);
     if (!$artist->delete()) {
         $api->output(500, 'Error during artist deletion');
         //something gone wrong :(
         return;
     }
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:artist.php

示例3: 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


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