承接 gokulsrinivas/sangria 相关项目开发

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

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

gokulsrinivas/sangria

Composer 安装命令:

composer require gokulsrinivas/sangria

包简介

A collection of useful libraries to make life easier.

README 文档

README

A Set of lightweight PHP libraries to make your life easier.

FAQ: Why the name Sangria?

Ans: Because I like this song and I like to drink/eat fruits.

Installation

  • Add "gokulsrinivas/sangria":"dev-master" to "require" in your composer.json.
  • Do a composer install
  • If you're not using this in a framework like laravel, be sure to include "vendor/autoload.php" in your file. vendor is the folder that is created after the composer install.
  • use Sangria\JSONResponse / IMAPAuth / LDAPAuth / HelperFunctions
  • See usage below.
  • Write cleaner code.
  • Feel Awesome.
  • Build cool stuff.
  • Happy coding!

Usage

Sangria\JSONResponse

This class is helpful to API Developers who need to return JSON representations of strings, objects, collections etc.

This class follows the following JSON structure.

{
  "status_code": 200,
  "message": "OK"
}
  • Include the class with use Sangria\JSONResponse;
  • Definition JSONResponse::response($status_code=400,$message=NULL,$strict_mode=false)
  • The $status_code can be HTTP status codes or your own custom status codes.
  • If the $status_code is a HTTP status code and the message is NULL, a default reason phrase is added. (If $strict_mode is false (default) )
  • If the $strict_mode is set to true, the data given as $message is encoded. So, NULL is encoded as null.
  • The $status_code defaults to 400.
  • Sangria\JSONResponse can be safely used in Laravel as all eloquent models and collections can be passed as $message.

Sample Code

<?php

use Sangria\JSONResponse;

$status_code = 200;
$message = new StdClass();
$message->prop1 = "asdf";
$message->prop2 = array("asdf");
$message->prop3 = array(array("asdf"));
$message->prop4 = true;

$response_string = JSONResponse::response($status_code,$message);
echo $response_string;

Output

{
  "status_code": 200,
  "message": {
    "prop1": "asdf",
    "prop2": [
      "asdf"
    ],
    "prop3": [
      [
        "asdf"
      ]
    ],
    "prop4": true
  }
}

Sangria\IMAPAuth

This class is useful for developers who just need to authenticate a username/password combo via IMAP.

  • Include the class with use Sangria\IMAPAuth;
  • Definition IMAPAuth::auth($user_name,$user_pass,$imap_option="/imap/ssl/novalidate-cert",$imap_retries=0)
  • The $imap_option is a string beginning with / listed as Optional flags for names as given in the page for imap on php.net.
  • If the $imap_retries is the number of retries.

Configuration

  • Please set the __SANGRIA_IMAP_SERVER_ADDR__ and __SANGRIA_IMAP_SERVER_PORT__ to the desired address and port in config.php in vendor/gokulsrinivas/sangria if installed via composer.

Sample Code

<?php

use Sangria\IMAPAuth;

if(IMAPAuth::auth('username','********'))
{
	echo "Authenticated";
}
else
{
	echo "Authentication Failed";
}

Output

Authenticated

Sangria\LDAPAuth

This class is useful for developers who just need to authenticate a username/password combo via LDAP.

  • Include the class with use Sangria\LDAPAuth;
  • Definition LDAPAuth::auth($user_name,$user_pass)

Configuration

  • Please set the __SANGRIA_LDAP_SERVER_ADDR__ to the desired address in config.php in vendor/gokulsrinivas/sangria if installed via composer.

Sample Code

<?php

use Sangria\LDAPAuth;

if(LDAPAuth::auth('username','********'))
{
	echo "Authenticated";
}
else
{
	echo "Authentication Failed";
}

Output

Authenticated

Sangria\HelperFunctions

This class is helpful for development and debugging. This includes dd(), ddp() and isEmail() functions to speed up your development.

* dd()

While debugging, you might need to var_dump() the variable and die(). This function helps you to do just that.

Source Code

<?php
use Sangria\HelperFunctions;

$a = 4*"2";
Helperfunctions::dd($a);
echo "done";

Output

int(8)

* ddp()

While debugging, you might need to var_dump() the variable and die(). If your objects are complex or if you want to use the dumped data in javascript, you might need it in JSON format. This function helps you to do just that.

Source Code

<?php
use Sangria\HelperFunctions;

$a = new StdClass();

$a->name = "Hello";
$a->surname = "World";
$a->nicknames = ["Hi",["My","Name","Is"],"Sangria"];
$a->adult = true;
$a->balance = 2334.34;
$a->age = 19;

Helperfunctions::ddp($a);
echo "done";

Output

{
    "name": "Hello",
    "surname": "World",
    "nicknames": [
        "Hi",
        [
            "My",
            "Name",
            "Is"
        ],
        "Sangria"
    ],
    "adult": true,
    "balance": 2334.34,
    "age": 19
}

* isEmail()

This function is useful to check whether a given string is a valid email.

Source Code

<?php
use Sangria\HelperFunctions;

$email_string = "hi    @hi.com";

if(Helperfunctions::isEmail($email_string))
{
	echo "Valid Email";
}
else
{
	echo "Invalid Email";
}

Output

Invalid Email

Contribute

There can never be enough tests. Feel free to write more test cases!

If you want to add features, improve them, or report issues, feel free to send a pull request! Please include tests for new features.

Contributors

Gokul Srinivas

License

MIT

gokulsrinivas/sangria 适用场景与选型建议

gokulsrinivas/sangria 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.48k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.48k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-04-05