❌

Normal view

Canvas: an open-source PHP framework that runs alongside your legacy code

I’ve been building Canvas, an open-source PHP framework. I built it for myself. It started because I wanted to modernize an existing PHP application incrementally and couldn’t get the integration I wanted with Symfony. Over time it grew into a standalone framework for building new applications that can also run alongside existing PHP code. I’m happily using it in my projects because it works the way I like it to, and I open sourced it so anyone who wants to can use it too.

It is deliberately similar to Symfony in some regards: it uses Symfony’s HttpFoundation, routes are annotations on controller methods, and the ORM is a Data Mapper like Doctrine. Where it differs:

  • Legacy Bridge: Canvas checks its own routes first. If it does not find a match, it will fall through to your existing PHP files. E.g. The Strangler Fig Pattern. Legacy files can use Canvas services through a canvas() helper.
  • AOP for cross-cutting concerns: instead of a middleware pipeline or kernel events, authentication, logging and caching are aspects declared with InterceptWith on a controller method or class, with before/around/after phases and priorities. Aspects are inherited, so a base controller’s aspects apply to all its subclasses.
  • Contextual dependency injection: resolve different implementations of the same interface in different situations. The context can be static, as with Laravel’s contextual bindings, but Canvas also lets you compute it per request, declared directly on the annotation.
  • ObjectQuel: a QUEL-inspired query language instead of DQL. Relationships are traversed with via, and queries that outgrow DQL, such as window functions or recursive traversal, stay in the language instead of dropping to raw SQL.

I designed it this way because I think explicit structure, clear boundaries between responsibilities, and endpoint behavior that is easy to discover make a codebase easier to work in.

I’ve also written a technical comparison with Laravel and Symfony covering routing, dependency injection, persistence, and the trade-offs involved.

If you find it interesting, I'd be happy to hear your thoughts.

submitted by /u/Big_Tadpole7174 to r/PHP
[link] [comments]
❌