sonypradana/php-library
Composer 安装命令:
composer require sonypradana/php-library
包简介
library to build php mvc
README 文档
README
Php mvc with minum mvc framework. is simple and easy to use
Note: This repository contains the core code of the php-mvc. If you want to build an application, visit the main php-mvc.
Note: This repository high inspire with
laravel\frameworkandsymfony\symfony.
Feature
- MVC base
- Container (dependency injection)
- Route
- Model (database class relation)
- View and Controller
- MyQuery (database query builder)
- Collection (array collection)
- Console (assembling beutifull console app)
- Template (create class using class generator)
- Cron
- Now (time managing)
- Http request and responese
- Str (string manipulation)
Built in Query Builder
of cource we are support CRUD data base, this a sample
Select data
DB::table('table_name') ->select(['column_1']) ->equal('column_2', 'fast_mvc') ->order("column_1", MyQuery::ORDER_ASC) ->limit(1, 10) ->all() ;
the result will show data from query, its same with SQL query
SELECT `column_1` FROM `table_name` WHERE (`column_2` = 'fast_mvc') ORDER BY `table_name`.`column_1` ASC LIMIT 1, 10
Update data
DB::table('table_name') ->update() ->values([ 'column_1' => 'simple_mvc', 'column_2' => 'fast_mvc', 'column_3' => 123 ]) ->equal('column_4', 'fast_mvc') ->execute() ;
the result is boolen true if sql success excute quert, its same with SQL query
UPDATE `table_name` SET `column_1` = 'simple_mvc', `column_2` = 'fast_mvc', 'column_3' = 123 WHERE (`column_4` = 'speed')
Insert and Delete
// insert DB::table('table_name') ->insert() ->values([ 'column_1' => '', 'column_2' => 'simple_mvc', 'column_3' => 'fast_mvc' ]) ->execute() ; // delete DB::table('table_name') ->delete() ->equal('column_3', 'slow_mvc') ->execute() ;
its supported cancel transation if you needed
use System\Support\Facades; PDO::transaction(function() { DB::table('table_name') ->insert() ->value('age', 22) ->execute() ; // some condition if (false === $statment) { return false; } return true; });
Create Database Table
create database table
Schema::table('users', function(Column $column) { $column('user')->varchar(50); $column('pwd')->varchar(500)->notNull(); $column->primeryKeys('user'); }) ->excute();
Collection
Array collection, handel functional array as chain method
Create New Collection
$coll = new Collection(['vb_net', 'c_sharp', 'java', 'python', 'php', 'javascript', 'html']); $arr = $coll ->remove('html') ->sort() ->filter(fn ($item) => strlen($item) > 4) ->map(fn ($item) => ucfirst($item)) ->each(function($item) { echo $item . PHP_EOL; }) ->all() ; // arr = ['c_sharp', 'javascript', 'python', 'vb_net']
Available Methods
add()remove()set()clear()replace()each()mapfilter()sort()sortDesc()sortKey()sortKeyDesc()sortBy()sortByDecs()all()
Console
Assembling beautifull console app make easy
- naming parameter
- coloring console (text and background)
Build simple console app
class GreatConsole extends Console { public function main() { // getter to get param form cli argument $name = $this->name ?? 'animus'; style("Great console Aapplication") ->textGreen() ->newLines() ->push("hay my name is ") ->push($name) ->textYellow() ->out() ; } }
Run your app
- create bootstrapper
#!usr/bin/env php // $argv come with default global php return (new greatConsole($argv))->main();
- on your console
php cli greate --name php_mvc # output: # Great console application # hay my name is php_mvc
Str
Make string manipulation.
Str::chartAt('i love php', 3); // o Str::concat(['i', 'love', 'php']); // i love php Str::indexOf('i love php', 'p'); // 8 Str::lastIndexOf('i love php', 'p'); // 10 Str::match('i love php', '/love/'); // love // ... // and many more
chartAtconcatindexOflastIndexOfmatchslicesplitreplacetoUpperCasetoLowerCasefirstUpperfirstUpperAlltoSnackCasetoKebabCasetoPascalCasetoCamelCasecontainsstartsWithendsWithslugtemplatelengthrepeatisStringisEmptyfillfillEndlimit
Costume macro
costume macro string;
Str::macro('prefix', fn($text, $prefix) => $prefix.$test); echo Str::prefix('cool', 'its '); // its cool
String class
use chain string class.
$string = new Text('I Love rust'); echo $string->replace('rust', 'php')->lower()->slug(); // i-love-php echo $string->length(); // 10 echo $string->isEmpty(); // false
String Regex
Str::is('some@email.com', Regex::EMAIL); // true
avlilable regex
emailuserplain_textslughtml_tagjs_inlinepassword_complexpassword_moderatedate_yyyymmdddate_ddmmyyyydate_ddmmmyyyyip4ip6ip4_6url
sonypradana/php-library 适用场景与选型建议
sonypradana/php-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.65k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php-library」 「php-mvc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sonypradana/php-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sonypradana/php-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sonypradana/php-library 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Initialize Script
A modern PHP library for converting color codes between RGB, HEX, and HSL color spaces.
It's a barebone security class written on PHP
It's a barebone security class written on PHP
Modern PHP Sanitization Library
统计信息
- 总下载量: 3.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-07