Giter Site home page Giter Site logo

loveorigami / yii2-plugins-system Goto Github PK

View Code? Open in Web Editor NEW
115.0 20.0 23.0 850 KB

Yii2 plugins system module with event manager and https://github.com/loveorigami/yii2-shortcodes-pack

License: MIT License

PHP 100.00%
shortcodes shortcode yii2 plugins yii2-plugins

yii2-plugins-system's Introduction

Getting started with Yii2-plugins-system

Latest Stable Version Total Downloads License

Yii2-plugins-system is designed to work out of the box. It means that installation requires minimal steps. Only one configuration step should be taken and you are ready to have plugin system on your Yii2 website.

"Plugins"

1. Download

Yii2-plugins-system can be installed using composer. Run following command to download and install Yii2-plugins-system:

composer require "loveorigami/yii2-plugins-system": ">=3.*"

2. Update database schema

The last thing you need to do is updating your database schema by applying the migrations. Make sure that you have properly configured db application component, add in our console config namespace migration - more here

return [
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationNamespaces' => [
                 ...
                'lo\plugins\migrations'
            ],
        ],
    ],
];

and run the following command:

$ php yii migrate

3. Configure application

Let's start with defining module in @backend/config/main.php:

'modules' => [
    'plugins' => [
        'class' => 'lo\plugins\Module',
        'pluginsDir'=>[
            '@lo/plugins/core', // default dir with core plugins
            // '@common/plugins', // dir with our plugins
        ]
    ],
],

That's all, now you have module installed and configured in advanced template.

Next, open @frontend/config/main.php and add following:

...
'bootstrap' => ['log', 'plugins'],
...
'components' => [
    'plugins' => [
        'class' => lo\plugins\components\PluginsManager::class,
        'appId' => 1 // lo\plugins\BasePlugin::APP_FRONTEND,
        // by default
        'enablePlugins' => true,
        'shortcodesParse' => true,
        'shortcodesIgnoreBlocks' => [
            '<pre[^>]*>' => '<\/pre>',
            //'<div class="content[^>]*>' => '<\/div>',
        ]
    ],
    'view' => [
        'class' => lo\plugins\components\View::class,
    ]
    ...
]

Also do the same thing with

  • @backend/config/main.php
  • @console/config/main.php
  • @api/config/main.php
  • our modules
  • etc...
...
'bootstrap' => ['log', 'plugins'],
...
'components' => [
    'plugins' => [
        'class' => lo\plugins\components\PluginsManager::class,
        'appId' => 2 // lo\plugins\BasePlugin::APP_BACKEND or our appId
    ],
    'view' => [
        'class' => lo\plugins\components\View::class,
    ]
    ...
]

Base AppId lo\plugins\BasePlugin::

  • const APP_FRONTEND = 1;
  • const APP_BACKEND = 2;
  • const APP_COMMON = 3;
  • const APP_API = 4;
  • const APP_CONSOLE = 5;

Shortcodes

Core plugins (examples)

Your plugins

Contributing to this project

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.

License

Yii2-plugins-system is released under the MIT License. See the bundled LICENSE.md for details.

yii2-plugins-system's People

Contributors

loveorigami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-plugins-system's Issues

composer install fail

composer require "loveorigami/yii2-plugins-system": "*"

[InvalidArgumentException]
Could not find package * at any version for your minimum-stability (stable)

I got the error, any updates ? thanks

core seo handler

use Yii;
use yii\web\Application;

/**
 * Class Pagination
 */
class Pagination
{
    /**
     * @param \yii\base\ViewEvent $event
     */
    public static function updateTitle(\yii\base\ViewEvent $event)
    {
        if (Yii::$app instanceof Application === true && Yii::$app->request->get('page') !== null) {
            Yii::$app->view->title .= Yii::t(
                'app',
                ' - Page {page}',
                ['page' => (int) Yii::$app->request->get('page')]
            );
        }
    }
}

get classes with closure

public static function getAllClasses()
    {
        $result = [];
        foreach (self::getAllAliases() as $alias) {
            $path = \Yii::getAlias($alias);
            $files = is_dir($path) ? BaseFileHelper::findFiles($path) : [$path];
            foreach ($files as $filePath) {
                if (!preg_match('/.*\/[A-Z]\w+\.php/', $filePath)) {
                    continue;
                }
                $className = str_replace([$path, '.php', '/', '@'], [$alias, '', '\\', ''], $filePath);
                $result[] = $className;
            }
        }
        return $result;
    }

use here
https://github.com/loveorigami/yii2-plugins-system/blob/master/src/repositories/PluginDirRepository.php#L36

Could not find package

Like title, when I try to install extension by composer, return me this error below:

[InvalidArgumentException]  
  Could not find package >.   
                              
  Did you mean one of these?  
      psr/log                 
      twig/twig               
      symfony/yaml            
      nesbot/carbon           
      twbs/bootstrap      

Thanks

ClassName Validator

use Yii;
use yii\validators\Validator;
/**
 * ClassnameValidator checks if the attribute value is a valid class name that can be used by application
 *
 * Usage:
 *
 * ```
 * public function rules()
 * {
 *      return [
 *          [
 *              ['class_name_attribute'],
 *              DevGroup\AdminUtils\validators\ClassnameValidator::className(),
 *          ]
 *      ];
 * }
 *
 * ```
 *
 * @package DevGroup\AdminUtils\validator
 */
class ClassnameValidator extends Validator
{
    /**
     * @inheritdoc
     * @return null|array
     */
    public function validateValue($value)
    {
        if (class_exists($value) === false) {
            return [
                AdminModule::t('app', 'Unable to find specified class.'),
                []
            ];
        } else {
            return null;
        }
    }
}

App Basic

Здравствуйте. Такой вопрос, а если Yii стоит basic, а не advanced? Я например выставляю в config-е APP ID = 1 (FRONTEND). В Event-ах плагину Hello World выставляю Frontend. Сохраняю всё это дело...потом когда захожу редактировать данный Event, в конфигурации начинается замена и пропадает форма редактирования кода. Вообщем вопрос в том, как быть тем у кого App Basic стоит?

Чисто теоретически оно понятно, что нужно сделать разные конфиги для модуля frontend и backend (у меня админка отделена модулем), а практически оно не получается

yii2-plugins-system

Добрый день!
Подскажите пожалуйста, установленное расширение подключает новые или встроенные шорткоды и плагины нормально, все как в гайде)
image
но вместо того, чтобы обработать и отобразить во вьюшке результат, выводит только
image
или
image

Ошибка в миграциях

Добрый день. Не получается запустить миграции, пишет:
Migration failed. Directory specified in migrationPath doesn't exist: @vendor/loveorigami/yii2-plugins-system/migrations
если запустить как
php yii migrate/up --migrationPath=@vendor/loveorigami/yii2-plugins-system/src/migrations
то файлы миграций находит, но выполнить не может, т.к при создании класса миграции не видит (скорее всего из-за namespace)
Class 'm170105_094230_drop_tables' not found
Не могли бы удалить namespace из миграций или подсказать как решить проблему?

can't install yii2-plugins-system with error

Problem 1
- Installation request for loveorigami/yii2-plugins-system ^1.0 -> satisfiable by loveorigami/yii2-plugins-system[1.0].
- loveorigami/yii2-plugins-system 1.0 requires tpoxa/shortcodes dev-master -> no matching package found.

Call Instance parse?

how to call instance parsing shortcode like example bellow?
ex: \lo\plugins\core\ShortcodeHandler::parseShortcodes('[gallery id="2"]')

the problem when calling a shortcode inside which there is a shortcode
only displays shortcode strings

Info events

Make view events from reflection

    public static function getEventNames($className)
    {
        $result = [];
        $reflection = new \ReflectionClass($className);
        foreach ($reflection->getConstants() as $name => $value) {
            if (!preg_match('/^EVENT/', $name)) {
                continue;
            }
            $result[$name] = $value;
        }
        return $result;
    }

fix adding to pool

need add to pool with check in _shortcodes
needd for parsing from widget!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.