Skip to content

Commit f320c33

Browse files
authored
Merge pull request #13153 from nextcloud/feat/document-app.php-removal
feat: Document app.php removal and adapt related documentation
2 parents 7e7d1e0 + 7799a81 commit f320c33

File tree

4 files changed

+5
-100
lines changed

4 files changed

+5
-100
lines changed

developer_manual/app_development/bootstrap.rst

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ The overall process is as follows:
113113
process lifetime, no other apps nor all of the server components are ready. Therefore the app **must not** try to use
114114
anything except the API provided by the context. That shall ensure that all apps can safely run their registration logic
115115
before any services are queried (instantiated) from the DI container or related code is run.
116-
2) Nextcloud will load groups of certain apps early, e.g. filesystem or session apps, and other later. For that purpose, their optional
117-
:ref:`app-php` will be included. As ``app.php`` is deprecated, apps should try not to rely on this step.
116+
2) Nextcloud will load groups of certain apps early, e.g. filesystem or session apps, and other later.
118117
3) Nextcloud will query the app's ``Application`` class (again), no matter whether it implements ``IBootstrap`` or not.
119118
4) Nextcloud will invoke the :ref:`boot <app-bootstrap-boot>` method of every ``Application`` instance that implements ``IBootstrap``. At this stage
120119
you may assume that all registrations via ``IBootstrap::register`` have completed.
@@ -190,42 +189,11 @@ With the help of ``Closure::fromCallable`` you can also delegate to other method
190189
public function register(IRegistrationContext $context): void {}
191190
192191
public function boot(IBootContext $context): void {
193-
$context->injectFn(Closure::fromCallable([$this, 'registerFoo']));
192+
$context->injectFn($this->registerFoo(...));
194193
}
195194
196195
protected function registerFoo(IFooManager $manager): void {
197196
$manager->registerCustomFoo(MyFooImpl::class);
198197
}
199198
200199
}
201-
202-
Nextcloud 19 and older
203-
**********************
204-
205-
Nextcloud will load groups of certain apps early, like filesystem or session apps, and other later. For this their optional
206-
:ref:`app-php` will be included. The ``Application`` class is only queried for some requests, so there is no guarantee that
207-
it's constructor will be invoked.
208-
209-
210-
.. _app-php:
211-
212-
app.php (deprecated)
213-
--------------------
214-
215-
Nextcloud will ``require_once`` every installed and enabled app's ``appinfo/app.php`` file if it exists. The app can use
216-
this file to run registrations of autoloaders, services, event listeners and similar.
217-
218-
To leverage the advantages of object-oriented programming, it's recommended to put the logic into an :ref:`Application<application-php>`
219-
class and query an instance like
220-
221-
.. code-block:: php
222-
:caption: appinfo/app.php
223-
224-
<?php
225-
226-
declare(strict_types=1);
227-
228-
// Register the composer autoloader for packages shipped by this app, if applicable
229-
include_once __DIR__ . '/../vendor/autoload.php';
230-
231-
$app = \OC::$server->query(\OCA\MyApp\AppInfo\Application::class);

developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_32.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ Removed APIs
9494
- ``addTranslations`` was replace by ``\OCP\Util::addTranslations`` in 24
9595

9696
- Template function ``vendor_script`` was unused and removed
97+
- The support for ``app.php`` files, deprecated since Nextcloud 19, was removed. Existence of the file is still checked to show an error if present, but that will be removed in a later version. Please move to ``OCP\AppFramework\Bootstrap\IBoostrap`` instead.

developer_manual/basics/events.rst

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -401,71 +401,7 @@ Hooks
401401

402402
.. sectionauthor:: Bernhard Posselt <dev@bernhard-posselt.com>
403403

404-
Hooks are used to execute code before or after an event has occurred. This is for instance useful to run cleanup code after users, groups or files have been deleted. Hooks should be registered in the :doc:`app.php <../app_development/init>`:
405-
406-
.. code-block:: php
407-
408-
<?php
409-
namespace OCA\MyApp\AppInfo;
410-
411-
$app = new Application();
412-
$app->getContainer()->query('UserHooks')->register();
413-
414-
The hook logic should be in a separate class that is being registered in the `App constructor <dependency_injection.html#using-a-container>`__:
415-
416-
.. code-block:: php
417-
418-
<?php
419-
420-
namespace OCA\MyApp\AppInfo;
421-
422-
use \OCP\AppFramework\App;
423-
424-
use \OCA\MyApp\Hooks\UserHooks;
425-
426-
427-
class Application extends App {
428-
429-
public function __construct(array $urlParams=array()){
430-
parent::__construct('myapp', $urlParams);
431-
432-
$container = $this->getContainer();
433-
434-
/**
435-
* Controllers
436-
*/
437-
$container->registerService('UserHooks', function($c) {
438-
return new UserHooks(
439-
$c->get(\OCP\IUserManager::class)
440-
);
441-
});
442-
}
443-
}
444-
445-
.. code-block:: php
446-
447-
<?php
448-
449-
namespace OCA\MyApp\Hooks;
450-
451-
use OCP\IUserManager;
452-
453-
class UserHooks {
454-
455-
private $userManager;
456-
457-
public function __construct(IUserManager $userManager){
458-
$this->userManager = $userManager;
459-
}
460-
461-
public function register() {
462-
$callback = function($user) {
463-
// your code that executes before $user is deleted
464-
};
465-
$this->userManager->listen('\OC\User', 'preDelete', $callback);
466-
}
467-
468-
}
404+
Hooks are used to execute code before or after an event has occurred. This is for instance useful to run cleanup code after users, groups or files have been deleted. Hooks should be registered in the :doc:`Bootstrapping process <../app_development/bootstrap>`.
469405

470406
Available hooks
471407
```````````````

developer_manual/basics/request_lifecycle.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In the beginning, all requests are sent to Nextcloud's :file:`index.php` which i
2222
* Filesystem
2323
* Logging
2424

25-
The type of the app is determined by inspecting the app's :doc:`configuration file <../app_development/info>` (:file:`appinfo/info.xml`). Loading apps means that the :doc:`main file <../app_development/init>` (:file:`appinfo/app.php`) of each installed app is being loaded and executed. That means that if you want to execute code before a specific app is being run, you can place code in your app's :doc:`../app_development/init` file.
25+
The type of the app is determined by inspecting the app's :doc:`configuration file <../app_development/info>` (:file:`appinfo/info.xml`). Each installed app is being loaded and executed (see :doc:`Bootstrap <../app_development/bootstrap>`). That means that if you want to execute code before a specific app is being run, you can place code in your app's :doc:`../app_development/init` file.
2626

2727
Afterwards the following steps are performed:
2828

0 commit comments

Comments
 (0)