Добро пожаловать в наше сообщество TopForo.ru

Станьте частью чего-то великого, присоединяйтесь сегодня!

Иконка ресурса

Мод XenForo Получение информации о пользователе CLI

Создать файл GetUser.php в src/XF/CLI/Command
Код:
Expand Collapse Copy
namespace XF\Cli\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GetUser extends Command
{
    protected function configure()
    {
        $this
            ->setName('users:get')
            ->setDescription('Get user specified by --user parameter')
            ->addOption(
                'user',
                'u',
                InputOption::VALUE_REQUIRED,
                'User Id'
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $id = intval($input->getOption('user'));
        if (!$id) {
            $output->writeln('Invalid user id');
            return 22;
        }

        $finder = \XF::em()->getFinder('XF:User')->where('user_id', $id);
        $entity = $finder->fetchOne();

        if ($entity === null) {
            $output->writeln('Invalid user id');
            return 22;
        }

        $data = $entity->toArray();
        unset ($data['secret_key']);

        $output->writeln(json_encode($data, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));

        return 0;
    }
}
В терминале вызвать команду:
Код:
Expand Collapse Copy
php cmd.php users:get --user id
Автор
DetectorDevil
Просмотры
14
Первый выпуск
Обновление

Оценки

0,00 звёзд 0 оценок

Другие ресурсы пользователя DetectorDevil

Назад
Назад
Сверху Снизу