mirror of
https://github.com/nextcloud/documentation.git
synced 2025-08-15 22:35:00 +00:00
Merge pull request #13153 from nextcloud/feat/document-app.php-removal
feat: Document app.php removal and adapt related documentation
This commit is contained in:
@ -113,8 +113,7 @@ The overall process is as follows:
|
||||
process lifetime, no other apps nor all of the server components are ready. Therefore the app **must not** try to use
|
||||
anything except the API provided by the context. That shall ensure that all apps can safely run their registration logic
|
||||
before any services are queried (instantiated) from the DI container or related code is run.
|
||||
2) Nextcloud will load groups of certain apps early, e.g. filesystem or session apps, and other later. For that purpose, their optional
|
||||
:ref:`app-php` will be included. As ``app.php`` is deprecated, apps should try not to rely on this step.
|
||||
2) Nextcloud will load groups of certain apps early, e.g. filesystem or session apps, and other later.
|
||||
3) Nextcloud will query the app's ``Application`` class (again), no matter whether it implements ``IBootstrap`` or not.
|
||||
4) Nextcloud will invoke the :ref:`boot <app-bootstrap-boot>` method of every ``Application`` instance that implements ``IBootstrap``. At this stage
|
||||
you may assume that all registrations via ``IBootstrap::register`` have completed.
|
||||
@ -190,7 +189,7 @@ With the help of ``Closure::fromCallable`` you can also delegate to other method
|
||||
public function register(IRegistrationContext $context): void {}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerFoo']));
|
||||
$context->injectFn($this->registerFoo(...));
|
||||
}
|
||||
|
||||
protected function registerFoo(IFooManager $manager): void {
|
||||
@ -198,34 +197,3 @@ With the help of ``Closure::fromCallable`` you can also delegate to other method
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Nextcloud 19 and older
|
||||
**********************
|
||||
|
||||
Nextcloud will load groups of certain apps early, like filesystem or session apps, and other later. For this their optional
|
||||
:ref:`app-php` will be included. The ``Application`` class is only queried for some requests, so there is no guarantee that
|
||||
it's constructor will be invoked.
|
||||
|
||||
|
||||
.. _app-php:
|
||||
|
||||
app.php (deprecated)
|
||||
--------------------
|
||||
|
||||
Nextcloud will ``require_once`` every installed and enabled app's ``appinfo/app.php`` file if it exists. The app can use
|
||||
this file to run registrations of autoloaders, services, event listeners and similar.
|
||||
|
||||
To leverage the advantages of object-oriented programming, it's recommended to put the logic into an :ref:`Application<application-php>`
|
||||
class and query an instance like
|
||||
|
||||
.. code-block:: php
|
||||
:caption: appinfo/app.php
|
||||
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// Register the composer autoloader for packages shipped by this app, if applicable
|
||||
include_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$app = \OC::$server->query(\OCA\MyApp\AppInfo\Application::class);
|
||||
|
@ -94,3 +94,4 @@ Removed APIs
|
||||
- ``addTranslations`` was replace by ``\OCP\Util::addTranslations`` in 24
|
||||
|
||||
- Template function ``vendor_script`` was unused and removed
|
||||
- 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.
|
||||
|
@ -401,71 +401,7 @@ Hooks
|
||||
|
||||
.. sectionauthor:: Bernhard Posselt <dev@bernhard-posselt.com>
|
||||
|
||||
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>`:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
namespace OCA\MyApp\AppInfo;
|
||||
|
||||
$app = new Application();
|
||||
$app->getContainer()->query('UserHooks')->register();
|
||||
|
||||
The hook logic should be in a separate class that is being registered in the `App constructor <dependency_injection.html#using-a-container>`__:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
namespace OCA\MyApp\AppInfo;
|
||||
|
||||
use \OCP\AppFramework\App;
|
||||
|
||||
use \OCA\MyApp\Hooks\UserHooks;
|
||||
|
||||
|
||||
class Application extends App {
|
||||
|
||||
public function __construct(array $urlParams=array()){
|
||||
parent::__construct('myapp', $urlParams);
|
||||
|
||||
$container = $this->getContainer();
|
||||
|
||||
/**
|
||||
* Controllers
|
||||
*/
|
||||
$container->registerService('UserHooks', function($c) {
|
||||
return new UserHooks(
|
||||
$c->get(\OCP\IUserManager::class)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
namespace OCA\MyApp\Hooks;
|
||||
|
||||
use OCP\IUserManager;
|
||||
|
||||
class UserHooks {
|
||||
|
||||
private $userManager;
|
||||
|
||||
public function __construct(IUserManager $userManager){
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
public function register() {
|
||||
$callback = function($user) {
|
||||
// your code that executes before $user is deleted
|
||||
};
|
||||
$this->userManager->listen('\OC\User', 'preDelete', $callback);
|
||||
}
|
||||
|
||||
}
|
||||
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>`.
|
||||
|
||||
Available hooks
|
||||
```````````````
|
||||
|
@ -22,7 +22,7 @@ In the beginning, all requests are sent to Nextcloud's :file:`index.php` which i
|
||||
* Filesystem
|
||||
* Logging
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
Afterwards the following steps are performed:
|
||||
|
||||
|
Reference in New Issue
Block a user