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


PHP Guardian::instance方法代码示例

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


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

示例1: authorize_list

 public static function authorize_list($identity = null, $accessType, $blueprintKey, $where = null)
 {
     $tag = "Guardian::authorize_list()";
     Log::debug("{$tag} <identity={$identity}, accessType={$accessType}, blueprintKey={$blueprintKey}, where={$where}>");
     if ($accessType != "SELECT") {
         Log::warning("{$tag}: accessType != SELECT");
         throw new Exception("{$tag}: accessType != SELECT");
     }
     $instance = Guardian::instance();
     // Convenience variables
     $xml = $instance->xml;
     list($guardian_identity_table, , ) = explode(".", BPConfig::$guardian_identity_blueprint);
     Log::debug("* Identity Table = {$guardian_identity_table}");
     // Sanitize arguments
     if ($identity != null) {
         if (empty($identity) || !is_numeric($identity)) {
             Log::debug("! Setting identity to null");
             $identity = null;
         }
     }
     /*
     // LAST MINUTE PROCESSING
     // Define a placeholder $listRows to hold results of GuardianListDrafter:initListRows() (if necessary)
     */
     $listRows = null;
     // Search Resources for a block matching the requested blueprintKey
     foreach ($xml->Resource as $resource) {
         $key = (string) $resource["key"];
         Log::debug("{$tag}: Considering Resource with key '{$key}'");
         if ($key == "*" || $key == $blueprintKey || strpos($key, "*") !== false && strpos($blueprintKey, substr($key, 0, strpos($key, "*"))) === 0) {
             Log::debug("{$tag}: Resource matches requested blueprint key");
             foreach ($resource->AccessGroup as $accessGroup) {
                 $type = (string) $accessGroup["type"];
                 Log::debug("{$tag}: Considering AccessGroup of type '{$type}'");
                 if ($type == "*" || strpos($type, $accessType) !== false) {
                     Log::debug("{$tag}: AccessGroup includes requested access type");
                     // The requestor must pass ALL rules in an <AccessGroup> to be granted access
                     $flag_failure = false;
                     foreach ($accessGroup->children() as $rule) {
                         $kind = $rule->getName();
                         Log::debug("{$tag}: Evaluating rule '{$kind}'");
                         if ($kind != "Ownership") {
                             if ($instance->test_access_rule($rule, $identity, null) === false) {
                                 Log::debug("{$tag}: Failed rule '{$kind}'. No access under this group");
                                 $flag_failure = true;
                                 // Immediately stop checking rules under this AccessGroup, and move on to the next AccessGroup
                                 break;
                             }
                         } else {
                             // LAST MINUTE PROCESSING; init ListDrafter
                             if ($listRows == null) {
                                 Log::debug("{$tag}: Initializing GuardianListDrafter to build a list of entities for ownership testing");
                                 try {
                                     $entityBP = BlueprintReader::read($blueprintKey . ".entity.xml");
                                     if ($where != null) {
                                         $params = array("where" => $where);
                                     } else {
                                         $params = null;
                                     }
                                     $listDrafter = new GuardianListDrafter($entityBP, null, $params);
                                     $listRows = $listDrafter->getListRows();
                                 } catch (Exception $e) {
                                     Log::error("{$tag}: Caught: " . $e->getMessage());
                                     throw $e;
                                 }
                             }
                             if ($instance->test_access_list_rule_ownership($rule, $identity, $listRows) === false) {
                                 Log::debug("{$tag}: Failed rule '{$kind}'. No access under this group");
                                 $flag_failure = true;
                                 // Immediately stop checking rules under this AccessGroup, and move on to the next AccessGroup
                                 break;
                             }
                         }
                     }
                     if ($flag_failure === false) {
                         Log::debug("{$tag}: Passed all rules of access group");
                         return true;
                     } else {
                         // continue with next AccessGruop
                     }
                 } else {
                     Log::debug("{$tag}: AccessGroup does not include requested access type");
                 }
             }
             // END: foreach($resource->AccessGroup as $accessGroup)
         } else {
             Log::debug("{$tag}: Resource does not match requested blueprint key");
         }
     }
     // END: foreach($xml->Resource as $resource)
     return false;
 }
开发者ID:benjaminhough,项目名称:blueprints-web-kit,代码行数:92,代码来源:Guardian.php


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