承接 parsgit/night 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

parsgit/night

Composer 安装命令:

composer create-project parsgit/night

包简介

Night Framework.

README 文档

README

PHP Composer

Night Framework

A simple and lightweight framework that gives you more speed .


Install

composer create-project parsgit/night blog


The Basics

Input Value

// input all params
$all = input();

// sample
$name = input('name');

$name = input('name','default_value_if_not_exists');
// get Requests
$name = get('name','Default value');

// post Requests
$name = post('name');
$age = post('age',18);

Path Helper

root_path();   // root project directory path
public_path(); // public directory path
app_path();    // app directory path
storage_path(); // storage directory path
views_path();   // views directory path

night framework sample usage in path helper

$app_path=app_path('Storage/text.txt');

echo $app_path; 
//output sample : var/www/site/html/app/Storage/text.txt

Url Helper

url

To get and use the url address

url();// yoursite.com
url('account/login'); // yoursite.com/account/login

route_url / params_url

Get route address For example we enter the http://yoursite.com/account/login address in the browser The output will be as follows

$route=route_url();
//output: account/login

$route=params_url();
// output array:['account','login']

method / isGet / isPost

//Returns the REQUEST METHOD type
$request = method();  // POST or GET

//If the REQUEST METHOD of the get type returns true
if(isGet()){
  // code
}

//If the REQUEST METHOD of the post type returns true
if(isPost()){
  // post
}

Basic Controllers

pageController.php

<?php
namespace Controllers;

class pageController{

  // yoursite.com/page
  function Action(){
    return view('html_name');
  }

  // yoursite.com/page/id
  function idAction(){
   $id=get('id',0);
   return $id;
  }
}

Database

Get Start

sample for normal use query

$users=DB::select('select * from users where active=?',[true]);

DB::insert('insert into users (name,age,username,password) values (?,?,?,?)',
[
'ben',
25,
'ben25',
Hash::create('123456')
]);

DB::update('...');
DB::delete('...');

Using Multiple Database Connections

When using multiple connections, you may access each connection via the in method on the DB facade.

//DB::in(database_config_name)

$pages  = DB::in('blog')->select('select * from pages');
$users = DB::in('site')->select('select * from users');

//or in query builder
$count=DB::in('site')->table('users')->count();

Query Builder

night framework database query builder provides a convenient, fluent interface to creating and running database queries.

<?php
namespace Controllers;
use App\Web\DB;

class pageController{

  // yoursite.com/page/get-list
  function get_listAction(){
  
   $pages=DB::table('page')->get();
   return $pages;
   
  }
}

select

$user = DB::table('users')->where('name', 'John')->first();
echo $user->name;

// ⇒ find user by id field
$user = DB::table('users')->find(20);

//support other functions:
// where / orWhere
// whereBetween / orWhereBetween
// whereNotBetween / orWhereNotBetween
// whereIn / whereNotIn / orWhereIn / orWhereNotIn
// whereNull / whereNotNull / orWhereNull / orWhereNotNull
// whereDate / whereMonth / whereDay / whereYear / whereTime
// whereColumn / orWhereColumn

union

The query builder also provides a quick way to "union" two queries together. For example, you may create an initial query and use the union method to union it with a second query:

$first = DB::table('users')
            ->whereNull('first_name');

$users = DB::table('users')
            ->whereNull('last_name')
            ->union($first)
            ->get();

count

// ⇒ get count users list
$count_users = DB::table('users')->count(); // return int

sum

// ⇒ get count users list
$score = DB::table('users')->sum(`score`); // return int

join / leftJoin / rightJoin

// => join
$users = DB::table('users')
            ->join('car', 'users.id=car.user_id')
            ->get();

// => left Join
$users = DB::table('users')
            ->leftJoin('posts', 'users.id=posts.user_id')
            ->get();

// right join
$users = DB::table('users')
            ->rightJoin('posts', 'users.id=posts.user_id')
            ->get();
       
  // full Join
$users = DB::table('users')
            ->fullJoin('posts', 'users.id=posts.user_id')
            ->get();

orderBy

The orderBy method allows you to sort the result of the query by a given column.

$users = DB::table('users')
                ->orderBy('name', 'desc')
                ->get();

latest / oldest

The latest and oldest methods allow you to easily order results by date. By default, result will be ordered by the created_at column. Or, you may pass the column name that you wish to sort by:

$user = DB::table('users')
                ->latest()
                ->first();

inRandomOrder

The inRandomOrder method may be used to sort the query results randomly. For example, you may use this method to fetch a random user:

$randomUser = DB::table('users')
                ->inRandomOrder()
                ->first();

groupBy / having / duplicate

The groupBy and having methods may be used to group the query results. The havingmethod's signature is similar to that of the where method:

$users = DB::table('users')
                ->groupBy('account_id')
                ->having('account_id', '>', 100)
                ->get();

You may pass multiple arguments to the groupBy method to group by multiple columns:

$users = DB::table('users')
                ->groupBy('first_name', 'status')
                ->having('account_id', '>', 100)
                ->get();

To find fields that contain duplicate information . The following code will find users whose phone numbers are duplicates

$users = DB::table('users')
                ->duplicate('phone', 2)
                ->get();

skip / take

To limit the number of results returned from the query, or to skip a given number of results in the query, you may use the skip and take methods:

$users = DB::table('users')->skip(10)->take(5)->get();

Alternatively, you may use the limit and offset methods:

$users = DB::table('users')
                ->offset(10)
                ->limit(5)
                ->get();

Insert

The query builder also provides an insert method for inserting records into the database table. The insert method accepts an array of column names and values:

DB::table('users')->insert(
    ['email' => 'john@example.com', 'votes' => 0]
);

Updates

In addition to inserting records into the database, the query builder can also update existing records using the update method. The update method, like the insert method, accepts an array of column and value pairs containing the columns to be updated. You may constrain the update query using where clauses:

DB::table('users')
            ->where('id', 1)
            ->update(['votes' => 1]);

The query builder also provides convenient methods for incrementing or decrementing the value of a given column. This is a shortcut, providing a more expressive and terse interface compared to manually writing the update statement.

Both of these methods accept at least one argument: the column to modify. A second argument may optionally be passed to control the amount by which the column should be incremented or decremented:

DB::table('users')->increment('votes');

DB::table('users')->increment('votes', 5);

DB::table('users')->decrement('votes');

DB::table('users')->decrement('votes', 5);

Delete

The query builder may also be used to delete records from the table via the deletemethod. You may constrain delete statements by adding where clauses before calling the delete method:

DB::table('users')->delete();

DB::table('users')->where('votes', '>', 100)->delete();

If you wish to truncate the entire table, which will remove all rows and reset the auto-incrementing ID to zero, you may use the truncate method:

DB::table('users')->truncate();

File

upload

<?php
namespace Controllers;

use App\Web\File;

class fileController{

  // yoursite.com/file/upload
  function uploadAction(){
   $upload=File::upload('myfile');
  }
}

path / toStorage

save path file location use the path method

$upload->path(public_path('imge'));

or path to storage

$upload->toStorage('image/products');

maxSize / limit_ext / limit_type

maxSize(int amount)

The maxSize method is used to limit the file size

$upload->maxSize(250); // limit max size 250 kb 

$upload->maxSize(3 * 1023); // limit max size 3 mg
limit_ext(array of extension)

By the limit_ext method we limit the file to its extension

$upload->limit_ext(['jpg','png','gif']);
limit_type(array of extension)

By the limit_type method we limit the file to its mime type

$upload->limit_type(['image/jpage']);

rename / randomName

rename(string name_file)

The rename method is used to save the file with the custom name

$uplaod->rename('my_file_name');

// or change custom file extension
$uplaod->rename('my_file_name','pngo');//my_file_name.pngo

randomName()

The randomName method creates a unique name for the file. The name contains 10 random number and the time in seconds sample name: f_25813_38893_158593089589.png

$upload->randomName();

save

The save method is used to save the file to the server

$upload->save();

code sample

<?php
namespace Controllers;

use App\Web\File;

class fileController{

  // yoursite.com/file/upload
  function uploadAction(){
  
   $upload=File::upload('myfile')
   ->limit_ext(['png','jpg'])
   ->maxSize(1024)      //1 mg
   ->toStorage('image') //Storage/image directory
   ->save();            // save file
	
	if($upload->status()==true){
		// Upload Is Done :)
		return['upload'=>true,'name'=>$upload->getFileName()];
	}
	else{
		// Upload Is Failed :(
		$errors=$upload->getErrors();
		return['upload'=>false,'errors'=>$errors];
	}
  }
}

status

The status method is used to check the file upload status if the upload is done correctly Return true Otherwise return false

if($upload->status()==true){
    //Code ...
}

getErrors

Get the array of errors

$upload->getErrors();

parsgit/night 适用场景与选型建议

parsgit/night 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「fastphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 parsgit/night 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 parsgit/night 我们能提供哪些服务?
定制开发 / 二次开发

基于 parsgit/night 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-10