xp-forge / frontend

Web frontends
1 stars 1 forks source link

Handlers #10

Closed thekid closed 5 years ago

thekid commented 5 years ago

This pull request creates a new HandlersIn class to supersede ClassesIn, which is now deprecated. Because the old implementation will simply register any instantiable class as delegate, there's no real way to put DTOs and related code next to the handler classes; instead, these would always need to be in a separate package. Refactoring code means replacing ClassesIn With HandlersIn inside the application and adding the @handler annotation to all classes.

⚠️ Keeps BC until next major release by retaining the ClassesIn class. See also https://github.com/xp-forge/rest-api/pull/10

Below is the rendered documentation on the HandlersIn class from README.md:


Organizing your code

In real-life situations, you will not want to put all of your code into the Home class. In order to separate code out into various classes, place all handler classes inside a dedicated package:

@FileSystemCL<./src/main/php>
package de.thekid.example.handlers {

  public class de.thekid.example.handlers.Home
  public class de.thekid.example.handlers.User
  public class de.thekid.example.handlers.Group
}

Then use the delegation API provided by the HandlersIn class:

use web\frontend\{Frontend, HandlersIn};

// ...inside the routes() method, as seen above:
new Frontend(new HandlersIn('de.thekid.example.handlers'), $templates);