Update Yenc support to properly detect and use available extensions

This commit is contained in:
DariusIII
2017-07-21 10:42:11 +02:00
parent 39da819328
commit dc8b83e800
6 changed files with 36 additions and 39 deletions
+3 -3
View File
@@ -37,7 +37,7 @@ class Yenc extends YencServiceProvider
'name' => 'default',
'file' => true,
];
return static::config($options['name'])->decode($text);
return static::config($options)->decode($text);
}
/**
@@ -54,7 +54,7 @@ class Yenc extends YencServiceProvider
'file' => true,
];
return static::config($options['name'])->decodeIgnore($text);
return static::config($options)->decodeIgnore($text);
}
/**
@@ -72,6 +72,6 @@ class Yenc extends YencServiceProvider
{
$options += ['name' => 'default'];
return static::config($options['name'])->encode($data, $filename, $line, $crc32);
return static::config($options)->encode($data, $filename, $line, $crc32);
}
}
@@ -22,7 +22,7 @@ namespace App\Extensions\util\yenc\adapter;
use yenc\yenc;
class NzedbYenc extends \App\Extensions\util\Yenc
class NzedbYenc
{
public static function decode(&$text, $ignore = false, array $options = [])
{
+2 -3
View File
@@ -17,9 +17,8 @@
* @copyright 2016 nZEDb
*/
namespace app\extensions\util\yenc\adapter;
namespace App\Extensions\util\yenc\adapter;
use App\Extensions\util\Yenc;
use nntmux\Logger;
@@ -28,7 +27,7 @@ use nntmux\Logger;
*
* @package app\extensions\util\yenc\adapter
*/
class Php extends Yenc
class Php
{
public static function decode(&$text, $ignore = false)
{
+18 -16
View File
@@ -2,8 +2,9 @@
namespace App\Providers;
use App\Extensions\util\Yenc;
use Illuminate\Support\ServiceProvider;
use App\Extensions\util\yenc\adapter\NzedbYenc;
use App\Extensions\util\yenc\adapter\Php;
class YencServiceProvider extends ServiceProvider
{
@@ -15,7 +16,7 @@ class YencServiceProvider extends ServiceProvider
*/
public function boot()
{
//
}
/**
@@ -25,31 +26,32 @@ class YencServiceProvider extends ServiceProvider
*/
public function register()
{
//
}
/**
* @param array $options
*
* @return mixed
* @internal param $option
*
*/
public static function config(array $options = [])
{
$defaults = [
['name' =>
[
'default' => [
'adapter' => ''
],
'nzedb' => [
'adapter' => 'NzedbYenc'
],
'php' => [
'adapter' => 'Php'
],
]
'default' => 'Php'
]
]
];
$options += $defaults;
return $options['name'];
$namespace = '\App\Extensions\util\yenc\adapter\\';
$class = $namespace . $options[0]['name']['default'];
return new $class;
}
}
+2
View File
@@ -3,6 +3,8 @@
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'nntmux' . DIRECTORY_SEPARATOR . 'constants.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'nntmux' . DIRECTORY_SEPARATOR . 'bootstrap.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'nntmux.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'yenc.php';
use Dotenv\Dotenv;
+10 -16
View File
@@ -17,8 +17,6 @@
* @copyright 2016 nZEDb
*/
use app\models\Settings;
if (defined('NN_INSTALLER') && NN_INSTALLER !== false) {
$adapter = 'Php';
@@ -36,25 +34,21 @@ if (defined('NN_INSTALLER') && NN_INSTALLER !== false) {
break;
} else {
trigger_error('Your version of the php-yenc extension is out of date and will be
ignored. Please update it to use the extension.', E_USER_WARNING);
ignored. Please update it to use the extension.', E_USER_WARNING
);
}
default:
$adapter = 'Php';
}
}
\App\Extensions\util\Yenc::config([
'default' => [
'adapter' => $adapter
],
'nzedb' => [
'adapter' => 'NzedbYenc'
],
'php' => [
'adapter' => 'Php'
],
]);
\App\Providers\YencServiceProvider::config([
['name' =>
[
'default' => $adapter
]
]
]
);
?>