2017 © Pedro Peláez
 

project whirlpool

An MVC framework based on Composer components.

image

whirlpool/whirlpool

An MVC framework based on Composer components.

  • Monday, February 22, 2016
  • by TomWright
  • Repository
  • 1 Watchers
  • 1 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Whirlpool Framework

Introduction

Whirlpool framework is a lightweight MVC framework based on a few different composer packages., (*1)

Installation

Installing the framework

The best way to install the framework is through composer. The following command will install the framework to /new/project/location, (*2)

composer create-project whirlpool/whirlpool /new/project/location

Setting up the environment

By default, whirlpool expects all web requests to go to the index.php file in the public directory. I suggest setting the "public" directory as your web/document root., (*3)

Getting Started

Routing

By default, routes are located at application/routes.php. You can add/remove more route definition locations by looking in config/routing.php under routeFiles., (*4)

// If a user comes in on this url: site.com/my-page
// And we want to execute a method in this controller: GeneralController
// With a name of: myPageAction
// We would add the following route definition.
$r->addRoute('GET', '/my-page', 'general@myPage');

If no method is specified the default will be used which can be found in config/routing.php. For more help with creating routes please see FastRoute, (*5)

Controllers

Controllers are located at application/controllers. Each method that can be an action should be followed by "Action". Each controller should end with the text "Controller" and the file name must match the controller name. A BaseController is provided with Whirlpool and it is recommended that your controllers extend Whirlpool\BaseController., (*6)

Models

The models are located at application/models. The Whirlpool\BaseModel extends Eloquent so extending from it will give you access to all the wonderful things that Eloquent provides. For help with Eloquent see the documentation, (*7)

Autoloading More Directories

You are able to specify more directories from which Whirlpool will auto-load from in the config/autoload file. The 'directory' array will add directories for standard requests, and the 'subdomainDirectory' will add directories for requests that come in on a subdomain. For example.., (*8)

return [

    'directories' => [
        '/repositories/',
    ],

    'subdomainDirectories' => [

    ],

];

This allows you to create classes in application/repositories and have them autoloaded., (*9)

Views

Views are handled with Twig. When your controller extends from Whirlpool\BaseController you will have access to the twig object via $this->twig. A shortcut to display views has also been provided in the form of $this->displayView($viewName [, array $data = array()]);., (*10)

Database Configuration

In order to use Models you need to have a database connection. The credentials for this connection can be set in config/database.php. An example configuration file can be found at config/example_database.php., (*11)

Multiple Databases

You can interact with multiple databases in a way that is very similar to Laravel as we are using Eloquent. All you need to do is ensure that the new database credentials have been set up in config/database.php with a name of your choosing. You can set the name for that connection by either specifying it in the array key, or setting 'name' => 'my-second-connection'., (*12)

Once the name is set simply open a model and set the connection name., (*13)

protected $connection = 'my-second-connection';

You are also able to do the following, where User is a model., (*14)

$user = new User();
$user->setConnection('my-second-connection');

Subdomains

Subdomains can be a useful way to separate logic for different sections of your applications. You can use Request::subdomain() to get the active subdomain. Please note that there is a list of subdomains to ignore in config/general.php., (*15)

Get going with subdomains

All you have to do to start using a subdomain is to create a folder in application/subdomains. Inside this new folder you will need to create the folders controllers, models and views. This folder will be used as the main application folder when the specified subdomain is active, and the application/models folder will act as a fallback., (*16)

Hooks

Introduction to hooks

There are several hooks that you can manipulate in order to run custom code at a fixed point in the applications life cycle., (*17)

Hooks should be created in config/hooks.php in the following format:, (*18)

return [
    'hook-name' => function ($argument1, $argument2) {
        // This code will be run when the hook is triggered
    },
];

List of default hooks

Hook Name Arguments Timing
whirlpool-initialized whirlpool Once Whirlpool::init() has been executed.
whirlpool-load-action path When an action is about to be loaded.
whirlpool-loaded-action action When an action has just been loaded.
whirlpool-execute-action action When an action is about to be executed.
whirlpool-controller-initialized controller, action When the main controller has just been instantiated.
whirlpool-executed-action response When an action has just been executed.
whirlpool-class-not-found class When the Whirlpool autoloader cannot find a class.

Dependency Injection

You can use dependency injection in your classes very easily. Just include a type hint to your class constructor!, (*19)

class SomeObject()
{
    public function output()
    {
        echo "Hello World.";
    }
}
class MyController {
    public function __construct(SomeObject $ob)
    {
        $ob->output();
    }
};
$controller = Whirlpool::make('MyController');

The Versions

22/02 2016

dev-master

9999999-dev

An MVC framework based on Composer components.

  Sources   Download

The Requires

 

framework mvc whirlpool

22/02 2016

0.0.6

0.0.6.0

An MVC framework based on Composer components.

  Sources   Download

The Requires

 

framework mvc whirlpool

27/01 2016

0.0.5

0.0.5.0

An MVC framework based on Composer components.

  Sources   Download

The Requires

 

framework mvc whirlpool

06/01 2016

0.0.4

0.0.4.0

An MVC framework based on Composer components.

  Sources   Download

The Requires

 

framework mvc whirlpool

27/04 2015

0.0.3

0.0.3.0

An MVC framework based on Composer components.

  Sources   Download

The Requires

 

framework mvc whirlpool

02/02 2015

0.0.2

0.0.2.0

An MVC framework based on Composer components.

  Sources   Download

The Requires

 

framework mvc whirlpool

02/02 2015

0.0.1

0.0.1.0

An MVC framework based on Composer components.

  Sources   Download

The Requires

 

framework mvc whirlpool