Effectively Reuse the Code
Between PHP Projects
www.oroinc.com
Andrey Yatsenko
Passionate about Symfony & DX
- Trainer
- Developer
- Community Evangelist
7 offices in 5 Countries
(USA , Germany, France, Ukraine, Poland)
Global Partner Network
Open-source applications
About Oro Inc.
www.oroinc.com
Oro Applications
11 Applications
● commerce
● commerce-crm
● commerce-crm-de
● commerce-crm-ee
● commerce-crm-ee-de
● commerce-demo
● commerce-enterprise
● crm
● crm-demo
● crm-enterprise
● platform
How to share code between applications?
#1 Copy & Paste
● Easy to do
● Hard to maintain the changes
End up with many versions
of the same package
#2 Don’t reinvent the wheel
Reuse as much as you can!
#2 Don’t reinvent the wheel
At ORO we don't.
● 190+ production dependencies
● 760+ dev & testing dependencies
#3 Many Repositories
● Every reusable package is a separate GIT repository
● Application repositories require package repositories
What to extract to the package?
We can declare every Symfony bundle as a new package.
What to extract to the package?
We can declare every Symfony bundle as a new package.
At ORO we have 170 + unique bundles
What to extract to the package?
Recommendations:
1. A single package has many related bundles
2. Start from big packages and extract when needed
3. Same root namespace for all the packages
Oro Applications
11 Applications
● commerce
● commerce-crm
● commerce-crm-de
● commerce-crm-ee
● commerce-crm-ee-de
● commerce-demo
● commerce-enterprise
● crm
● crm-demo
● crm-enterprise
● platform
37 Reusable Packages Contain 170+ Bundles
● apruve
● authorizenet
● calendar
● call
● commerce
● commerce-crm
● commerce-crm-ee
● commerce-demo
● commerce-enterprise
● crm
● crm-demo
● crm-enterprise
● customer-portal
● demo-data
● dotmailer
● dpd
● ews
● german-localization
● google-hangout
● healthcheck
● infinitepay
● ldap
● magento-contact-us
● marketing
● oauth2-server
● outlook
● paypal-express
● platform
● platform-enterprise
● redis-config
● serialized-fields
● task
● test-security
● twig-inspector
● view-switcher
● wirecard
● zendesk
How to attach packages to an application?
# 3.1 Git Submodules
● Easy to start
● Hard to manage the code changes for a single task
# 3.2 Composer Packages
Each repo has its own composer.json
● Publish at Packagist.org
● Publish privately in Packagist.com or Satis
● Do not publish, but attach it as VCS repository
Pros:
● Versioning
● Simplified dependency management
Cons:
● Publishing is overhead
● Hard to manage the code changes for a single task
# 3.2 Composer Packages
What about storing all the projects in a single repo?
What about storing all the projects in a single repo?
And delivering/deploying only what we need to.
#4 Monorepo
● All packages and applications are in a single repository
● Packages are not tight to a single technology
● Git Subtree allows to publish many repos from monorepo
#4 Monorepo
Pros:
● Easy to do cross package changes
Cons:
● Repository size
#4 Monorepo
Famous monorepos:
#4 Monorepo at ORO
11 Applications
● commerce
● commerce-crm
● commerce-crm-de
● commerce-crm-ee
● commerce-crm-ee-de
● commerce-demo
● commerce-enterprise
● crm
● crm-demo
● crm-enterprise
● platform
37 Reusable Packages Contain 170+ Bundles
● apruve
● authorizenet
● calendar
● call
● commerce
● commerce-crm
● commerce-crm-ee
● commerce-demo
● commerce-enterprise
● crm
● crm-demo
● crm-enterprise
● customer-portal
● demo-data
● dotmailer
● dpd
● ews
● german-localization
● google-hangout
● healthcheck
● infinitepay
● ldap
● magento-contact-us
● marketing
● oauth2-server
● outlook
● paypal-express
● platform
● platform-enterprise
● redis-config
● serialized-fields
● task
● test-security
● twig-inspector
● view-switcher
● wirecard
● zendesk
Do all tools work with a monorepo?
PHPStorm & Monorepo
● Excluded folders
● Custom CLI command to switch active application in a monorepo
PHPStorm & Monorepo
Git Subtree & Monorepo
Automated split of the monorepo to many repositories
Pros:
● Saved history
● Supports two way sync
● Easy to add new repository
Cons:
● Requires CI integration
GitHub Code Owners & Monorepo
Define who is responsible for the code in .github/CODEOWNERS
Summary
No silver bullet
Solutions:
1. Copy & Paste
2. Don't write the code
3. Many repos
3.1. Git Submodules
3.2. Composer Packages
■ Public
■ Private
■ Unpublished
4. Monorepo
Thank you!

Effectively Reuse the Code Between PHP Projects

  • 1.
    Effectively Reuse theCode Between PHP Projects
  • 2.
    www.oroinc.com Andrey Yatsenko Passionate aboutSymfony & DX - Trainer - Developer - Community Evangelist
  • 3.
    7 offices in5 Countries (USA , Germany, France, Ukraine, Poland) Global Partner Network Open-source applications About Oro Inc. www.oroinc.com
  • 5.
    Oro Applications 11 Applications ●commerce ● commerce-crm ● commerce-crm-de ● commerce-crm-ee ● commerce-crm-ee-de ● commerce-demo ● commerce-enterprise ● crm ● crm-demo ● crm-enterprise ● platform
  • 6.
    How to sharecode between applications?
  • 7.
    #1 Copy &Paste ● Easy to do ● Hard to maintain the changes End up with many versions of the same package
  • 8.
    #2 Don’t reinventthe wheel Reuse as much as you can!
  • 9.
    #2 Don’t reinventthe wheel At ORO we don't. ● 190+ production dependencies ● 760+ dev & testing dependencies
  • 10.
    #3 Many Repositories ●Every reusable package is a separate GIT repository ● Application repositories require package repositories
  • 11.
    What to extractto the package? We can declare every Symfony bundle as a new package.
  • 12.
    What to extractto the package? We can declare every Symfony bundle as a new package. At ORO we have 170 + unique bundles
  • 13.
    What to extractto the package? Recommendations: 1. A single package has many related bundles 2. Start from big packages and extract when needed 3. Same root namespace for all the packages
  • 14.
    Oro Applications 11 Applications ●commerce ● commerce-crm ● commerce-crm-de ● commerce-crm-ee ● commerce-crm-ee-de ● commerce-demo ● commerce-enterprise ● crm ● crm-demo ● crm-enterprise ● platform 37 Reusable Packages Contain 170+ Bundles ● apruve ● authorizenet ● calendar ● call ● commerce ● commerce-crm ● commerce-crm-ee ● commerce-demo ● commerce-enterprise ● crm ● crm-demo ● crm-enterprise ● customer-portal ● demo-data ● dotmailer ● dpd ● ews ● german-localization ● google-hangout ● healthcheck ● infinitepay ● ldap ● magento-contact-us ● marketing ● oauth2-server ● outlook ● paypal-express ● platform ● platform-enterprise ● redis-config ● serialized-fields ● task ● test-security ● twig-inspector ● view-switcher ● wirecard ● zendesk
  • 15.
    How to attachpackages to an application?
  • 16.
    # 3.1 GitSubmodules ● Easy to start ● Hard to manage the code changes for a single task
  • 17.
    # 3.2 ComposerPackages Each repo has its own composer.json ● Publish at Packagist.org ● Publish privately in Packagist.com or Satis ● Do not publish, but attach it as VCS repository
  • 18.
    Pros: ● Versioning ● Simplifieddependency management Cons: ● Publishing is overhead ● Hard to manage the code changes for a single task # 3.2 Composer Packages
  • 19.
    What about storingall the projects in a single repo?
  • 20.
    What about storingall the projects in a single repo? And delivering/deploying only what we need to.
  • 21.
    #4 Monorepo ● Allpackages and applications are in a single repository ● Packages are not tight to a single technology ● Git Subtree allows to publish many repos from monorepo
  • 22.
    #4 Monorepo Pros: ● Easyto do cross package changes Cons: ● Repository size
  • 23.
  • 24.
    #4 Monorepo atORO 11 Applications ● commerce ● commerce-crm ● commerce-crm-de ● commerce-crm-ee ● commerce-crm-ee-de ● commerce-demo ● commerce-enterprise ● crm ● crm-demo ● crm-enterprise ● platform 37 Reusable Packages Contain 170+ Bundles ● apruve ● authorizenet ● calendar ● call ● commerce ● commerce-crm ● commerce-crm-ee ● commerce-demo ● commerce-enterprise ● crm ● crm-demo ● crm-enterprise ● customer-portal ● demo-data ● dotmailer ● dpd ● ews ● german-localization ● google-hangout ● healthcheck ● infinitepay ● ldap ● magento-contact-us ● marketing ● oauth2-server ● outlook ● paypal-express ● platform ● platform-enterprise ● redis-config ● serialized-fields ● task ● test-security ● twig-inspector ● view-switcher ● wirecard ● zendesk
  • 25.
    Do all toolswork with a monorepo?
  • 26.
    PHPStorm & Monorepo ●Excluded folders
  • 27.
    ● Custom CLIcommand to switch active application in a monorepo PHPStorm & Monorepo
  • 28.
    Git Subtree &Monorepo Automated split of the monorepo to many repositories Pros: ● Saved history ● Supports two way sync ● Easy to add new repository Cons: ● Requires CI integration
  • 29.
    GitHub Code Owners& Monorepo Define who is responsible for the code in .github/CODEOWNERS
  • 30.
    Summary No silver bullet Solutions: 1.Copy & Paste 2. Don't write the code 3. Many repos 3.1. Git Submodules 3.2. Composer Packages ■ Public ■ Private ■ Unpublished 4. Monorepo
  • 31.