diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index 2a87bc3..0000000 --- a/appinfo/app.php +++ /dev/null @@ -1,5 +0,0 @@ -uid = ($user) ? $user->getUID() : ''; - $this->settings = new Settings($this->uid); - $this->userFolder = Helper::getUserFolder($this->uid); - $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 () { + } + public function register(IRegistrationContext $context): void + { + $context->registerService('httpClient', function () { $options = [ 'ipv4' => true, ]; return Client::create($options); }); - $container->registerService('crawler', function () { + $context->registerService('crawler', function () { return new Crawler(); }); $sites = Helper::getSearchSites(); foreach ($sites as $site) { //fully qualified class name $className = $site['class']; - $container->registerService($className, function (IContainer $container) use ($className) { - $crawler = $container->query('crawler'); - $client = $container->query('httpClient'); + $context->registerService($className, function (ContainerInterface $container) use ($className) { + $crawler = $container->get('crawler'); + $client = $container->get('httpClient'); 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']); + } }