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


PHP ACL::get_user_token_access方法代码示例

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


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

示例1: get_access

	/**
	 * Returns an access Bitmask for the given user on this post
	 * @param User $user The user mask to fetch
	 * @return Bitmask
	 */
	public function get_access( $user = null )
	{
		if ( ! $user instanceof User ) {
			$user = User::identify();
		}

		if ( $user->can( 'super_user' ) ) {
			return ACL::get_bitmask( 'full' );
		}

		// Collect a list of applicable tokens
		$tokens = array(
			'post_any',
			'post_' . Post::type_name( $this->content_type ),
		);

		if ( $user->id == $this->user_id ) {
			$tokens[] = 'own_posts';
		}

		$tokens = array_merge( $tokens, $this->get_tokens() );

		// collect all possible token accesses on this post
		$token_accesses = array();
		foreach ( $tokens as $token ) {
			$access = ACL::get_user_token_access( $user, $token );
			if ( $access instanceof Bitmask ) {
				$token_accesses[] = ACL::get_user_token_access( $user, $token )->value;
			}
		}

		// now that we have all the accesses, loop through them to build the access to the particular post
		if ( in_array( 0, $token_accesses ) ) {
			return ACL::get_bitmask( 0 );
		}
		return ACL::get_bitmask( Utils::array_or( $token_accesses ) );
	}
开发者ID:rynodivino,项目名称:system,代码行数:42,代码来源:post.php

示例2: get_access

 /**
  * Returns an access Bitmask for the given user on this comment. Read access is determined
  * by the associated post. Update/delete is determined by the comment management tokens.
  * @param User $user The user mask to fetch
  * @return Bitmask
  */
 public function get_access($user = null)
 {
     if (!$user instanceof User) {
         $user = User::identify();
     }
     // these tokens automatically grant full access to the comment
     if ($user->can('super_user') || $user->can('manage_all_comments') || $user->id == $this->post->user_id && $user->can('manage_own_post_comments')) {
         return ACL::get_bitmask('full');
     }
     /* If we got this far, we can't update or delete a comment. We still need to check if we have
      * read access to it. Collect a list of applicable tokens
      */
     $tokens = array('post_any', 'post_' . Post::type_name($this->post->content_type));
     if ($user->id == $this->post->user_id) {
         $tokens[] = 'own_posts';
     }
     $tokens = array_merge($tokens, $this->post->get_tokens());
     $token_accesses = array();
     // grab the access masks on these tokens
     foreach ($tokens as $token) {
         $access = ACL::get_user_token_access($user, $token);
         if ($access instanceof Bitmask) {
             $token_accesses[] = ACL::get_user_token_access($user, $token)->value;
         }
     }
     // now that we have all the accesses, loop through them to build the access to the particular post
     if (in_array(0, $token_accesses)) {
         return ACL::get_bitmask(0);
     }
     if (ACL::get_bitmask(Utils::array_or($token_accesses))->read) {
         return ACL::get_bitmask('read');
     }
     // if we haven't returned by this point, we can neither manage the comment nor read it
     return ACL::get_bitmask(0);
 }
开发者ID:habari,项目名称:system,代码行数:41,代码来源:comment.php


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