Top Banner
Magento2 Code Generation BY Ashutosh Srivastava
19

Magento Meetup New Delhi- Magento2 code generation

Feb 11, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Magento Meetup New Delhi- Magento2 code generation

Magento2 Code Generation

BYAshutosh Srivastava

Page 2: Magento Meetup New Delhi- Magento2 code generation

Basic questions that can explain

the concept ?

What is code generation ?

What is the need of code generation in magento2 ?

How code generation works ?

Page 3: Magento Meetup New Delhi- Magento2 code generation

What is code

generation ?

code generation simply means the creation of non-existent classes automatically .

Page 4: Magento Meetup New Delhi- Magento2 code generation

What is the need of code generation in magento2 ?

to facilitate DI(Dependency Injection) in magento2.

to facilitate plugin system in magento2.

fast class loading.

Page 5: Magento Meetup New Delhi- Magento2 code generation

How Code Generation

Works?

Factory classesInterceptor

classesProxy classes

Page 6: Magento Meetup New Delhi- Magento2 code generation

Factory Code

Generation

if a class is suffixed with factory and it is passed to the object manager or in the constructor and if the class is not existing then magento will create the class automatically.

Page 7: Magento Meetup New Delhi- Magento2 code generation
Page 8: Magento Meetup New Delhi- Magento2 code generation
Page 9: Magento Meetup New Delhi- Magento2 code generation

Plugin Code Generation

if a plugin is defined in the di.xml, then its interceptor class is created in the var/generation .

Page 10: Magento Meetup New Delhi- Magento2 code generation
Page 11: Magento Meetup New Delhi- Magento2 code generation
Page 12: Magento Meetup New Delhi- Magento2 code generation

Proxy Code Generation

since magento2 uses DI design pattern and you can pass the class reference in the constructor and when the class is loaded is starts a domino effect to overcome this problem magento2 uses proxy design pattern .

Page 13: Magento Meetup New Delhi- Magento2 code generation
Page 14: Magento Meetup New Delhi- Magento2 code generation
Page 15: Magento Meetup New Delhi- Magento2 code generation
Page 16: Magento Meetup New Delhi- Magento2 code generation
Page 17: Magento Meetup New Delhi- Magento2 code generation
Page 18: Magento Meetup New Delhi- Magento2 code generation

Benefits of Code

Generation

• don't need to write test cases for the generated classes

• fast class loading

• best solution for customization

• generalized approach

Page 19: Magento Meetup New Delhi- Magento2 code generation

Thanks Questions?