我有越来越多的服务类共享一个公共接口(比方说BarService和BazService,实现FooInterface)。
所有这些都需要使用相同的装饰器进行装饰。阅读文档,我知道我可以做到:
services:
App\BarDecorator:
# overrides the App\BarService service
decorates: App\BarService
Run Code Online (Sandbox Code Playgroud)
由于我必须为不同的服务使用相同的装饰器,我想我需要这样做:
services:
bar_service_decorator:
class: App\BarDecorator
# overrides the App\BarService service
decorates: App\BarService
baz_service_decorator:
class: App\BarDecorator
# overrides the App\BazService service
decorates: App\BazService
Run Code Online (Sandbox Code Playgroud)
问题是:这会很快重复。并且每次FooInterface创建一个新的实现时,都需要将另一个集合添加到配置中。
如何声明我要装饰所有FooInterface自动实现的服务,而不必单独声明每个服务?
我试图阻止用户登录,他的状态为非活动状态。我正在将 API 平台与 LexikJWT 捆绑包一起使用。
我尝试JWTAuthentication通过扩展来进行防护JWTTokenAuthenticator->checkCredentials,但问题是这在用户登录后才起作用。
我想要实现的是向用户返回一条消息,要求他首先激活其帐户,或任何其他消息,最好是任何自定义条件下的任何自定义消息。
我的安全 YAML 如下所示:
security:
encoders:
App\Entity\User:
algorithm: bcrypt
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/_(profiler|wdt)
security: false
api:
pattern: ^/api/
stateless: true
anonymous: true
provider: app_user_provider
json_login:
check_path: /api/authentication_token
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
guard:
authenticators:
- app.jwt_token_authenticator
main:
anonymous: true
access_control:
- { path: ^/api/authentication_token, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/graphql, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/public-api, roles: IS_AUTHENTICATED_ANONYMOUSLY …Run Code Online (Sandbox Code Playgroud) 我有以下问题:我有一个使用 Laravel 4.2、PHP 5.5.9 和 Composer 的旧项目。我试图在另一台计算机上设置它(使用 Laravel 4.2.2 和 PHP 5.6),但所需的包之一具有缺少的依赖项,因为管理该 GitHub 帐户的人决定删除它。因此,无法通过 Composer 安装所需的包。
现在,旧项目已下载这些包,我可以手动复制它们。我不知道的是如何以这种方式正确地将它们添加到项目中并阻止作曲家尝试重新下载它们。
没有给出代码示例,因为不需要。
我有一个类,我将一个实例Symfony\Component\HttpClient\HttpClient作为构造函数参数注入其中。
我正在查看https://symfony.com/doc/current/components/http_client.html#testing-http-clients-and-responses的文档页面,建议将其$client = new MockHttpClient($responses);用作创建模拟客户端的一种方式.
当我将模拟客户端传递给我的班级时,我收到错误消息:
类型错误:传递给的参数 3
App\Allocator\Strategy\AbstractStrategy::__construct()必须是 的实例Symfony\Component\HttpClient\HttpClient,Symfony\Component\HttpClient\MockHttpClient接收的实例。
我如何获得一个满足输入约束并允许我模拟响应的 Mock?
是否可以在 Doctrine(对于 MySQL)中设置连接超时?
我想设置5秒。我的连接超时。
从官方文档中可以看出,当前在 Symfony 框架中手动哈希密码的过程如下:
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
public function register(UserPasswordEncoderInterface $encoder)
{
// whatever *your* User object is
$user = new App\Entity\User();
$plainPassword = 'ryanpass';
$encoded = $encoder->encodePassword($user, $plainPassword);
$user->setPassword($encoded);
}
Run Code Online (Sandbox Code Playgroud)
该encodePassword方法需要将 User 实例作为其第一个参数传递。因此,在调用该方法时,用户实例必须预先存在:这意味着必须在没有有效散列密码的情况下实例化“用户”。我希望将密码作为构造函数参数提供,以便用户实体在创建时处于有效状态。
是否有其他方法使用 Symfony 对密码进行哈希处理?
作曲家版本:2.0.4
操作系统:macOS 10.15.7
当我运行 composer 诊断时,我遇到了 DNS 解析器问题,如附图所示
我可以从终端 ping getcomposer.org、packagist.org、github.com - 所有站点。
curl -i packagist.org -L 也按预期工作,没有任何错误
然而,通过作曲家诊断,我遇到了 DNS 解析器问题
这在我将 PHP 从 7.4.1 升级到 7.4.12 并更新到 composer 2 之后开始发生
可能是什么问题,我该如何解决
作为可搜索的文本代码 - composer 2.0.4 诊断失败
$ composer diagnose
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: FAIL
The following exception probably indicates you have misconfigured DNS resolver(s)
[Composer\Downloader\TransportException] Resolving timed out after 10003 milliseconds
Checking https connectivity to packagist: FAIL
The following exception …Run Code Online (Sandbox Code Playgroud) 在我的 Symfony 应用程序中,我有一个User序列化的实体。在该unserialize()方法中,我这样做了:
public function unserialize($serialized)
{
[
$this->id,
$this->email,
$this->password,
$this->enabled
] = unserialize($serialized);
}
Run Code Online (Sandbox Code Playgroud)
但 PhpStorm 用红色下划线unserialize($serialized)显示以下消息:
请在第二个参数中指定允许反序列化的类。
我不知道应该用什么作为第二个参数。经过一番研究,我发现我们可以这样写:
unserialize($serializeObj, ["allowed_classes" => true]);
Run Code Online (Sandbox Code Playgroud)
但我也发现了这一点:
unserialize($serializeObj, ["allowed_classes" => true]);
Run Code Online (Sandbox Code Playgroud)
我有点困惑,我不知道我应该在我的案例中放入什么,这样 PhpStorm 就不会抱怨这一点。
我最近从 Symfony 3.4 升级到 4.4
代码库非常大,并且有很多container->get('logger')来自各地的引用。
我一直试图公开这项服务,但我找不到任何例子。错误:
编译容器时,“logger”服务或别名已被删除或内联。您应该将其公开,或者停止直接使用容器并使用依赖项注入。
在我的service.yml尝试中,我没有运气:
Psr\Log\LoggerInterface:
public: true
Psr\Log\LoggerInterface:
alias: 'logger'
public: true
Psr\Log\LoggerInterface:
alias: 'monolog.logger'
public: true
Run Code Online (Sandbox Code Playgroud)
我怎样才能公开该logger服务?
注意:在从 3.4->4.4 的升级中,我们没有更新代码库以使用 Symfony Flex
如何搜索匹配两个或更多值的数组?
Array
(
[1440972000] => Array
(
[mitarbeiterid] => 1
[von] => 1441006800
[doppeltermin] => n
[stundentermin] => n
[abgesagt] => n
)
)
Run Code Online (Sandbox Code Playgroud)
我想搜索"mitarbeiterid"和"von".这只是一个例子,在这个数组中有几百个条目.
我只知道如何搜索例如"von"但是如何组合搜索参数?