我使用以下中间件在到期时刷新我的令牌:
import {AsyncStorage} from 'react-native';
import moment from 'moment';
import fetch from "../components/Fetch";
import jwt_decode from 'jwt-decode';
/**
* This middleware is meant to be the refresher of the authentication token, on each request to the API,
* it will first call refresh token endpoint
* @returns {function(*=): Function}
* @param store
*/
const tokenMiddleware = store => next => async action => {
if (typeof action === 'object' && action.type !== "FETCHING_TEMPLATES_FAILED") {
let eToken = await AsyncStorage.getItem('eToken');
if …Run Code Online (Sandbox Code Playgroud) 当我启动我的PHPUnit测试套件时,我达到了MySQL的最大连接限制(200).
热门修复是将max_connection设置为500,但我正在寻找Zend Framework 2上下文中更好的解决方案.
我试图把一些tearDown方法,但没有运气似乎是无用或不完整的解决方案.
这是一个代码示例:
protected function tearDown()
{
// i have two entitymanager
$this->getObjectManager()->get('doctrine.connection.orm_alternate')->close();
$this->getObjectManager()->get('doctrine.connection.orm_default')->close();
$this->application = null;
gc_collect_cycles();
parent::tearDown();
}
Run Code Online (Sandbox Code Playgroud)
我也尝试使用processIsolation转为true但是有些测试是如此之长以至于我认为我的控制台已经冻结或类似的东西....
使用doctrine2连接和Zend Framework,如何在PHPunit测试期间防止这种"连接太多"?
到目前为止,我试图修改@awons的提示
$this->getObjectManager()->get('doctrine.connection.orm_alternate')->close();
至
$this->getObjectManager()->get('doctrine.entitymanager.orm_alternate')->close();
我检查了拆机是否被叫,是的.
我不明白的是:在每次测试中,都会创建一个新的连接实例,为什么这不是同一个实例?(像单身人士或登记处)?但是这个实例永远不会关闭,即使它在测试通过后也没有使用过.
我误会了什么,但不知道是什么.
使用PHPUnit创建测试时遇到一些问题.
这是我的设置:
protected function setUp()
{
$serviceManager = Bootstrap::getServiceManager();
$this->mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$this->mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface');
$this->mockDriver->expects($this->any())->method('checkEnvironment')->will($this->returnValue(true));
$this->mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($this->mockConnection));
$this->mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
$this->mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$this->mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($this->mockStatement));
$this->adapter = new Adapter($this->mockDriver, $this->mockPlatform);
$this->sql = new Sql($this->adapter);
$mockTableGateway = $this->getMock('Zend\Db\TableGateway\TableGateway', array(), array(), '', false);
$maiFormuleRevisionTable = $this->getMockBuilder('Maintenance\Model\BDD\PMaiFormulerevisionTable')
->setMethods(array())
->setConstructorArgs(array($mockTableGateway, $this->adapter, $this->sql))
->getMock();
$maiFormulerevisionService = $this->getMockBuilder('Maintenance\Service\Model\PMaiFormulerevisionService')
->setMethods(array())
->setConstructorArgs(array($maiFormuleRevisionTable))
->getMock();
$this->assertTrue($maiFormulerevisionService instanceof PMaiFormulerevisionService);
$this->controller = new RevisionsController($maiFormulerevisionService);
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$config = $serviceManager->get('Config');
$routerConfig = …Run Code Online (Sandbox Code Playgroud) 根据马可的Pivetta看法这个,这个老问题 和我的回答的另一个问题
我在询问自己在Zend Framework 2应用程序中使用我们的服务的更好方法.
实际上我们可以ServiceLocatorAwareInterface结合使用ServiceLocatorAwareTrait.事实上在ZF3中,服务定位器将被移除在控制器中它们可能也会删除此接口,或建议不使用它的人,这是有道理的.
我看到我们的服务如何构建的唯一方法是:
不要在服务中使用ServiceLocator,请使用DependancyInjection.
问题是 :
有些项目非常大,你要么:
您可能需要在服务中使用的一些示例:
也许对于其中的一些观点,它们可以通过我不知道的技巧来解决.
我的问题是:
在一个服务中拥有15个或更多Dependancies并放弃ServiceLocator,在控制器中,还是在服务中,这是一个好习惯吗?
从评论中编辑
为了说明我的观点,我粘贴了一个构造函数:
public function __construct(
ToolboxService $toolboxService,
EntityService $entityService,
UserService $userService,
ItemService $itemService,
CriteriaService $criteriaService,
Import $import,
Export $export,
PhpRenderer $renderer
) {
$this->toolboxService = $toolboxService;
$this->entityService = $entityService;
$this->userService = $userService;
$this->emOld = $this->toolboxService->getEmOld();
$this->emNew = $this->toolboxService->getEmNew();
$this->serviceLocator = $this->toolboxService->getServiceLocator();
$this->itemService = $itemService;
$this->criteriaService = …Run Code Online (Sandbox Code Playgroud) 我正在使用带有 Symfony 4 信使组件的工作人员。
这位工人是
为了在 Symfony 上配置这个工作器,我已经这样做了(中间件很重要):
// config/packages/framework.yaml
framework:
messenger:
buses:
command_bus:
middleware:
# each time a message is handled, the Doctrine connection
# is "pinged" and reconnected if it's closed. Useful
# if your workers run for a long time and the database
# connection is sometimes lost
- doctrine_ping_connection
# After handling, the Doctrine connection is closed,
# which can free up database connections in a worker,
# instead of keeping …Run Code Online (Sandbox Code Playgroud) 我正在开始一个新项目,我也是Zend Framework 2的新手.你有什么建议从你想作为变量传递的html代码生成pdf($ html)?我在网上看到DOMPDF非常好,但我不知道如何使用它,查看文档.什么是初学者最简单的方法?
在Windows 7计算机上启动tomcat8作为服务用于开发目的可能真的...很烦人.
我有这个错误:
Failed creating java C:\Program Files (x86)\Java\jdk1.8.0_40\jre\bin\server\jvm.dll
Run Code Online (Sandbox Code Playgroud)
我看到了:
C:\Program Files (x86)\Java\jdk1.8.0_40\bin
Run Code Online (Sandbox Code Playgroud)
那msvcr100.dll不是我在windows/system32文件夹中的文件.事实上,在我的windows/System32文件夹中,我有msvcr100.dll与x64版本相对应的内容.Tomcat服务无法启动并告诉我它不是有效的32位版本.
我解决这个问题的方法是在C:\ Program Files中安装jdk1.8.0_40并在tomcat8w.exe中查找名为Java virtual Machine的java选项卡中的路径,我将此字段设置为:
C:\Program Files\Java\jdk1.8.0_40\jre\bin\server\mvcr100.dll
Run Code Online (Sandbox Code Playgroud)
现在,对于服务Tomcat8,它将使用x64 dll,并且所有工作正常.
我的问题是,我可以用msvcr100.dllx86版本替换windows\system32中的安全吗?或者我的解决方案很好?
我试图将使用OpenCV用C++编写的现有计算机视觉代码移植到Android NDK.我按照此处提供的信息成功地为Java和NDK导入了OpenCV库版本3.4.0(使用官方预构建的Android软件包):Satck Overflow Answer - 在Android上对OpenCV进行CMake配置.
我能够使用Java和C++中的OpenCV功能编译和运行一些代码.但是,我遇到了与某些OpenCV函数相关的2个"未定义引用"链接错误:持久性JSON读取器和2D描述符匹配器.
以下是我收到的错误消息:
Build command failed.
Error while executing process D:\Librairies\Android_SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\Dev\Android\PageDetector\app\.externalNativeBuild\cmake\debug\x86_64 --target page-recognition-lib}
[1/1] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\recognition-lib.so
FAILED: cmd.exe /C "cd . && D:\Librairies\Android_SDK\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=x86_64-none-linux-android --gcc-toolchain=D:/Librairies/Android_SDK/ndk-bundle/toolchains/x86_64-4.9/prebuilt/windows-x86_64 --sysroot=D:/Librairies/Android_SDK/ndk-bundle/sysroot -fPIC -isystem D:/Librairies/Android_SDK/ndk-bundle/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -frtti -fexceptions -std=gnu++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot D:/Librairies/Android_SDK/ndk-bundle/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -LD:/Librairies/Android_SDK/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libpage-recognition-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\recognition-lib.so.so [...] -llog …Run Code Online (Sandbox Code Playgroud) 使用下面列出的这个配置,我遇到了一些我无法单独解决的奇怪问题,因为我在 Symfony 中太新了。
security:
encoders:
App\Api\User\Entity\User:
algorithm: bcrypt
cost: 12
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
users:
id: 'App\Api\Auth\Provider\AuthProvider'
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# Api will be stateless, a token will be generated
api_login:
pattern: /api/login
stateless: true
context: api
anonymous: true
provider: users
form_login:
check_path: /api/login
username_parameter: email
password_parameter: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
# For web calls no need to be stateless
web_login:
pattern: /login
stateless: false
context: web
anonymous: true
provider: users
guard:
entry_point: 'App\User\Auth\Guard\LoginAuthenticator'
authenticators: …Run Code Online (Sandbox Code Playgroud) 我需要添加boostrap容器+ 60px.
我怎么能这样做,没有changin boostrap本身?
我试过这个媒体查询,但它不起作用.
@media (min-width: 1200px) {
.container{
max-width: 1260px;
}
}
Run Code Online (Sandbox Code Playgroud)
你能帮帮我吗?谢谢 :)