Alhadhur22 / footup

A Rich Featured Mini PHP MVC Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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("fuck@you.yh");

  var_dump($c->firstByEmail('faus@fizz.io'));
  ..........................
  

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 youssoufmbae2@gmail.com 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.

About

A Rich Featured Mini PHP MVC Framework

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:PHP 91.5%Language:HTML 7.7%Language:Smarty 0.8%