Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 扩展Symfony 2 FOS用户包的用户提供程序_Php_Symfony_Fosuserbundle - Fatal编程技术网

Php 扩展Symfony 2 FOS用户包的用户提供程序

Php 扩展Symfony 2 FOS用户包的用户提供程序,php,symfony,fosuserbundle,Php,Symfony,Fosuserbundle,Iam使用FOS用户包登录我的网站。对于一项要求,我需要在Fos用户包用户提供程序中进行更改( FOS\UserBundle\Security\UserProvider) 我已经创建了一个userProvider,它扩展了中的原始userProvider FOS和已重写loadUserByUsername方法以进行更改。具体如下 <?php /* * This file is part of the FOSUserBundle package. * * (c) FriendsOfS

Iam使用FOS用户包登录我的网站。对于一项要求,我需要在Fos用户包用户提供程序中进行更改(

FOS\UserBundle\Security\UserProvider)

我已经创建了一个userProvider,它扩展了中的原始userProvider FOS和已重写loadUserByUsername方法以进行更改。具体如下

<?php

/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Common\UtilityBundle\Security;

use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;
use FOS\UserBundle\Model\User;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Propel\User as PropelUser;
use FOS\UserBundle\Security\UserProvider as FOSProvider;
use Symfony\Component\DependencyInjection\ContainerInterface;

class UserProvider extends FOSProvider
{
/**
 *
 * @var ContainerInterface 
 */
protected $container;
protected $userManager;


public function __construct(UserManagerInterface $userManager, ContainerInterface $container) {
    $this->userManager = $userManager;
    $this->container = $container;
}

/**
 * {@inheritDoc}
 */
public function loadUserByUsername($username)
{

    $user = $this->findUserUsername($username);

    if (!$user) {
        throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
    }

    return $user;
}

/**
 * {@inheritDoc}
 */
public function refreshUser(SecurityUserInterface $user)
{
    if (!$user instanceof User && !$user instanceof PropelUser) {
        throw new UnsupportedUserException(sprintf('Expected an instance of FOS\UserBundle\Model\User, but got "%s".', get_class($user)));
    }

    if (!$this->supportsClass(get_class($user))) {
        throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), get_class($user)));
    }

    if (null === $reloadedUser = $this->userManager->findUserBy(array('id' => $user->getId()))) {
        throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $user->getId()));
    }

    return $reloadedUser;
}

/**
 * {@inheritDoc}
 */
public function supportsClass($class)
{
    $userClass = $this->userManager->getClass();

    return $userClass === $class || is_subclass_of($class, $userClass);
}

/**
 * Finds a user by username.
 *
 * This method is meant to be an extension point for child classes.
 *
 * @param string $username
 *
 * @return UserInterface|null
 */
protected function findUserUsername($username)
{
    return $this->userManager->findUserByUsername($username);
}

/**
 * Finds a user by username.
 *
 * This method is meant to be an extension point for child classes.
 *
 * @param string $username
 *
 * @return UserInterface|null
 */
protected function findUserClub($username, $club)
{
    return $this->userManager->findUserByClub($club, $username);
}
}
我的security.yml如下所示:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    providers:
        fg_security_userprovider:
            id: fg.security.authentication.userprovider
在我的parameter.yml中,我将参数设置为:

Common_utility.security.user_provider.class: Common\UtilityBundle\Security\UserProvider
但我一直收到如下错误:

未捕获异常 'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException' 消息“服务”security.authentication.manager“具有 依赖于不存在的服务 中的“security.user.provider.concrete.fos_userbundle” /供应商/symfony/symfony/src/symfony/Component/DependencyInjection/Compiler/CheckExceptionNonValidReferenceBehaviorPass.php:59


有人知道如何让它工作吗?

请从security.yml粘贴防火墙选项。也许有个打字错误。实际上你最好粘贴整个security.yml。
Common_utility.security.user_provider.class: Common\UtilityBundle\Security\UserProvider