SlideShare una empresa de Scribd logo
1 de 101
Descargar para leer sin conexión
T3CON08                  Inspiring people to
Development with FLOW3   share
The History of FLOW3
      (short version)
The Long History of TYPO3
 Since 1998

 33 core members

 committed 500.000 lines of code

 resulting in a code base of

 300.000 lines today
The Long History of TYPO3
 Since 1998

 33 core members

 committed 500.000 lines of code

 resulting in a code base of

 300.000 lines today
TYPO3 today
     TYPO3 v4 is nearly feature complete

     Focus of the last releases were usbility improvements for the users

     Grown architecture, no unit tests

     Fundamental changes are risky / impossible

     Often used as application framework - but it's a CMS




Development with FLOW3                                             Inspiring people to
                                                                   share
TYPO3 tomorrow?




Development with FLOW3   Inspiring people to
                         share
Why
start from
 scratch?
Topictext




            Source: The Secret Archives of TYPO3
”We need a new framework!“
Buy none get two for free.




Development with FLOW3       Inspiring people to
                             share
TYPO3 tomorrow
     FLOW3 acts as a reliable basis for any kind of web application

     TYPO3 v5 is a package based on FLOW3

     Extensions are packages as well, all based on FLOW3


     Packages can be used

       as extensions for TYPO3

       as libraries for standalone applications


Development with FLOW3                                                Inspiring people to
                                                                      share
The FLOW3 experience
 Flow [fl!] The mental state of operation in which the person is fully immersed in
 what he or she is doing by a feeling of energized focus, full involvement, and
 success in the process of the activity. Proposed by positive psychologist Mihály
 Csíkszentmihályi, the concept has been widely referenced across a variety of fields.

 FLOW3 [fl!'three] The application framework which takes care of all hassle and lets
 you play the fun part.




Development with FLOW3                                             Inspiring people to
                                                                   share
FLOW3 = Application Framework
     Not just a collection of components or code snippet library

     Comes with ready-to-go default configuration

     Package based

     Runs with PHP 5.3 or later

     Comes with a powerful JSR-283 based Content Repository




Development with FLOW3                                             Inspiring people to
                                                                   share
Get the FLOW experience
     Intuitive APIs

     Readable source code (like a book)

     Consistent naming for classes, methods and properties


     Focus on the essential, the framework takes care of the infrastructure




Development with FLOW3                                             Inspiring people to
                                                                   share
FLOW3 modules
     AOP                 Locale        Reflection

     Component           Log           Resource

     Configuration        MVC           Session

     Cache               Package       Utility

     Error               Persistence   Validation

     Event               Property      ... and more



Development with FLOW3                           Inspiring people to
                                                 share
Getting Started




Development with FLOW3   Inspiring people to
                         share
Getting Started


Requirements
       Some webserver (tested with Apache and IIS)

       PHP 5.3 or higher (see http://snaps.php.net/)

          PHP extensions: zlib, PDO and PDO SQLite and the usual stuff

       Some database (tested with SQLite, MySQL and Postgres)




Development with FLOW3                                               Inspiring people to
                                                                     share
Getting Started


Download
       Currently available through Subversion

          Checkout the FLOW3 Distribution:
          svn co https://svn.typo3.org/FLOW3/distribution/trunk

          or try the TYPO3 Distribution:
          svn co https://svn.typo3.org/TYPO3v5/distribution/trunk

       Nightly builds will follow as soon as we've set up our release mechanism




Development with FLOW3                                              Inspiring people to
                                                                    share
Getting Started


Grant File Permissions
       The webserver needs

          read access for all files of the distribution and

          write access in the Public and Data directory

       On Linux / Mac just call sudo ./fixpermissions.sh

       On legacy operating systems: ask your system administrator




Development with FLOW3                                              Inspiring people to
                                                                    share
Getting Started


Create a package
In order to create a new package, just create
a new folder within the Packages directory.




Development with FLOW3                          Inspiring people to
                                                share
Getting Started


Create a Default Controller
    Create a subfolder in your package: Classes/Controller/

    Create the controller class file:




Development with FLOW3                                        Inspiring people to
                                                              share
Bootstrap




Development with FLOW3   Inspiring people to
                         share
Bootstrap


Public/




Development with FLOW3   Inspiring people to
                         share
Bootstrap


Public/index.php
       This file is the default main script

       It launches FLOW3 in the Production context

       The webserver's web root should point to the Public directory


  define('FLOW3_PATH_PUBLIC', str_replace('', '/', __DIR__) . '/');
  require(FLOW3_PATH_PUBLIC . '../Packages/FLOW3/Classes/F3_FLOW3.php');

  $framework = new F3::FLOW3();
  $framework->run();




Development with FLOW3                                                     Inspiring people to
                                                                           share
Bootstrap


Public/index_dev.php
       This script is used for development

       It launches FLOW3 in the Development context

       More scripts like this can be created for additional contexts


  define('FLOW3_PATH_PUBLIC', str_replace('', '/', __DIR__) . '/');
  require(FLOW3_PATH_PUBLIC . '../Packages/FLOW3/Classes/F3_FLOW3.php');

  $framework = new F3::FLOW3('Development');
  $framework->run();




Development with FLOW3                                                     Inspiring people to
                                                                           share
Bootstrap


$FLOW3->run()
       run() is a convenience method which

            initializes the FLOW3 framework

            resolves a request handler

            handles and responses to the request




Development with FLOW3                             Inspiring people to
                                                   share
Bootstrap


$FLOW3->initialize()
       The initialization process is divided into different stages:
            Initialize FLOW3
            Initialize the packages
            Initialize the components
            Initialize the settings
            Initialize the resources
       The configuration for each level can't be changed once the initialization level
       is reached


Development with FLOW3                                                Inspiring people to
                                                                      share
Bootstrap


Beware of Caching
       Don't forget to run FLOW3 in Development context while
       you're developing because

            component configuration is cached in production mode,
            so new classes won't be recognized

            resources are cached in production mode, so changes
            won't be detected

            and many more things might be cached which lead to
            unexpected errors if you change some code in your
            package


Development with FLOW3                                             Inspiring people to
                                                                   share
Bootstrap


Just in Case
       If you need to clear the cache, just remove all files from the
       Data/Temporary/ directory

       Yes, there will be a backend function and command line tool
       for this




Development with FLOW3                                                 Inspiring people to
                                                                       share
Solving Beginner's Problems




Development with FLOW3        Inspiring people to
                              share
Topictext




Development with FLOW3   Inspiring people to
                         share
Model - View - Controller




Development with FLOW3      Inspiring people to
                            share
The MVC Pattern


Model
       an object which contains data and business logic of a
       certain domain

       doesn't contain any information about the presentation of
       that data, but rather defines the behaviour

       in the FLOW3 project we prefer a special kind of model, the
       Domain Model




Development with FLOW3                                               Inspiring people to
                                                                     share
The MVC Pattern


View
       represents the display of the model on the web or another
       output channel

       views only display data, they don't build or modify it




Development with FLOW3                                             Inspiring people to
                                                                   share
The MVC Pattern


Controller
       reacts on user input, selects and manipulates the model as
       accordingly

       selects a view and passes it the prepared model for
       rendering




Development with FLOW3                                              Inspiring people to
                                                                    share
MVC


Action Controller
      An action controller

        accepts a request

        evaluates arguments

        calls the action defined in the request

        and adds output to the response




Development with FLOW3                           Inspiring people to
                                                 share
MVC


Action Controller: Important Methods
      Actions - methods just need an "Action" suffix:
      public function indexAction() { ... }
      public function deleteAction() { ... }

      Initialization for the whole controller:
      public function initializeController() { ... }

      Initialization of arguments:
      public function initializeArguments() { ... }

      Initialization before any action is called:
      public function initializeAction() { ... }




Development with FLOW3                                 Inspiring people to
                                                       share
DEMO

Development with FLOW3     Inspiring people to
                           share
Validation




Development with FLOW3   Inspiring people to
                         share
Validating Arguments
     All arguments passed to an Action Controller (more precisely: Request
     Handling Controller) are automatically validated

     White List policy: Only registered arguments are available

     Accessing the $_GET and $_POST super globals is dangerous, dirty, deprecated
     and will probably be intercepted in the future




Development with FLOW3                                            Inspiring people to
                                                                  share
Validating Arguments
     FLOW3 comes with a bunch of built in validators:

       AlphaNumeric, EmailAddress, Float, Integer, NotEmpty, Number,
       NumberRange, RegularExpression, UUID, Text

     Custom validators can be created (especially for Domain Models)

     All validators can be chained (and nested)




Development with FLOW3                                           Inspiring people to
                                                                 share
DEMO

Development with FLOW3     Inspiring people to
                           share
Components




Development with FLOW3   Inspiring people to
                         share
Components


Components
      Components are re-usable, properly encapsulated objects

      The lifecycle of a component and the combination of active
      components is managed by the Component Manager

      All classes in the TYPO3 context are considered as
      components

      Components are configurable




Development with FLOW3                                             Inspiring people to
                                                                   share
Components


Class ! Component
      Classes are automatically registered as components if

        they reside in the Classes directory of a package and

        their name follows the FLOW3 naming conventions




Development with FLOW3                                          Inspiring people to
                                                                share
Components


Example




Development with FLOW3   Inspiring people to
                         share
Components


Playing with building blocks
      The combination of components used is configurable
      (orchestration)

      The less components know about each other the easier it is
      to reuse them in a variety of contexts

      Create your own LEGO set by creating cleanly separated,
      decoupled components!




Development with FLOW3                                             Inspiring people to
                                                                   share
Components


Component Dependencies
      Components seldomly come alone

      Components depend on other components which depend on
      other components which ...

      Problem:

        Components explicitly refer to other components:
        $phoneBookManager = new PhoneBookManager




Development with FLOW3                                        Inspiring people to
                                                              share
Components


Dependency Injection
      A component doesn't ask for the instance of another
      component but gets it injected

      This methodology is referred to as the "Hollywood
      Principle":
      "Don't call us, we'll call you"

      Enforces loose coupling and high cohesion

      Makes you a better programmer




Development with FLOW3                                      Inspiring people to
                                                            share
Components


Constructor without Dependency Injection




Development with FLOW3            Inspiring people to
                                  share
Components


Component with Constructor Injection




Development with FLOW3            Inspiring people to
                                  share
Components


Component with Setter Injection




Development with FLOW3            Inspiring people to
                                  share
Components


Autowiring
      FLOW3's framework tries to autowire constructor arguments
      and arguments of inject* methods

      The type of the component to be injected is determined by
      the argument type (type hinting)

      Autowiring does not work with Setter Injection through
      regular setters (set* methods)

      Dependencies are only autowired if no argument is passed
      explicitly



Development with FLOW3                                            Inspiring people to
                                                                  share
Components


Fetching components manually
      Although Dependency Injection is strongly recommended, there
      might be cases in which components need to be created or retrieved
      manually

      Use the getComponent() method in these cases.

      $component = $componentManager->getComponent($componentName, $arg1, $arg2, ...);




Development with FLOW3                                            Inspiring people to
                                                                 share
Components


Component scope
      Component objects always live in a certain scope

      Currently supported scopes are:

        Singleton - Only one instance exists during one script
        run

        Prototype - Each getComponent() call returns a fresh
        instance




Development with FLOW3                                           Inspiring people to
                                                                 share
Components


Component scope
      The scope can be defined through

        an annotation in the component class (recommended)

        through the component configuration in a
        Components.php file

      The default scope is "Singleton"




Development with FLOW3                                       Inspiring people to
                                                             share
Components


Component scope




Development with FLOW3   Inspiring people to
                         share
Components


Creating Prototypes
      Dependency Injection can be used in almost any case,
      there's no need to call getComponent()

      But what if you need to instantiate a component within a
      method?




Development with FLOW3                                           Inspiring people to
                                                                 share
Components


Creating Prototypes
      Solution A: Call getComponent()




Development with FLOW3                  Inspiring people to
                                        share
Components


Creating Prototypes
      Solution B: Call a factory method




Development with FLOW3                    Inspiring people to
                                          share
Components


Creating Prototypes
      Planned feature: Automatically generated factory methods




Development with FLOW3                                           Inspiring people to
                                                                 share
Domain Driven Design
     A domain is the activity or business of the user

     Domain Driven Design is about

       focussing on the domain and domain logic

       accurately mapping the domain concepts to software

       forming a ubiquitous language among the project members




Development with FLOW3                                           Inspiring people to
                                                             share
Domain Driven Design


Ubiquitous language
       The common vocabulary is an important prerequisite
       for successful collaboration

       Use the same words for discussion, modeling, development
       and documentation




Development with FLOW3                                            Inspiring people to
                                                                  share
Domain Driven Design


Layered Architecture

                       View
    Presentation       Controller

                       Application Logic (Service Layer)
        Domain         Domain Model (Domain Layer)

                       Data Mapper (part of Content Repository)
     Data source       Data Source Abstraction




Development with FLOW3                                            Inspiring people to
                                                                  share
Domain Driven Design


Layered Architecture

                       View
    Presentation       Controller

                       Application Logic (Service Layer)
        Domain         Domain Model (Domain Layer)

                       Data Mapper (part of Content Repository)
     Data source       Data Source Abstraction




Development with FLOW3                                            Inspiring people to
                                                                  share
Persistence




Development with FLOW3   Inspiring people to
                         share
Persistence


JSR-283 based Content Repository
       Defines a uniform API for accessing content repositories

       A Content Repository

          is a kind of object database for storage, search and retrieval of hierarchical
          data

          provides methods for versioning, transactions and monitoring

       TYPO3CR is the first working port of JSR-170 / JSR-283

       Karsten Dambekalns is member of the JSR-283 expert group


Development with FLOW3                                                 Inspiring people to
                                                                       share
Persistence


Transparent Persistence
       Explicit support for Domain-Driven Design

       Class Schemata are defined by the Domain Model class

          No need to write an XML or YAML schema definition

          No need to define the database model and object model multiple
          times at different places

       Automatic persistence in the JSR-283 based Content Repository

       Legacy data sources can be mounted


Development with FLOW3                                             Inspiring people to
                                                                   share
DEMO

Development with FLOW3     Inspiring people to
                           share
Configuration




Hitchhiker's Guide FLOW3
Development with to FLOW3   Inspiring people to
                            share
Configuration




Hitchhiker's Guide FLOW3
Development with to FLOW3   Inspiring people to
                            share
Configuration


Configuration Format
       The default configuration format is PHP

       Configuration options reside in a configuration object

       The configuration object provides array access and a fluent
       interface

       Configuration options are self-documenting




Development with FLOW3                                             Inspiring people to
                                                                   share
Configuration


Configuration Format




Development with FLOW3   Inspiring people to
                         share
Configuration


Configuration Types
       FLOW3 distinguishes between different configuration types
       for different purposes:

         FLOW3 - reserved for FLOW3 configuration

         Package - package related configuration

         Component - configuration for components, including
         Dependency Injection

         Routes - special configuration for defining MVC routes



Development with FLOW3                                            Inspiring people to
                                                                  share
Configuration


Configuration Types




Development with FLOW3   Inspiring people to
                         share
Configuration


The Cascade
       Each package defines possible configuration options by
       setting default values

       Default configuration can be altered by user-defined
       configuration files

       User configuration can only modify existing configuration
       options

       Modifying non-existent configuration options results in an
       error



Development with FLOW3                                             Inspiring people to
                                                                   share
Configuration


Application Context
       An application context is a set of configuration for a specific context

       FLOW3 is shipped with configuration for these contexts:

         Production
         Development
         Testing
         Staging

       FLOW3 is always launched in one defined context



Development with FLOW3                                               Inspiring people to
                                                                     share
Configuration


Application Context
       Configuration defined in the top level of a Configuration
       directory is the base configuration

       Specialized configuration for application contexts reside in
       subdirectories named after the context

       Application context configuration overrides the base
       configuration




Development with FLOW3                                               Inspiring people to
                                                                     share
Configuration


Application Context




Development with FLOW3   Inspiring people to
                         share
REST Services




Development with FLOW3   Inspiring people to
                         share
Security




Development with FLOW3   Inspiring people to
                         share
Playground




Development with FLOW3   Inspiring people to
                         share
Things to play with


F3BLOG
       Try out the Blog Example:
       svn co https://svn.typo3.org/FLOW3/Distribution/branches/BlogExample/




Development with FLOW3                                   Inspiring people to
                                                         share
Things to play with


TYPO3CR Admin
       Play with persistence and watch your object in the TYPO3CR Admin




Development with FLOW3                                             Inspiring people to
                                                                  share
Things to play with


Testrunner
       Experiment with Test-Driven Development and watch the tests in
       FLOW3's test runner




Development with FLOW3                                            Inspiring people to
                                                                  share
Progress

             Developing TYPO3 5.0 ...




Development with FLOW3                  Inspiring people to
                                        share
Current State
     AOP

     Component

     Configuration

     Cache

     Error

     Event

                    0    25   50   75   100

Development with FLOW3                        Inspiring people to
                                              share
Current State
     Locale

     Log

     MVC

     Package

     Persistence

     Property

                    0    20   40   60   80

Development with FLOW3                       Inspiring people to
                                             share
Current State
     Reflection

     Resource

     Session

     Utility

     Validation

                    0    25   50   75   100



Development with FLOW3                        Inspiring people to
                                              share
Next Steps
     First FLOW3 beta release end of this year

     First pilot projects based on FLOW3 in winter '08 / spring '09

     Further development of the CMS package

     Planned release of TYPO3 5.0 beta: end of 2009




Development with FLOW3                                                Inspiring people to
                                                                      share
Links
     FLOW3 Website
     http://flow3.typo3.org

     TYPO3 Forge
     http://forge.typo3.org

     Coding Guidelines
     http://flow3.typo3.org/documentation/coding-guidelines/

     Further Reading
     http://flow3.typo3.org/about/principles/further-reading/



Development with FLOW3                                         Inspiring people to
                                                               share
Further Reading
http://flow3.typo3.org/about/principles/further-reading/




Development with FLOW3                       Inspiring people to
                                             share
Questions




Development with FLOW3   Inspiring people to
                         share
T3CON08 FLOW3 Tutorial

Más contenido relacionado

Más de Robert Lemke

A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)Robert Lemke
 
Neos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteNeos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteRobert Lemke
 
A practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSA practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSRobert Lemke
 
Neos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteNeos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteRobert Lemke
 
IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes Robert Lemke
 
IPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersIPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersRobert Lemke
 
Docker in Production - IPC 2016
Docker in Production - IPC 2016Docker in Production - IPC 2016
Docker in Production - IPC 2016Robert Lemke
 
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Robert Lemke
 
The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)Robert Lemke
 
Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Robert Lemke
 
Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Robert Lemke
 
Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Robert Lemke
 
Turning Neos inside out / React.js HH
Turning Neos inside out / React.js HHTurning Neos inside out / React.js HH
Turning Neos inside out / React.js HHRobert Lemke
 
Docker in Production - IPC 15 München
Docker in Production - IPC 15 MünchenDocker in Production - IPC 15 München
Docker in Production - IPC 15 MünchenRobert Lemke
 
Two Stack CMS - code.talks 2015
Two Stack CMS - code.talks 2015Two Stack CMS - code.talks 2015
Two Stack CMS - code.talks 2015Robert Lemke
 
Two Stack CMS – code.talks Hamburg 2015
Two Stack CMS – code.talks Hamburg 2015Two Stack CMS – code.talks Hamburg 2015
Two Stack CMS – code.talks Hamburg 2015Robert Lemke
 
Neos: Assets in the Cloud - Inspiring Conference 2015
Neos: Assets in the Cloud - Inspiring Conference 2015Neos: Assets in the Cloud - Inspiring Conference 2015
Neos: Assets in the Cloud - Inspiring Conference 2015Robert Lemke
 
Neos – Past, Present, Future – Keynote Inspiring Conference 2015
Neos – Past, Present, Future – Keynote Inspiring Conference 2015Neos – Past, Present, Future – Keynote Inspiring Conference 2015
Neos – Past, Present, Future – Keynote Inspiring Conference 2015Robert Lemke
 
SPHERE.IO & Neos (eCommerce Camp Jena)
SPHERE.IO & Neos (eCommerce Camp Jena)SPHERE.IO & Neos (eCommerce Camp Jena)
SPHERE.IO & Neos (eCommerce Camp Jena)Robert Lemke
 
Multi Language Websites with TYPO3 Neos
Multi Language Websites with TYPO3 NeosMulti Language Websites with TYPO3 Neos
Multi Language Websites with TYPO3 NeosRobert Lemke
 

Más de Robert Lemke (20)

A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)
 
Neos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteNeos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome Keynote
 
A practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSA practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRS
 
Neos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteNeos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome Keynote
 
IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes
 
IPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersIPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for Developers
 
Docker in Production - IPC 2016
Docker in Production - IPC 2016Docker in Production - IPC 2016
Docker in Production - IPC 2016
 
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
 
The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)
 
Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)
 
Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!
 
Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!
 
Turning Neos inside out / React.js HH
Turning Neos inside out / React.js HHTurning Neos inside out / React.js HH
Turning Neos inside out / React.js HH
 
Docker in Production - IPC 15 München
Docker in Production - IPC 15 MünchenDocker in Production - IPC 15 München
Docker in Production - IPC 15 München
 
Two Stack CMS - code.talks 2015
Two Stack CMS - code.talks 2015Two Stack CMS - code.talks 2015
Two Stack CMS - code.talks 2015
 
Two Stack CMS – code.talks Hamburg 2015
Two Stack CMS – code.talks Hamburg 2015Two Stack CMS – code.talks Hamburg 2015
Two Stack CMS – code.talks Hamburg 2015
 
Neos: Assets in the Cloud - Inspiring Conference 2015
Neos: Assets in the Cloud - Inspiring Conference 2015Neos: Assets in the Cloud - Inspiring Conference 2015
Neos: Assets in the Cloud - Inspiring Conference 2015
 
Neos – Past, Present, Future – Keynote Inspiring Conference 2015
Neos – Past, Present, Future – Keynote Inspiring Conference 2015Neos – Past, Present, Future – Keynote Inspiring Conference 2015
Neos – Past, Present, Future – Keynote Inspiring Conference 2015
 
SPHERE.IO & Neos (eCommerce Camp Jena)
SPHERE.IO & Neos (eCommerce Camp Jena)SPHERE.IO & Neos (eCommerce Camp Jena)
SPHERE.IO & Neos (eCommerce Camp Jena)
 
Multi Language Websites with TYPO3 Neos
Multi Language Websites with TYPO3 NeosMulti Language Websites with TYPO3 Neos
Multi Language Websites with TYPO3 Neos
 

T3CON08 FLOW3 Tutorial

  • 1. T3CON08 Inspiring people to Development with FLOW3 share
  • 2. The History of FLOW3 (short version)
  • 3. The Long History of TYPO3 Since 1998 33 core members committed 500.000 lines of code resulting in a code base of 300.000 lines today
  • 4. The Long History of TYPO3 Since 1998 33 core members committed 500.000 lines of code resulting in a code base of 300.000 lines today
  • 5. TYPO3 today TYPO3 v4 is nearly feature complete Focus of the last releases were usbility improvements for the users Grown architecture, no unit tests Fundamental changes are risky / impossible Often used as application framework - but it's a CMS Development with FLOW3 Inspiring people to share
  • 6. TYPO3 tomorrow? Development with FLOW3 Inspiring people to share
  • 8. Topictext Source: The Secret Archives of TYPO3
  • 9. ”We need a new framework!“
  • 10. Buy none get two for free. Development with FLOW3 Inspiring people to share
  • 11. TYPO3 tomorrow FLOW3 acts as a reliable basis for any kind of web application TYPO3 v5 is a package based on FLOW3 Extensions are packages as well, all based on FLOW3 Packages can be used as extensions for TYPO3 as libraries for standalone applications Development with FLOW3 Inspiring people to share
  • 12. The FLOW3 experience Flow [fl!] The mental state of operation in which the person is fully immersed in what he or she is doing by a feeling of energized focus, full involvement, and success in the process of the activity. Proposed by positive psychologist Mihály Csíkszentmihályi, the concept has been widely referenced across a variety of fields. FLOW3 [fl!'three] The application framework which takes care of all hassle and lets you play the fun part. Development with FLOW3 Inspiring people to share
  • 13. FLOW3 = Application Framework Not just a collection of components or code snippet library Comes with ready-to-go default configuration Package based Runs with PHP 5.3 or later Comes with a powerful JSR-283 based Content Repository Development with FLOW3 Inspiring people to share
  • 14. Get the FLOW experience Intuitive APIs Readable source code (like a book) Consistent naming for classes, methods and properties Focus on the essential, the framework takes care of the infrastructure Development with FLOW3 Inspiring people to share
  • 15. FLOW3 modules AOP Locale Reflection Component Log Resource Configuration MVC Session Cache Package Utility Error Persistence Validation Event Property ... and more Development with FLOW3 Inspiring people to share
  • 16. Getting Started Development with FLOW3 Inspiring people to share
  • 17. Getting Started Requirements Some webserver (tested with Apache and IIS) PHP 5.3 or higher (see http://snaps.php.net/) PHP extensions: zlib, PDO and PDO SQLite and the usual stuff Some database (tested with SQLite, MySQL and Postgres) Development with FLOW3 Inspiring people to share
  • 18. Getting Started Download Currently available through Subversion Checkout the FLOW3 Distribution: svn co https://svn.typo3.org/FLOW3/distribution/trunk or try the TYPO3 Distribution: svn co https://svn.typo3.org/TYPO3v5/distribution/trunk Nightly builds will follow as soon as we've set up our release mechanism Development with FLOW3 Inspiring people to share
  • 19. Getting Started Grant File Permissions The webserver needs read access for all files of the distribution and write access in the Public and Data directory On Linux / Mac just call sudo ./fixpermissions.sh On legacy operating systems: ask your system administrator Development with FLOW3 Inspiring people to share
  • 20. Getting Started Create a package In order to create a new package, just create a new folder within the Packages directory. Development with FLOW3 Inspiring people to share
  • 21. Getting Started Create a Default Controller Create a subfolder in your package: Classes/Controller/ Create the controller class file: Development with FLOW3 Inspiring people to share
  • 22.
  • 23.
  • 24. Bootstrap Development with FLOW3 Inspiring people to share
  • 25. Bootstrap Public/ Development with FLOW3 Inspiring people to share
  • 26. Bootstrap Public/index.php This file is the default main script It launches FLOW3 in the Production context The webserver's web root should point to the Public directory define('FLOW3_PATH_PUBLIC', str_replace('', '/', __DIR__) . '/'); require(FLOW3_PATH_PUBLIC . '../Packages/FLOW3/Classes/F3_FLOW3.php'); $framework = new F3::FLOW3(); $framework->run(); Development with FLOW3 Inspiring people to share
  • 27. Bootstrap Public/index_dev.php This script is used for development It launches FLOW3 in the Development context More scripts like this can be created for additional contexts define('FLOW3_PATH_PUBLIC', str_replace('', '/', __DIR__) . '/'); require(FLOW3_PATH_PUBLIC . '../Packages/FLOW3/Classes/F3_FLOW3.php'); $framework = new F3::FLOW3('Development'); $framework->run(); Development with FLOW3 Inspiring people to share
  • 28. Bootstrap $FLOW3->run() run() is a convenience method which initializes the FLOW3 framework resolves a request handler handles and responses to the request Development with FLOW3 Inspiring people to share
  • 29. Bootstrap $FLOW3->initialize() The initialization process is divided into different stages: Initialize FLOW3 Initialize the packages Initialize the components Initialize the settings Initialize the resources The configuration for each level can't be changed once the initialization level is reached Development with FLOW3 Inspiring people to share
  • 30. Bootstrap Beware of Caching Don't forget to run FLOW3 in Development context while you're developing because component configuration is cached in production mode, so new classes won't be recognized resources are cached in production mode, so changes won't be detected and many more things might be cached which lead to unexpected errors if you change some code in your package Development with FLOW3 Inspiring people to share
  • 31. Bootstrap Just in Case If you need to clear the cache, just remove all files from the Data/Temporary/ directory Yes, there will be a backend function and command line tool for this Development with FLOW3 Inspiring people to share
  • 32. Solving Beginner's Problems Development with FLOW3 Inspiring people to share
  • 33. Topictext Development with FLOW3 Inspiring people to share
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. Model - View - Controller Development with FLOW3 Inspiring people to share
  • 39. The MVC Pattern Model an object which contains data and business logic of a certain domain doesn't contain any information about the presentation of that data, but rather defines the behaviour in the FLOW3 project we prefer a special kind of model, the Domain Model Development with FLOW3 Inspiring people to share
  • 40. The MVC Pattern View represents the display of the model on the web or another output channel views only display data, they don't build or modify it Development with FLOW3 Inspiring people to share
  • 41. The MVC Pattern Controller reacts on user input, selects and manipulates the model as accordingly selects a view and passes it the prepared model for rendering Development with FLOW3 Inspiring people to share
  • 42. MVC Action Controller An action controller accepts a request evaluates arguments calls the action defined in the request and adds output to the response Development with FLOW3 Inspiring people to share
  • 43. MVC Action Controller: Important Methods Actions - methods just need an "Action" suffix: public function indexAction() { ... } public function deleteAction() { ... } Initialization for the whole controller: public function initializeController() { ... } Initialization of arguments: public function initializeArguments() { ... } Initialization before any action is called: public function initializeAction() { ... } Development with FLOW3 Inspiring people to share
  • 44. DEMO Development with FLOW3 Inspiring people to share
  • 45.
  • 46. Validation Development with FLOW3 Inspiring people to share
  • 47. Validating Arguments All arguments passed to an Action Controller (more precisely: Request Handling Controller) are automatically validated White List policy: Only registered arguments are available Accessing the $_GET and $_POST super globals is dangerous, dirty, deprecated and will probably be intercepted in the future Development with FLOW3 Inspiring people to share
  • 48. Validating Arguments FLOW3 comes with a bunch of built in validators: AlphaNumeric, EmailAddress, Float, Integer, NotEmpty, Number, NumberRange, RegularExpression, UUID, Text Custom validators can be created (especially for Domain Models) All validators can be chained (and nested) Development with FLOW3 Inspiring people to share
  • 49. DEMO Development with FLOW3 Inspiring people to share
  • 50. Components Development with FLOW3 Inspiring people to share
  • 51. Components Components Components are re-usable, properly encapsulated objects The lifecycle of a component and the combination of active components is managed by the Component Manager All classes in the TYPO3 context are considered as components Components are configurable Development with FLOW3 Inspiring people to share
  • 52. Components Class ! Component Classes are automatically registered as components if they reside in the Classes directory of a package and their name follows the FLOW3 naming conventions Development with FLOW3 Inspiring people to share
  • 53. Components Example Development with FLOW3 Inspiring people to share
  • 54. Components Playing with building blocks The combination of components used is configurable (orchestration) The less components know about each other the easier it is to reuse them in a variety of contexts Create your own LEGO set by creating cleanly separated, decoupled components! Development with FLOW3 Inspiring people to share
  • 55. Components Component Dependencies Components seldomly come alone Components depend on other components which depend on other components which ... Problem: Components explicitly refer to other components: $phoneBookManager = new PhoneBookManager Development with FLOW3 Inspiring people to share
  • 56. Components Dependency Injection A component doesn't ask for the instance of another component but gets it injected This methodology is referred to as the "Hollywood Principle": "Don't call us, we'll call you" Enforces loose coupling and high cohesion Makes you a better programmer Development with FLOW3 Inspiring people to share
  • 57. Components Constructor without Dependency Injection Development with FLOW3 Inspiring people to share
  • 58. Components Component with Constructor Injection Development with FLOW3 Inspiring people to share
  • 59. Components Component with Setter Injection Development with FLOW3 Inspiring people to share
  • 60. Components Autowiring FLOW3's framework tries to autowire constructor arguments and arguments of inject* methods The type of the component to be injected is determined by the argument type (type hinting) Autowiring does not work with Setter Injection through regular setters (set* methods) Dependencies are only autowired if no argument is passed explicitly Development with FLOW3 Inspiring people to share
  • 61. Components Fetching components manually Although Dependency Injection is strongly recommended, there might be cases in which components need to be created or retrieved manually Use the getComponent() method in these cases. $component = $componentManager->getComponent($componentName, $arg1, $arg2, ...); Development with FLOW3 Inspiring people to share
  • 62. Components Component scope Component objects always live in a certain scope Currently supported scopes are: Singleton - Only one instance exists during one script run Prototype - Each getComponent() call returns a fresh instance Development with FLOW3 Inspiring people to share
  • 63. Components Component scope The scope can be defined through an annotation in the component class (recommended) through the component configuration in a Components.php file The default scope is "Singleton" Development with FLOW3 Inspiring people to share
  • 64. Components Component scope Development with FLOW3 Inspiring people to share
  • 65. Components Creating Prototypes Dependency Injection can be used in almost any case, there's no need to call getComponent() But what if you need to instantiate a component within a method? Development with FLOW3 Inspiring people to share
  • 66. Components Creating Prototypes Solution A: Call getComponent() Development with FLOW3 Inspiring people to share
  • 67. Components Creating Prototypes Solution B: Call a factory method Development with FLOW3 Inspiring people to share
  • 68. Components Creating Prototypes Planned feature: Automatically generated factory methods Development with FLOW3 Inspiring people to share
  • 69. Domain Driven Design A domain is the activity or business of the user Domain Driven Design is about focussing on the domain and domain logic accurately mapping the domain concepts to software forming a ubiquitous language among the project members Development with FLOW3 Inspiring people to share
  • 70. Domain Driven Design Ubiquitous language The common vocabulary is an important prerequisite for successful collaboration Use the same words for discussion, modeling, development and documentation Development with FLOW3 Inspiring people to share
  • 71. Domain Driven Design Layered Architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper (part of Content Repository) Data source Data Source Abstraction Development with FLOW3 Inspiring people to share
  • 72. Domain Driven Design Layered Architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper (part of Content Repository) Data source Data Source Abstraction Development with FLOW3 Inspiring people to share
  • 73. Persistence Development with FLOW3 Inspiring people to share
  • 74. Persistence JSR-283 based Content Repository Defines a uniform API for accessing content repositories A Content Repository is a kind of object database for storage, search and retrieval of hierarchical data provides methods for versioning, transactions and monitoring TYPO3CR is the first working port of JSR-170 / JSR-283 Karsten Dambekalns is member of the JSR-283 expert group Development with FLOW3 Inspiring people to share
  • 75. Persistence Transparent Persistence Explicit support for Domain-Driven Design Class Schemata are defined by the Domain Model class No need to write an XML or YAML schema definition No need to define the database model and object model multiple times at different places Automatic persistence in the JSR-283 based Content Repository Legacy data sources can be mounted Development with FLOW3 Inspiring people to share
  • 76. DEMO Development with FLOW3 Inspiring people to share
  • 77. Configuration Hitchhiker's Guide FLOW3 Development with to FLOW3 Inspiring people to share
  • 78. Configuration Hitchhiker's Guide FLOW3 Development with to FLOW3 Inspiring people to share
  • 79. Configuration Configuration Format The default configuration format is PHP Configuration options reside in a configuration object The configuration object provides array access and a fluent interface Configuration options are self-documenting Development with FLOW3 Inspiring people to share
  • 80. Configuration Configuration Format Development with FLOW3 Inspiring people to share
  • 81. Configuration Configuration Types FLOW3 distinguishes between different configuration types for different purposes: FLOW3 - reserved for FLOW3 configuration Package - package related configuration Component - configuration for components, including Dependency Injection Routes - special configuration for defining MVC routes Development with FLOW3 Inspiring people to share
  • 82. Configuration Configuration Types Development with FLOW3 Inspiring people to share
  • 83. Configuration The Cascade Each package defines possible configuration options by setting default values Default configuration can be altered by user-defined configuration files User configuration can only modify existing configuration options Modifying non-existent configuration options results in an error Development with FLOW3 Inspiring people to share
  • 84. Configuration Application Context An application context is a set of configuration for a specific context FLOW3 is shipped with configuration for these contexts: Production Development Testing Staging FLOW3 is always launched in one defined context Development with FLOW3 Inspiring people to share
  • 85. Configuration Application Context Configuration defined in the top level of a Configuration directory is the base configuration Specialized configuration for application contexts reside in subdirectories named after the context Application context configuration overrides the base configuration Development with FLOW3 Inspiring people to share
  • 86. Configuration Application Context Development with FLOW3 Inspiring people to share
  • 87. REST Services Development with FLOW3 Inspiring people to share
  • 88. Security Development with FLOW3 Inspiring people to share
  • 89. Playground Development with FLOW3 Inspiring people to share
  • 90. Things to play with F3BLOG Try out the Blog Example: svn co https://svn.typo3.org/FLOW3/Distribution/branches/BlogExample/ Development with FLOW3 Inspiring people to share
  • 91. Things to play with TYPO3CR Admin Play with persistence and watch your object in the TYPO3CR Admin Development with FLOW3 Inspiring people to share
  • 92. Things to play with Testrunner Experiment with Test-Driven Development and watch the tests in FLOW3's test runner Development with FLOW3 Inspiring people to share
  • 93. Progress Developing TYPO3 5.0 ... Development with FLOW3 Inspiring people to share
  • 94. Current State AOP Component Configuration Cache Error Event 0 25 50 75 100 Development with FLOW3 Inspiring people to share
  • 95. Current State Locale Log MVC Package Persistence Property 0 20 40 60 80 Development with FLOW3 Inspiring people to share
  • 96. Current State Reflection Resource Session Utility Validation 0 25 50 75 100 Development with FLOW3 Inspiring people to share
  • 97. Next Steps First FLOW3 beta release end of this year First pilot projects based on FLOW3 in winter '08 / spring '09 Further development of the CMS package Planned release of TYPO3 5.0 beta: end of 2009 Development with FLOW3 Inspiring people to share
  • 98. Links FLOW3 Website http://flow3.typo3.org TYPO3 Forge http://forge.typo3.org Coding Guidelines http://flow3.typo3.org/documentation/coding-guidelines/ Further Reading http://flow3.typo3.org/about/principles/further-reading/ Development with FLOW3 Inspiring people to share
  • 100. Questions Development with FLOW3 Inspiring people to share