Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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/

Slide 4

Slide 4 text

2016 Spryker Systems GmbH 4 Developing CakePHP Plugins SOLID ● 5 useful principles

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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).

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

2016 Spryker Systems GmbH 8 Developing CakePHP Plugins I - Interface segregation principle ● Don’t create one interface containing too many different method stubs

Slide 9

Slide 9 text

2016 Spryker Systems GmbH 9 Developing CakePHP Plugins D - Dependency inversion principle ● Enforce class dependencies via constructor argument (dependency injection).

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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 :-)

Slide 15

Slide 15 text

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.

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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.

Slide 19

Slide 19 text

Developing CakePHP Plugins 2016 Spryker Systems GmbH 19 Examples • https://github.com/UseMuffin/Slug

Slide 20

Slide 20 text

www.spryker.com 20 Questions?

Slide 21

Slide 21 text

www.spryker.com 21 Happy baking!