ZfDayIt 2014 - There is a module for everything

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

description

There is a module for evenrything, zend framework is a modular framework. How can I write good code? Packaging and reuse code is an important practice for write good application.

Transcript of ZfDayIt 2014 - There is a module for everything

Page 1: ZfDayIt 2014 - There is a module for everything

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

Gianluca Arbezzano@GianArb

https://github.com/GianArb

Page 2: ZfDayIt 2014 - There is a module for everything

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

There is a module for everything!

Page 3: ZfDayIt 2014 - There is a module for everything

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

How?!

Page 4: ZfDayIt 2014 - There is a module for everything

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

Page 5: ZfDayIt 2014 - There is a module for everything

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

Packaging ANDCode Reuse

Page 6: ZfDayIt 2014 - There is a module for everything

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

PSR are your best friends!

PHP-CS-Fixerhttp://cs.sensiolabs.org/

PSR standards are the pillarsof interoperability

Page 7: ZfDayIt 2014 - There is a module for everything

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

Where/is/my/dir?

Follow the framework tree

Page 8: ZfDayIt 2014 - There is a module for everything

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

Page 9: ZfDayIt 2014 - There is a module for everything

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

There are different configuration layers

module.config.phpglobal.phplocal.php….

Use /config/autoload directory for manageoptions override!

Page 10: ZfDayIt 2014 - There is a module for everything

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

Good Implementation!

ZendDeveloperTools\Modulepublic function onBootstrap(EventInterface $event) {

…… if (!$options->isEnabled()) { return; } …... $em->attachAggregate($sm->get('ZendDeveloperTools\ProfilerListener')); if ($options->isToolbarEnabled()) { $sem->attach('profiler', $sm->get('ZendDeveloperTools\ToolbarListener'), null); ……. }

Page 11: ZfDayIt 2014 - There is a module for everything

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', ), ),);

Page 12: ZfDayIt 2014 - There is a module for everything

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

Think abaut an overridable

configuration

Page 13: ZfDayIt 2014 - There is a module for everything

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

ConfigApplication'controllers' => array( 'invokables' => array( 'Application\Controller\Index' => 'Application\Controller\IndexController', ),),

MyModule'controllers' => array( 'invokables' => array( 'Application\Controller\Index' => ’MyModule\Controller\IndexController', ),),

Page 14: ZfDayIt 2014 - There is a module for everything

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

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

Directorty Structure:view/ index/ index/ index.phtml

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

Directory Structure:view/ index/ index/ index.phtml

Page 15: ZfDayIt 2014 - There is a module for everything

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

Console Usageclass Module {

public function getConsoleUsage(AdapterInterface $console) {

return array( array('test [--params=]', 'Description of test command’),array('run ', 'Start anction')

); }

}

Page 16: ZfDayIt 2014 - There is a module for everything

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

Console entry point

Examplehttps://github.com/doctrine/DoctrineModule/tree/master/bin

Composer:

{…,“bin”: [

bin/console-file],…

}

Page 17: ZfDayIt 2014 - There is a module for everything

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

Service locator!

ServiceFactory VS ClosureClosure isn’t serializable

Module.php is more readable

Closures limit the ability to cache the cofiguration

Page 18: ZfDayIt 2014 - There is a module for everything

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

Register Event to increase flexibility!

Page 19: ZfDayIt 2014 - There is a module for everything

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

Aggregate & composition

Page 20: ZfDayIt 2014 - There is a module for everything

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

Composer or Not Composer

Both!

Page 21: ZfDayIt 2014 - There is a module for everything

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.*”],

}

https://github.com/robertboloc/zf2-components-list-generator

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

Page 22: ZfDayIt 2014 - There is a module for everything

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

Open Source.. Why?

Page 23: ZfDayIt 2014 - There is a module for everything

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

Portfolio

Page 24: ZfDayIt 2014 - There is a module for everything

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

More implementations

= More BUG FIXS

andMore features

Page 25: ZfDayIt 2014 - There is a module for everything

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

Implement your module into Zend Skeleton Application

Page 26: ZfDayIt 2014 - There is a module for everything

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

Page 27: ZfDayIt 2014 - There is a module for everything

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

#IRC

#zftalk

#zftalk.modules

Page 28: ZfDayIt 2014 - There is a module for everything

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

Test PhpUnit

Page 29: ZfDayIt 2014 - There is a module for everything

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

Write Issues! help your future contributors

Page 30: ZfDayIt 2014 - There is a module for everything

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

Git: handle with care!

Page 31: ZfDayIt 2014 - There is a module for everything

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

README.md

Page 32: ZfDayIt 2014 - There is a module for everything

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

PhpDoc** * This is a summary. * * This is a description */

Page 33: ZfDayIt 2014 - There is a module for everything

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

Documentation

Page 34: ZfDayIt 2014 - There is a module for everything

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

Some good modules

Page 35: ZfDayIt 2014 - There is a module for everything

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

Some good modules

Page 36: ZfDayIt 2014 - There is a module for everything

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

Some good modules

Page 37: ZfDayIt 2014 - There is a module for everything

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

Modules Repository