Lightweight stack-based PHP framework based on ideas from Ruby's Rack and Ruby on Rails 3.
- Lightweight but extendable, only include the middleware and endpoints you want to use.
- Fast, no need to execute stuff you don't need.
- PHP >= 5.3
- PCRE Extension
- PCRE with UTF-8 support (
--enable-utf8
) - Reflection Extension
- Tokenizer Extension
- SPL (Standard PHP Library) Extension
- Iconv Extension (for
\Inject\Core\Middleware\Utf8Filter
) - Phix (for console commands, optional)
PCRE (usually with UTF-8 support), Reflection, SPL and Tokenizer extensions are already included in the default PHP configuration.
The recommended way to install Phix is to use the PEAR Installer:
sudo pear channel-discover pear.gradwell.com
sudo pear install --alldeps Gradwell/phix
Currently no readily made PEAR package is provided, but you can build one yourself if you have the tools:
phing pear-package
cd dist
pear install InjectFramework-<version>.tgz
If you do not want to install it via PEAR, just place the contents of the src/php/
directory somewhere in your PHP installation's include path.
If you have Phix installed you can just run:
phix inject:app <yourappname> <appfolder>
This will generate an application skeleton with the name <yourappname>
and place that in <appfolder>
.
This command requires that the src/php/Inject/
folder is placed in a folder in your PHP installation's include path (automatically done by PEAR), or that you run the command in the InjectFramework project directory or that you use the --include=<path/to/inject/frameworks/src/php/dir>
switch for Phix.
Note: This command does not yet generate a fully functional application skeleton as many core framework features are still missing.
To be able to run your application, you must have a PHP file which acts as an entry point. This entry point will set a few of PHP's configuration settings, load the Autoloader (PSR-0 compliant) and finally call the ServerAdapter
.
The ServerAdapter
will initialize the $env
variable, call your application's stack()
method, run the stack, and finally it will pass on the return value to the browser
In src/php/www/
you have a sample index.php.sample
file. Copy this file to your document root of your web-server (or wherever your web-server's PHP environment will find and be able to execute it) and rename it to index.php
(recommended filename).
Then you have to make two or three changes to this file:
Change the path to the autoloader, depending on if it is in PHP's include path or not, depending on where you have put it:
include 'Inject/Autoloader.php';
Change the
\Sample\Application
class name to the application name of your application (\<yourappname>\Application
):\Inject\Web\ServerAdapter\Generic::run(\MyApp\Application::instance());
- If needed, change the
ServerAdapter
implementation depending on the web-server you are using.
The basic principle of the framework is like an onion; it consists of layers. Each of these layers will perform a specific set of actions, either pre-processing the request, post-processing the response, implementing application flow logic or all of the above.
A layer in the framework is called "Middleware", as it lies in between the browser and your controller action. These middleware can be added and removed depending on the needs of your application.
For more detailed specifications, see Middleware Specifications.