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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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