Git Product home page Git Product logo

barbare's Introduction

Barbare

framework for my own project

Application

services

routes

It provides all routes for the application.

router
$app->getService('router');

Retrieve an url by name

$router->url('route_name', ['arg' => 'value']);

Retrieve an route object by url The object will be filled with the callback property and all arguments.

$router->findRoute('/link/to/my/page.html');
route

Name of the route

$route->getFullName()

Match with an url. Will return this object or an child route if found. false otherwise.

$route->match('/link/to/my/page.html');

Get url

$route->getFullUrl(['arg' => 'value']);

Get callback

$route->getCallback();

Get param

$route->getParam($name);

request

$app->getService('request');

Get route. Return the actuel route used

$request->getRoute();

Return data form request ($_REQUEST & $_FILES)

$request->getData();

Match the request method

$request->is('post');

Containers

Component

Ajouter dans la config

'components' => [
    ...
    'mycomponent' => function ($container) {
        // do stuff
    },
    'myothercomponent' => '\My\Class\Component',
    ...
]
Class Component {
    public function construct($container) {
        // Do stuff
    }
}

You can load a component by closure or callable classname. $container is an injection dependency container, it's contain all components of the application. The main component is 'application', this is the object of the full application. If you write a callable classname, your component will be instanciated with $container as arg. You can acces to your component in controller :

$this->get('mycomponent');

And all the rest is as you wish ;)

Helper

Ajouter dans la config

'components' => [
    ...
    'myhelper' => function ($container) {
        return function($arg1, $arg2) {
            // do stuff
        }
    },
    'myotherhelper' => '\My\Class\Helper',
    ...
]

Class Helper {
    public function construct($container) {
        // Do stuff
    }
    public function __invoke($arg1, $arg2) {
        // Do stuff
    }
}

If you write a class name for your helper, it has to be invokable with a public function named __invoke(). $container arg in __construct method, contain all helper in Injection Dependancy Container. List of defaults services in container :

  • view : The main view of the application

MVC

Controller

Il faut etendre la class Barbare\Framework\Mvc\Controller pour créer son controller C'est une action de votre controller qui est appellé lors d'un Dispatch Pour effectuer des traitements a l'initialisation du controller, vous devez les faire dans une method init. Les composants sont initialisé avant l'appelle de cette methode.

class MyController
{
    public function init()
    {
        // Do stuff
    }
    public function myAction($arg1, $arg2)
    {
        $this->get('model'); // Acces to 'model' component
    }
}

Some methods can be used :

  • dispatch($routeName, $params = []), for dispatching an other callable route.
  • redirect($routeName, $params = []), for redirect to an other callable route

Components

views

Render your view $this->get('view')->render($params = []);. This will stop the execuption script.

Add params to your view :

$this->get('view')->setVariable($key, $value);
OR
$this->get('view')->setVariables($values);

Get the layout

$this->get('view')->getLayout();

barbare's People

Contributors

fozeek avatar clementgos avatar

Watchers

James Cloos avatar  avatar

Forkers

clementgos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.