footup / framework
FootUp MVC 框架:一个功能丰富且轻量级的 PHP MVC 框架
Requires
- php: >=7.4||^8.2.7
- ext-intl: *
- ext-json: *
- ext-mbstring: *
- ext-pdo: *
This package is auto-updated.
Last update: 2024-09-25 16:16:36 UTC
README

FOOTUP MVC FRAMEWORK - 0.1.7-alpha.9
一个功能丰富且轻量级的 PHP MVC 框架
- CLI 支持生成 控制器、模型、中间件、迁移、种子、资产 和 视图 文件(感谢使用和修改adhocore/php-cli)
- 翻译支持
- 使用 PHP 文件或 .env 进行配置(将 env 重命名为 .env)
- 请求
- 响应
- 验证器(表单验证 - 不验证上传文件)感谢 pdscopes/php-form-validator
- 分页(分页和分页视图)感谢 iranianpep/paginator
- 会话
- 电子邮件(CodeIgniter 4 电子邮件类)
- 路由
- 控制器和中间件(但在这里我们只称之为中间件并特定化)
- 模型关系($hasOne, $hasMany, $belongsTo, $belongsToMany)
- 模型查询构建器
- 模型事件回调
- 文件(上传文件)
- 可扩展的(您可以集成任何您想要的库,并可以使用 psr4 自动加载机制在 App 目录中添加(新文件夹和类))
README 应该更新 -- (我很快将为 FootUp PHP MVC 框架创建文档网站)
目录树
FOOTUP MVC Framework
├── app
│ ├── Config
│ │ ├── Autoload.php
│ │ ├── Config.php
│ │ ├── Constants.php
│ │ ├── Email.php
│ │ ├── Form.php
│ │ ├── Fuel.php
│ │ ├── Paginator.php
│ │ └── Routes.php
│ ├── Controller
│ │ ├── BaseController.php
│ │ └── Home.php
│ ├── Functions.php
│ ├── Lang
│ ├── Libs
│ ├── Middle
│ │ └── Maintenance.php
│ ├── Migration
│ ├── Model
│ │ └── Contact.php
│ ├── Seed
│ └── View
│ └── home.php
├── composer.json
├── core
│ ├── Boot.php
│ ├── Cli
│ │ ├── Commands
│ │ │ ├── Assets.php
│ │ │ ├── Controller.php
│ │ │ ├── Middle.php
│ │ │ ├── Migfree.php
│ │ │ ├── Migrate.php
│ │ │ ├── MigrateTrait.php
│ │ │ ├── Migrown.php
│ │ │ ├── Migrup.php
│ │ │ ├── Model.php
│ │ │ ├── Multiple.php
│ │ │ ├── Scaffold.php
│ │ │ ├── Seeder.php
│ │ │ ├── Seed.php
│ │ │ ├── Serve.php
│ │ │ └── View.php
│ │ ├── Exception
│ │ │ ├── Exception.php
│ │ │ ├── InvalidArgumentException.php
│ │ │ ├── InvalidParameterException.php
│ │ │ └── RuntimeException.php
│ │ ├── Helper
│ │ │ ├── InflectsString.php
│ │ │ ├── Normalizer.php
│ │ │ ├── OutputHelper.php
│ │ │ └── Shell.php
│ │ ├── Input
│ │ │ ├── Argument.php
│ │ │ ├── Command.php
│ │ │ ├── Groupable.php
│ │ │ ├── Option.php
│ │ │ ├── Parameter.php
│ │ │ ├── Parser.php
│ │ │ └── Reader.php
│ │ ├── IO
│ │ │ └── Interactor.php
│ │ ├── Konsole.php
│ │ ├── logo
│ │ ├── logo_txt
│ │ ├── Output
│ │ │ ├── Color.php
│ │ │ ├── Cursor.php
│ │ │ ├── Table.php
│ │ │ └── Writer.php
│ │ └── Tpl
│ │ ├── Controller.tpl
│ │ ├── Middle.tpl
│ │ ├── Migrate.tpl
│ │ ├── Model.tpl
│ │ ├── Seed.tpl
│ │ └── View.tpl
│ ├── Config
│ │ ├── Autoload.php
│ │ ├── Config.php
│ │ ├── DotEnv
│ │ │ ├── DotEnv.php
│ │ │ └── Exception
│ │ │ ├── Exception.php
│ │ │ └── InvalidPathException.php
│ │ ├── Email.php
│ │ └── Mime.php
│ ├── Controller.php
│ ├── Database
│ │ ├── DbConnection.php
│ │ ├── Migration
│ │ │ └── Migration.php
│ │ ├── Migration.php
│ │ ├── QueryBuilder.php
│ │ ├── Schema
│ │ │ ├── Column.php
│ │ │ ├── ForeignKey.php
│ │ │ ├── IndexColumn.php
│ │ │ ├── Index.php
│ │ │ ├── Schema.php
│ │ │ └── Table.php
│ │ ├── Seeder
│ │ │ └── Seeder.php
│ │ └── Seeder.php
│ ├── Debug
│ │ ├── Contracts
│ │ │ └── HandlersInterface.php
│ │ ├── Exceptions
│ │ │ ├── CompileErrorException.php
│ │ │ ├── CompileWarningException.php
│ │ │ ├── CoreErrorException.php
│ │ │ ├── CoreWarningException.php
│ │ │ ├── DepricatedException.php
│ │ │ ├── NoticeException.php
│ │ │ ├── ParseErrorException.php
│ │ │ ├── RecoverableErrorException.php
│ │ │ ├── StrictErrorException.php
│ │ │ ├── UserDeprecatedException.php
│ │ │ ├── UserErrorException.php
│ │ │ ├── UserNoticeException.php
│ │ │ ├── UserWarningException.php
│ │ │ └── WarningException.php
│ │ ├── Handlers.php
│ │ ├── HandlersSetter.php
│ │ ├── Reporter.php
│ │ ├── resources
│ │ │ ├── assets
│ │ │ │ ├── css
│ │ │ │ │ ├── custom.min.css
│ │ │ │ │ ├── enlighterjs.min.css
│ │ │ │ │ └── spectre.min.css
│ │ │ │ └── js
│ │ │ │ ├── custom.min.js
│ │ │ │ └── enlighterjs.min.js
│ │ │ └── views
│ │ │ └── 500.php
│ │ ├── Support
│ │ │ └── functions.php
│ │ └── View.php
│ ├── Files
│ │ ├── File.php
│ │ └── FileSystem.php
│ ├── footup-ascii-art.png
│ ├── 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.json
│ │ │ ├── date.json
│ │ │ ├── db.json
│ │ │ ├── email.json
│ │ │ ├── file.json
│ │ │ ├── http.json
│ │ │ ├── paginator.json
│ │ │ ├── validator.json
│ │ │ └── view.json
│ │ └── Lang.php
│ ├── Model.php
│ ├── Orm
│ │ ├── BaseModel.php
│ │ └── ModelQueryBuilder.php
│ ├── Paginator
│ │ ├── AbstractPaginator.php
│ │ ├── Page.php
│ │ ├── PaginatorException.php
│ │ ├── PaginatorInterface.php
│ │ ├── Paginator.php
│ │ └── View
│ │ └── default.php
│ ├── Routing
│ │ ├── Middle.php
│ │ ├── Route.php
│ │ └── Router.php
│ └── Utils
│ ├── Arrays
│ │ ├── Arrayable.php
│ │ ├── ArrDots.php
│ │ ├── Arr.php
│ │ ├── Collection.php
│ │ └── Dots.php
│ ├── ClassLocator.php
│ ├── Shared.php
│ ├── Str.php
│ └── Validator
│ ├── Validate.php
│ └── Validator.php
├── env
├── footup
├── LICENSE
├── public
│ ├── assets
│ │ ├── avatar.jpg
│ │ ├── css
│ │ │ └── style.css
│ │ └── js
│ │ └── script.js
│ ├── error
│ │ ├── 404.html
│ │ └── 500.html
│ ├── favicon.svg
│ ├── index.php
│ └── uploads
├── README.md
└── server.php
描述
FOOTUP MVC 框架主要关注速度和极简主义。它的大小为 250 Kb 压缩包,148 kb xz。它在 0.001 秒 内渲染(我使用 PHP 8.0.7 环境编写和测试它)。
我的目标是做一件事情,让我成为第一个轻松使用它的人。我添加了一些有助于我在整个工作日中更快工作的功能。
要求
嘿!您可以直接下载它并使用它,而无需任何外部依赖。它支持 composer 库,但我尚未将 footup 发布到 packagist。
所以您需要
- PDO 扩展
- mb_string
- intl
- json
教程
CLI
目前我仅添加了生成命令
显示帮助
nuka@hacker_pc:~$ php footup
生成控制器
nuka@hacker_pc:~$ php footup controller controllerName
不要那么害羞,试试看
请求
请求和路由类是 宝马引擎。它们包含许多有用的东西。这里是如何使用请求的
您在控制器中吗?使用如下方式
// using get function to get the page=3 present in the url $this->request->get("page"); // you can use like this to get the page $this->request->page; // What ? you typing enough ? and that ? request()->page; // And What ? how to get file with name: image ? // You can use as below $this->request->image; // or $this->request->file('image') // And What if image[] as multiple files ? // You can use as below $this->request->files('image'); # Yes you can access the request using the global function request()
但是,是的,通过请求,您可以通过验证器验证数据,如下所示
// using get function to validate the page=3 present in the url $this->request->withGetInput()->validate(["page" => "is:int"]); // What ? you typing enough ? and that ? request()->withGetInput()->validate(["page" => "is:int"]); # Yes you can access the request using the global function request()
不要那么害羞,探索请求类,您的编辑器将自动完成
响应对象在控制器中可用
// using get function to validate the page=3 present in the url $this->response->json(["page" => 2]); // second parameter to echo directly # Yes you can access the response using the global function response()
会话
这是一个共享类,所以其中的数据保持相同,以下是一个示例
// using set function to set session value $this->session->set(["page" => 2]); // or $this->session->page = 2 // What ? you typing enough ? and that ? session("page", 2); // session()->set("page", 2); or session()->page = 2; // What ? i want to get the page ? // So session("page"); // session()->get("page"); or session()->page; # Yes you can access the session using the global function session() as shown
验证器
如果您使用验证器验证数据,则验证函数返回所有通过时的 TRUE,否则返回 FALSE
// Via request // with post data $this->request->withPostInput()->validate(["page" => "is:int"]); // With post and get data request()->withInput()->validate(["page" => "is:int"]); // With other data request()->with(["page" => 2])->validate(["page" => "is:int"]); // So how to get Error ? // Simple validator()->getError("page"); // request()->getValidator()->getErrors(); to grab all # Yes you can access the validator using the global function validator() # You can validate using the global function validate() too
我会写文档,如果如果如果…… LOL -- 如果您可以做到,请帮助我!
我想我不喜欢写 LOL
使用模型
<?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"); // Generating form ****** $contact->getForm(); var_dump($c->firstByEmail('faus@fizz.io')); ..........................
全局函数 | 全局函数
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()
还有许多其他全局函数
上传文件 | 上传文件
#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
获取自动生成的表单 | 获取自动生成的表单
$contact = new ContactModel(); $contact->getForm("#", [], true /* true to print */ ) # or use echo $contact->getForm();
查询构建器方法 | 模型查询构建器方法
# model->from($table, $reset = true): $this
使用 $reset = false 以防止重新开始一个请求。使用 $table 来更改表(您很少使用此方法)
# model->join($table, $fields, $type = 'INNER', $operator = '='): $this
- $type 必须是 ['INNER', 'LEFT OUTER', 'RIGHT OUTER', 'FULL OUTER'] 中的一个
- $fields 字符串或数组,例如: "user.id = article.id_user" | ["user.id" => "article.id_user"]
# model->leftJoin($table, $fields, $operator = '='): $this
- $fields 字符串或数组,例如: "user.id = article.id_user" | ["user.id" => "article.id_user"]
# model->rightJoin($table, $fields, $operator = '='): $this
- $fields 字符串或数组,例如: "user.id = article.id_user" | ["user.id" => "article.id_user"]
# model->where($key, $val = null, $operator = null, $link = ' AND ', $escape = true): $this
- $key 字符串或数组,例如: "id = 1" | ["id" => 1]
- $link 字符串,where 中的 $link 是 AND | OR | IS
- $fields 字符串或数组,例如: "arnauld" | [2, 3, 5] 用于 $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
此方法应在 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
如果 $raw_sql 为 null,则方法返回一个字符串,否则返回 $this。
/** * 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: 获取数据的对象,默认: $this
- $db_array: 数据库字段,例如: ['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: 获取 primaryKey 数据的对象,默认: $this
/** * Removes an object from the database. * * @param object * @return boolean */ public function remove($objet = null)
注意:如果您已经使用过像 CodeIgniter 4 这样的框架,您将很快掌握其他方法,如 groupBy, having, limit, offset, distinct, between, select, last, find, min, count, max, avg, one, first 以及动态方法如 firstBy{Field}, lastBy{Field}, findBy{Field},其中 {Field} 是表的属性。
/** * 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)
创建 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" ]); } }
库的信用
Paginator iranianpep/paginator
表单验证器 pdscopes/php-form-validator
PHP 数组 pdscopes/php-arrays
PHP CLI by Adhocore adhocore/php-cli
许可证
BSD 3-Clause License
版权所有 (c) 2021, Faustfizz youssoufmbae2@gmail.com 保留所有权利。
重新分发和使用源代码和二进制形式,无论是否修改,只要满足以下条件
-
源代码的重新分发必须保留上述版权声明、本条件列表和以下免责声明。
-
二进制形式的重新分发必须在使用文档和其他材料中复制上述版权声明、本条件列表和以下免责声明。
-
未经事先书面许可,不得使用版权所有者或其贡献者的姓名来认可或推广由此软件派生出的产品。
本软件由版权所有者和贡献者提供,按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性和针对特定目的的适用性的暗示保证。在任何情况下,版权所有者或贡献者均不对任何直接、间接、偶然、特殊、示范性或后果性的损害(包括但不限于替代商品或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,无论这种损害是由于何种原因引起的,也不论是根据何种责任理论,无论是合同、严格责任还是侵权(包括疏忽或不计),即使被告知了此类损害的可能性。