LoginSignup
0
0

More than 1 year has passed since last update.

EC-CUBE3でassets ファイルのコピー

Posted at

Filesystemのuse記載

use Symfony\Component\Filesystem\Filesystem;

コピー元とコピー先の指定

PluginManager.php
private $srcAssets = __DIR__ . '/Resource/assets';
private $dstAssets = '/my_plugin)'; // /{プラグインコード(全て小文字}

コピー関数

PluginManager.php
private function copyAssets(Application $app)
{
    $file = new Filesystem();
    $file->mirror($this->srcAssets, $app['config']['plugin_html_realdir'].$this->dstAssets.'/assets');
}

削除関数

PluginManager.php
private function removeAssets(Application $app) 
{
    $file = new Filesystem();
    $file->remove($app['config']['plugin_html_realdir'].$this->dstAssets);
}

PluginManger.php全体

PluginManager.php
<?php

namespace Plugin\MyPlugin;

use Eccube\Application;
use Eccube\Plugin\AbstractPluginManager;
use Symfony\Component\Filesystem\Filesystem;

class PluginManager extends AbstractPluginManager
{

    private $srcAssets = __DIR__ . '/Resource/assets';
    private $dstAssets = '/my_plugin)';// /{プラグインコード(全て小文字}

    /**
     * プラグインインストール時の処理
     *
     * @param $config
     * @param Application $app
     * @throws \Exception
     */
    public function install($config, Application $app)
    {
        $this->copyAssets($app);
        $this->migrationSchema($app, __DIR__.'/Resource/doctrine/migration', $config['code']);

    }

    /**
     * プラグイン削除時の処理
     *
     * @param $config
     * @param Application $app
     */
    public function uninstall($config, Application $app)
    {
        $this->removeAssets($app);
        $this->migrationSchema($app, __DIR__.'/Resource/doctrine/migration', $config['code'], 0);
    }

    /**
     * プラグイン有効時の処理
     *
     * @param $config
     * @param Application $app
     * @throws \Exception
     */
    public function enable($config, Application $app)
    {
    }

    /**
     * プラグイン無効時の処理
     *
     * @param $config
     * @param Application $app
     * @throws \Exception
     */
    public function disable($config, Application $app)
    {
    }

    /**
     * プラグイン更新時の処理
     *
     * @param $config
     * @param Application $app
     * @throws \Exception
     */
    public function update($config, Application $app)
    {
    }

    /**
     * リソースファイルなどをコピー
     *
     * @param Application $app
     */
    private function copyAssets(Application $app)
    {
        $file = new Filesystem();
        $file->mirror($this->srcAssets, $app['config']['plugin_html_realdir'].$this->dstAssets.'/assets');
    }

    /**
     * コピーしたリソースファイルなどを削除
     *
     * @param Application $app
     */
    private function removeAssets(Application $app)
    {
        $file = new Filesystem();
        $file->remove($app['config']['plugin_html_realdir'].$this->dstAssets);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0