Fwk\Core (Application Framework)
, (*1)
Core is a zero-configuration application framework that makes developers happy :), (*2)
Installation
Via Composer:, (*3)
{
"require": {
"fwk/core": "dev-master",
}
}
If you don't use Composer, you can still download this repository and add it
to your include_path PSR-0 compatible, (*4)
Introduction
Core can be used diffently depending on your application needs and how you plan to maintain and make it evolves in time. There is no directory-structure dependencies nor "recommended pattern". Knowing how to configure PHP 5.3+ on your environment is the only prerequisite., (*5)
A Request to an Application calls an Action_ (Controller) which sometimes uses _Services_ (Model) to return a _Result_ (View). Fwk\Core let you use any type of Action thanks to _ActionProxies. An object containing the Request_ (and the _Response) is shared during the runtime, it is the Context. The runtime creates Events emitted by the Application that can be used by Listeners to extends its behavior., (*6)
Included ActionProxies are:, (*7)
- CallableActionProxy(
callable): calls callable
- ControllerActionProxy(
className,methodName): instanciate className and calls methodName
- IncludeActionProxy(
file.php): includes file.php
- ServiceActionProxy(
serviceName): executes the Service registered as serviceName
- ServiceControllerActionProxy(
serviceName, methodName): executes methodName on the Service registered as serviceName
Its suggested to use Fwk\Core\Action\ProxyFactory as a shortcut to the corresponding Fwk\Core\ActionProxy, like:, (*8)
$app->register('Hello', ProxyFactory::factory(function() { /* ... */ })); // CallableActionProxy
$app->register('Hello', ProxyFactory::factory('+file.php')); // IncludeActionProxy
$app->register('Hello', ProxyFactory::factory('HelloWorld\\HelloController:show')); // ControllerActionProxy
$app->register('Hello', ProxyFactory::factory('@service')); // ServiceActionProxy
$app->register('Hello', ProxyFactory::factory('@service:method')); // ServiceControllerActionProxy
Hello World Application
This is probably the simplest example:, (*9)
``` php
<?php
namespace HelloWorld;, (*10)
// we're index.php in the 'public' http folder (the doc_root)
require DIR .'/../vendor/autoload.php';, (*11)
$app = new \Fwk\Core\Application('helloWorld');, (*12)
// the easy way
$app['Hello'] = function($name = null) {
return 'Hello '. (!empty($name) ? $name : 'World');
};, (*13)
// the above is a shortcut to this:
$app->register(
'Hello',
new \Fwk\Core\Action\CallableActionProxy(
function($name = null) {
return 'Hello '. (!empty($name) ? $name : 'World');
}
)
);, (*14)
// The is needed to respond to / (or index.php)
$app->setDefaultAction('Hello');, (*15)
// execute
$response = $app->run();
if ($response instanceof \Symfony\Component\HttpFoundation\Response) {
$response->send();
} else {
echo $response;
}
```, (*16)
That's it! Now open your browser to http://localhost/wherever/index.php or http://localhost/wherever/index.php?name=John+Doe !, (*17)
More documentation on its way..., (*18)
- Issues on Github: https://github.com/fwk/Events/issues
- Follow Fwk on Twitter: @phpfwk
Legal
Fwk is licensed under the 3-clauses BSD license. Please read CREDITS and LICENSE for full details., (*19)