Пример #1
0
 public static function getRelatedFromPolicy(Policy $policy)
 {
     $ret = array();
     $authm = new AuthManager();
     $apim = new ApiManager();
     $allAuths = $authm->getAllAuths(true);
     $relatedAuthIds = array();
     $relatedAuths = array();
     $authPropsArr = array();
     $allApis = $apim->getAllApis(true);
     $relatedApiIds = array();
     $relatedApis = array();
     $apiPropsArr = array();
     foreach ($allAuths as $auth) {
         /**
          * @var $auth Auth
          */
         foreach ($policy->getAuthIds() as $authBucket) {
             if ($authBucket->getAuthIds() && in_array($auth->getId(), $authBucket->getAuthIds())) {
                 $relatedAuths[] = $auth;
             }
         }
     }
     foreach ($relatedAuths as $auth) {
         $props = $auth->getProperties();
         if (!empty($props)) {
             $authPropsArr[$auth->getId()] = array_keys($props);
         }
     }
     $relatedApiIds = $policy->getApiIds();
     foreach ($allApis as $api) {
         /**
          * @var $api Api
          */
         if (in_array($api->getId(), $relatedApiIds)) {
             $relatedApis[] = $api;
         }
     }
     foreach ($relatedApis as $api) {
         $props = $api->getProperties();
         if (!empty($props)) {
             if ($api->getDisplayName()) {
                 $apiPropsArr[$api->getDisplayName()] = array_keys($props);
             } else {
                 $apiPropsArr[$api->getId()] = array_keys($props);
             }
         }
     }
     if (!empty($authPropsArr)) {
         $ret["auth"] = $authPropsArr;
     }
     if (!empty($apiPropsArr)) {
         $ret["api"] = $apiPropsArr;
     }
     return json_encode($ret);
 }