PHP Classes

Caribu MVC: MVC framework with controllers using annotations

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 156 All time: 9,017 This week: 43Up
Version License PHP version Categories
caribu-mvc 1.0.0GNU General Publi...7Design Patterns, PHP 7
Description 

Author

This package is a MVC framework with controllers using annotations.

It provides base controller classes that need to be extended by applications to handler application requests.

The package extracts annotations from the actual application controller classes to determine how requests should be routed.

Picture of Maik Greubel
  Performance   Level  
Innovation award
Innovation award
Nominee: 4x

 

Example

<?php
namespace Nkey\Caribu\Mvc\Tests;

use \
Nkey\Caribu\Mvc\Controller\AbstractController;
use \
Nkey\Caribu\Mvc\Controller\Request;

/**
 * A simple test controller
 *
 * @author Maik Greubel <greubel@nkey.de>
 *
 * This file is part of Caribu MVC package
 */
class SimpleController extends AbstractController
{

   
/**
     * @webMethod
     *
     * @title Hey there page
     */
   
public function index()
    {
        echo
"Hey, there!\n\n";
    }

   
/**
     * @responseType text/plain
     *
     * @param \Nkey\Caribu\Mvc\Controller\Request $request
     */
   
public function paramTest(Request $request)
    {
        foreach (
$request->getParams() as $param => $value) {
           
printf("%s => %s\n", $param, $value);
        }
    }

    public function
formTest(Request $request)
    {
        if(
$request->getParam("loggedin", 'boolean')) {
           
printf('<a href="%ssimple/logout">logout</a>', $request->getContextPrefix());
        } else {
           
$this->viewParams['form']['login'] = array(
               
"controller" => "simple",
               
"action" => "login",
               
"fields" => array(
                    array(
"name" => "username"),
                    array(
"name" => "password", "type" => "password")
                ),
               
"buttons" => array(
                    array(
"name" => "Login")
                )
            );

            echo
"{form=login}";
        }
    }

    public function
login(Request $request)
    {
        if(
$request->getParam("username") == "test" && $request->getParam("password") == "tset") {
           
$_SESSION['loggedin'] = true;
        }
       
$this->response->addHeader('Location', sprintf('%ssimple/formTest', $request->getContextPrefix()));
    }

    public function
logout(Request $request)
    {
        unset(
$_SESSION["loggedin"]);
       
$this->response->addHeader('Location', sprintf('%ssimple/formTest', $request->getContextPrefix()));
    }
}



Details

Build Status Scrutinizer Code Quality Code Coverage Dependency Status

caribu-mvc

Tiny annotation based MVC framework

For now only a simple example, what you can do with Caribu MVC.

composer.json:

{
  "require" : {
    "nkey/caribu-mvc" : "dev-master",
    "nkey/phpgenerics" : "dev-master",
    "psr/log" : "1.0.0"
  }
}

public/index.php:

<?php
require dirname(__FILE__) . '/../vendor/autoload.php';

use \Nkey\Caribu\Mvc\Controller\AbstractController;
use \Nkey\Caribu\Mvc\Controller\Request;
use \Nkey\Caribu\Mvc\Application;
use \Nkey\Caribu\Mvc\View\AbstractView;

use \Generics\Logger\ExtendedLogger;

/
 * A simple test controller
 *
 * @author Maik Greubel <greubel@nkey.de>
 *
 *         This file is part of Caribu MVC package
 */
class IndexController extends AbstractController
{

    /
     * @webMethod
     *
     * @title Hey there page
     */
    public function index()
    {
        echo "Hey, there!\n\n";
    }

    /
     * @responseType text/plain
     *
     * @param \Nkey\Caribu\Mvc\Controller\Request $request
     */
    public function paramTest(Request $request)
    {
        foreach ($request->getParams() as $param => $value) {
            printf("%s => %s\n", $param, $value);
        }
    }
}

// Preparing
Application::getInstance()->registerController('IndexController')
    ->setLogger(new ExtendedLogger());

// Serving
Application::getInstance()->serve();

Then in your browser window open http://host/ and see the output of index() web method. The address http://host/index, as well as http://host/index/index provides the same functionality.

Surf to http://host/index/paramTest/param1/Hello/param2/Caribu or to get the same output the address http://host/index/paramTest?param1=Hello&param2=Caribu

Documentation follows soon in wiki.


  Files folder image Files (45)  
File Role Description
Files folder imagecontrib (2 files)
Files folder imagesrc (1 directory)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file build.xml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpdox.xml Data Auxiliary data
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:156
This week:0
All time:9,017
This week:43Up