研究员我已经创建了一个创建一个简单按钮的组件:
class AppButton extends Component {
setOnClick() {
if(!this.props.onClick && typeof this.props.onClick == 'function') {
this.props.onClick=function(){ alert("Hello"); }
}
}
setMessage() {
if(!this.props.message){
this.props.message="Hello"
}
}
render(){
this.setOnClick()
this.setMessage()
return (
<button onClick={this.props.onClick}>{this.props.message}</button>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个组件,可以呈现2个按钮:
class App extends Component {
render() {
return (
<AppButton onClick={function(){ alert('Test Alert') } } message="My Button" />
<AppButton />
);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
TypeError:无法定义属性"message":对象不可扩展
在线上说:
this.props.message="Hello"
Run Code Online (Sandbox Code Playgroud)
在方法setMessage
的的AppButton
类.
我使用了生成反应应用程序,npm
并且我package.json
有以下内容
{
"name": "sample",
"version": "0.1.0", …
Run Code Online (Sandbox Code Playgroud) 当我在控制台上输入时我想要:
docker ^a docker container^ stop
Run Code Online (Sandbox Code Playgroud)
在终止之前执行脚本.那可能吗?
对于我记录的旧 API 以便成功进行身份验证,我需要提供以下标头:
X-Access-Token: {token}
Accept: application/json; version=public/v2
Run Code Online (Sandbox Code Playgroud)
对于令牌部分,我需要通过以下方式记录它:
X-Access-Token: {token}
Accept: application/json; version=public/v2
Run Code Online (Sandbox Code Playgroud)
但是我如何记录这一点以进行身份验证,我需要提供Accept: application/json; version=public/v2
. 标Accept
头必须包含application/json; version=public/v2
任何其他返回406 Not Acceptable
标头。
Accept
另外,具有值的标头application/json; version=public/v2
应该在我的请求中。响应标头始终为application/json
.
你知道我如何记录这一点吗?
我尝试使用VSCode的调试"功能"来调试react应用程序,到目前为止,通过快速Web搜索,我发现许多资源声称如何使用VSCode的Crome调试器来完成这项工作,例如:
但我找不到用firefox做到这一点的方法.到目前为止,我在VSCode上安装了"Debugger for firefox",并提供了以下调试选项:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug app",
"type": "firefox",
"request": "attach"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我按照文档说明运行:
firefox -start-debugger-server -no-remote
Run Code Online (Sandbox Code Playgroud)
我尝试通过VSCode初始化调试过程,当我这样做时,我得到错误:
连接ECONNREFUSED 127.0.0.1:6000
可以通过运行以下命令的GNU/Linux机器确认Tha错误
netstat -ntlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:37893 0.0.0.0:* LISTEN 9368/node
tcp 0 0 …
Run Code Online (Sandbox Code Playgroud) 我构建了一个基于php:5.6-fpm-alpine
图像的图像,我运行一个基于symfony的应用程序,因此我运行cli和基于Web的php脚本.
所以我通过以下方式在我正在运行的容器上生成了一个shell:
docker exec -ti ^container_id^ /bin/sh
Run Code Online (Sandbox Code Playgroud)
在shell上我导出了以下环境变量:
export PHP_IDE_CONFIG="serverName=0.0.0.0:5092"
export XDEBUG_CONFIG="idekey=PHPSTORM"
Run Code Online (Sandbox Code Playgroud)
并且已按照以下链接中的说明设置IDE:
但是当我在phpstorm上启用Xdebug时,即使它正常调试我也会收到以下错误消息:
你知道为什么会这样吗?
假设我们有这两种方法:
function superFunction($superhero,array $clothes){
if($superhero===CHUCK_NORRIS){
wear($clothes);
} else if($superhero===SUPERMAN) {
wear($clothes[1]);
}
}
function wear(array $clothes)
{
for($piece in $clothes){
echo "Wearing piece";
}
}
Run Code Online (Sandbox Code Playgroud)
所以我想要实现的是将 PhpStorm 中的断点放入函数中wear
,但我想仅当$superhero
变量具有我可以做到这一点的值时才被解雇CHUCK_NORRIS
。想象一下,该函数superFunction
被调用了无数次,并且F9一直按下去会适得其反。
在我个人的Symfony 3.2项目(https://github.com/pc-magas/photoalbum)上因为我想获得一个Json而不是基于http://www.webtipblog.com/adding-an-ajax-login的重定向-form-to-a-symfony-project /我做了以下身份验证管理器:
<?php
namespace AppBundle\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
class AuthenticationHandler implements AuthenticationSuccessHandlerInterface, AuthenticationFailureHandlerInterface
{
private $router;
private $session;
/**
* Constructor
*
* @author Joe Sexton <joe@webtipblog.com>
* @param RouterInterface $router
* @param Session $session
*/
public function __construct( RouterInterface $router, Session $session )
{
$this->router = $router;
$this->session = $session;
}
/**
* onAuthenticationSuccess
* …
Run Code Online (Sandbox Code Playgroud) 在我的工作中,我被要求将在 iis/azure 上运行的 php 应用程序迁移到在 GNU+Linux 机器上通过 nginx 和 fpm 运行。
然后在这个过程中,我遇到了一个名为web.config
包含条目的文件,例如:
<action name="SomeName" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions>
<add input="{URL}" pattern="^some_regex^">
</conditions>
<action type="Rewrite" url="index.php?someaction={C:1}">
</action>
Run Code Online (Sandbox Code Playgroud)
或者
<action name="SomeName" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions>
<add input="{URL}" pattern="^some_regex^">
</conditions>
<action type="Rewrite" url="index.php?someaction={R:1}">
</action>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我认为这样的 nginx 映射:
^some_regex^ index.php?someaction=$1;
Run Code Online (Sandbox Code Playgroud)
会在两个动作中完成工作(以某种方式)。但是我仍然无法理解正则表达式机器上 {C:1} 和 {R:1} 之间的区别我知道在我的 nginx 中类似于 $1(一个子正则表达式匹配)但是与 web.config 不同的是 {C: 1} 和 {R:1} 条目?
我问是因为我可能需要稍微更改 nginx 的子正则表达式匹配项是 {C:1} 还是 {R:1}。
我有以下 Laravel 控制器:
namespace App\Controller;
use App\Jobs\MyJob;
class JobDispatchControler
{
public function callJob(Request $request)
{
MyJob::dispatch();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的控制器有以下路由:
Route::get('/job',"\App\Controller\JobDispatchControler@callJob");
Run Code Online (Sandbox Code Playgroud)
我想测试我是否拨打电话/job
将分派MyJob
工作:
namespace Test\App\MyJob;
use Illuminate\Foundation\Testing\TestCase;
use Illuminate\Support\Facades\Queue;
use App\Jobs\MyJob;
class TestDispatchJob extends TestCase
{
public function testJobDispatch()
{
Queue::fake();
self::get("/job");
Queue::assertPushed(MyJob::class);
}
}
Run Code Online (Sandbox Code Playgroud)
但是一旦我通过 phpunit 运行测试,我就会收到以下错误:
Time: 4.63 seconds, Memory: 34.00 MB
There was 1 failure:
1) Test\App\MyJob::testJobDispatch
The expected [App\Jobs\MyJob] job was not pushed.
/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/QueueFake.php:33
/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
/var/www/html/tests/App/MyJob/TestDispatchJob.php:26
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Run Code Online (Sandbox Code Playgroud)
你知道我为什么不能断言我的工作没有被派遣吗? …
对于我的应用程序,我想限制我的颜色调色板,因此我创建了一个充满包含颜色实例的常量的类:
class Colors
{
static var red = Color(0xFFFF1212);
static var blue = Color(0xFF1212FF);
static var green = Color(0xFF12F1FA);
}
Run Code Online (Sandbox Code Playgroud)
但有时MaterialColor
需要a。所以我需要以某种方式将 Color 实例转换为MaterialColor
实例。但建造者需要提供一个样本(某种调色板)。我怎样才能做到这一点?