我正在尝试使用SDK的版本3将图像上传到S3存储桶,但是我收到以下错误:
在" https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg " 上执行"PutObject"时出错; AWS HTTP错误:cURL错误6:无法解析主机's3.Ireland.amazonaws.com'(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)
这是我第一次尝试这样做,所以我不太自信.
通过AWS界面上传文件,其URL就像https://s3-eu-west-1.amazonaws.com/my-bucket-name/testFileThroughWeb.jpg.因此,它似乎与AWS SDK创建的PUT文件不同(即https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg)
我想指出的另一件事是我传递给S3Client构造函数的版本.它创建的实例在我使用的存储桶策略中传递stable密钥的值.versionversion: "2012-10-17"
这是存储桶策略的配置:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::my-bucket-name/*"
}
]
}
Run Code Online (Sandbox Code Playgroud)
要将图像保存在存储桶中,我使用以下代码:
public function testS3Action()
{
$fileToUpload = 'http://example.com/an/image.jpg';
// Get the remote file extension
$remoteImageExtension = explode('.', $fileToUpload);
$remoteImageExtension = array_pop($remoteImageExtension);
$fs = new Symfony\Component\Filesystem\Filesystem();
$tempImage = tempnam(sys_get_temp_dir(), 'image.') . '.' . $remoteImageExtension;
/**
* …Run Code Online (Sandbox Code Playgroud) 我刚刚安装了Encore来测试它并开始在我的项目中使用它(非常棒的工作!!!真的,谢谢!).
我马上就遇到了问题.
尝试运行时,./node_modules/.bin/encore dev我收到异常:
无法确定webpack上下文.(您是从项目外的目录执行webpack吗?).尝试传递--context选项.
我只是按照官方文档中关于第一个示例的说明进行操作,结果是此异常.
我的项目结构如下:
my-app-root-folder
- app
- bin
- nome_modules
- src
- tests
- var
- vendor
- web
...
composer.json
composer.lock
webpack.config.js
Run Code Online (Sandbox Code Playgroud)
所以,基本上,我有一个Symfony 3.3项目的经典结构,加上一些与之相关的文件夹JS.
任何人都可以帮我解决这个问题吗?
这是我第一次采用更复杂的解决方案来管理css和javascript资产.
Unitl现在我已经把所有这些文件放进去了src/AppBundle/Resources/public/所以我对这个新流程并不十分熟悉.
谢谢!
我正在使用 SentryBundle 将 Sentry 集成到我的 Symfony 应用程序中。
我不想记录“NotFoundExceptions”,所以我这样配置了捆绑包:
sentry:
dsn: '%env(SENTRY_DSN)%'
register_error_listener: false # Disables the ErrorListener
monolog:
error_handler:
enabled: true
level: error
messenger:
enabled: true # flushes Sentry messages at the end of each message handling
capture_soft_fails: true # captures exceptions marked for retry too
options:
environment: '%kernel.environment%'
# release: '%env(VERSION)%' #your app version
excluded_exceptions:
- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎还不够,因为异常继续记录在 Sentry 中。
我究竟做错了什么?
我将本地开发设置从 Linux 移植到新的 Mac 机器,但在让 Xdebug 在 Mac M1 Pro 机器中与 PhpStorm 配合使用时遇到问题。
我有一个包含 PHP 的容器,其中 Xdebug 安装并配置如下:
zend_extension=/usr/lib/php8/modules/xdebug.so
xdebug.mode=debug
xdebug.idekey=PHPSTORM
xdebug.client_port=9001
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.log=/var/log/xdebug.log
Run Code Online (Sandbox Code Playgroud)
在 PhpStorm 中,我正在监听端口 9001(我将 9000 用于其他服务)。
以下是 docker 容器内的 Xdebug 日志:/var/log/xdebug.log
/var/www/html/app # tail -f /var/log/xdebug.log
[49] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[49] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[49] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.18.0.4:9001.
[49] [Step Debug] WARN: Creating socket for '172.18.0.4:9001', poll success, but …Run Code Online (Sandbox Code Playgroud) 例如:
$contents = file_get_contents(image.png);
Run Code Online (Sandbox Code Playgroud)
是否可以从$ contents创建SplFileObject对象?
谢谢!
我必须检查变量是DateTime对象还是简单的字符串才能在模板中使用它。
如果变量是DateTime,我必须将其格式化为日期;如果是字符串,只需打印即可。
{% if post.date is DateTime %}
{% set postDate = post.date|date %}
{% else %}
{% set postDate = post.date %}
{% endif %}
<p>Il {{ postDate }}
Run Code Online (Sandbox Code Playgroud)
我认为我应该使用Twig测试(也可以在关于StackOverflow的答案中建议)进行此操作arrays,但是我不太了解我应该将代码以及如何在应用程序中注册代码放在Symfony App的哪个文件夹中。
一旦编写了测试,如何在Symfony的Twig模板中使用它?
我正在尝试通过 PhpStorm (v2022.3.2) 使用 Xdebug (v3) 从 Docker 容器内部调试 PHPUnit 测试方法。
Xdebug 已正确设置,PhpStorm 中的服务器也是如此。
事实上,如果我从命令行运行测试,Xdebug 将在断点处停止:
XDEBUG_SESSION=1 PHP_IDE_CONFIG="serverName=myapp.localhost" vendor/bin/phpunit --testdox --filter testProfileUpdate
Run Code Online (Sandbox Code Playgroud)
如果我单击测试方法左侧的“bug”图标来调试测试,则会收到以下错误:
未建立连接。可能“xdebug.remote_host=host.docker.internal”不正确。更改“xdebug.remote_host”。
查看PhpStorm 执行的调试测试方法的命令,我看到的是:
[docker://myapp:latest/]:php -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=host.docker.internal /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/phpunit.xml --filter "/(ProfileTest::testProfileUpdate)( .*)?$/" --test-suffix ProfileTest.php /opt/project/tests --teamcity
Run Code Online (Sandbox Code Playgroud)
我还尝试配置另外两个标志:
-dxdebug.idekey="serverName=myapp.localhost"-dxdebug.session=1结果命令是这样的:
[docker://myapp:latest/]:php -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=host.docker.internal -dxdebug.idekey="serverName=myapp.localhost" -dxdebug.session=1 /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/phpunit.xml --filter "/(ProfileTest::testProfileUpdate)( .*)?$/" --test-suffix ProfileTest.php /opt/project/tests --teamcity
Run Code Online (Sandbox Code Playgroud)
同样使用此配置,Xdebug 不会启动并且断点将被忽略(并且会弹出错误消息)。
我尝试禁用 PhpStorm 自动传递的参数,转到“设置”>“PHP”>“调试”。
然后,在“高级设置”部分中,我取消标记了“通过命令行传递所需的配置选项”选项。
现在,生成的命令是这样的:
[docker://myapp:latest/]:php /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/phpunit.xml --filter …Run Code Online (Sandbox Code Playgroud) 我试图在检测到特定信用卡架构时简单地更改图像.
所以,我的代码从这开始:
<div class="form-group cc-number-group">
<label for="cc-number" class="control-label">Card number <small class="text-muted">[<span class="cc-brand"></span>]</small></label>
<div class="input-group">
<input style="border-right: 0;" id="cc-number" type="tel" size="20" data-stripe="number" class="form-control cc-number card-generic form-control input-sm" autocomplete="cc-number" />
<div class="input-group-addon">
<img height="16px" class="credit-card-icon" src="/bundles/bundlename/images/credit.png" />
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
经过大量的尝试和失败,我写了这段代码:
switchCreditCardIcon = function(vendor) {
var path = $('.credit-card-icon').attr('src').split('/');
path.pop(-1);
path.push(vendor + '.png');
newPath = document.domain + path.join('/');
$('.credit-card-icon').attr('src', path);
};
Run Code Online (Sandbox Code Playgroud)
因此,例如,如果我输入Visa信用卡,则新的vendor是"签证".
现在,如果我执行console.log(newPath)控制台日志,127.0.0.1/bundles/bundlename/images/visa.png但src属性设置为,bundles,bundlename,images,visa.png如此,我收到一个错误:
http://127.0.0.1:8000/path/to/page/,bundles,bundlename,images,visa.png 404(未找到)
但是,除了错误之外,也许有一种更简单的方法可以做到这一点......任何人都可以给我一些建议吗?
我必须将一个动作的模板呈现为一个简单的.txt文件。
我怎样才能做到这一点?除了使用Response对象还有其他方法吗?
使用Response对象:
$content = $this->get('templating')->render(
'AppBundle:Company:accountBillingInvoice.txt.twig',
[
'invoice' => 'This is the invoice'
]
);
$response = new Response($content , 200);
$response->headers->set('Content-Type', 'text/plain');
Run Code Online (Sandbox Code Playgroud)