fixed deprecation warnings
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace OCA\NCDownloader\AppInfo;
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2,96 +2,68 @@
|
|||||||
|
|
||||||
namespace OCA\NCDownloader\AppInfo;
|
namespace OCA\NCDownloader\AppInfo;
|
||||||
|
|
||||||
use OCA\NCDownloader\Controller\Aria2Controller;
|
|
||||||
use OCA\NCDownloader\Controller\MainController;
|
|
||||||
use OCA\NCDownloader\Controller\YtdlController;
|
|
||||||
use OCA\NCDownloader\Aria2\Aria2;
|
use OCA\NCDownloader\Aria2\Aria2;
|
||||||
use OCA\NCDownloader\Http\Client;
|
use OCA\NCDownloader\Http\Client;
|
||||||
use OCA\NCDownloader\Tools\Helper;
|
use OCA\NCDownloader\Tools\Helper;
|
||||||
use OCA\NCDownloader\Db\Settings;
|
use OCA\NCDownloader\Db\Settings;
|
||||||
use OCA\NCDownloader\Ytdl\Ytdl;
|
use OCA\NCDownloader\Ytdl\Ytdl;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\IContainer;
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
class Application extends App
|
class Application extends App implements IBootstrap
|
||||||
{
|
{
|
||||||
public function __construct(array $urlParams = array())
|
public function __construct(array $urlParams = array())
|
||||||
{
|
{
|
||||||
parent::__construct('ncdownloader', $urlParams);
|
parent::__construct('ncdownloader', $urlParams);
|
||||||
$user = Helper::getUser();
|
}
|
||||||
$this->uid = ($user) ? $user->getUID() : '';
|
public function register(IRegistrationContext $context): void
|
||||||
$this->settings = new Settings($this->uid);
|
{
|
||||||
$this->userFolder = Helper::getUserFolder($this->uid);
|
$context->registerService('httpClient', function () {
|
||||||
$container = $this->getContainer();
|
|
||||||
$container->registerService('UserId', function (IContainer $container) {
|
|
||||||
return $this->uid;
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService('Aria2', function (IContainer $container) {
|
|
||||||
$config = Helper::getAria2Config($this->uid);
|
|
||||||
return new Aria2($config);
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService('Ytdl', function (IContainer $container) {
|
|
||||||
$config = Helper::getYtdlConfig($this->uid);
|
|
||||||
return new Ytdl($config);
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService('Settings', function (IContainer $container) {
|
|
||||||
return new Settings($this->uid);
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService('MainController', function (IContainer $container) {
|
|
||||||
return new MainController(
|
|
||||||
$container->query('AppName'),
|
|
||||||
$container->query('Request'),
|
|
||||||
$container->query('UserId'),
|
|
||||||
\OC::$server->getL10N('ncdownloader'),
|
|
||||||
//\OC::$server->getRootFolder(),
|
|
||||||
$container->query('Aria2'),
|
|
||||||
$container->query('Ytdl')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService('Aria2Controller', function (IContainer $container) {
|
|
||||||
return new Aria2Controller(
|
|
||||||
$container->query('AppName'),
|
|
||||||
$container->query('Request'),
|
|
||||||
$container->query('UserId'),
|
|
||||||
\OC::$server->getL10N('ncdownloader'),
|
|
||||||
\OC::$server->getRootFolder(),
|
|
||||||
$container->query('Aria2')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
$container->registerService('YtdlController', function (IContainer $container) {
|
|
||||||
return new YtdlController(
|
|
||||||
$container->query('AppName'),
|
|
||||||
$container->query('Request'),
|
|
||||||
$container->query('UserId'),
|
|
||||||
\OC::$server->getL10N('ncdownloader'),
|
|
||||||
$container->query('Aria2'),
|
|
||||||
$container->query('Ytdl')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
$container->registerService('httpClient', function () {
|
|
||||||
$options = [
|
$options = [
|
||||||
'ipv4' => true,
|
'ipv4' => true,
|
||||||
];
|
];
|
||||||
return Client::create($options);
|
return Client::create($options);
|
||||||
});
|
});
|
||||||
$container->registerService('crawler', function () {
|
$context->registerService('crawler', function () {
|
||||||
return new Crawler();
|
return new Crawler();
|
||||||
});
|
});
|
||||||
$sites = Helper::getSearchSites();
|
$sites = Helper::getSearchSites();
|
||||||
foreach ($sites as $site) {
|
foreach ($sites as $site) {
|
||||||
//fully qualified class name
|
//fully qualified class name
|
||||||
$className = $site['class'];
|
$className = $site['class'];
|
||||||
$container->registerService($className, function (IContainer $container) use ($className) {
|
$context->registerService($className, function (ContainerInterface $container) use ($className) {
|
||||||
$crawler = $container->query('crawler');
|
$crawler = $container->get('crawler');
|
||||||
$client = $container->query('httpClient');
|
$client = $container->get('httpClient');
|
||||||
return $className::create($crawler, $client);
|
return $className::create($crawler, $client);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function boot(IBootContext $c): void
|
||||||
|
{
|
||||||
|
$user = Helper::getUser();
|
||||||
|
$uid = ($user) ? $user->getUID() : '';
|
||||||
|
//$settings = new Settings($uid);
|
||||||
|
//$userFolder = Helper::getUserFolder($uid);
|
||||||
|
$context = $c->getAppContainer();
|
||||||
|
|
||||||
|
$context->registerService(Aria2::class, function (ContainerInterface $c) use ($uid) {
|
||||||
|
$config = Helper::getAria2Config($uid);
|
||||||
|
return new Aria2($config);
|
||||||
|
});
|
||||||
|
$context->registerService(Ytdl::class, function (ContainerInterface $c) use ($uid) {
|
||||||
|
$config = Helper::getYtdlConfig($uid);
|
||||||
|
return new Ytdl($config);
|
||||||
|
});
|
||||||
|
|
||||||
|
$context->registerService(Settings::class, function (ContainerInterface $c) use ($uid){
|
||||||
|
return new Settings($uid);
|
||||||
|
});
|
||||||
|
|
||||||
|
//$context->injectFn([$this, 'registerSearchProviders']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user