小编yiv*_*ivi的帖子

即使对于用户www-data可写,is_writable对于NFS共享也返回false

我有一个相对的文件夹'files / crm-upload',我想在其中上传文件。我的代码检查is_writable()是否为true,只有在这种情况下才继续进行。

该文件夹作为带有rw和sec = sys的NFS共享挂载。

我已经编写了一个测试脚本,我也在apache上执行了该脚本以查看访问权限,结果是:

files/crm-upload/php_touch modification time has been changed to present time 
My effective UID is 33 but my UID is really 33
files/crm-upload/ is owned by 33 and has permissions 40777
is_readable('files/crm-upload/') gives true
is_readable('files/crm-upload/php_touch') gives true
is_writable('files/crm-upload/') gives false
is_writable('files/crm-upload/php_touch') gives true
is_writable('files/crm-upload/25/') gives true
is_writable('files/images/') gives true
file_exists('files/crm-upload/') gives true
file_exists('files/crm-upload/php_touch') gives true
Some stat uids: 

files/crm-upload/: 33
files/crm-upload/php_touch: 33
files/images/: 33
Run Code Online (Sandbox Code Playgroud)

所以:

  • 触摸共享上的文件有效
  • uid是正确的
  • 目录具有正确的权限
  • 共享中的子文件夹和文件的is_writable返回true

怎么可能只有已挂载共享的根文件夹不可写,而其他所有东西都不能写?

这是Ubuntu 18.04。客户端,没有运行SELinux ...

php linux apache ubuntu nfs

5
推荐指数
1
解决办法
168
查看次数

通过可迭代的类名获取服务-注入标记的服务

我正在努力通过类别名称从注入的已标记服务组中获取特定服务。

这是一个示例:我标记实现DriverInterface为的所有服务app.driver并将其绑定到$drivers变量。

在其他一些服务中,我需要获取所有已标记app.driver并实例化的驱动程序,并且仅使用其中一些驱动程序。但是需要的驱动程序是动态的。

services.yml

_defaults:
        autowire: true
        autoconfigure: true
        public: false
        bind:
            $drivers: [!tagged app.driver]

_instanceof:
        DriverInterface:
            tags: ['app.driver']
Run Code Online (Sandbox Code Playgroud)

其他一些服务:

/**
 * @var iterable
 */
private $drivers;

/**
 * @param iterable $drivers
 */
public function __construct(iterable $drivers) 
{
    $this->drivers = $drivers;
}

public function getDriverByClassName(string $className): DriverInterface
{
    ????????
}
Run Code Online (Sandbox Code Playgroud)

因此,将实现的服务DriverInterface注入到$this->driversparam中作为可迭代的结果。我只能foreach通过它们,但是所有服务都将被实例化。

是否有其他方法可以将这些服务注入,以通过类名从它们获得特定服务而无需实例化其他服务?

我知道有可能将那些驱动程序公开并改为使用容器,但是我想避免以其他方式将容器注入服务中。

php autowired symfony symfony-dependency-injection

5
推荐指数
2
解决办法
285
查看次数

Git 从composer.json 保存部署令牌url,防止推送到存储库

我正在开发一个基于模块的 Laravel CMS。

这是私有的,这意味着我需要使用 git 部署令牌,因此我可以使用 Composer 来安装/管理这些模块。

例子:

"repositories"      : {
"repo-name": {
  "type": "vcs",
  "url": "https://gitlab+deploy-token-xxxxx:password@gitlab.com/url-to-repo.git"
},
Run Code Online (Sandbox Code Playgroud)

这通常工作得很好,这意味着当我创建一个新项目时,我可以安装我的模块。

但是 Windows / Git 将部署令牌保存为 Windows 中的 Git 凭据,覆盖了我的正常登录。

这意味着,当我开发模块并想要推送更改时,Gitlab 会拒绝它,因为 Git 尝试使用部署密钥而不是我的正常 Git 凭据来上传我的更改。

我的问题:是否有可能以某种方式阻止 Git 将此部署令牌保存为全局 Git 凭证,这样它就不会覆盖我常用的 Git 凭证?

git composer-php

5
推荐指数
1
解决办法
1425
查看次数

如何避免记录由 Api-Platform 正确转换为状态代码的预期异常?

在我们的 Api-Platform 项目的一些路线中,throw对于一些常见的错误情况,例外是n。

例如,在调用 时POST /ordersNewOrderHandler如果合适,可以抛出这两个中的任何一个:

  • NotEnoughStock
  • NotEnoughCredit

所有这些异常都属于一个DomainException层次结构。

这些异常通过使用配置正确转换400响应上的状态代码exception_to_status,并且响应包括适当的错误消息。到现在为止还挺好。

exception_to_status:
    App\Order\NotEnoughStock: !php/const Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST
    App\Order\NotEnoughCredit: !php/const Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST
Run Code Online (Sandbox Code Playgroud)

唯一的问题是异常仍被记录为CRITICAL错误,被视为“未捕获的异常”。即使在生产中,这也会被记录下来。

我原以为通过转换为正确的状态代码(例如!== 500),这些异常将被视为“已处理”,因此不会污染日志。

从处理程序抛出异常很方便,因为它有助于处理事务并自动生成适当的错误响应消息。它适用于网络和控制台。

这些交易不应该被视为已处理吗?是否有必要创建另一个异常侦听器来处理这个问题?如果创建异常侦听器,如何做才能不干扰 Api-Platform 错误规范化?

php error-handling symfony api-platform.com

5
推荐指数
1
解决办法
834
查看次数

Composer PSR-4 自动加载接口弃用通知

我无法理解这个简单的界面有什么问题。

<?php

namespace App\Interfaces;

use Illuminate\View\View;

interface renderData
{
        public function renderAsHtml(): View;
}
Run Code Online (Sandbox Code Playgroud)

当我composer dump-autoload收到以下通知时

弃用通知:位于 ./app/Interfaces/RenderData.php 的类 App\Interfaces\renderData 不符合 psr-4 自动加载标准。它不会再在 Composer v2.0 中自动加载。

composer.json 自动加载部分:

    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
     },
Run Code Online (Sandbox Code Playgroud)

文件夹结构为:

<root_project>
 app
 Console
 ...
Run Code Online (Sandbox Code Playgroud)

我已经尝试将 app 重命名为 App 然后转储自动加载,但问题仍然存在。

php phar laravel composer-php

5
推荐指数
2
解决办法
6756
查看次数

当我使用 ImageTk 时,我的图像不透明

我正在尝试将图像放入带有ImageTk和的窗口中PhotoImage。下面是代码:

import tkinter as tk
import random as r
from PIL import ImageTk, Image


window = tk.Tk()

HEIGHT = window.winfo_screenwidth()
WIDTH = window.winfo_screenheight()
RESOL = str(str(HEIGHT) + "x" + str(WIDTH+7) + "+" + str(-7) + "+" + str(0))
window.geometry(RESOL)

x = int(HEIGHT)/2
y = int(WIDTH)/2
updatex = HEIGHT + (0.6 * HEIGHT)

main = tk.Frame(window, height = WIDTH, width = HEIGHT)
main.configure(bg = "white", highlightthickness = 0)
main.place(x = x, y = y, anchor = "center") …
Run Code Online (Sandbox Code Playgroud)

python tkinter python-3.x photoimage

5
推荐指数
1
解决办法
101
查看次数

位于 ./foo/bar/utility/baz.php 的 Foo\Bar\Baz 类不符合 psr-4 自动加载标准。跳绳

在运行时作曲家updateinstallrequiredump-autoload,等; 我突然开始收到一条黄色的弃用通知,上面写着:

位于 ./foo/bar/utility/baz.php 的 Foo\Bar\Baz 类不符合 psr-4 自动加载标准。跳过。

在 Composer 2.0 之前,曾经得到:

弃用通知:位于 ./foo/bar/Baz.php 的 Foo\Bar\Baz 类不符合 psr-4 自动加载标准。它不会再在 Composer v2.0 中自动加载。在 phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

为什么我会收到此通知或警告?我需要什么才能摆脱它并为 Composer 2.0 做好准备?

php autoload composer-php

5
推荐指数
1
解决办法
3693
查看次数

无法安装 symfony/maker-bundle

我是 Symfony 的新手,我尝试安装symfony/maker-bundle,但它给了我以下错误:

Using version ^1.22 for symfony/maker-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.4.*"
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - ocramius/proxy-manager 2.9.0 requires composer-runtime-api ^2.0.0 -> no matching package found.
    - ocramius/proxy-manager 2.9.0 requires composer-runtime-api ^2.0.0 -> no matching package found.
    - ocramius/proxy-manager 2.9.0 requires composer-runtime-api ^2.0.0 -> no matching package found.
    - Installation …
Run Code Online (Sandbox Code Playgroud)

php symfony composer-php

5
推荐指数
1
解决办法
2051
查看次数

Sylius 安装崩溃,因为“未定义标识符”

我正在尝试在 ubuntu 上安装 Sylius 1.8,并且在运行时按照安装指南进行操作,但出现composer install以下错误:

Run composer recipes at any time to see the status of your Symfony recipes.

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!  
!!   // Clearing the cache for the prod environment with debug                      
!!   // false                                                                       
!!  
!!  
!!  In FileLoader.php line 180:
!!                                                                                 
!!    No identifier defined "Sylius\Bundle\ApiBundle\Command\RegisterShopUser". Y  
!!    ou should add #[\ApiPlatform\Core\Annotation\ApiProperty(identifier: true)]  
!!    " on the property identifying the resource." in . (which …
Run Code Online (Sandbox Code Playgroud)

php symfony sylius api-platform.com

5
推荐指数
1
解决办法
612
查看次数

如何在发送前获取模板电子邮件的渲染正文?

我想在发送之前获得电子邮件的渲染。

我创建了一个TemplatedEmailwithhtmlTemplatecontext,它可以很好地发送,但是如何使用上下文获取生成的模板以将其保存在数据库中?(客户的需求)

我尝试过,getBody()但似乎只适用于文本模板,因为我得到A message must have a text or an HTML part or attachments.

$email = new TemplatedEmail();
$email->htmlTemplate($htmlTemplate);
$email->from($from)->to(...$to)->subject($subject);
$email->context($context);

dd($email->getBody());
Run Code Online (Sandbox Code Playgroud)

我想使用渲染方法,但我在服务中,不确定这是否是存储在数据库中的好方法。

php symfony symfony-mailer

5
推荐指数
1
解决办法
3139
查看次数