Developing CakePHP Plugins

Developing CakePHP Plugins

6b6225db96d6fb4a34c6d50a9171d13f?s=128

Mark Sch.

May 29, 2016
Tweet

Transcript

  1. 1 by Mark Scherer CakePHP 3 Hands-on: Developing CakePHP Plugins

  2. 2016 Spryker Systems GmbH 2 Developing CakePHP Plugins About me

    • @dereuromark • Open Source developer since 2007 • CakePHP developer since 1.2 (2006) • Core developer since 5+ years. • www.dereuromark.de
  3. 2016 Spryker Systems GmbH 3 Developing CakePHP Plugins Agenda •

    Clean Code: SOLID and Package Principles • Basics of plugin development • Examples Details @ www.dereuromark.de/2016/01/29/developing-cakephp-3-plugins-its-fun/
  4. 2016 Spryker Systems GmbH 4 Developing CakePHP Plugins SOLID •

    5 useful principles
  5. 2016 Spryker Systems GmbH 5 Developing CakePHP Plugins S -

    Single responsibility • Keep classes simple, doing a specific task. • Watch out for constructor argument count.
  6. 2016 Spryker Systems GmbH 6 Developing CakePHP Plugins O -

    Open/closed principle • Your code should be open for extension, but closed for modification. • Code against abstract not concrete classes (interfaces in PHP).
  7. 2016 Spryker Systems GmbH 7 Developing CakePHP Plugins L -

    Liskov substitution principle • Every subclass or derived class should be substitutable for their base/parent class. • Only narrow, never widen, the input for sub classes
  8. 2016 Spryker Systems GmbH 8 Developing CakePHP Plugins I -

    Interface segregation principle • Don’t create one interface containing too many different method stubs
  9. 2016 Spryker Systems GmbH 9 Developing CakePHP Plugins D -

    Dependency inversion principle • Enforce class dependencies via constructor argument (dependency injection).
  10. 2016 Spryker Systems GmbH 10 Developing CakePHP Plugins Principles of

    package cohesion • Reuse-release equivalence principle • Common-reuse principle • Common-closure principle Principles of package coupling • Acyclic dependencies principle • Stable-dependencies principle • Stable-abstractions principle
  11. Developing CakePHP Plugins 2016 Spryker Systems GmbH 11 Reuse-release equivalence

    principle • Release as much code as can be reused • You can only reuse the amount of code you can actually release
  12. Developing CakePHP Plugins 2016 Spryker Systems GmbH 12 Building a

    feature • Plugin vs. core feature
  13. Developing CakePHP Plugins 2016 Spryker Systems GmbH 13 Building a

    plugin • Check awesome list first! https://github.com/FriendsOfCake/awesome-cakephp • cake bake plugin • Skeleton builder for composer: https://github.com/usemuffin/skeleton
  14. Developing CakePHP Plugins 2016 Spryker Systems GmbH 14 Releasing a

    plugin • Version control • Package definition file • SemVer and BC in minor versions • Meta files and documentation • Tests, CI and coverage And don’t forget to maintain it :-)
  15. Developing CakePHP Plugins 2016 Spryker Systems GmbH 15 Common-reuse principle

    • Code that is used together, should be ideally in the same package Common-closure principle • A package should not have more than one reason to change.
  16. Developing CakePHP Plugins 2016 Spryker Systems GmbH 16 Example https://github.com/dereuromark/cakephp-tools

    One 2.x plugin to rule them all - or not ;)
  17. Developing CakePHP Plugins 2016 Spryker Systems GmbH 17 Refactoring •

    dereuromark/cakephp-shim • dereuromark/cakephp-ajax • dereuromark/cakephp-geo • dereuromark/cakephp-feed • dereuromark/cakephp-tinyauth • dereuromark/cakephp-meta • dereuromark/cakephp-flash • dereuromark/cakephp-mobile On top of dereuromark/cakephp-tools now 6 extracted 3.x plugins with clear groups
  18. Developing CakePHP Plugins 2016 Spryker Systems GmbH 18 Package coupling

    (ADP, SDP, SAP) • Prevent cycling dependencies • Change is easiest when a package has not many dependencies (stable), so make sure if it does those are also not blocked for change. • Stable packages ideally have a lot of abstraction (interface, …) exposed to the depending parts so their stability does not prevent them from being extended.
  19. Developing CakePHP Plugins 2016 Spryker Systems GmbH 19 Examples •

    https://github.com/UseMuffin/Slug
  20. www.spryker.com 20 Questions?

  21. www.spryker.com 21 Happy baking!