123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- /**
- * @package Grav\Common\User
- *
- * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
- * @license MIT License; see LICENSE file for details.
- */
- namespace Grav\Common\User;
- use Grav\Common\Grav;
- use Grav\Common\User\DataUser;
- use Grav\Common\User\FlexUser;
- use Grav\Common\User\Interfaces\UserCollectionInterface;
- use Grav\Common\User\Interfaces\UserInterface;
- if (!defined('GRAV_USER_INSTANCE')) {
- throw new \LogicException('User class was called too early!');
- }
- if (defined('GRAV_USER_INSTANCE') && GRAV_USER_INSTANCE === 'FLEX') {
- /**
- * @deprecated 1.6 Use $grav['accounts'] instead of static calls. In type hints, please use UserInterface.
- */
- class User extends FlexUser\User
- {
- /**
- * Load user account.
- *
- * Always creates user object. To check if user exists, use $this->exists().
- *
- * @param string $username
- *
- * @return UserInterface
- * @deprecated 1.6 Use $grav['accounts']->load(...) instead.
- */
- public static function load($username)
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use $grav[\'accounts\']->' . __FUNCTION__ . '() instead', E_USER_DEPRECATED);
- return static::getCollection()->load($username);
- }
- /**
- * Find a user by username, email, etc
- *
- * Always creates user object. To check if user exists, use $this->exists().
- *
- * @param string $query the query to search for
- * @param array $fields the fields to search
- * @return UserInterface
- * @deprecated 1.6 Use $grav['accounts']->find(...) instead.
- */
- public static function find($query, $fields = ['username', 'email'])
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use $grav[\'accounts\']->' . __FUNCTION__ . '() instead', E_USER_DEPRECATED);
- return static::getCollection()->find($query, $fields);
- }
- /**
- * Remove user account.
- *
- * @param string $username
- * @return bool True if the action was performed
- * @deprecated 1.6 Use $grav['accounts']->delete(...) instead.
- */
- public static function remove($username)
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use $grav[\'accounts\']->delete() instead', E_USER_DEPRECATED);
- return static::getCollection()->delete($username);
- }
- /**
- * @return UserCollectionInterface
- */
- protected static function getCollection()
- {
- return Grav::instance()['accounts'];
- }
- }
- } else {
- /**
- * @deprecated 1.6 Use $grav['accounts'] instead of static calls. In type hints, use UserInterface.
- */
- class User extends DataUser\User
- {
- /**
- * Load user account.
- *
- * Always creates user object. To check if user exists, use $this->exists().
- *
- * @param string $username
- *
- * @return UserInterface
- * @deprecated 1.6 Use $grav['accounts']->load(...) instead.
- */
- public static function load($username)
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use $grav[\'accounts\']->' . __FUNCTION__ . '() instead', E_USER_DEPRECATED);
- return static::getCollection()->load($username);
- }
- /**
- * Find a user by username, email, etc
- *
- * Always creates user object. To check if user exists, use $this->exists().
- *
- * @param string $query the query to search for
- * @param array $fields the fields to search
- * @return UserInterface
- * @deprecated 1.6 Use $grav['accounts']->find(...) instead.
- */
- public static function find($query, $fields = ['username', 'email'])
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use $grav[\'accounts\']->' . __FUNCTION__ . '() instead', E_USER_DEPRECATED);
- return static::getCollection()->find($query, $fields);
- }
- /**
- * Remove user account.
- *
- * @param string $username
- * @return bool True if the action was performed
- * @deprecated 1.6 Use $grav['accounts']->delete(...) instead.
- */
- public static function remove($username)
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use $grav[\'accounts\']->delete() instead', E_USER_DEPRECATED);
- return static::getCollection()->delete($username);
- }
- /**
- * @return UserCollectionInterface
- */
- protected static function getCollection()
- {
- return Grav::instance()['accounts'];
- }
- }
- }
|