Upgrade to 3.7.1

This commit is contained in:
Bastian Allgeier
2022-07-12 13:33:21 +02:00
parent 7931eb5e47
commit 1ad1eaf387
377 changed files with 63981 additions and 63824 deletions

View File

@@ -21,128 +21,128 @@ use Kirby\Toolkit\Str;
*/
class Users extends Collection
{
/**
* All registered users methods
*
* @var array
*/
public static $methods = [];
/**
* All registered users methods
*
* @var array
*/
public static $methods = [];
public function create(array $data)
{
return User::create($data);
}
public function create(array $data)
{
return User::create($data);
}
/**
* Adds a single user or
* an entire second collection to the
* current collection
*
* @param \Kirby\Cms\Users|\Kirby\Cms\User|string $object
* @return $this
* @throws \Kirby\Exception\InvalidArgumentException When no `User` or `Users` object or an ID of an existing user is passed
*/
public function add($object)
{
// add a users collection
if (is_a($object, self::class) === true) {
$this->data = array_merge($this->data, $object->data);
/**
* Adds a single user or
* an entire second collection to the
* current collection
*
* @param \Kirby\Cms\Users|\Kirby\Cms\User|string $object
* @return $this
* @throws \Kirby\Exception\InvalidArgumentException When no `User` or `Users` object or an ID of an existing user is passed
*/
public function add($object)
{
// add a users collection
if (is_a($object, self::class) === true) {
$this->data = array_merge($this->data, $object->data);
// add a user by id
} elseif (is_string($object) === true && $user = App::instance()->user($object)) {
$this->__set($user->id(), $user);
// add a user by id
} elseif (is_string($object) === true && $user = App::instance()->user($object)) {
$this->__set($user->id(), $user);
// add a user object
} elseif (is_a($object, 'Kirby\Cms\User') === true) {
$this->__set($object->id(), $object);
// add a user object
} elseif (is_a($object, 'Kirby\Cms\User') === true) {
$this->__set($object->id(), $object);
// give a useful error message on invalid input;
// silently ignore "empty" values for compatibility with existing setups
} elseif (in_array($object, [null, false, true], true) !== true) {
throw new InvalidArgumentException('You must pass a Users or User object or an ID of an existing user to the Users collection');
}
// give a useful error message on invalid input;
// silently ignore "empty" values for compatibility with existing setups
} elseif (in_array($object, [null, false, true], true) !== true) {
throw new InvalidArgumentException('You must pass a Users or User object or an ID of an existing user to the Users collection');
}
return $this;
}
return $this;
}
/**
* Takes an array of user props and creates a nice and clean user collection from it
*
* @param array $users
* @param array $inject
* @return static
*/
public static function factory(array $users, array $inject = [])
{
$collection = new static();
/**
* Takes an array of user props and creates a nice and clean user collection from it
*
* @param array $users
* @param array $inject
* @return static
*/
public static function factory(array $users, array $inject = [])
{
$collection = new static();
// read all user blueprints
foreach ($users as $props) {
$user = User::factory($props + $inject);
$collection->set($user->id(), $user);
}
// read all user blueprints
foreach ($users as $props) {
$user = User::factory($props + $inject);
$collection->set($user->id(), $user);
}
return $collection;
}
return $collection;
}
/**
* Finds a user in the collection by ID or email address
* @internal Use `$users->find()` instead
*
* @param string $key
* @return \Kirby\Cms\User|null
*/
public function findByKey(string $key)
{
if (Str::contains($key, '@') === true) {
return parent::findBy('email', Str::lower($key));
}
/**
* Finds a user in the collection by ID or email address
* @internal Use `$users->find()` instead
*
* @param string $key
* @return \Kirby\Cms\User|null
*/
public function findByKey(string $key)
{
if (Str::contains($key, '@') === true) {
return parent::findBy('email', Str::lower($key));
}
return parent::findByKey($key);
}
return parent::findByKey($key);
}
/**
* Loads a user from disk by passing the absolute path (root)
*
* @param string $root
* @param array $inject
* @return static
*/
public static function load(string $root, array $inject = [])
{
$users = new static();
/**
* Loads a user from disk by passing the absolute path (root)
*
* @param string $root
* @param array $inject
* @return static
*/
public static function load(string $root, array $inject = [])
{
$users = new static();
foreach (Dir::read($root) as $userDirectory) {
if (is_dir($root . '/' . $userDirectory) === false) {
continue;
}
foreach (Dir::read($root) as $userDirectory) {
if (is_dir($root . '/' . $userDirectory) === false) {
continue;
}
// get role information
$path = $root . '/' . $userDirectory . '/index.php';
if (is_file($path) === true) {
$credentials = F::load($path);
}
// get role information
$path = $root . '/' . $userDirectory . '/index.php';
if (is_file($path) === true) {
$credentials = F::load($path);
}
// create user model based on role
$user = User::factory([
'id' => $userDirectory,
'model' => $credentials['role'] ?? null
] + $inject);
// create user model based on role
$user = User::factory([
'id' => $userDirectory,
'model' => $credentials['role'] ?? null
] + $inject);
$users->set($user->id(), $user);
}
$users->set($user->id(), $user);
}
return $users;
}
return $users;
}
/**
* Shortcut for `$users->filter('role', 'admin')`
*
* @param string $role
* @return static
*/
public function role(string $role)
{
return $this->filter('role', $role);
}
/**
* Shortcut for `$users->filter('role', 'admin')`
*
* @param string $role
* @return static
*/
public function role(string $role)
{
return $this->filter('role', $role);
}
}