Symfony-首次使用dotrine后PROD崩溃-错误:无法访问私有属性PhpFilesAdapter::$appe



受影响的Symfony版本:4.4.11(PHP 7.4.12(

身份验证系统在本地上正常工作。

当我在远程部署应用程序时,我会收到错误(通过sentint.io(。

Error: Cannot access private property SymfonyComponentCacheAdapterPhpFilesAdapter::$appendOnly
#28 /vendor/symfony/cache/Traits/PhpFilesTrait.php(83): SymfonyComponentCacheAdapterAbstractAdapter::doFetch
#27 /vendor/symfony/cache/Traits/AbstractAdapterTrait.php(44): SymfonyComponentCacheAdapterAbstractAdapter::getItem
#26 /vendor/symfony/cache/DoctrineProvider.php(54): SymfonyComponentCacheDoctrineProvider::doFetch
#25 /vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(199): DoctrineCommonCacheCacheProvider::getNamespaceVersion
#24 /vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(176): DoctrineCommonCacheCacheProvider::getNamespacedId
#23 /vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(59): DoctrineCommonCacheCacheProvider::fetch
#22 /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php(178): DoctrinePersistenceMappingAbstractClassMetadataFactory::getMetadataFor
#21 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(288): DoctrineORMEntityManager::getClassMetadata
#20 /vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php(37): DoctrineBundleDoctrineBundleRepositoryContainerRepositoryFactory::getRepository
#19 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(739): DoctrineORMEntityManager::getRepository
#18 /src/Security/LoginFormAuthenticator.php(80): AppSecurityLoginFormAuthenticator::getUser
#17 /vendor/symfony/security-guard/Provider/GuardAuthenticationProvider.php(105): SymfonyComponentSecurityGuardProviderGuardAuthenticationProvider::authenticateViaGuard
#16 /vendor/symfony/security-guard/Provider/GuardAuthenticationProvider.php(99): SymfonyComponentSecurityGuardProviderGuardAuthenticationProvider::authenticate
#15 /vendor/symfony/security-core/Authentication/AuthenticationProviderManager.php(85): SymfonyComponentSecurityCoreAuthenticationAuthenticationProviderManager::authenticate
#14 /vendor/symfony/security-guard/Firewall/GuardAuthenticationListener.php(152): SymfonyComponentSecurityGuardFirewallGuardAuthenticationListener::executeGuardAuthenticator
#13 /vendor/symfony/security-guard/Firewall/GuardAuthenticationListener.php(117): SymfonyComponentSecurityGuardFirewallGuardAuthenticationListener::authenticate
#12 /vendor/symfony/security-http/Firewall/AbstractListener.php(27): SymfonyComponentSecurityHttpFirewallAbstractListener::__invoke
#11 /vendor/symfony/security-bundle/Security/LazyFirewallContext.php(64): SymfonyBundleSecurityBundleSecurityLazyFirewallContext::__invoke
#10 /vendor/symfony/security-http/Firewall.php(140): SymfonyComponentSecurityHttpFirewall::handleRequest
#9 /vendor/symfony/security-http/Firewall.php(130): SymfonyComponentSecurityHttpFirewall::callListeners
#8 /vendor/symfony/security-http/Firewall.php(98): SymfonyComponentSecurityHttpFirewall::onKernelRequest
#7 /vendor/symfony/event-dispatcher/EventDispatcher.php(304): SymfonyComponentEventDispatcherEventDispatcher::SymfonyComponentEventDispatcher{closure}
#6 /vendor/symfony/event-dispatcher/EventDispatcher.php(264): SymfonyComponentEventDispatcherEventDispatcher::doDispatch
#5 /vendor/symfony/event-dispatcher/EventDispatcher.php(239): SymfonyComponentEventDispatcherEventDispatcher::callListeners
#4 /vendor/symfony/event-dispatcher/EventDispatcher.php(73): SymfonyComponentEventDispatcherEventDispatcher::dispatch
#3 /vendor/symfony/http-kernel/HttpKernel.php(134): SymfonyComponentHttpKernelHttpKernel::handleRaw
#2 /vendor/symfony/http-kernel/HttpKernel.php(80): SymfonyComponentHttpKernelHttpKernel::handle
#1 /vendor/symfony/http-kernel/Kernel.php(201): SymfonyComponentHttpKernelKernel::handle
#0 /public/index.php(25): null

它发生在对学说的第一次召唤上。

我怀疑条令缓存无法正常工作,但无法了解为什么以及如何解决它。

我尝试对缓存使用redis,但在使用其他适配器时也出现了类似的错误。

SymfonyComponentErrorHandlerErrorUndefinedMethodError: Attempted to call an undefined method named "getFile" of class "SymfonyComponentCacheAdapterRedisAdapter".
#28 /vendor/symfony/cache/Traits/PhpFilesTrait.php(165): SymfonyComponentCacheAdapterAbstractAdapter::doHave
#27 /vendor/symfony/cache/Traits/AbstractAdapterTrait.php(44): SymfonyComponentCacheAdapterAbstractAdapter::getItem
#26 /vendor/symfony/cache/DoctrineProvider.php(54): SymfonyComponentCacheDoctrineProvider::doFetch
#25 /vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(199): DoctrineCommonCacheCacheProvider::getNamespaceVersion
#24 /vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(176): DoctrineCommonCacheCacheProvider::getNamespacedId
#23 /vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(59): DoctrineCommonCacheCacheProvider::fetch
#22 /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php(178): DoctrinePersistenceMappingAbstractClassMetadataFactory::getMetadataFor
#21 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(288): DoctrineORMEntityManager::getClassMetadata
#20 /vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php(37): DoctrineBundleDoctrineBundleRepositoryContainerRepositoryFactory::getRepository
#19 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(739): DoctrineORMEntityManager::getRepository
#18 /src/Security/LoginFormAuthenticator.php(80): AppSecurityLoginFormAuthenticator::getUser
#17 /vendor/symfony/security-guard/Provider/GuardAuthenticationProvider.php(105): SymfonyComponentSecurityGuardProviderGuardAuthenticationProvider::authenticateViaGuard
#16 /vendor/symfony/security-guard/Provider/GuardAuthenticationProvider.php(99): SymfonyComponentSecurityGuardProviderGuardAuthenticationProvider::authenticate
#15 /vendor/symfony/security-core/Authentication/AuthenticationProviderManager.php(85): SymfonyComponentSecurityCoreAuthenticationAuthenticationProviderManager::authenticate
#14 /vendor/symfony/security-guard/Firewall/GuardAuthenticationListener.php(152): SymfonyComponentSecurityGuardFirewallGuardAuthenticationListener::executeGuardAuthenticator
#13 /vendor/symfony/security-guard/Firewall/GuardAuthenticationListener.php(117): SymfonyComponentSecurityGuardFirewallGuardAuthenticationListener::authenticate
#12 /vendor/symfony/security-http/Firewall/AbstractListener.php(27): SymfonyComponentSecurityHttpFirewallAbstractListener::__invoke
#11 /vendor/symfony/security-bundle/Security/LazyFirewallContext.php(64): SymfonyBundleSecurityBundleSecurityLazyFirewallContext::__invoke
#10 /vendor/symfony/security-http/Firewall.php(140): SymfonyComponentSecurityHttpFirewall::handleRequest
#9 /vendor/symfony/security-http/Firewall.php(130): SymfonyComponentSecurityHttpFirewall::callListeners
#8 /vendor/symfony/security-http/Firewall.php(98): SymfonyComponentSecurityHttpFirewall::onKernelRequest
#7 /vendor/symfony/event-dispatcher/EventDispatcher.php(304): SymfonyComponentEventDispatcherEventDispatcher::SymfonyComponentEventDispatcher{closure}
#6 /vendor/symfony/event-dispatcher/EventDispatcher.php(264): SymfonyComponentEventDispatcherEventDispatcher::doDispatch
#5 /vendor/symfony/event-dispatcher/EventDispatcher.php(239): SymfonyComponentEventDispatcherEventDispatcher::callListeners
#4 /vendor/symfony/event-dispatcher/EventDispatcher.php(73): SymfonyComponentEventDispatcherEventDispatcher::dispatch
#3 /vendor/symfony/http-kernel/HttpKernel.php(134): SymfonyComponentHttpKernelHttpKernel::handleRaw
#2 /vendor/symfony/http-kernel/HttpKernel.php(80): SymfonyComponentHttpKernelHttpKernel::handle
#1 /vendor/symfony/http-kernel/Kernel.php(201): SymfonyComponentHttpKernelKernel::handle

LoginFormAuthenticator

<?php
[...]
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements PasswordAuthenticatedInterface
{
use TargetPathTrait;
public const LOGIN_ROUTE = 'app_login';
private const GENERIC_ERROR_MESSAGE = 'Email or password invalid.';
private const APP_ACCESS_ERROR_MESSAGE = 'You don't have access to this App..';
private AuthApiClientInterface $authApiClientService;
private EntityManagerInterface $entityManager;
private UrlGeneratorInterface $urlGenerator;
private CsrfTokenManagerInterface $csrfTokenManager;
private UserPasswordEncoderInterface $passwordEncoder;
public function __construct(
EntityManagerInterface $entityManager,
UrlGeneratorInterface $urlGenerator,
CsrfTokenManagerInterface $csrfTokenManager,
AuthApiClientInterface $authApiClientService
) {
$this->entityManager = $entityManager;
$this->urlGenerator = $urlGenerator;
$this->csrfTokenManager = $csrfTokenManager;
$this->authApiClientService = $authApiClientService;
}
public function supports(Request $request)
{
return self::LOGIN_ROUTE === $request->attributes->get('_route') && $request->isMethod('POST');
}
public function getCredentials(Request $request)
{
$credentials = [
'email' => $request->request->get('email'),
'password' => $request->request->get('password'),
'csrf_token' => $request->request->get('_csrf_token'),
];
$request->getSession()->set(Security::LAST_USERNAME, $credentials['email']);
return $credentials;
}
public function getUser($credentials, UserProviderInterface $userProvider)
{
$token = new CsrfToken('authenticate', $credentials['csrf_token']);
if (!$this->csrfTokenManager->isTokenValid($token)) {
throw new InvalidCsrfTokenException();
}
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $credentials['email']]);
if (!$user) {
// fail authentication with a custom error
throw new CustomUserMessageAuthenticationException(self::GENERIC_ERROR_MESSAGE);
}
return $user;
}
public function checkCredentials($credentials, UserInterface $user)
{
$authResponse = $this->authApiClientService->authenticationRequest(
$credentials['email'],
$credentials['password'],
'EASY_ADMIN'
);
$statusCode = $authResponse->getStatusCode();
switch ($statusCode) {
case 200:
case 204:
return true;
case 401:
throw new CustomUserMessageAuthenticationException(self::GENERIC_ERROR_MESSAGE);
case 403:
throw new CustomUserMessageAuthenticationException(self::APP_ACCESS_ERROR_MESSAGE);
}
throw new HttpException(502, "Unexpected Authentication error ($statusCode)");
}
/**
* Used to upgrade (rehash) the user's password automatically over time.
* @param $credentials
* @return string|null
*/
public function getPassword($credentials): ?string
{
return $credentials['password'];
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) {
return new RedirectResponse($targetPath);
}
return new RedirectResponse('/');
}
protected function getLoginUrl()
{
return $this->urlGenerator->generate(self::LOGIN_ROUTE);
}
}

停用操作缓存预加载解决了问题。

相关内容

  • 没有找到相关文章

最新更新