Zend Framework 1 had modules. Their name is pretty much everything Zend Framework 2 modules share with them, though. The whole framework architecture has been rewritten to encourage software reuse and extension. In this talk I’ll share our experiences on ZF2 module creation and usage.
5. A Module is…
5
A collection of code and other
files that solves a more specific
atomic problem of the larger
business problem.
ZF2 RFC
6. A re-usable piece of
functionality that can be used
to construct a more complex
application.
6
Evan Coury - http://evan.pro/zf2-modules-talk.html
A Module is…
7. A re-usable piece of
functionality that can be used
to construct a more complex
application.
7
Evan Coury - http://evan.pro/zf2-modules-talk.html
A Module is…
9. • 15.Reuse-in-the-small is a
solved problem.
• 16.Reuse-in-the-large remains
a mostly unsolved problem.
9
Robert R. Glass – Facts and Fallacies of Software Engineering
About Software Reuse
10. What I remember about ZF1 Modules…
10
Model
Admin Panel
content management, store management, contact requests, ...
Web Site
contents, product catalogue, contact form, …
11. What could we reuse?
11
Model
Admin Panel
content management, store management, contact requests, ...
Web Site
contents, product catalogue, contact form, …
49. 49
Format a date
Handle a
contact form
Handle ACLs
Integrate
an ORM
Encapsulate
a whole application
50. Let’s think about ZF1 once again…
50
Model
Admin Panel
content management, store management, contact requests, ...
Web Site
contents, product catalogue, contact form, …
51. This is how modules are now…
51
Web Site
Model
Admin Panel
Content
Management
52. Focus on features
52
Web Site
Model
Admin Panel
Product
Catalogue
Contact
Form
Content
Management
77. index.php
<?php
/**
* This makes our life easier when dealing with paths. Everything is
* relative to the application root now.
*/
chdir(dirname(__DIR__));
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
ZendMvcApplication::init(require 'config/application.config.php')->run();
78. index.php
<?php
/**
* This makes our life easier when dealing with paths. Everything is
* relative to the application root now.
*/
chdir(dirname(__DIR__));
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
ZendMvcApplication::init(require 'config/application.config.php')->run();
80. Module.php
namespace Application;
use ZendMvcModuleRouteListener;
use ZendMvcMvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{[…]}
public function getConfig() {
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig() {}
}
80
86. This is for all modules
86
return array(
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'SpeckPaypal',
'Application',
),
),
...
config/application.config.php
98. This happens for all modules
98
return array(
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'SpeckPaypal',
'Application',
),
),
...
config/application.config.php
Order
is Important!
99. LET’S LOOK AROUND FIRST!
Picture credits: http://www.flickr.com/photos/billward/5626976800
127. In a Controller Factory
<?php
public function createService(ServiceLocatorInterface $services){
$serviceLocator = $services->getServiceLocator();
$cartService = $serviceLocator->get('CartItem');
$controller = new CartController($cartService);
return $controller;
}
}
135. A re-usable piece of
functionality that can be used
to construct a more complex
application.
135
Evan Coury - http://evan.pro/zf2-modules-talk.html
Back to definition
136. A re-usable piece of
functionality that can be used
to construct a more complex
application.
136
Evan Coury - http://evan.pro/zf2-modules-talk.html
Now I understand it better!
137. I hope you too.
Stefano Maraspin
@maraspin
s.maraspin@mvassociati.it