dongzhong7443 2018-10-25 09:45
浏览 49

未检测到第三方(供应商)Symfony Bundle中的命令。 怎么了?

as instructed in https://github.com/glennthehuman/encryption-bundle/blob/master/Resources/doc/index.md

I executed: php bin/console jagilpe:encryption:user:generate_keys But I got:

There are no commands defined in the "jagilpe:encryption:user" namespace.

So, I checked this folder structure With the code:

<?php

namespace Jagilpe\EncryptionBundle\Command;

use Doctrine\Common\Util\ClassUtils;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Jagilpe\EncryptionBundle\Entity\PKEncryptionEnabledUserInterface;
use Symfony\Component\Console\Helper\ProgressBar;

class CreateUserKeysCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('jagilpe:encryption:user:generate_keys')
            ->setDescription('Generates the encryption keys of a user')
            ->addArgument(
                'usename',
                InputArgument::OPTIONAL,
                'The name of the user whose keys we want to create.'
            )
            ->addOption(
                'all',
                null,
                InputOption::VALUE_NONE,
                'If the keys of all users should be generated.'
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // Input parameters
        $userName = $input->getArgument('usename');
        $allUsers = $input->getOption('all');

        if (!$userName && !$allUsers) {
            throw new \RuntimeException('Wrong parameters given');
        }

        if ($userName && $allUsers) {
            throw new \RuntimeException('Ambiguous parameters given');
        }

        $users = $this->getUsers($userName);

        $total = count($users);
        $message = "Generating the encryption keys for $total users";
        $output->writeln($message);
        $progress = new ProgressBar($output, $total);
        foreach ($users as $user) {
            $this->generateKeys($user);
            $this->saveUser($user);
            $progress->advance();
        }
        $progress->finish();
        $output->writeln('');
    }

    private function getUsers($userName)
    {
        $container = $this->getContainer();
        $entityManager = $container->get('doctrine')->getManager();
        $encryptionSettings = $container->getParameter('jagilpe_encryption.settings');
        $userClasses = $encryptionSettings['user_classes'];

        $users = array();
        foreach ($userClasses as $userClass) {
            $userRepo = $entityManager->getRepository($userClass);

            if ($userName) {
                $user = $userRepo->findOneBy(array('username' => $userName));
                $users = array($user);
                break;
            }
            else {
                $users = array_merge($users, $userRepo->findAll());
            }
        }

        return $users;
    }

    private function generateKeys(PKEncryptionEnabledUserInterface $user)
    {
        if (!$user->getPublicKey() || !$user->getPrivateKey()) {
            $container = $this->getContainer();
            $keyManager = $container->get('jagilpe_encryption.key_manager');
            $keyManager->generateUserPKIKeys($user);
        }
    }

    private function saveUser(PKEncryptionEnabledUserInterface $user)
    {
        $userClass = ClassUtils::getClass($user);
        $userRepo = $this->getContainer()->get('doctrine')->getManager()->getRepository($userClass);
        $userRepo->save($user);
    }
}

What's wrong with this?

By the way, I was able to install the bundle without any problem. The source codes can be correctly accessed and used in my own codes. I just cannot run the aforementioned command properly. I also created my own command in my own Command directory and they were properly detected and executed.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大