11<?php
2+
3+ declare (strict_types=1 );
4+
25/**
36 * @copyright Copyright (c) 2016, ownCloud, Inc.
47 *
3134
3235namespace OCA \Files \AppInfo ;
3336
37+ use OC \Search \Provider \File ;
3438use OCA \Files \Capabilities ;
3539use OCA \Files \Collaboration \Resources \Listener ;
3640use OCA \Files \Collaboration \Resources \ResourceProvider ;
4246use OCA \Files \Notification \Notifier ;
4347use OCA \Files \Service \TagService ;
4448use OCP \AppFramework \App ;
49+ use OCP \AppFramework \Bootstrap \IBootContext ;
50+ use OCP \AppFramework \Bootstrap \IBootstrap ;
51+ use OCP \AppFramework \Bootstrap \IRegistrationContext ;
4552use OCP \Collaboration \Resources \IProviderManager ;
46- use OCP \EventDispatcher \IEventDispatcher ;
4753use OCP \IContainer ;
54+ use OCP \IL10N ;
55+ use OCP \IServerContainer ;
56+ use OCP \Notification \IManager ;
57+ use OCP \Util ;
4858
49- class Application extends App {
59+ class Application extends App implements IBootstrap {
5060 public const APP_ID = 'files ' ;
5161
5262 public function __construct (array $ urlParams =[]) {
5363 parent ::__construct (self ::APP_ID , $ urlParams );
54- $ container = $ this ->getContainer ();
55- $ server = $ container ->getServer ();
64+ }
5665
66+ public function register (IRegistrationContext $ context ): void {
5767 /**
5868 * Controllers
5969 */
60- $ container ->registerService ('APIController ' , function (IContainer $ c ) use ($ server ) {
70+ $ context ->registerService ('APIController ' , function (IContainer $ c ) {
71+ /** @var IServerContainer $server */
72+ $ server = $ c ->query (IServerContainer::class);
73+
6174 return new ApiController (
6275 $ c ->query ('AppName ' ),
6376 $ c ->query ('Request ' ),
@@ -73,37 +86,95 @@ public function __construct(array $urlParams=[]) {
7386 /**
7487 * Services
7588 */
76- $ container ->registerService ('TagService ' , function (IContainer $ c ) use ($ server ) {
77- $ homeFolder = $ c ->query ('ServerContainer ' )->getUserFolder ();
89+ $ context ->registerService ('TagService ' , function (IContainer $ c ) {
90+ /** @var IServerContainer $server */
91+ $ server = $ c ->query (IServerContainer::class);
92+
7893 return new TagService (
79- $ c -> query ( ' ServerContainer ' ) ->getUserSession (),
80- $ c -> query ( ' ServerContainer ' ) ->getActivityManager (),
81- $ c -> query ( ' ServerContainer ' ) ->getTagManager ()->load (self ::APP_ID ),
82- $ homeFolder ,
94+ $ server ->getUserSession (),
95+ $ server ->getActivityManager (),
96+ $ server ->getTagManager ()->load (self ::APP_ID ),
97+ $ server -> getUserFolder () ,
8398 $ server ->getEventDispatcher ()
8499 );
85100 });
86101
87102 /*
88103 * Register capabilities
89104 */
90- $ container ->registerCapability (Capabilities::class);
105+ $ context ->registerCapability (Capabilities::class);
91106
92- /**
93- * Register Collaboration ResourceProvider
94- */
107+ $ context ->registerEventListener (LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
108+ $ context ->registerEventListener (LoadSidebar::class, LoadSidebarListener::class);
109+ }
110+
111+ public function boot (IBootContext $ context ): void {
112+ $ this ->registerCollaboration ($ context );
113+ Listener::register ($ context ->getServerContainer ()->getEventDispatcher ());
114+ $ this ->registerNotification ($ context );
115+ $ this ->registerSearchProvider ($ context );
116+ $ this ->registerTemplates ();
117+ $ this ->registerNavigation ($ context );
118+ $ this ->registerHooks ();
119+ }
120+
121+ /**
122+ * Register Collaboration ResourceProvider
123+ */
124+ private function registerCollaboration (IBootContext $ context ): void {
95125 /** @var IProviderManager $providerManager */
96- $ providerManager = $ container ->query (IProviderManager::class);
126+ $ providerManager = $ context -> getAppContainer () ->query (IProviderManager::class);
97127 $ providerManager ->registerResourceProvider (ResourceProvider::class);
98- Listener::register ($ server ->getEventDispatcher ());
99-
100- /** @var IEventDispatcher $dispatcher */
101- $ dispatcher = $ container ->query (IEventDispatcher::class);
102- $ dispatcher ->addServiceListener (LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
103- $ dispatcher ->addServiceListener (LoadSidebar::class, LoadSidebarListener::class);
128+ }
104129
105- /** @var \OCP\Notification\IManager $notifications */
106- $ notifications = $ container ->query (\OCP \Notification \IManager::class);
130+ private function registerNotification (IBootContext $ context ): void {
131+ /** @var IManager $notifications */
132+ $ notifications = $ context ->getAppContainer ()->query (IManager::class);
107133 $ notifications ->registerNotifierService (Notifier::class);
108134 }
135+
136+ /**
137+ * @param IBootContext $context
138+ */
139+ private function registerSearchProvider (IBootContext $ context ): void {
140+ $ context ->getServerContainer ()->getSearch ()->registerProvider (File::class, ['apps ' => ['files ' ]]);
141+ }
142+
143+ private function registerTemplates (): void {
144+ $ templateManager = \OC_Helper::getFileTemplateManager ();
145+ $ templateManager ->registerTemplate ('application/vnd.oasis.opendocument.presentation ' , 'core/templates/filetemplates/template.odp ' );
146+ $ templateManager ->registerTemplate ('application/vnd.oasis.opendocument.text ' , 'core/templates/filetemplates/template.odt ' );
147+ $ templateManager ->registerTemplate ('application/vnd.oasis.opendocument.spreadsheet ' , 'core/templates/filetemplates/template.ods ' );
148+ }
149+
150+ private function registerNavigation (IBootContext $ context ): void {
151+ /** @var IL10N $l10n */
152+ $ l10n = $ context ->getAppContainer ()->query (IL10N ::class);
153+ \OCA \Files \App::getNavigationManager ()->add ([
154+ 'id ' => 'files ' ,
155+ 'appname ' => 'files ' ,
156+ 'script ' => 'list.php ' ,
157+ 'order ' => 0 ,
158+ 'name ' => $ l10n ->t ('All files ' )
159+ ]);
160+ \OCA \Files \App::getNavigationManager ()->add ([
161+ 'id ' => 'recent ' ,
162+ 'appname ' => 'files ' ,
163+ 'script ' => 'recentlist.php ' ,
164+ 'order ' => 2 ,
165+ 'name ' => $ l10n ->t ('Recent ' )
166+ ]);
167+ \OCA \Files \App::getNavigationManager ()->add ([
168+ 'id ' => 'favorites ' ,
169+ 'appname ' => 'files ' ,
170+ 'script ' => 'simplelist.php ' ,
171+ 'order ' => 5 ,
172+ 'name ' => $ l10n ->t ('Favorites ' ),
173+ 'expandedState ' => 'show_Quick_Access '
174+ ]);
175+ }
176+
177+ private function registerHooks (): void {
178+ Util::connectHook ('\OCP\Config ' , 'js ' , '\OCA\Files\App ' , 'extendJsConfig ' );
179+ }
109180}
0 commit comments