Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dragomano/Plugin-Loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5
Choose a base ref
...
head repository: dragomano/Plugin-Loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 5 commits
  • 9 files changed
  • 1 contributor

Commits on May 27, 2024

  1. Implement Hook attribute

    dragomano committed May 27, 2024
    Copy the full SHA
    ac54a96 View commit details
  2. Update version

    dragomano committed May 27, 2024
    Copy the full SHA
    fc273b6 View commit details

Commits on Nov 14, 2024

  1. Update LICENSE

    dragomano committed Nov 14, 2024
    Copy the full SHA
    a7c4ce3 View commit details
  2. Update README files

    dragomano committed Nov 14, 2024
    Copy the full SHA
    c0ef3d1 View commit details
  3. Refactor code

    dragomano committed Nov 14, 2024
    Copy the full SHA
    9d2ab9f View commit details
Showing with 249 additions and 199 deletions.
  1. +1 −1 LICENSE
  2. +7 −18 README.md
  3. +9 −19 README.ru.md
  4. +28 −0 Sources/PluginLoader/HasInvoke.php
  5. +22 −0 Sources/PluginLoader/Hook.php
  6. +119 −111 Sources/PluginLoader/Integration.php
  7. +31 −32 Sources/PluginLoader/Plugin.php
  8. +31 −17 Sources/PluginLoader/app.php
  9. +1 −1 package-info.xml
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2023, Bugo
Copyright (c) 2023-2024, Bugo

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
25 changes: 7 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
[![SMF 2.1](https://img.shields.io/badge/SMF-2.1-ed6033.svg?style=flat)](https://github.com/SimpleMachines/SMF2.1)
![License](https://img.shields.io/github/license/dragomano/plugin-loader)
![Hooks only: Yes](https://img.shields.io/badge/Hooks%20only-YES-blue)
![PHP](https://img.shields.io/badge/PHP-^7.0-blue.svg?style=flat)
![PHP](https://img.shields.io/badge/PHP-^8.0-blue.svg?style=flat)
[![Crowdin](https://badges.crowdin.net/plugin-loader/localized.svg)](https://crowdin.com/project/plugin-loader)

[Описание на русском](README.ru.md)
@@ -12,7 +12,7 @@ This concept mod is inspired by the Wedge plugin system. It adds plugin support

Plugins are standalone modifications that do not need to be installed or removed through the Package Manager. They don't make changes to SMF files and run entirely on hooks.

The key source file of the plugin is **plugin.php** with the anonymous class and the **hooks** method, which is executed through the _integrate_pre_load_ hook. Also in the directory of each plugin should be a file **plugin-info.xml**, which contains the key data of the plugin:
The entry point of each plugin is **plugin.php** with an anonymous class inside. Also in the directory of each plugin should be a file **plugin-info.xml**, which contains the key data of the plugin:

* name
* description
@@ -88,15 +88,11 @@ Plugins that require creation of tables in the database for their work must cont
<?php

/**
* plugin.php
*
* @package Example
* @link https://plugin-site.com
* @author Author https://author-site.com
* @copyright 2023 Author
* @copyright 2024 Author
* @license https://opensource.org/licenses/MIT The MIT License
*
* @version 0.1
*/

use Bugo\PluginLoader\Plugin;
@@ -106,17 +102,9 @@ if (!defined('SMF'))

return class extends Plugin
{
public function getName(): string
{
return 'example';
}

public function hooks(): void
{
add_integration_function('integrate_load_theme', __CLASS__ . '::loadTheme#', false, __FILE__);
add_integration_function('integrate_menu_buttons', __CLASS__ . '::menuButtons#', false, __FILE__);
}
public const NAME = 'example';

#[Hook('integrate_load_theme', self::class . '::loadTheme#', __FILE__)]
public function loadTheme(): void
{
// Your code
@@ -141,6 +129,7 @@ return class extends Plugin
// var_dump($this->getSettings());
}

#[Hook('integrate_menu_buttons', self::class . '::menuButtons#', __FILE__)]
public function menuButtons($buttons): void
{
// var_dump($buttons);
@@ -149,7 +138,7 @@ return class extends Plugin

```

As you can see, all the hooks required by the plugin are listed in the `hooks` method, which is executed if the plugin is enabled.
As you can see, all hooks required by the plugin are defined using the `Hook` attribute.

## Example plugin language file

28 changes: 9 additions & 19 deletions README.ru.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
[![SMF 2.1](https://img.shields.io/badge/SMF-2.1-ed6033.svg?style=flat)](https://github.com/SimpleMachines/SMF2.1)
![License](https://img.shields.io/github/license/dragomano/plugin-loader)
![Hooks only: Yes](https://img.shields.io/badge/Hooks%20only-YES-blue)
![PHP](https://img.shields.io/badge/PHP-^7.0-blue.svg?style=flat)
![PHP](https://img.shields.io/badge/PHP-^8.0-blue.svg?style=flat)
[![Crowdin](https://badges.crowdin.net/plugin-loader/localized.svg)](https://crowdin.com/project/plugin-loader)

[Description in English](README.md)
@@ -12,7 +12,7 @@

Плагины — это автономные модификации, которым не требуется установка или удаление через Менеджер пакетов. Они не вносят изменения в файлы SMF и работают полностью на хуках.

Ключевым source-файлом у плагина является **plugin.php** с анонимным классом внутри и методом **hooks**, выполняемым через хук _integrate_pre_load_. Также в директории каждого плагина должен находиться файл **plugin-info.xml**, содержащий ключевые данные плагина:
Точкой входа каждого плагина является **plugin.php** с анонимным классом внутри. Также в директории каждого плагина должен находиться файл **plugin-info.xml**, содержащий ключевые данные плагина:

* название
* описание
@@ -88,35 +88,24 @@ example_plugin/
<?php

/**
* plugin.php
*
* @package Example
* @link https://plugin-site.com
* @author Author https://author-site.com
* @copyright 2023 Author
* @copyright 2024 Author
* @license https://opensource.org/licenses/MIT The MIT License
*
* @version 0.1
*/

use Bugo\PluginLoader\Hook;
use Bugo\PluginLoader\Plugin;

if (!defined('SMF'))
if (! defined('SMF'))
die('No direct access...');

return class extends Plugin
{
public function getName(): string
{
return 'example';
}

public function hooks(): void
{
add_integration_function('integrate_load_theme', __CLASS__ . '::loadTheme#', false, __FILE__);
add_integration_function('integrate_menu_buttons', __CLASS__ . '::menuButtons#', false, __FILE__);
}
public const NAME = 'example';

#[Hook('integrate_load_theme', self::class . '::loadTheme#', __FILE__)]
public function loadTheme(): void
{
// Ваш код
@@ -141,6 +130,7 @@ return class extends Plugin
// var_dump($this->getSettings());
}

#[Hook('integrate_menu_buttons', self::class . '::menuButtons#', __FILE__)]
public function menuButtons($buttons): void
{
// var_dump($buttons);
@@ -149,7 +139,7 @@ return class extends Plugin

```

Как видите, все требуемые плагином хуки перечисляются в методе `hooks`, который выполняется только при включении плагина.
Как видите, все требуемые плагином хуки определяются с помощью атрибута `Hook`.

## Пример языкового файла плагина

28 changes: 28 additions & 0 deletions Sources/PluginLoader/HasInvoke.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @package Plugin Loader
* @link https://github.com/dragomano/Plugin-Loader
* @author Bugo <bugo@dragomano.ru>
* @copyright 2023-2024 Bugo
* @license https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License
*/

namespace Bugo\PluginLoader;

use ReflectionClass;

trait HasInvoke
{
public function __invoke(): void
{
$reflectionClass = new ReflectionClass(static::class);
foreach ($reflectionClass->getMethods() as $method) {
$attributes = $method->getAttributes(Hook::class);

foreach ($attributes as $attribute) {
$attribute->newInstance();
}
}
}
}
22 changes: 22 additions & 0 deletions Sources/PluginLoader/Hook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php /** @noinspection PhpMultipleClassDeclarationsInspection */

/**
* @package Plugin Loader
* @link https://github.com/dragomano/Plugin-Loader
* @author Bugo <bugo@dragomano.ru>
* @copyright 2023-2024 Bugo
* @license https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License
*/

namespace Bugo\PluginLoader;

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
final class Hook
{
public function __construct(string $name, string $method, string $file)
{
add_integration_function($name, $method, false, $file);
}
}
Loading