Gianluca Arbezzano
@GianArb

https://github.com/GianArb
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
There is a module for
everything!

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
How?!

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Packaging AND
Code Reuse

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
PSR are your best friends!
PSR standards are the pillars
of interoperability
PHP-CS-Fixer
http://cs.sensiolabs.org/

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Where/is/my/dir?

Follow the framework tree
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Configuration is necessary..
• Do not overdo
• Don’t be lazy
• Choose pertinent index names
• User namespace
• Set default values

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
There are different
configuration layers
module.config.php
global.php
local.php
….
Use /config/autoload directory for manage
options override!
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Good Implementation!
ZendDeveloperToolsModule
public function onBootstrap(EventInterface $event)
{
……
if (!$options->isEnabled()) {
return;
}
…...
$em->attachAggregate($sm->get('ZendDeveloperToolsProfilerListener'));
if ($options->isToolbarEnabled()) {
$sem->attach('profiler', $sm->get('ZendDeveloperToolsToolbarListener'), null);
…….
}
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
How to register a module inside
your application
return array(
'modules' => array(
’Application',
’MyModule’,
…..
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Think abaut an
overridable
configuration
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Config
Application
'controllers' => array(
'invokables' => array(
'ApplicationControllerIndex' => 'ApplicationControllerIndexController',
),
),

MyModule
'controllers' => array(
'invokables' => array(
'ApplicationControllerIndex' => ’MyModuleControllerIndexController',
),
),

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Override views
Application

MyModule

Config:

Config:

'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),

'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),

Directorty Structure:

Directory Structure:

view/
index/
index/
index.phtml

view/
index/
index/
index.phtml

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Console Usage
class Module {
public function getConsoleUsage(AdapterInterface $console)
{
return array(
array('test [--params=]', 'Description of test command’),
array('run ', 'Start anction')
);
}
}

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Console entry point
Example
https://github.com/doctrine/DoctrineModule/tree/master/bin

Composer:
{
…,
“bin”: [
bin/console-file
],
…
}
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Service locator!
ServiceFactory VS Closure
Closure isn’t serializable
Module.php is more readable

Closures limit the ability to cache the cofiguration

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Register Event to
increase flexibility!

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Aggregate & composition

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Composer or Not Composer

Both!
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Zend Framework is modular!
{
“name”: “my-module/use-only-feed-component”,
“description”:”Automatic feed reader”,
“licence” : “MIT”,
…..,
“require”:[
“zend-framework/zend-framework” : “2.2.*”
],
}

"require": {
"php": ">=5.3.3",
"zendframework/zend-feed": "self.version”
},

https://github.com/robertboloc/zf2-components-list-generator
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Open Source..
Why?

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Portfolio

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
More
implementations
=
More BUG FIXS
and
More features
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Implement your module into
Zend Skeleton Application

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Gianluca Arbezzano - @GianArb – https://github.com/GianArb
#IRC
#zftalk

#zftalk.modules

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Test
PhpUnit

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Write Issues!
help your future contributors

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Git: handle with care!

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
README.md

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
PhpDoc
**
* This is a summary.
*
* This is a description
*/

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Documentation

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Some good modules

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Some good modules

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Some good modules

Gianluca Arbezzano - @GianArb – https://github.com/GianArb
Modules Repository

Gianluca Arbezzano - @GianArb – https://github.com/GianArb

ZfDayIt 2014 - There is a module for everything