一个简单但强大的PHP纳米框架,用于以光速构建API。

1.0.0 2016-12-08 04:24 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:31:19 UTC


README

Rad Logo

一个用于以光速构建API的PHP纳米框架。

文档

Rad提供以下基本类,帮助您开始构建API。

Rad\Base

一个基类,执行了很多我无暇细述的功能。

Rad\Router

一个基本但健壮的路由器,它将HTTP请求URI作为构造函数参数:__construct($route)

提供各种方法来根据给定的URI执行操作。

示例

$router = Rad\Router($currentURI);
$entity = Rad\Base;

$router->get('/users', function ($params, $query) {
	$entity->deliver($userClass->getList());
});

$router->get('/users/:userID', function ($params, $query) {
	$entity->deliver($userClass->getUser($params["userID"]));
});

Rad\Controller

一个提供基本API控制器的类。自动收集发送到php://input的数据作为$this->input,以及其他我迟早会写到的酷功能。

Rad\Tools

一个类,提供了一组常用的(根据我的经验)工具,所有这些工具都可以作为静态方法访问。

推荐用法

use Rad\Tools as Tools;

class MyClass {
	public function example () {
		echo Tools::firstName('Austin Billings');
		# Returns "Austin"
	}
}

更多信息请参阅他们的文档

Rad\Courier

一个类,它扩展了Rad\Base,并允许您通过SendgridMandrillAmazon SES或纯PHP轻松发送电子邮件,几乎不需要额外努力。

快速CLI示例(也可以轻松用作Web服务)

从终端

composer require austinbillings/rad
touch MySendScript.php

现在,有趣的部分

<?php 
# MySendScript.php

require('./vendor/autoload.php');

# $blast is the HTML content of our email message
# As long as the first character of the HTML is '<',
# a plaintext version is automatically generated and sent as well.
#
# It can be specified separately by the #setMessage() function,
# or by using an associative array here, like this:
#
# $blast = ["text" => $myTextMessage, "html" => $myHtmlVersion];
#
$blast = file_get_contents(__DIR__ . '/blast.html');
echo "Blast size is ".strlen($blast)." chars\n\n";

# Let's use dat Courier.
$sender = new Rad\Courier([
  "system" => "SendGrid", # case insensitive, accepts sendgrid, mandrill, ses, defaults to PHP
  "sendGridKey"=> "SG.abcdefghijklm_abcdefgh.1-gabby0123456789abcdefghijklmnopqrstuvwxyz",
  
  "to" => $someListOfEmails, # You can use a string OR an array here
  "from" => "austin@awesome-marketing.net", # Address of the SENDER
  "name" => "GroundUP Music Festival", # Name of the SENDER
  
  "subject" => "GroundUp Music Festival lands on Miami Beach next week!",
]);

$sender->setMessage($blast);

# ->send() synchronously returns a boolean: true if all sent, false if any failure.
echo ($sender->send() ? 'Sent successfully!' : 'Send failed.')."\n";

# ----------------------------------------------------------------------
#                       yeah, it's that easy!
# ----------------------------------------------------------------------

然后,只需运行您的脚本即可发送电子邮件。

php MySendScript.php
> Blast size is 3175 chars
>
> Sent successfully!

太棒了!