Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing CakePHP Plugins

Developing CakePHP Plugins

Mark Sch.

May 29, 2016
Tweet

More Decks by Mark Sch.

Other Decks in Technology

Transcript

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

    View full-size slide

  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

    View full-size slide

  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/

    View full-size slide

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

    View full-size slide

  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.

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

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

    View full-size slide

  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.

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  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.

    View full-size slide

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

    View full-size slide

  20. www.spryker.com
    20
    Questions?

    View full-size slide

  21. www.spryker.com
    21
    Happy baking!

    View full-size slide