Skip to content
phlogisticfugu edited this page Aug 25, 2014 · 11 revisions

squirt is a lightweight PHP dependency injection framework.

Why squirt?

  • Provides all the benefits of dependency injection
  • Separate configuration from code. Squirt configuration files contain only configuration (logins, connection timeouts, and which classes to instantiate and inject where) and no code, while code contains only code, and no configuration.
  • Keep your code DRY. Service configurations can extend each other, to reduce repetition. Dependencies are automatically and recursively injected by name.
  • Supports three modes of injected parameter overrides:
    • Service configurations can extend and override each other, providing shared default parameters. One can also override the instantiated class with a subclass, if needed.
    • Configuration files can include and override one another, providing clean package-level defaults which one can override in application code, and integration test configurations that selectively override things like logging and database connections.
    • End user code can provide selective overrides at instantiation time, to aid in ad-hoc configuration for testing (great for quick debug flags) and troubleshooting.
  • Make unit testing easier/possible. Mock objects can be injected into instances when unit testing. And configuration file overrides simplify integration tests.
  • Designed for simplicity. Injected parameters include both injected objects and injected configuration values in a natural manner. There's only one method to learn: $squirtServiceBuilder->get(), as opposed to all the methods in most dependency injection containers. There are no annotations to learn, and no XML or YAML.
  • Designed for performance. Squirt config files are written in PHP, so opcode caches already optimize them. Squirt also supports Doctrine caches on the entire configuration
  • Designed for compatibility. If you use external libraries (and you should), it is very easy to write a wrapper class to add squirt support. All that is needed for Squirt compatibility is a static factory() function which takes in an array of parameters (including injected dependencies and configuration values) and returns an instance.
    • Amazon's Guzzle3-based AWS-PHP-SDK is already compatible.