webdevlabs/phreak
Composer 安装命令:
composer create-project webdevlabs/phreak
包简介
Phreak! the ultimate development tool for lamez :)
关键字:
README 文档
README
ultra-light fast php framework powered by:
- Phroute (url routing)
- PHP-DI (dependency injection container)
- Smarty (template engine)
- Stash (caching library)
- Zend Diactoros (request/response handlers)
- RelayPHP (middleware dispatcher)
- PSR7-Middlewares (collection of PSR-7 middlewares)
Installation
composer create-project webdevlabs/phreak
Serve app localy with the built-in PHP web server
php -S localhost:8000 -t public
Autoloader
Very simple and understandable using the Namespace as file path. All directory names are converted to lowercase, file cases are kept as written. Example:
<?php
use App\Controllers\Front;
will autoload the file \app\controllers\Front.php
Simple Routing
Calls the App\Controllers\User::displayUser($id) method with {id} parameter as an argument
$router->get('/users/{id}', ['App\Controllers\User','displayUser']);
Controller Routing
Calls the App\Controllers\Front.php with the proper request method.
$router->controller('/', 'App\Controllers\Front');
- GET request on http://host/login will call the App\Controllers\Front::getLogin() method.
- POST request on http://host/login will call the App\Controllers\Front::postLogin() method.
- GET request on http://host/article/some-article-uri will call the App\Controllers\Front::getArticle($uri) method with $uri parameter as an argument.
Advanced Routing
Filters
Calls class App\Models\Auth with method checkLogin() and break on return false.
$router->filter('auth', ['App\Models\Auth','checkLogin']);
Group all requests under http://host/profile/ through filter
$router->group([
'prefix'=>'profile',
'before'=>'auth'
],
function ($router) {
$router->controller('/', 'App\Controllers\Account\Profile');
});
More advanced routings can be found at Phroute's page.
Validation
public function postComment ()
{
$input = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$val = new \System\Validation($input);
$val->addRule('name', 'Empty name field', ['required']);
$val->addRule('comment', 'Empty comment field', ['required','minLength=5']);
$val->addRule('comment', 'Comment too big', ['maxLength=500']);
if ($val->validate()) {
echo 'Comment post ok';
} else {
$this->template->assign('errors',$val->getErrors());
$this->template->display("errors.tpl");
}
}
Simple controller
<?php
namespace App\Controllers;
use System\Template;
use System\Language;
class Front
{
private $template;
private $language;
public function __construct (Template $template, Language $language)
{
$this->template = $template;
$this->language = $language;
}
public function getIndex()
{
$this->template->assign('title', 'Phreak!');
$this->template->assign('languages', $this->language->available_languages);
$this->template->display('layout.tpl');
}
}
More advanced examples can be found in the 'modules' directory.
Events
use System\Event;
class ... {
public function __construct (Event $event)
{
$this->event = $event;
$this->event->bind('someEventName', function () { echo "stay foolish"; });
}
public function getSome () {
$this->event->trigger('someEventName');
}
}
Database
You now have different options for managing your database. There are 2 existing database drivers. Sample database wrapper class DB:: and the well known database mapper Eloquent.
You control what database driver to load directly from config/database.php
Example PDO driver fetch queries:
* Result: single column
* $count = DB::column('SELECT COUNT(*) FROM `user`);
* Result: an array(key => value) results (i.e. for making a selectbox)
* $pairs = DB::pairs('SELECT `id`, `username` FROM `user`);
* Result: a single row result
* $user = DB::row('SELECT * FROM `user` WHERE `id` = ?', array($user_id));
* Result: a single row result
* $user = DB::row('SELECT * FROM `user` WHERE `id` = :varname', array(":varname"=>"some variable"));
* Result: an array of results
* $banned_users = DB::fetch('SELECT * FROM `user` WHERE `banned` = ?', array(TRUE));
* Result: any query
* $dosql = DB::query('UPDATE `settigs` WHERE `setid`=?', ['somesetid']);
* Result: insert user
* DB::insert('users', ['username'=>'test','password'=>'testpass']);
* Result: update user password where user_id = 1
* DB::update('users', ['password'=>'testpass'], '1', 'user_id');
The new available method for managing your database is Eloquent (from the Laravel framework).
The Eloquent ORM provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.
Examples of phreak eloquent usage can be found at the 'modules/eloq' made for demonstration.
Full documentation can be found at Eloquent's page.
Console Commands
You can also execute phreak controllers from your console/crontab by calling the console.php file where the parameters are the filename of the controller.
Calls the App\Commands\SomeController.php with the proper request method.
php console.php SomeController
All console controllers are located in the "app/commands" folder. The folder location is defined in the 'app/ConsoleController.php' and can be changed.
webdevlabs/phreak 适用场景与选型建议
webdevlabs/phreak 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「hmvc」 「phreak」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webdevlabs/phreak 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webdevlabs/phreak 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webdevlabs/phreak 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Alfabank REST API integration
Starter Codeigniter 3 HMVC for boost your development time.
HMVC structure for Laravel
Twig and HMVC Integration for Code Igniter 3.x
CodeIgniter-HMVC
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-02