fwk / core
Fwk Core System
Requires
- php: >=5.3.4
- fwk/di: 1.*
- fwk/events: dev-master
- fwk/xml: dev-master
- symfony/http-foundation: dev-master
Requires (Dev)
- filp/whoops: dev-master
Suggests
- symfony/console: Required to use the Console Component
This package is not auto-updated.
Last update: 2024-10-26 14:25:29 UTC
README
Core is a zero-configuration application framework that makes developers happy :)
Installation
Via Composer:
{
"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
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.
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.
Included ActionProxies are:
- CallableActionProxy(
callable
): callscallable
- ControllerActionProxy(
className
,methodName
): instanciateclassName
and callsmethodName
- IncludeActionProxy(
file.php
): includesfile.php
- ServiceActionProxy(
serviceName
): executes the Service registered asserviceName
- ServiceControllerActionProxy(
serviceName
,methodName
): executesmethodName
on the Service registered asserviceName
Its suggested to use Fwk\Core\Action\ProxyFactory
as a shortcut to the corresponding Fwk\Core\ActionProxy
, like:
$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:
<?php namespace HelloWorld; // we're index.php in the 'public' http folder (the doc_root) require __DIR__ .'/../vendor/autoload.php'; $app = new \Fwk\Core\Application('helloWorld'); // the easy way $app['Hello'] = function($name = null) { return 'Hello '. (!empty($name) ? $name : 'World'); }; // the above is a shortcut to this: $app->register( 'Hello', new \Fwk\Core\Action\CallableActionProxy( function($name = null) { return 'Hello '. (!empty($name) ? $name : 'World'); } ) ); // The is needed to respond to / (or index.php) $app->setDefaultAction('Hello'); // execute $response = $app->run(); if ($response instanceof \Symfony\Component\HttpFoundation\Response) { $response->send(); } else { echo $response; }
That's it! Now open your browser to http://localhost/wherever/index.php or http://localhost/wherever/index.php?name=John+Doe !
More documentation on its way...
Contributions / Community
- 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.