mvenghaus/magento2-script-bootstrap

magento 2 脚本启动器

1.0.0 2024-04-12 11:42 UTC

This package is auto-updated.

Last update: 2024-09-12 14:08:39 UTC


README

使用常规舒适的方式运行您的(快速且简单的)脚本

有时,您可能希望运行小型的 Magento 脚本,而不必为它们创建额外的模块。为此,您需要自己启动 Magento。这个模块就在这里派上用场,它为您管理启动过程。

有哪些好处?

  • 即时设置(1个简单文件)
  • 没有模块意味着无需部署(设置:升级,...)

安装

composer require mvenghaus/magento2-script-bootstrap

注意 这不是一个 Magento 模块,因此您无需运行 setup:upgrade。

示例

假设您在根目录下有一个名为 "scripts" 的文件夹。

scripts/hello-world.php

<?php declare(strict_types=1);

use Mvenghaus\ScriptBootstrap\Bootstrap;
use Mvenghaus\ScriptBootstrap\Contracts\ScriptInterface;

use Magento\Framework\Filter\TranslitUrl;

// magento bootstrap
require __DIR__ . '/../app/bootstrap.php';

class Script implements ScriptInterface
{
    public function __construct(
        private readonly TranslitUrl $translitUrl,
    ) {
    }

    public function run(): void
    {
        echo $this->translitUrl->filter('Hello World');
    }
}

Bootstrap::run(Script::class);