-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
5,754 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
* text eol=lf | ||
*.png binary | ||
|
||
/.github export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/*.md export-ignore | ||
/composer.json export-ignore | ||
/composer.lock export-ignore | ||
/rector.php export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea/ | ||
.phpunit.result.cache | ||
.vscode/ | ||
coverage.xml | ||
coverage/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
# SMF Compat | ||
|
||
![SMF 2.1](https://img.shields.io/badge/SMF-2.1-ed6033.svg?style=flat) | ||
![PHP](https://img.shields.io/badge/PHP-^8.0-blue.svg?style=flat) | ||
|
||
## Description | ||
|
||
The package is designed to prepare current SMF 2.1 modifications for the future migration to 3.0. | ||
|
||
The proposed utility classes eliminate the need to declare global variables in your modification code. | ||
|
||
As a result, your modifications will be able to work in both SMF branches, with minimal changes. | ||
|
||
## Installation | ||
|
||
In the root directory of your modification, run the command: | ||
|
||
```bash | ||
composer require bugo/smf-compat | ||
``` | ||
|
||
Then in `app.php` (or other similar _entry point_), inlcude `autoload.php`: | ||
|
||
```php | ||
require_once __DIR__ . '/vendor/autoload.php'; | ||
``` | ||
|
||
## Usage | ||
|
||
### Old code | ||
|
||
```php | ||
<?php | ||
|
||
class Example | ||
{ | ||
public function method1() | ||
{ | ||
global $txt; | ||
|
||
echo $txt['hello_world']; | ||
} | ||
|
||
public function method2() | ||
{ | ||
global $user_info, $modSettings; | ||
|
||
echo $user_info['name']; | ||
|
||
var_dump($modSettings); | ||
} | ||
} | ||
``` | ||
|
||
### New code | ||
|
||
```php | ||
<?php | ||
|
||
use Bugo\Compat\Lang; | ||
use Bugo\Compat\User; | ||
use Bugo\Compat\Config; | ||
|
||
class Example | ||
{ | ||
public function method1() | ||
{ | ||
echo Lang::$txt['hello_world']; | ||
} | ||
|
||
public function method2() | ||
{ | ||
echo User::$info['name']; | ||
|
||
var_dump(Config::$modSettings); | ||
} | ||
} | ||
``` | ||
|
||
After upgrading to SMF 3.0, it will be enough to replace the used classes: | ||
|
||
```diff | ||
-use Bugo\Compat\Lang; | ||
+use SMF\Lang; | ||
-use Bugo\Compat\User; | ||
+use SMF\User; | ||
-use Bugo\Compat\Config; | ||
+use SMF\Config; | ||
``` | ||
|
||
Or use class aliases in `app.php` (or other similar _entry point_) of your application: | ||
|
||
```php | ||
<?php | ||
|
||
if (str_starts_with(SMF_VERSION, '3.0')) { | ||
class_alias('SMF\\Lang', 'Bugo\\Compat\\Lang'); | ||
class_alias('SMF\\User', 'Bugo\\Compat\\User'); | ||
class_alias('SMF\\Config', 'Bugo\\Compat\\Config'); | ||
} | ||
``` | ||
|
||
In this case, your modification will be able to support both versions of SMF. | ||
|
||
--- | ||
|
||
## Описание | ||
|
||
Пакет предназначен для подготовки текущих модификаций SMF 2.1 к будущей миграции на 3.0. | ||
|
||
Предлагаемые утилитарные классы позволяют избавиться от необходимости объявлять глобальные переменные в коде ваших модификаций. | ||
|
||
В результате ваши модификации смогут работать в обеих линейках SMF, с минимальными изменениями. | ||
|
||
## Установка | ||
|
||
В корневой директории вашей модификации выполните команду: | ||
|
||
```bash | ||
composer require bugo/smf-compat | ||
``` | ||
|
||
Затем в `app.php` (или в другой аналогичной _точке входа_) подключите `autoload.php`: | ||
|
||
```php | ||
require_once __DIR__ . '/vendor/autoload.php'; | ||
``` | ||
|
||
## Использование | ||
|
||
### Старый код | ||
|
||
```php | ||
<?php | ||
|
||
class Example | ||
{ | ||
public function method1() | ||
{ | ||
global $txt; | ||
|
||
echo $txt['hello_world']; | ||
} | ||
|
||
public function method2() | ||
{ | ||
global $user_info, $modSettings; | ||
|
||
echo $user_info['name']; | ||
|
||
var_dump($modSettings); | ||
} | ||
} | ||
``` | ||
|
||
### Новый код | ||
|
||
```php | ||
<?php | ||
|
||
use Bugo\Compat\Lang; | ||
use Bugo\Compat\User; | ||
use Bugo\Compat\Config; | ||
|
||
class Example | ||
{ | ||
public function method1() | ||
{ | ||
echo Lang::$txt['hello_world']; | ||
} | ||
|
||
public function method2() | ||
{ | ||
echo User::$info['name']; | ||
|
||
var_dump(Config::$modSettings); | ||
} | ||
} | ||
``` | ||
|
||
После перехода на SMF 3.0 достаточно будет заменить используемые классы: | ||
|
||
```diff | ||
-use Bugo\Compat\Lang; | ||
+use SMF\Lang; | ||
-use Bugo\Compat\User; | ||
+use SMF\User; | ||
-use Bugo\Compat\Config; | ||
+use SMF\Config; | ||
``` | ||
|
||
Или использовать алиасы в `app.php` (или в другой аналогичной _точке входа_) вашего приложения: | ||
|
||
```php | ||
<?php | ||
|
||
if (str_starts_with(SMF_VERSION, '3.0')) { | ||
class_alias('SMF\\Lang', 'Bugo\\Compat\\Lang'); | ||
class_alias('SMF\\User', 'Bugo\\Compat\\User'); | ||
class_alias('SMF\\Config', 'Bugo\\Compat\\Config'); | ||
} | ||
``` | ||
|
||
В этом случае ваша модификация сможет поддерживать обе версии SMF. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "bugo/smf-compat", | ||
"description": "Wrappers to work with global variables and deprecated functions in SMF", | ||
"type": "library", | ||
"keywords": [ | ||
"smf", | ||
"utilities", | ||
"compatibility" | ||
], | ||
"homepage": "https://github.com/dragomano/smf-compat", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Bugo", | ||
"email": "bugo@dragomano.ru" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Bugo\\Compat\\": "src/Compat/" | ||
}, | ||
"files": [ | ||
"src/compat.php" | ||
] | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\": "tests/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^8.0" | ||
}, | ||
"require-dev": { | ||
"pestphp/pest": "^1.23", | ||
"rector/rector": "^0.19" | ||
}, | ||
"scripts": { | ||
"check": "vendor/bin/rector process --dry-run --clear-cache", | ||
"tests": "vendor/bin/pest", | ||
"tests-coverage": "vendor/bin/pest --coverage --min=90", | ||
"tests-coverage-clover": "vendor/bin/pest --min=90 --coverage-clover coverage.xml", | ||
"tests-coverage-html": "vendor/bin/pest --min=90 --coverage-html coverage" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"pestphp/pest-plugin": true | ||
} | ||
} | ||
} |
Oops, something went wrong.