定制 mvenghaus/magento2-script-bootstrap 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mvenghaus/magento2-script-bootstrap

最新稳定版本:1.1.0

Composer 安装命令:

composer require mvenghaus/magento2-script-bootstrap

包简介

Bootstrap for your magento 2 scripts

README 文档

README

Run your (quick & dirty) scripts with the usual comfort

Sometimes, you might want to run small Magento scripts without creating an additional module for them. To achieve this, you need to bootstrap Magento yourself. This is where this module comes in handy, it manages the bootstrap process for you.

What are the benefits?

  • instant setup (1 simple file)
  • no module means no deployment (setup:upgrade, ...)

Installation

composer require mvenghaus/magento2-script-bootstrap

NOTE It's not a magento module so you don't have to run setup:upgrade.

Basic Example

Let's assume you have a folder "scripts" in your root directory.

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);

Just run it

php script/hello-world.php

Modfiy the enviroment

You can use the following PHP attributes on your run method to modify your environment.

#[SetAreaCode]

You can easily update your area code with this attribute.

#[SetArea(\Magento\Framework\App\Area::AREA_ADMINHTML)]

#[SetSecureArea]

Certain operations, such as deleting in Magento, need to be performed within a 'secure area.' This attribute activates that functionality.

#[SetSecureArea]

Example

...
    #[SetArea(\Magento\Framework\App\Area::AREA_ADMINHTML)]
    #[SetSecureArea]
    public function run(): void
    {
        echo $this->translitUrl->filter('Hello World');
    }

...

统计信息

  • 总下载量: 421
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固