Make a rule based on an ID.

@param string $nid A normalized ID.
@return array Returns an array representing a rule.
322465
private function makeRule($nid) {
        $rule = isset($this->rules[$nid]) ? $this->rules[$nid] : [];

        if (class_exists($nid)) {
            for ($class = get_parent_class($nid); !empty($class); $class = get_parent_class($class)) {
                // Don't add the rule if it doesn't say to inherit.
                if (!isset($this->rules[$class]) || (isset($this->rules[$class]['inherit']) && !$this->rules[$class]['inherit'])) {
                    break;
                }
                $rule += $this->rules[$class];
            }

            // Add the default rule.
            if (!empty($this->rules['*']['inherit'])) {
                $rule += $this->rules['*'];
            }

            // Add interface calls to the rule.
            $interfaces = class_implements($nid);
            foreach ($interfaces as $interface) {
                if (isset($this->rules[$interface])) {
                    $interfaceRule = $this->rules[$interface];

                    if (isset($interfaceRule['inherit']) && $interfaceRule['inherit'] === false) {
                        continue;
                    }

                    if (!isset($rule['shared']) && isset($interfaceRule['shared'])) {
                        $rule['shared'] = $interfaceRule['shared'];
                    }

                    if (!isset($rule['constructorArgs']) && isset($interfaceRule['constructorArgs'])) {
                        $rule['constructorArgs'] = $interfaceRule['constructorArgs'];
                    }

                    if (!empty($interfaceRule['calls'])) {
                        $rule['calls'] = array_merge(
                            isset($rule['calls']) ? $rule['calls'] : [],
                            $interfaceRule['calls']
                        );
                    }
                }
            }
        } elseif (!empty($this->rules['*']['inherit'])) {
            // Add the default rule.
            $rule += $this->rules['*'];
        }

        return $rule;
    }
1368794
protected function normalizeId($id)
    {
        if (null !== $this->getSessionPrefix()) {
            return $this->getSessionPrefix() . self::ID_SEPARATOR . $id;
        }

        return $id;
    }
496935
public function getGroups($uid) {
        static $groups = array();
        if (isset($groups[$uid]))
            return $groups[$uid];
        $user_groups = M()
            ->table($this->_config['AUTH_GROUP_ACCESS'] . ' a')
            ->where("a.uid='$uid' and g.status='1'")
            ->join($this->_config['AUTH_GROUP']." g on a.group_id=g.id")
            ->field('uid,group_id,title,rules')->select();
        $groups[$uid]=$user_groups?:array();
        return $groups[$uid];
    }
730022
public function make(string $id, array $parameters = [], bool $createNew = false)
    {
        if (isset($this->alias[$id])) {
            $id = $this->alias[$id];
        }

        if ($createNew || ! isset($this->objects[$id])) {
            $concrete = isset($this->bindings[$id]) ?
                        $this->bindings[$id] :
                        $id;

            $this->objects[$id] = $this->resolve($concrete, $parameters);
        }

        return $this->objects[$id];
    }
885605
public function rule($id) {
        $id = $this->normalizeID($id);

        if (!isset($this->rules[$id])) {
            $this->rules[$id] = [];
        }
        $this->currentRuleName = $id;
        $this->currentRule = &$this->rules[$id];

        return $this;
    }
31774
public function getRuleIds($uid){
        
        $groups = $this->getGroup($uid);
        
        $rules = [];
        foreach ($groups as $g){
            $rule = $g['rules'] ? explode(',', $g['rules']) : '';
            if ($rule){
                $rules = array_merge($rules , $rule);
            } 
        }
        
        return $rules;
    }
1135441
public function nextNodeSibling($nID)
    {
        //if ($nID == $this->tree->TreeLastPage) return -37;
        if (!$this->hasNode($nID) || $this->allNodes[$nID]->parentID <= 0) {
            return -3;
        }
        $nodeOverride = $this->moveNextOverride($nID);
        if ($nodeOverride > 0) {
            return $nodeOverride;
        }
        $nextSibling = SLNode::where('NodeTree', $this->treeID)
            ->where('NodeParentID', $this->allNodes[$nID]->parentID)
            ->where('NodeParentOrder', (1+$this->allNodes[$nID]->parentOrd))
            ->select('NodeID')
            ->first();
        if ($nextSibling && isset($nextSibling->NodeID)) {
            return $nextSibling->NodeID;
        }
        return $this->nextNodeSibling($this->allNodes[$nID]->parentID);
    }
329822
private function &getEntryForGuid( $guid )
	{
		if ( ! isset( $this->uniqueFactIds[ $guid ] ) )
		{
			return false;
		}

		// Get the element
		$facts = $this->getElement( $this->uniqueFactIds[ $guid ] );

		// And find the entry with the corresponding guid
		foreach ( $facts as $key => &$entry )
		{
			if ( $entry['guid'] == $guid ) return $entry;
		}

		return false;
	}
1077954
public Rule getRule(int id) {
    Rule returnRule = null;
    for (Rule rule : this.getRules().getRule()) {
      if (rule.getId() == id) {
        returnRule = rule;
        break;
      }
    }
    return returnRule;
  }
675060
public static function factory($id)
    {
        $id = (string)$id;
        if (!isset(static::$roles[$id])) {
            static::$roles[$id] = new static($id);
        }
        return static::$roles[$id];
    }
254535
protected function loadNodeDataBranch($nID = -3)
    {
        $this->sessData->setCoreID($GLOBALS["SL"]->coreTbl, $this->coreID); // not sure why this is needed
        $nIDtmp = $nID;
        $parents = [$nID];
        while ($this->hasNode($nIDtmp)) {
            $nIDtmp = $this->allNodes[$nIDtmp]->getParent();
            if (intVal($nIDtmp) > 0) {
                $parents[] = $nIDtmp;
            }
        }
        $this->sessData->dataBranches = [ [
            "branch" => $GLOBALS["SL"]->coreTbl, 
            "loop"   => '', 
            "itemID" => $this->coreID 
        ] ];
        if (sizeof($parents) > 1) {
            for ($i = (sizeof($parents)-2); $i >= 0; $i--) {
                if ($this->allNodes[$parents[$i]]->nodeType == 'Data Manip: New') {
                    $this->loadManipBranch($parents[$i], true);
                } elseif (trim($this->allNodes[$parents[$i]]->dataBranch) != '') {
                    $nBranch = $this->allNodes[$parents[$i]]->dataBranch;
                    $addBranch = $addLoop = '';
                    $itemID = -3;
                    if ($this->allNodes[$parents[$i]]->isLoopRoot()) {
                        $addBranch = $GLOBALS["SL"]->dataLoops[$nBranch]->DataLoopTable;
                        $addLoop = $nBranch;
                        $itemID = $GLOBALS["SL"]->getSessLoopID($nBranch);
                    } else {
                        $addBranch = $nBranch;
                        list($itemInd, $itemID) = $this->sessData->currSessDataPos($nBranch, 
                            $this->allNodes[$parents[$i]]->isDataManip());
                        if ($itemID <= 0) {
                            if (isset($GLOBALS["SL"]->tblAbbr[$nBranch])) {
                                $lastInd = sizeof($this->sessData->dataBranches)-1;
                                $parBranch = $this->sessData->dataBranches[$lastInd]["branch"];
                                $lnkFld = $GLOBALS["SL"]->getForeignLnk($GLOBALS["SL"]->tblI[$parBranch],
                                    $GLOBALS["SL"]->tblI[$nBranch]);
                                if ($lnkFld != '') {
                                    $lnkFld = $GLOBALS["SL"]->tblAbbr[$parBranch] . $lnkFld;
                                    $row = $this->sessData->getRowById($parBranch, 
                                        $this->sessData->dataBranches[$lastInd]["itemID"]);
                                    if ($row && isset($row->{ $lnkFld })) {
                                        $itemID = $row->{ $lnkFld };
                                    }
                                }
                                if ($lnkFld == '' || $itemID <= 0) {
                                    $lnkFld = $GLOBALS["SL"]->getForeignLnk($GLOBALS["SL"]->tblI[$nBranch], 
                                        $GLOBALS["SL"]->tblI[$parBranch]);
                                    if ($lnkFld != '') {
                                        $lnkFld = $GLOBALS["SL"]->tblAbbr[$nBranch] . $lnkFld;
                                        $row = $this->sessData->getRowById($nBranch, 
                                            $this->sessData->dataBranches[$lastInd]["itemID"]);
                                        if ($row && isset($row->{ $lnkFld })) {
                                            $itemID = $row->{ $lnkFld };
                                        }
                                    }
                                }
                                if ($lnkFld == '' || $itemID <= 0) {
                                    $lnkFld = $GLOBALS["SL"]->getForeignLnk($GLOBALS["SL"]->tblI[$nBranch], 
                                        $GLOBALS["SL"]->tblI[$parBranch]);
                                    if ($parBranch == 'users' && $lnkFld == 'UserID' 
                                        && isset($this->sessData->dataSets[$nBranch]) 
                                        && sizeof($this->sessData->dataSets[$nBranch]) > 0) {
                                        $lnkFld = $GLOBALS["SL"]->tblAbbr[$nBranch] . $lnkFld;
                                        foreach ($this->sessData->dataSets[$nBranch] as $row) {
                                            if (isset($row->{ $lnkFld }) && $row->{ $lnkFld } 
                                                == $this->sessData->dataBranches[$lastInd]["itemID"] ) {
                                                $itemID = $row->getKey();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    $foundBranch = false; // $this->sessData->chkDataBranch($addBranch, $dataBranch);
                    if (!$foundBranch) {
                        $this->sessData->dataBranches[] = [
                            "branch" => $addBranch,
                            "loop"   => $addLoop,
                            "itemID" => $itemID
                        ];
                    }
                }
            }
        }
        return $this->sessData->dataBranches;
    }
913433
protected function parserValidationRules($rules, $id = null)
    {

        if($id === null)
        {
            return $rules;
        }

        array_walk($rules, function(&$rules, $field) use ($id)
        {
            if(!is_array($rules))
            {
                $rules = explode("|", $rules);
            }

            foreach($rules as $ruleIdx => $rule)
            {
                // get name and parameters
                @list($name, $params) = array_pad(explode(":", $rule), 2, null);

                // only do someting for the unique rule
                if(strtolower($name) != "unique") {
                    continue; // continue in foreach loop, nothing left to do here
                }

                $p = array_map("trim", explode(",", $params));

                // set field name to rules key ($field) (laravel convention)
                if(!isset($p[1])) {
                    $p[1] = $field;
                }

                // set 3rd parameter to id given to getValidationRules()
                $p[2] = $id;

                $params = implode(",", $p);
                $rules[$ruleIdx] = $name.":".$params;
            }
        });

        return $rules;
    }
697053
protected function checkRule($name , $uid){
        
        $rule = $this->getRule($name);
        
        if (!$rule){
            $this->errorCode = '100001';
            $this->errorMsg = '验证规则不存在';
            
            return false;
        }else{
            $ruleIds = $this->getRuleIds($uid);
            $ruleId = $rule['id'];
            
            $check = in_array($ruleId , $ruleIds);
            if ($check){
                
                return true;
            }else{

                $this->errorCode = '100002';
                $this->errorMsg = '验证规则无权限';
                return false;
            }
            
        }
    }
1343082
public function getCategories(array $nids) {

    $condition = TRUE; // Could feasibly want TRUE under different circumstances
    if($nids){
      $condition = "n.nid NOT IN (".implode(',', $nids).")";
    }

    $sql = "SELECT title 
            FROM {node_field_data} n
            WHERE n.type = 'activity'
            AND " . $condition . "
            AND n.status = '1'
            ORDER BY title ASC";

    $connection = \Drupal::database();
    $query = $connection->query($sql);
    $result = $query->fetchCol();
    natsort($result);
    return $result;
  }
278732
public static function getRules($update, $id)
	{
		if (is_null($update))
		{
			return static::$registerRules;
		}
		static::$updateRules['name'] .= ','.$id.',user_id';
		static::$updateRules['email'] .= ','.$id.',user_id';
		return static::$updateRules;
	}
76672
public function getRule($rule, $domain = null)
    {
        return isset($this->rule[$domain][$rule]) ? $this->rule[$domain][$rule] : [];
    }
193218
protected function getAbstractId($id)
    {
        if (isset($this->aliases[$id])) {
            $id = $this->aliases[$id];
        }

        return $id;
    }