https://github.com/othercodes/fcontroller
Front controller and registry that allow us to use several modules with only one entry point or interface.
https://github.com/othercodes/fcontroller
Last synced: 8 months ago
JSON representation
Front controller and registry that allow us to use several modules with only one entry point or interface.
- Host: GitHub
- URL: https://github.com/othercodes/fcontroller
- Owner: othercodes
- License: mit
- Created: 2016-04-23T15:14:21.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-07T14:56:50.000Z (over 8 years ago)
- Last Synced: 2025-10-11T05:37:20.031Z (8 months ago)
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# FController
[](https://travis-ci.org/othercodes/fcontroller) [](https://packagist.org/packages/othercode/fcontroller) [](https://packagist.org/packages/othercode/fcontroller)
FController is a container for controllers/modules. This package allow us to register several controllers/modules
that can be called in a simply way from a common entry point. In the same way we can register multiple libraries
or services. These services or libraries will be available in all modules.
## Installation
### With Composer
First we have to add the dependencies to the ***composer.json*** file:
```javascrip
"require": {
"othercode/fcontroller": "*",
}
```
Then we have to run the following command:
```bash
composer update
```
### Stand Alone
We need to download the package, then extract the content and include in your code the `fcontroller/autoload.php` file.
```php
require_once 'fcontroller/autoload.php';
```
## Basic Usage
First of all we must have the modules we want to the FController handle. For example we have this two dummy modules (classes):
```php
namespace OtherCode\Examples;
class DummyOne extends \OtherCode\FController\Modules\BaseModule
{
public function sayHello($name)
{
$this->storage->name = $name;
return "Hello, " . $name . "!";
}
}
```
The DummyOne Module has one method `sayHello($name)` that accepts one string as parameter. This method return us a string.
```php
namespace OtherCode\Examples;
class DummyTwo extends \OtherCode\FController\Modules\BaseModule
{
public function sayGoodBye()
{
return "GoodBye, " . $this->storage->name . "!";
}
}
```
The DummyTwo Module has once again only one method named `sayGoodBye()`, this method also, return us a string.
Lets create a simply application that holds our two modules:
```php
namespace OtherCode\Examples;
require_once 'fcontroller/autoload.php';
require_once 'DummyOne.php';
require_once 'DummyTwo.php';
$app = \OtherCode\FController\FController::getInstance();
$app->setModule('dummy1', 'OtherCode\Examples\DummyOne');
$app->setModule('dummy2', 'OtherCode\Examples\DummyTwo');
try {
$response1 = $app->run("dummy1.sayHello", array('name' => 'Rick'));
$response2 = $app->run("dummy2.sayGoodBye");
var_dump($response1, $response2);
} catch (\Exception $e) {
var_dump($e);
}
```
The code above illustrate how we can call two different modules using one entry point. Also we can use
services inside our modules.
This package also has a message queue that can be used to display informative messages from our modules.