A Rich Featured Mini PHP MVC Framework

Overview

Footup MVC PHP Framework

Un mini framework MVC PHP qui comporte :

  • CLI support for generating class
  • Translation support
  • Config using PHP File or .env (Rename env to .env)
  • Gestion de Requête (Request)
  • Gestion de Reponse (Response)
  • Session
  • Email
  • Routing
  • Controller Middleware
  • Model RelationShips ($hasOne, $hasMany, $belongsTo, $belongsToMany)
  • Model QueryBuilder
  • Model Events CallBacks
  • Fichiers (Upload File)
  • Extensible (You can integrate any library you want and you can add (news folders and class) in the App Directory in condition you use psr4)

Directories tree

.
├── app
│   ├── Config
│   │   ├── Autoload.php
│   │   ├── Config.php
│   │   ├── Constants.php
│   │   ├── Email.php
│   │   ├── Form.php
│   │   └── Routes.php
│   ├── Controller
│   │   ├── BaseController.php
│   │   └── Home.php
│   ├── Functions.php
│   ├── Lang
│   ├── Libs
│   ├── Middle
│   │   └── Maintenance.php
│   ├── Model
│   │   └── Contact.php
│   └── View
│       └── accueil.php
├── core
│   ├── Boot.php
│   ├── Cli
│   │   ├── CLI.php
│   │   ├── Colors.php
│   │   ├── Console.php
│   │   ├── Exception.php
│   │   ├── Generator.php
│   │   ├── Options.php
│   │   ├── TableFormatter.php
│   │   └── Tpl
│   │       ├── Controller.tpl
│   │       ├── Middle.tpl
│   │       ├── Model.tpl
│   │       └── View.tpl
│   ├── Config
│   │   ├── Autoload.php
│   │   ├── Config.php
│   │   ├── DotEnv
│   │   │   ├── DotEnv.php
│   │   │   └── Exception
│   │   │       ├── Exception.php
│   │   │       └── InvalidPathException.php
│   │   ├── Email.php
│   │   └── Mime.php
│   ├── Controller.php
│   ├── Files
│   │   ├── File.php
│   │   └── FileSystem.php
│   ├── Footup.php
│   ├── Functions.php
│   ├── Html
│   │   ├── Form.php
│   │   └── Html.php
│   ├── Http
│   │   ├── Request.php
│   │   ├── Response.php
│   │   └── Session.php
│   ├── I18n
│   │   ├── Exceptions
│   │   │   └── I18nException.php
│   │   ├── TimeDifference.php
│   │   └── Time.php
│   ├── Lang
│   │   ├── fr
│   │   │   ├── Core.php
│   │   │   ├── Date.php
│   │   │   ├── Db.php
│   │   │   ├── Email.php
│   │   │   ├── File.php
│   │   │   ├── Http.php
│   │   │   └── View.php
│   │   └── Lang.php
│   ├── Model.php
│   ├── Orm
│   │   └── BaseModel.php
│   └── Routing
│       ├── Middle.php
│       ├── Route.php
│       └── Router.php
├── public
│   ├── assets
│   │   ├── css
│   │   │   └── style.css
│   │   └── js
│   │       └── script.js
│   ├── error
│   │   ├── 404.html
│   │   └── 500.html
│   ├── index.php
│   └── uploads
├── env
├── foot
├── LICENSE
└── README.md

Description

Ce framework utilise les namespaces pour auto-loading des class. Pour interagir avec une base de données, le framework Footup utilise l'extension PDO.

Vous êtes libre et maître de votre code, soyez à l'aise

-- retrouvez toutes les configurations dans le dossier app/Config --

Ce framework a tout ce qu'il faut pour vous aider à developper vite votre application.

#TO-DO: Une documentation complète doit être rédigée si possible

Exemple d'Utilisation du CLI

nuka@hacker_pc:~$ php foot 

Exemple de Model

<?php

namespace App\Model;
use Footup\Model;

class Contact extends Model{
  // If not defined, the name of this class is used
  protected $table = 'contact';
  /**
   * PrimaryKey
   *
   * @var string
   */
  protected $primaryKey = 'idcont';

  protected $beforeInsert         = [];
  protected $beforeFind           = [];
  protected $beforeDelete         = [];
  protected $beforeUpdate         = [];
  protected $afterInsert          = [];
  protected $afterFind            = [];
  protected $afterDelete          = [];
  protected $afterUpdate          = [];
}

// Using the model Contact
.....
  use App\Model\Contact;
  ....
  // Retrouve tout | retrieve all
  $contacts = Contact::all();
  ------------ others methods --------------
  $c = new Contact();
  $contacts = $c->get();
  foreach($contacts as $contact)
    echo $contact->email;
  
  # you can also use 
  $contact->setEmail("[email protected]");

  var_dump($c->firstByEmail('[email protected]'));
  ..........................
  

Globals Functions | Fonctions glabales

request($index = null, $arg = null)

  /**
   * Une fonction pour exposer l'objet Request
   *
   * @param mixed $index
   * @param mixed $arg
   * @return Footup\Http\Request|mixed
   */
  request($index = null, $arg = null)

calledController($withNamespace = true)

  /**
   * Retrouve le controlleur en cours d'utilisation
   *
   * @param boolean $withNamespace
   * @return string
   */
  calledController($withNamespace = true)

calledMethod()

  /**
   * Retrouve la méthode couremment utilisée
   *
   * method of the current called controller
   * 
   * @return string
   */
  calledMethod()

And many mores others globals functions

Uploading file | Téleverser un fichier

  #eg. file field = image
  # @uses one below
  request('image') or request()->image or request()->file('image')

  # remember that request is available directly in the controller so :
  $this->request->image

  # et pour enregistrer le fichier | and for saving :
  request('image')->save(?string $destinationName = null, bool $replace = true) or request()->image->save(?string $destinationName = null, bool $replace = true) or request()->file('image')->save(?string $destinationName = null, bool $replace = true)

  # remember that request is available directly in the controller so :
  $this->request->image

Getting Auto Genereted Form | Avoir un formulaire auto généré

  $contact = new ContactModel();
  $contact->getForm("#", [], true /* true to print */ )
  # or use
  echo $contact->getForm();

QueryBuilder Methods | Méthode de Model QueryBuilder

# model->from($table, $reset = true): $this

Utilise $reset = false si vous ne souhaiter pas recommencer une requête. Utilise $table pour changer de table (cette méthode vous l'utiliserez rarement)

# model->join($table, $fields, $type = 'INNER', $operator = '='): $this

  • $type doit être un dans ['INNER', 'LEFT OUTER', 'RIGHT OUTER', 'FULL OUTER']
  • $fields string|array ex: "user.id = article.id_user" | ["user.id" => "article.id_user"]

# model->leftJoin($table, $fields, $operator = '='): $this

  • $fields string|array ex: "user.id = article.id_user" | ["user.id" => "article.id_user"]

# model->rightJoin($table, $fields, $operator = '='): $this

  • $fields string|array ex: "user.id = article.id_user" | ["user.id" => "article.id_user"]

# model->where($key, $val = null, $operator = null, $link = ' AND ', $escape = true): $this

  • $key string|array ex: "id = 1" | ["id" => 1]
  • $link string where $link is AND | OR | IS
  • $fields string|array ex: "arnauld" | [2, 3, 5] for $operator IN | NOT IN

# model->whereOr($key, $val = null, $operator = null, $link = ' AND ', $escape = true): $this

  /**
    * @param string|array $key
    * @param null $operator
    * @param null $val
    * @return $this
    */
  public function whereOr($key, $val = null, $operator = null, $escape = true)

# model->whereIn($key, array $val, $escape = true) | whereOrIn($key, array $val, $escape = true): $this

  /**
   * @param $key
   * @param array $val
   * @return $this
   */
  public function whereIn($key, array $val, $escape = true)

# model->whereRaw($str) | whereOrRaw($str): $this

  /**
   * @param string $str
   * @return $this
   */
  public function whereRaw($str)

# model->whereNotIn($key, array $val, $escape = true) | whereOrNotIn($key, array $val, $escape = true): $this

  /**
   * @param $key
   * @param array $val
   * @return $this
   */
  public function whereNotIn($key, array $val, $escape = true)

# model->whereNotNull($key) | whereOrNotNull($key): $this

  /**
   * @param string $key
   * @return $this
   */
  public function whereNotNull($key)

# model->whereNull($key) | whereOrNull($key): $this

  /**
   * @param string $key
   * @return $this
   */
  public function whereNull($key)

# model->asc($field): $this

  /**
   * Adds an ascending sort for a field.
   *
   * @param string $field Field name
   * @return object Self reference
   */
  public function asc($field)

# model->desc($field): $this

  /**
   * Adds an descending sort for a field.
   *
   * @param string $field Field name
   * @return object Self reference
   */
  public function desc($field)

# model->orderBy($field, $direction = 'ASC'): $this

  /**
   * Adds fields to order by.
   *
   * @param string $field Field name
   * @param string $direction Sort direction
   * @return object Self reference
   */
  public function orderBy($field, $direction = 'ASC')

# model->insert($data): bool

  /**
   * Builds an insert query.
   *
   * @param array $data Array of key and values to insert
   * @return bool
   */
  public function insert(array $data = [])

# model->update($data): bool

Cette méthode doit être utilisée après une clause where

  /**
   * Builds an update query.
   *
   * @param array $data Array of keys and values, or string literal
   * @return bool
   */
  public function update($data)

# model->delete($where): bool

  /**
   * Builds a delete query.
   *
   * @param string|int|array $where Where conditions
   * @return bool
   */
  public function delete($where = null)

# model->sql($raw_sql): $this

Si $raw_sql est null, la méthode retourne une chaine de caractères, retourne $this sinon.

  /**
   * Gets or sets the SQL statement.
   *
   * @param string|array SQL statement
   * @return self|string SQL statement
   */
  public function sql($sql = null)

# model->save($objet = null, $db_fields = null): bool

  • $object: the object to get data on default: $this
  • $db_array: database fields ex: ['email', 'username']
  /**
   * Saves an object to the database.
   *
   * @param object $objet Class instance
   * @param array $db_fields Select database fields to save (insert or update)
   * @return boolean
   */
  public function save($objet = null, array $db_fields = null)

# model->remove($objet = null): bool

  • $object: the object to get primaryKey data on default: $this
  /**
   * Removes an object from the database.
   *
   * @param object
   * @return boolean
   */
  public function remove($objet = null)

NOTE: Si tu as déjà utilisé un framework comme CodeIgniter 4 tu maitriseras vite Autres méthodes groupBy, having, limit, offset, distinct, between, select, last, find, min, count, max, avg, one, first et des méthodes dynamiques comme firstBy{Field}, lastBy{Field}, findBy{Field} où {Field} est un attribut de la table.

/**
 * Gets the database connection instance PDO.
 *
 * @return object Database connection
 */
public function getDb()
  /**
   * Executes a sql statement.
   *
   * @return object Query results object
   * @throws Exception When database is not defined
   */
  public function execute(array $params = [])
  /**
   * Perform a query
   *
   * @param string $select
   * @param array|string $where
   * @param int $limit
   * @param int $offset
   * @return array - of object class
   */
  public function get($select = "*", $where = null, $limit = null, $offset = null)
  # Autres Méthodes
  ==================

  /**
   * Get the table name for this ER class.
   * 
   * @access public
   * @return string
   */
  getTable ()

  /**
   * Get the primaryKey
   * 
   * @access public
   * @return string
   */ 
  getPrimaryKey()

  /**
   * Get model property fields by data table.
   *
   * @access public
   * @return array of available columns
   */
  getFields()

  /**
   * Create new data row.
   *
   * @access public
   * @param array $properties
   * @return object Model instance
   * @return bool
   */
  create(Array $properties)

  /**
   * Find one model in the database.
   * or create if not exists.
   *
   * @access public
   * @param array $properties
   * @return object Model instance
   * @return array|bool if error occured
   */
  findOrCreate(Array $properties = null)

  /**
   * Find all model in the database.
   *
   * @access public
   * @param mixed $where
   * @return array|object
   */
  public static function all($where = null)

Exemple de création de Controller

<?php

namespace App\Controller;
use App\Model\Contact;

class Home extends BaseController{

  public function index(){
    // Retrouve la méthod utilisée | HTTP Verb
    if($this->request->method() === 'post'){

      // retrouve un fichier | retrouve uploaded file
      $image = $this->request->file('image');
      // save
      $image->save();
      // get the name of the moved file 
      echo $image->name;
    }

    // Using model Contact
    // all() est la seule méthode statique | all() is the only static method
    $contacts = Contact::all();
    $contacts = (new Contact())->get());
    
    // Afficher la vue | display the vue
    return $this->view("accueil", [
        "titre" => "Accueil"
    ]);
  }

}
  

License

BSD 3-Clause License

Copyright (c) 2021, Faustfizz [email protected] All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

You might also like...
Toro is a PHP router for developing RESTful web applications and APIs.

Toro Toro is a PHP router for developing RESTful web applications and APIs. It is designed for minimalists who want to get work done. Quick Links Offi

PHP routing (like laravel) (not complete yet)

PHP Router (under construction) This repository contains routing classes that enables you to define your routes similar to laravel 8 routes. Features

A PHP rewrite of HackRouter by Facebook

Hack-Routing Fast, type-safe request routing, parameter retrieval, and link generation. It's a port of hack-router By Facebook, Inc. Components HTTP E

A lightweight and simple object oriented PHP Router

bramus/router A lightweight and simple object oriented PHP Router. Built by Bram(us) Van Damme (https://www.bram.us) and Contributors Features Support

PhpRouter is a powerful, lightweight, and very fast HTTP URL router for PHP projects.

PhpRouter PhpRouter is a powerful, lightweight, and very fast HTTP URL router for PHP projects. Some of the provided features: Route parameters Predef

Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.

The PHP HTTP Flight Router divineniiquaye/flight-routing is a HTTP router for PHP 7.1+ based on PSR-7 and PSR-15 with support for annotations, created

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project.

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.

A lightweight and fast router for PHP
A lightweight and fast router for PHP

Piko Router A lightweight and blazing fast router (see benchmarks) using a radix trie to store dynamic routes. This router maps routes to user defined

A simple PHP Router

Panda Router Description the panda-router is a small alternative PHP router that can be used for small projects. With this router you can use differen

Releases(v0.1.4)
Owner
Youssouf Mbaé SA
FullStack Web Developer, Mobile Developer but also a Senior Backend developer.
Youssouf Mbaé SA
klein.php is a fast & flexible router for PHP 5.3+

Klein.php klein.php is a fast & flexible router for PHP 5.3+ Flexible regular expression routing (inspired by Sinatra) A set of boilerplate methods fo

null 2.6k Jan 7, 2023
PHP Router class - A simple Rails inspired PHP router class.

PHP Router class A simple Rails inspired PHP router class. Usage of different HTTP Methods REST / Resourceful routing Reversed routing using named rou

Danny van Kooten 565 Jan 8, 2023
Fast request router for PHP

FastRoute - Fast request router for PHP This library provides a fast implementation of a regular expression based router. Blog post explaining how the

Nikita Popov 4.7k Dec 23, 2022
PHP routing class. Lightweight yet flexible. Supports REST, dynamic and reversed routing.

AltoRouter AltoRouter is a small but powerful routing class, heavily inspired by klein.php. $router = new AltoRouter(); // map homepage $router->map(

Danny van Kooten 1.1k Jan 3, 2023
Pux is a fast PHP Router and includes out-of-box controller tools

Pux Pux is a faster PHP router, it also includes out-of-box controller helpers. 2.0.x Branch Build Status (This branch is under development) Benchmark

Yo-An Lin 1.3k Dec 21, 2022
A web router implementation for PHP.

Aura.Router Powerful, flexible web routing for PSR-7 requests. Installation and Autoloading This package is installable and PSR-4 autoloadable via Com

Aura for PHP 469 Jan 1, 2023
:tada: Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)

HTTP router for PHP 7.1+ (incl. PHP 8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger) Installation compo

Sunrise // PHP 151 Jan 5, 2023
Generate a PHP script for faster routing :rocket:

SwitchRoute Generating a PHP script for faster routing. The traditional way of routing uses regular expressions. This method was improved by FastRoute

Arnold Daniels 75 Nov 20, 2022
Convention based routing for PHP

Croute Convention based routing for PHP based on Symfony components. Croute is great because: You don't need to maintain a routing table Promotes cons

Michael O'Connell 12 Nov 9, 2021
:bird: Simple PHP router

Macaw Macaw is a simple, open source PHP router. It's super small (~150 LOC), fast, and has some great annotated source code. This class allows you to

Noah Buscher 895 Dec 21, 2022