Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Extension Development with Extbase

Extension Development with Extbase

The Extbase MVC framework has been actively used in the TYPO3 world for almost ten years. Shifting from individual applications to a streamlined framework providing routing, object-relational mapping, form & validation handling and connecting to the Fluid rendering engine improved defined common processes for developing applications. Albeit Extbase has strict conventions concerning naming, configuration, and implementation details, it offers already a good foundation for building new applications - considering a couple of key aspects allows developers to create even more individual and stable components.

This session focuses on analyzing the distinct sub-components of the Extbase MVC framework. It aims to demonstrate and explain technical details for different use-cases and aims to enable developers using the appropriate techniques that are required according to building applications.

Benjamin Kott

August 02, 2019
Tweet

More Decks by Benjamin Kott

Other Decks in Programming

Transcript

  1. EXTBASE LAYERS Application Layer Repository query builder Object Relational Mapping

    model reconstitution Services reusable processing Infrastructure Layer View output rendering Validation controller / domain Domain Model business logic Schema Doctrine DBAL Relation Handling (basically based on TCA) Behavior (often mixed in controllers) Extbase Routing Property Mapping model reconstitution View Helpers output functions Controller orchestration & delegation TYPO3 Routing Invocation CLI request HTTP request Domain Layer Presentation Layer Application Dispatcher symfony/routing plugin configuration TypoScript settings Orchestration controller actions action arguments domain invocation infrastructure invocation presentation invocation Templating Engine Fluid, Twig, Blade, … HTML, XML, JSON, …
  2. EXTBASE SECURITY ASPECTS  Extbase application is "accessible" by everybody

     no user or permission management in frontend  controller-action can be called directly .../?tx[controller]=User&tx[action]=delete&…  access control must be done individually  either by using dedicated plugins & frontend groups  or in each controller, authorizing actins (suggested)
  3. CAR RENTAL EXAMPLE # vin: string # color: string #

    brand: Brand # charge: Charge # tires: Tire[] # rentals: Rental[] # maintenances: Maintenance[] # images: FileReference[] <<Aggregate Root>> Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # employeeNumber <<abstract>> Employee + get…() + set…() Customer Mechanic Agent # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 n 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface
  4.  Using Doctrine DBAL QueryBuilder  Using custom query statements

     In order to be more flexible  Submitted data must be escaped/casted (security)
  5.  Omitting ORM layer, retrieve raw-data (array)  Pros &

    Cons of working with arrays or objects
  6. CAR RENTAL EXAMPLE # vin: string # color: string #

    brand: Brand # charge: Charge # tires: Tire[] # rentals: Rental[] # maintenances: Maintenance[] # images: FileReference[] <<Aggregate Root>> Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # employeeNumber <<abstract>> Employee + get…() + set…() Customer Mechanic Agent # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 n 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface
  7. CAR RENTAL EXAMPLE PRO  Car aggregate root  Everything

    available  Single entry point  Comfortable CON  Lots of DB queries  Memory footprint  Performance impact  Growing amount of associations
  8. CAR RENTAL EXAMPLE – BOUNDED CONTEXTS  Separate into contexts/scenarios

     Rental  Presenting cars  Handling reservations & rentals  Handle booking & pricing  Maintenance  Maintaining car  Check tires  Document actions
  9. CAR RENTAL EXAMPLE – BOUNDED CONTEXTS Extbase Maintenance Common Rental

    # vin: string # color: string # brand: Brand # tires: Tire[] # maintenances: Maintenance[] <<Aggregate Root>> Maintenance\Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # employeeNumber <<abstract>> Employee + get…() + set…() Customer Mechanic Agent # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface # vin: string # color: string # brand: Brand # rentals: Rental[] # images: FileReference[] <<Aggregate Root>> Rental\Car + get…() + set…() 1 1 1 1 n 1 1 1
  10. CAR RENTAL EXAMPLE - INHERITANCE  Agent extends Employee extends

    FrontendUser  Inheritance tree is probably too large  Superfluous information is retrieved  Only customerId, employeeId, … are required  Full FrontendUser used for authentication (In this case: username & password in View)
  11. CAR RENTAL EXAMPLE - INHERITANCE Extbase Maintenance Common Rental #

    vin: string # color: string # brand: Brand # tires: Tire[] # maintenances: Maintenance[] <<Aggregate Root>> Maintenance\Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # frontendUserId: int # customerId: string Customer + get…() + set…() # frontendUserId: int # employeeNumber: string Mechanic + get…() + set…() # frontendUserId: int # employeeNumber: string Agent + get…() + set…() # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface # vin: string # color: string # brand: Brand # rentals: Rental[] # images: FileReference[] <<Aggregate Root>> Rental\Car + get…() + set…() 1 1 1 1 n 1 1 1 FrontendUserService + retrieveUserById(int $id)
  12. CAR RENTAL EXAMPLE – PLUGIN & CONTROLLER ORCHESTRATION  Using

    Extbase plugin configuration  Should only contain required controller-actions  Permissions on plugin level (frontend groups)  Avoids potential side effects
  13. PROBLEMS  Every request fetches data from an external endpoint

     Reaching API-Limits quickly  Probably gets expensive  Bonus: Slow  Question: How often does the weather change?
  14. SOLUTION  Minimum effort / high impact  System only

    fetches new data after lifetime expired  Limited requests to API  Lot´s cheaper  Bonus: Faster  Answer: 30 minutes should be fine
  15. CACHING FRAMEWORK  The caching framework is really easy to

    use.  If you have a lot of requests fetching the same data, you can fetch them once, prepare them and save them for later.  Keep in mind that cache CAN have a lifetime.  If you do not set a lifetime you need to take care of invalidation
  16. REQUIREMENTS  Needs to validate input  Needs to show

    validation errors on property  Needs to persist data  Needs to be translatable  Needs to be dynamically created  Needs to add features through configuration  Needs to send notifications  Needs to be extendable in the future  Needs to work in every frontend environment
  17. Extbase EXT:form Validate Input Validation Error on Property Persist Data

    Dynamically Created Translateable Notifications Yes custom optional Yes Hard custom Yes Yes optional Yes Easy custom FEATURE COMPARISON
  18. 316 ADDITIONS 276 DELETIONS [!!!][TASK] USE TYPO3 FORM FRAMEWORK FOR

    COMMENT FORM 407A2AF699961F3C2726204F4A6C49E22E162A07