小编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
查看次数

如何注入一组实现相同接口的服务,而不声明每个服务的连接?

我正在开发一个应用程序,其中有一些处理程序作为我希望能够调用的服务。他们都实现了一个ItemHandlerInterface.

我希望能够在控制器中检索所有ItemHandlerInterface服务集合,而无需手动连接它们。

到目前为止,我具体标记了它们:

服务.yaml

_instanceof:
    App\Model\ItemHandlerInterface:
        tags: [!php/const App\DependencyInjection\ItemHandlersCompilerPass::ITEM_HANDLER_TAG]
        lazy: true
Run Code Online (Sandbox Code Playgroud)

并尝试在控制器中检索我的服务集合。如果只有一个服务实现,它就可以工作ItemHandlerInterface,但是一旦我创建了多个服务(如下面的TestHandler和 )Test2Handler,我最终会得到一个The service "service_locator.03wqafw.App\Controller\ItemUpdateController" has a dependency on a non-existent service "App\Model\ItemHandlerInterface".

如何动态检索实现我的接口的所有服务?

一种肮脏的解决方案是强制所有ItemHandlerInterface内容public: true并传递Container给我的控制器构造函数。但这很丑陋,我想找到一种更优雅的方式。

项目更新控制器

namespace App\Controller;

use App\Model\ItemHandlerInterface;
use App\Service\ItemFinder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Debug\Exception\ClassNotFoundException;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use App\Model\Item;
use Psr\Container\ContainerInterface;

/**
 * Class ItemUpdateController
 *
 * @package App\Controller
 */
class ItemUpdateController extends AbstractController
{
    /**
     * …
Run Code Online (Sandbox Code Playgroud)

php dependency-injection symfony

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

为什么 Windows 上的 PHP 7.4 会中止所有需要用户输入的命令行操作?

我有一个在 Symfony 5.0 上在 3 台不同的 Windows 10 PC 上进行开发的本地设置,当 PHP 版本为 7.3 时,它们都没有问题,当 PHP 版本为 7.4 时,它们都有相同的问题。

它发生在任何需要用户输入的执行中,例如: * php bin/console make:entity * php bin/console doctrine:migrations:migrate

其他php bin/console make:migration不需要用户输入的命令可以正常工作,因此等待输入似乎是问题所在。

以非交互模式运行它们适用于是/否,但对很多人来说是不可能的,比如 make:entity

这是终端的输出:

PS C:\path\project> php bin/console make:entity

 Class name of the entity to create or update (e.g. VictoriousPuppy):
 >

  Aborted.  


make:entity [-a|--api-resource] [--regenerate] [--overwrite] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<name>]

PS C:\path\project>
Run Code Online (Sandbox Code Playgroud)

中止立即发生,无需等待输入。我安装了 7.3 和 7.4 两个版本,切换到 7.3 使其工作正常,所以我查看了这两个 …

php symfony php-7.4

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

当我使用 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
查看次数

如何在 Api 平台上使用带有 Messenger 输入的路径中的 {id}?

我有这样的事情:

/**
 * @ORM/Entity
 * @ApiResource(
 *     itemOperations={
 *         "put_cancel": {
 *             "method": "PUT",
 *             "path": "/task/{id}/cancel",
 *             "messenger": "input",
 *             "input": CancelTaskCommand::class,
 *             "output": false
 *         },
 *     }
 * )
 */
class Foo {}
Run Code Online (Sandbox Code Playgroud)

取消FooCommand.php

final class CancelFooCommand
{
    /**
     * @var string
     * @ApiProperty(
     *     identifier=true,
     * )
     */
    public string $id = '';

    /**
     * @var string
     * @ApiProperty(
     *     attributes={
     *         "openapi_context"={
     *           "type": "string"
     *         }
     *     }
     * )
     */
    public string $note …
Run Code Online (Sandbox Code Playgroud)

php symfony api-platform.com

5
推荐指数
0
解决办法
265
查看次数

如何使用命令在独立应用程序中使用 symfony 的 DependencyInjection?

我一直在使用 symfony/console 来创建命令并像这样注册它们,一切正常:

垃圾箱/控制台:

#!/usr/bin/env php
<?php
require_once __DIR__ . '/../vendor/autoload.php';

use App\Commands\LocalitiesCommand;
use Symfony\Component\Console\Application;

$app = new Application();
$app->add(new LocalitiesCommand(new LocalitiesGenerator()));
$app->run();
Run Code Online (Sandbox Code Playgroud)

src/Commands/LocalitiesCommand.php:

<?php

declare(strict_types=1);

namespace App\Commands;

use App\LocalitiesGenerator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


final class LocalitiesCommand extends Command
{
    protected static $defaultName = 'app:generate-localities';

    public function __construct(private LocalitiesGenerator $localitiesGenerator)
    {
        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->setDescription('Generate localities.json file')
            ->setHelp('No arguments needed.');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->localitiesGenerator->generateJsonLocalities();
        $output->writeln("File localities.json generated!"); …
Run Code Online (Sandbox Code Playgroud)

php dependency-injection symfony symfony-console

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

Symfony 学说错误“DoctrineMigrationsBundle 需要启用 DoctrineBundle。”

我创建了一个新的 Symfony 项目,并且不断收到此消息“DoctrineMigrationsBundle 需要启用 DoctrineBundle”。错误并且无法摆脱它。显然我是这个星球上唯一一个收到此错误的人,因为谷歌并没有太大帮助。

在 config/bundles.php 文件中,我有以下内容应该“启用”DoctrineBundle,但我缺少一些东西并且无法告诉它是什么。

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
];
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony doctrine-orm

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