문제

I want to create a file locker in Magento 2. If i use the default \Magento\Framework\Lock\LockManagerInterface

Magento uses the database to save locks by default. https://devdocs.magento.com/guides/v2.3/install-gde/install/cli/install-cli-subcommands-lock.html

How I can use a fileLock with a custom folder in the var folder?

도움이 되었습니까?

해결책

di.xml

<type name="Magento\Framework\Lock\Backend\FileLock">
    <arguments>
        <argument name="path" xsi:type="string">var/lock</argument>
    </arguments>
</type>
<type name="Vendor\ModuleName\Test">
    <arguments>
        <argument name="fileLock" xsi:type="object">Magento\Framework\Lock\Backend\FileLock</argument>
    </arguments>
</type>

Test.php

namespace Vendor\ModuleName;

class Test
{
    /**
     * @var \Magento\Framework\Lock\LockManagerInterface
     */
    private $fileLock;

    /**
     * @var \Magento\Framework\Lock\LockManagerInterface $fileLock
     */
    public function __construct(
        \Magento\Framework\Lock\LockManagerInterface $fileLock,
    ) {
       $this->fileLock = $fileLock;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top