Your SlideShare is downloading. ×
T3CON08 FLOW3 Tutorial
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

T3CON08 FLOW3 Tutorial

1,519
views

Published on

FLOW3 is a powerful and mondern web application framework for PHP. And FLOW3 is the foundation of TYPO3 version 5. The fact that you can develop both, TYPO3 extensions and standalone applications …

FLOW3 is a powerful and mondern web application framework for PHP. And FLOW3 is the foundation of TYPO3 version 5. The fact that you can develop both, TYPO3 extensions and standalone applications based on the same framework allows for reusing your code, knowledge and infrastructure in a bigger variety of projects.

FLOW3 introduces many new development concepts to the PHP world, but still makes development much easier even without having to know them. However, a golden rule says: "Don’t fight your framework" - so it makes a lot of sense to understand the concepts behind FLOW3 in order to tap its full potential.

In this is tutorial the participants got a first-hand introduction to the concepts behind FLOW3


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,519
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. T3CON08 Inspiring people toDevelopment 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 its a CMSDevelopment with FLOW3 Inspiring people to share
  • 6. TYPO3 tomorrow?Development with FLOW3 Inspiring people to share
  • 7. Whystart from scratch?
  • 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 applicationsDevelopment 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 RepositoryDevelopment 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 infrastructureDevelopment 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 moreDevelopment with FLOW3 Inspiring people to share
  • 16. Getting StartedDevelopment with FLOW3 Inspiring people to share
  • 17. Getting StartedRequirements 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 StartedDownload 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 weve set up our release mechanismDevelopment with FLOW3 Inspiring people to share
  • 19. Getting StartedGrant 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 administratorDevelopment with FLOW3 Inspiring people to share
  • 20. Getting StartedCreate a packageIn order to create a new package, just createa new folder within the Packages directory.Development with FLOW3 Inspiring people to share
  • 21. Getting StartedCreate a Default Controller Create a subfolder in your package: Classes/Controller/ Create the controller class file:Development with FLOW3 Inspiring people to share
  • 22. BootstrapDevelopment with FLOW3 Inspiring people to share
  • 23. BootstrapPublic/Development with FLOW3 Inspiring people to share
  • 24. BootstrapPublic/index.php This file is the default main script It launches FLOW3 in the Production context The webservers 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
  • 25. BootstrapPublic/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
  • 26. Bootstrap$FLOW3->run() run() is a convenience method which initializes the FLOW3 framework resolves a request handler handles and responses to the requestDevelopment with FLOW3 Inspiring people to share
  • 27. 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 cant be changed once the initialization level is reachedDevelopment with FLOW3 Inspiring people to share
  • 28. BootstrapBeware of Caching Dont forget to run FLOW3 in Development context while youre developing because component configuration is cached in production mode, so new classes wont be recognized resources are cached in production mode, so changes wont be detected and many more things might be cached which lead to unexpected errors if you change some code in your packageDevelopment with FLOW3 Inspiring people to share
  • 29. BootstrapJust 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 thisDevelopment with FLOW3 Inspiring people to share
  • 30. Solving Beginners ProblemsDevelopment with FLOW3 Inspiring people to share
  • 31. TopictextDevelopment with FLOW3 Inspiring people to share
  • 32. Model - View - ControllerDevelopment with FLOW3 Inspiring people to share
  • 33. The MVC PatternModel an object which contains data and business logic of a certain domain doesnt 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 ModelDevelopment with FLOW3 Inspiring people to share
  • 34. The MVC PatternView represents the display of the model on the web or another output channel views only display data, they dont build or modify itDevelopment with FLOW3 Inspiring people to share
  • 35. The MVC PatternController reacts on user input, selects and manipulates the model as accordingly selects a view and passes it the prepared model for renderingDevelopment with FLOW3 Inspiring people to share
  • 36. MVCAction Controller An action controller accepts a request evaluates arguments calls the action defined in the request and adds output to the responseDevelopment with FLOW3 Inspiring people to share
  • 37. MVCAction 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
  • 38. DEMODevelopment with FLOW3 Inspiring people to share
  • 39. ValidationDevelopment with FLOW3 Inspiring people to share
  • 40. 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 futureDevelopment with FLOW3 Inspiring people to share
  • 41. 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
  • 42. DEMODevelopment with FLOW3 Inspiring people to share
  • 43. ComponentsDevelopment with FLOW3 Inspiring people to share
  • 44. ComponentsComponents 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 configurableDevelopment with FLOW3 Inspiring people to share
  • 45. ComponentsClass ! Component Classes are automatically registered as components if they reside in the Classes directory of a package and their name follows the FLOW3 naming conventionsDevelopment with FLOW3 Inspiring people to share
  • 46. ComponentsExampleDevelopment with FLOW3 Inspiring people to share
  • 47. ComponentsPlaying 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
  • 48. ComponentsComponent 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 PhoneBookManagerDevelopment with FLOW3 Inspiring people to share
  • 49. ComponentsDependency Injection A component doesnt ask for the instance of another component but gets it injected This methodology is referred to as the "Hollywood Principle": "Dont call us, well call you" Enforces loose coupling and high cohesion Makes you a better programmerDevelopment with FLOW3 Inspiring people to share
  • 50. ComponentsConstructor without Dependency InjectionDevelopment with FLOW3 Inspiring people to share
  • 51. ComponentsComponent with Constructor InjectionDevelopment with FLOW3 Inspiring people to share
  • 52. ComponentsComponent with Setter InjectionDevelopment with FLOW3 Inspiring people to share
  • 53. ComponentsAutowiring FLOW3s 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 explicitlyDevelopment with FLOW3 Inspiring people to share
  • 54. ComponentsFetching 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
  • 55. ComponentsComponent 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 instanceDevelopment with FLOW3 Inspiring people to share
  • 56. ComponentsComponent 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
  • 57. ComponentsComponent scopeDevelopment with FLOW3 Inspiring people to share
  • 58. ComponentsCreating Prototypes Dependency Injection can be used in almost any case, theres no need to call getComponent() But what if you need to instantiate a component within a method?Development with FLOW3 Inspiring people to share
  • 59. ComponentsCreating Prototypes Solution A: Call getComponent()Development with FLOW3 Inspiring people to share
  • 60. ComponentsCreating Prototypes Solution B: Call a factory methodDevelopment with FLOW3 Inspiring people to share
  • 61. ComponentsCreating Prototypes Planned feature: Automatically generated factory methodsDevelopment with FLOW3 Inspiring people to share
  • 62. 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 membersDevelopment with FLOW3 Inspiring people to share
  • 63. Domain Driven DesignUbiquitous language The common vocabulary is an important prerequisite for successful collaboration Use the same words for discussion, modeling, development and documentationDevelopment with FLOW3 Inspiring people to share
  • 64. Domain Driven DesignLayered Architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper (part of Content Repository) Data source Data Source AbstractionDevelopment with FLOW3 Inspiring people to share
  • 65. Domain Driven DesignLayered Architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper (part of Content Repository) Data source Data Source AbstractionDevelopment with FLOW3 Inspiring people to share
  • 66. PersistenceDevelopment with FLOW3 Inspiring people to share
  • 67. PersistenceJSR-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 groupDevelopment with FLOW3 Inspiring people to share
  • 68. PersistenceTransparent 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 mountedDevelopment with FLOW3 Inspiring people to share
  • 69. DEMODevelopment with FLOW3 Inspiring people to share
  • 70. ConfigurationHitchhikers Guide FLOW3Development with to FLOW3 Inspiring people to share
  • 71. ConfigurationHitchhikers Guide FLOW3Development with to FLOW3 Inspiring people to share
  • 72. ConfigurationConfiguration 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-documentingDevelopment with FLOW3 Inspiring people to share
  • 73. ConfigurationConfiguration FormatDevelopment with FLOW3 Inspiring people to share
  • 74. ConfigurationConfiguration 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 routesDevelopment with FLOW3 Inspiring people to share
  • 75. ConfigurationConfiguration TypesDevelopment with FLOW3 Inspiring people to share
  • 76. ConfigurationThe 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 errorDevelopment with FLOW3 Inspiring people to share
  • 77. ConfigurationApplication 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 contextDevelopment with FLOW3 Inspiring people to share
  • 78. ConfigurationApplication 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 configurationDevelopment with FLOW3 Inspiring people to share
  • 79. ConfigurationApplication ContextDevelopment with FLOW3 Inspiring people to share
  • 80. REST ServicesDevelopment with FLOW3 Inspiring people to share
  • 81. SecurityDevelopment with FLOW3 Inspiring people to share
  • 82. PlaygroundDevelopment with FLOW3 Inspiring people to share
  • 83. Things to play withF3BLOG Try out the Blog Example: svn co https://svn.typo3.org/FLOW3/Distribution/branches/BlogExample/Development with FLOW3 Inspiring people to share
  • 84. Things to play withTYPO3CR Admin Play with persistence and watch your object in the TYPO3CR AdminDevelopment with FLOW3 Inspiring people to share
  • 85. Things to play withTestrunner Experiment with Test-Driven Development and watch the tests in FLOW3s test runnerDevelopment with FLOW3 Inspiring people to share
  • 86. Progress Developing TYPO3 5.0 ...Development with FLOW3 Inspiring people to share
  • 87. Current State AOP Component Configuration Cache Error Event 0 25 50 75 100Development with FLOW3 Inspiring people to share
  • 88. Current State Locale Log MVC Package Persistence Property 0 20 40 60 80Development with FLOW3 Inspiring people to share
  • 89. Current State Reflection Resource Session Utility Validation 0 25 50 75 100Development with FLOW3 Inspiring people to share
  • 90. 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 2009Development with FLOW3 Inspiring people to share
  • 91. 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
  • 92. Further Readinghttp://flow3.typo3.org/about/principles/further-reading/Development with FLOW3 Inspiring people to share
  • 93. QuestionsDevelopment with FLOW3 Inspiring people to share

×