luismoralesp/primal
Composer 安装命令:
composer require luismoralesp/primal
包简介
Primal it's a PHP framework for Restful service.
README 文档
README
Primal it's a PHP framework for Restful service.
Install
Install using composer
composer.json
{
"require": {
"luismoralesp/primal": "1.0.5"
}
}
Get Started
The first stpep for use Primal is star a new proyect, we will use the bellow command:
$ php /vendor/luismoralesp/primal/install.php
$ php manage.php startapp myapp
Then we will have a new folder structure:
- myapp
- models
- views
- Myapp.php
- index.php
myapp folder is our proyect folder inside it we will found the models folder where we will put our models class files and views folder where we will put our view class files, by default a file class was createt with our project the name but with first word uppercase this important for this framework.
Inside the file we will found the bellow code:
<?php class Myapp extends JsonView { /** * This is an autogenerated code for started project **/ public function index(){ return '{"message": "Congratulation this is your first service using primal"}'; } }
and finally a file in the root, named index.php, here we will found the our project configuration routing, by default we will found this code:
<?php /** * Import kernel framework and routing */ require_once 'vendors/primal/kernel/Kernel.php'; require_once 'vendors/primal/kernel/Router.php'; /** * Set a default routing */ $router = Router::getInstance('myapp.myapp.index'); /** * Configure routing */ $router->setUrls([ 'hi' => 'myapp.myapp.index' ]); /** * Show routed service */ echo $router->rout(realpath(dirname(__FILE__)));
With the parameter in de Router::getInstance(default_rouing) will set the path to the serive method in the view file, using the bello format:
[app_name].[view_file].[method_name]
So, if we invoke / or /hi/ in the web browser
We will recive:
{"message": "Congratulation this is your first service using primal-php"}
Creating a model
A model reprecent directly a table in the data base, the model is an interface for manipulate each database table.
For define an model we will need to create a class with the same name that our table and extends it from base class Model.
Kernel::package('app'); class MyModel extends Model{
Each model need belong to an app, for this we must to use:
Kernel::package(package_name);
So in our class file we have to define our fields and contrains.
private $id; private $first_name; private $last_name; private $tel; public function __construct(){ $this->id = Constrain::pk($this); $this->first_name = Input::create_text('first_name'); $this->last_name = Input::create_text('last_name'); $this->tel = Input::create_integer('tel'); } /* So your getters and setters */
- The
Constrain::pkmethod is usedprimary keyfields for this model, see about more contrains in the INPUTS.md tuto. - The
Input::create_textandInput::create_integermethods specify a varchar and int columns respectly in the table reprecented by this model, read about more inputs in the INPUTS.md tuto.
For use that model class in our view file we will have to import it, using the bellow line:
Kernel::import('app.MyModel ');
Then we can use the model in our view, for example calling a filter method, it we will return all rows in our table for this model:
MyModel::persistence()->filter();
Then we will to have a view file like this:
<?php Kernel::import('app.MyModel '); class Myapp extends JsonView { /** * This is an autogenerated code for started project **/ public function index(){ return MyModel::persistence()->filter(); } }
luismoralesp/primal 适用场景与选型建议
luismoralesp/primal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「composer」 「easy-to-use」 「rest-api」 「JSON-API」 「php-framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 luismoralesp/primal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 luismoralesp/primal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 luismoralesp/primal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Simple ASCII output of array data
Alfabank REST API integration
Generate a Composer repository from installed WordPress plugins and themes.
An image upload package which provides lot of functions such as upload, resize, crop, rotate, delete.
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-03-19