Get user by condition.
@param array $condition
@return User|array
5359
public function getBy(array $condition) : User
    {
        if (!$user = User::find()->andWhere($condition)->limit(1)->one()) {
            throw new NotFoundException($this->i18n->t('setrun/user', 'User not found'));
        }
        return $user;
    }
613835
public function path(array $condition)
    {
        if (!in_array($condition['operator'], array('=', '!='))) {
            return false;
        }

        $path = $this->url->path();

        $found = false;

        foreach ((array) $condition['value'] as $pattern) {
            if (gplcart_path_match($path, $pattern)) {
                $found = true;
            }
        }

        return $condition['operator'] === '=' ? $found : !$found;
    }
278802
public function has_access($condition, Array $entity)
	{
		// get the group driver instance
		$group_driver = \Auth::group($entity[0]);

		// parse the requested permissions so we can check them
		$condition = static::_parse_conditions($condition);

		// if we couldn't parse the conditions, don't have a driver, or the driver doesn't export roles, bail out
		if ( ! is_array($condition) || empty($group_driver) || ! is_callable(array($group_driver, 'get_roles')))
		{
			return false;
		}

		// get the permission area and the permission rights to be checked
		$area    = $condition[0];

		// any actions defined?
		if ( ! is_array($condition[1]) and preg_match('#(.*)?\[(.*)?\]#', $condition[1], $matches))
		{
			$rights = (array) $matches[1];
			$actions = explode(',', $matches[2]);
		}
		else
		{
			$rights  = (array) $condition[1];
			$actions = array();
		}

		// fetch the current user object
		$user = Auth::get_user();

		// some storage to collect the current rights and revoked rights, and the global flag
		$current_rights = array();
		$revoked_rights = array();
		$global_access = null;

		// assemble the current users effective rights
		$cache_key = \Config::get('ormauth.cache_prefix', 'auth').'.permissions.user_'.($user ? $user->id : 0);
		try
		{
			list($current_rights, $revoked_rights, $global_access) = \Cache::get($cache_key);
		}
		catch (\CacheNotFoundException $e)
		{
			// get the role objects assigned to this group
			$current_roles  = $entity[1]->roles;

			// if we have a user, add the roles directly assigned to the user
			if ($user)
			{
				$current_roles = \Arr::merge($current_roles, Auth::get_user()->roles);
			}

			foreach ($current_roles as $role)
			{
				// role grants all access
				if ($role->filter == 'A')
				{
					$global_access = true;
				}

				// role denies all access
				elseif ($role->filter == 'D')
				{
					$global_access = false;
				}

				// role defines a permission revocation
				elseif ($role->filter == 'R')
				{
					// fetch the permissions of this role
					foreach ($role->permissions as $permission)
					{
						isset($revoked_rights[$permission->area][$permission->permission]) or $revoked_rights[$permission->area][$permission->permission] = array();
						foreach ($role->rolepermission as $rolepermission)
						{
							if ($rolepermission->role_id == $role->id and $rolepermission->perms_id == $permission->id)
							{
								$revoked_rights[$permission->area][$permission->permission] = array_merge(
									$revoked_rights[$permission->area][$permission->permission],
									array_intersect_key(
										$permission->actions ?: array(),
										array_flip($rolepermission->actions ?: array())
									)
								);
								break;
							}
						}
					}
				}

				// standard role, add it to the current rights set
				else
				{
					// fetch the permissions of this role
					foreach ($role->permissions as $permission)
					{
						isset($current_rights[$permission->area][$permission->permission]) or $current_rights[$permission->area][$permission->permission] = array();
						foreach ($role->rolepermission as $rolepermission)
						{
							if ($rolepermission->role_id == $role->id and $rolepermission->perms_id == $permission->id)
							{
								$current_rights[$permission->area][$permission->permission] = array_merge(
									$current_rights[$permission->area][$permission->permission],
									array_intersect_key(
										$permission->actions ?: array(),
										array_flip($rolepermission->actions ?: array())
									)
								);
								break;
							}
						}
					}
				}
			}

			// if this user doesn't have a global filter applied...
			if (is_array($current_rights))
			{
				if ($user)
				{
					// add the users group rights
					foreach ($user->group->permissions as $permission)
					{
						isset($current_rights[$permission->area][$permission->permission]) or $current_rights[$permission->area][$permission->permission] = array();
						foreach ($user->group->grouppermission as $grouppermission)
						{
							if ($grouppermission->group_id == $user->group_id and $grouppermission->perms_id == $permission->id)
							{
								$current_rights[$permission->area][$permission->permission] = array_merge(
									$current_rights[$permission->area][$permission->permission],
									array_intersect_key(
										$permission->actions ?: array(),
										array_flip($grouppermission->actions ?: array())
									)
								);
								break;
							}
						}
					}

					// add the users personal rights
					foreach ($user->permissions as $permission)
					{
						isset($current_rights[$permission->area][$permission->permission]) or $current_rights[$permission->area][$permission->permission] = array();
						foreach ($user->userpermission as $userpermission)
						{
							if ($userpermission->user_id == $user->id and $userpermission->perms_id == $permission->id)
							{
								$current_rights[$permission->area][$permission->permission] = array_merge(
									$current_rights[$permission->area][$permission->permission],
									array_intersect_key(
										$permission->actions ?: array(),
										array_flip($userpermission->actions ?: array())
									)
								);
								break;
							}
						}
					}
				}
			}

			// save the rights in the cache
			\Cache::set($cache_key, array($current_rights, $revoked_rights, $global_access));
		}

		// check for a revocation first
		foreach ($rights as $right)
		{
			// check revocation permissions
			if ( isset($revoked_rights[$area]) and array_key_exists($right, $revoked_rights[$area]))
			{
				$revoked = true;

				// need to check any actions?
				foreach ($actions as $action)
				{
					if ( ! in_array($action, $revoked_rights[$area][$right]))
					{
						$revoked = false;
						break;
					}
				}

				// right revoked?
				if ($revoked)
				{
					return false;
				}
			}
		}

		// was a global filter applied?
		if (is_bool($global_access))
		{
			// we're done here
			return $global_access;
		}

		// start checking rights, terminate false when right not found
		foreach ($rights as $right)
		{
			// check basic permissions
			if ( ! isset($current_rights[$area]) or ! array_key_exists($right, $current_rights[$area]))
			{
				return false;
			}

			// need to check any actions?
			foreach ($actions as $action)
			{
				if ( ! in_array($action, $current_rights[$area][$right]))
				{
					return false;
				}
			}
		}

		// all necessary rights were found, return true
		return true;
	}
103243
public function find($conditions)
    {
        $conditions[$this->_property] = $this->_root;

        $found = $this->getRepository()->find($conditions);

        return $found;
    }
42210
private static function filterCondition($condition)
    {
        foreach($condition as $k => $v) {
            if (is_array($v)) {
                $condition[$k] = array_values($v);
                foreach($v as $vv) {
                    if (is_array($vv)) {
                        throw new InvalidArgumentException('Nested arrays are not allowed in condition for findAll() and findOne().');
                    }
                }
            }
        }
        return $condition;
    }
1205116
public function find_index( $condition ) {
		$index = -1;

		for ( $i = 0, $count = count( $this->elements ); $i < $count; $i++ ) {
			if ( call_user_func( $condition, ($this->at( $i ) ) ) ) {
				$index = $i;
				break;
			}
		}

		return $index;
	}
409687
public function every( $condition ) {
		$response = true;

		foreach ( $this->elements as $element ) {
			$result = call_user_func( $condition, $element );

			if ( false === $result ) {
				$response = false;
				break;
			}
		}

		return $response;
	}
965371
public function getNextPosition(array $conditions): int
    {
        $columnName = $conditions['column'];

        $query = $this->connection->createQueryBuilder();
        $query->select($this->connection->getDatabasePlatform()->getMaxExpression($columnName) . ' AS ' . $columnName)
            ->from($conditions['table']);

        $this->applyConditions($query, $conditions['conditions']);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return (int) ($data[0][$columnName] ?? -1) + 1;
    }
557126
public function getUser() : ?User
    {
        $key = $this->getUserId();

        if (empty($key)) {
           return null;
        }

        return User::Store()->getById($key);
    }
1142958
public function route(array $condition)
    {
        if (!in_array($condition['operator'], array('=', '!='))) {
            return false;
        }

        $route = $this->route->get();
        return $this->compare($route['pattern'], $condition['value'], $condition['operator']);
    }
1281577
public function getItem(array $conditions = array())
    {
        $list = $this->getItems($conditions);

        if (empty($list)) {
            return $list;
        }

        return reset($list);
    }
1023166
public function one(string $condition = '', array $params = []) {
        $this->model->builder->select('*')
            ->from($this->model->tableName);
        if ($condition) {
            $this->model->builder->where($condition, $params);
        }
        $r = $this->model->builder->limit(1)
            ->query();
        if (!is_array($r) || 0 === count($r)) {
            return null;
        }
        return $this->model->setup($r[0]);
    }
1263005
public function parseCondition($condition)
    {
        if (strpos($condition, ':')) {
            $condition = ' ' . substr(strstr($condition, ':'), 1);
        }

        $condition = str_ireplace(array_keys($this->comparison), array_values($this->comparison), $condition);
        $this->tpl->parseVar($condition);

        // $this->tpl->parseVarFunction($condition); // XXX: 此句能解析表达式中用|分隔的函数，但表达式中如果有|、||这样的逻辑运算就产生了歧异
        return $condition;
    }
1346529
public function where($key, $condition)
    {
        $this->conditions[$key] = self::$conditionRegex[$condition];
        return $this;
    }
991887
public function filterOne(array $condition)
	{
		$cond = [];
		foreach ($condition as $key => $value) {
			$cond[$this->prepareColumn($key)] = $value;
		}
		$this->data_source = $this->data_source->findBy($cond);

		return $this;
	}
944464
public function setLength(array $condition)
    {
        if (is_array($condition) === true)  {
            $this->{key($condition)} = (int) current($condition);
        }

        return $this;
    }
741070
protected function getCondition($condition,$model){
        if(empty($condition)){
            return $condition;
        }
        if(is_array($condition)){
            foreach ($condition as $k=>$v){
                $result[$k]=$this->getCondition($v,$model);
            }
        }else{
            if(preg_match('/{([\w\d_]+):([\w\d_]+)}/',$condition,$match)){
                $result=$model->{$match[2]};
            }else{
                $result=$condition;
            }
        }
        return $result;
    }