Crud

Application development on steroids

by Christian "Jippi" Winther / @jippi
GitHub: friendsofcake/crud / FriendsOfCake.com/crud

What is CRUD?

  • - [C]reate
  • - [R]read
  • - [U]pdate
  • - [D]elete

Development goals

What do we aim for?

  • - Rapid development
  • - DRY code
  • - Maintainability
  • - Flexibility
  • - Extensibility
  • - Testability
  • - Reusability‎
  • - Focus on the business goals
  • - Error free code
  • - Unicorns

Possible solutions

  • CakePHP - Scaffolding
  • CakePHP - Bake
  • Community projects

CakePHP - Scaffolding

  • ✔ Rapid development
  • ✔ DRY code
  • ✘ Maintainability
  • ✘ Flexibility
  • ✘ Extensibility
  • ✔ Testability
  • ✔ Reusability‎
  • ✔ Focus on the business goals
  • ✔ Error free code
  • ✘ Unicorns

CakePHP - bake

  • ✔ Rapid development
  • ✘ DRY code
  • (✔) Maintainability
  • (✔) Flexibility
  • (✔) Extensibility
  • ✔ Testability
  • (✔) Reusability‎
  • ✔ Focus on the business problems
  • ✔ Error free code
  • ✘ Unicorns

Community projects

to mention just a few

  • milesj/Admin (active)
  • josegonzalez/cake_admin (~1 year ago; now Crud-view)
  • plusglobal/BrowniePHP (~2 months)
  • electblake/CakePHP-Adminster-Plugin (~7 months)

Community projects

Why they weren't a perfect fit

  • Configuration over conventions
  • Not flexible
  • Not extensible
  • Not unit tested
  • "All or nothing"
  • Lack of unicorns

Enter CRUD

  • ✔ Rapid development
  • ✔ DRY code
  • ✔ Maintainability
  • ✔ Flexibility
  • ✔ Extensibility
  • ✔ Testability
  • ✔ Reusability‎
  • ✔ Focus on the business goals
  • ✔ Error free code
  • ✔ Unicorns


Or so I like to think ...

✔ Rapid development

~5 minutes installation (composer & git).
Modify AppController, instant win in all controllers (Crud actions, listeners).
Default variables are bake view compatible.

✔ DRY code

0 lines of code for default crud / controller actions.
Only implement a controller action if you need to modify default behavior.
Put repeating logic into listeners or custom actions.

✔ Maintainable

Centralized code, reuse across controllers and applications.
Fix once, fix everywhere.
Skinny controllers.

✔ Flexible

Events... events everywhere.
Make your own actions & listeners.
Tries very hard not to get in your way.
Many configuration options, with sane defaults.

✔ Extensible

Listeners can very easily extend the capabilities of your application.
Replace Crud actions or listeners with your own.

✔ Testable

Crud got ~90% test coverage, build in features "just works".
Works very well with "testAction()".
Very easy to mock code in tests if you want to.
Doesn't get in the way of your own Controller tests

✔ Reusability‎

Reuse the same CRUD actions & listeners across controllers & projects.

Currently ~8 developers are actively involved in CRUD, 6 of them are CakePHP core devs:

  • jose_zap / lorenzo
  • savant / josegonzalez
  • AD7six
  • ADmad
  • Phally
  • Jippi

Most of us use CRUD in production.

CRUD (v2) is used in 400+ applications at Nodes.

✔ Focus on the business problems

All the basic CRUD logic is taken care of, focus on things that sets your business case apart from basic CRUD.

More secure than scaffold and bake out of the box.

✔ Unicorns

Use listeners to extend your application.
--> CakeDC/Search
--> CakePHP/DebugKit
Roll your own Crud actions.
One line and you got yourself a REST API.
We got documentation. (I know, right?!)

Code time

But first, lets clarify some terms

Crud Action

Same as a normal controller action.

Actions emit events that listeners can subscribe to.

Isolated in its own object, with configuration & logic.

Actions must be an object extending the CrudAction class.

Can be bound up until beforeFilter().

Crud Listener

Can be anything "callable".

Core Crud listeners are objects.

Could be as simple as a closure.

Listeners can also emit events.

Can be bound at any time during the request.

Code time

For real this time ...

Whew...

Only 3 slides left

Future of Crud

Crud View


On the fly views for all build-in & user provided crud actions.


Admin interface for free.


savant is spearheading this.

Future of Crud

Batch operations


[Add|Edit|Delete] multiple records

Thank you

Questions?


by Christian "Jippi" Winther / @jippi
GitHub: jippi/cakephp-crud / cakephp.nu