editllc / php-montage
该软件包最新版本(v1.0.3)没有提供许可信息。
Montage 的 PHP 库。
v1.0.3
2015-06-12 20:01 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- mockery/mockery: ^0.9.4
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-09-28 17:38:25 UTC
README
这是一个 PHP 包装类,它提供对 Edit LLC 的 Montage API 的简单访问。
要求
PHP >= 5.5.0(使用生成器)
使用方法
require "vendor/autoload.php";
use Montage\Montage;
//get an authenticated instance of the Montage wrapper
$montage = (new Montage('yourSubdomain'))->auth($username, $password);
//or if you have a token already
$montage = new Montage('yourSubdomain', $token);
//get a MontageSchema instance
$moviesSchema = $montage->schema('movies');
//or, magically...
$movieSchema = $montage->movies();
//Documents is an iterable object of the schema documents
foreach ($moviesSchema->documents as $movie) {
echo sprintf("Movie Title: %s\n", $movie->title);
}
->auth($username, $password)
将对 Montage 进行身份验证,并在 Montage 类实例上设置 $token
。该令牌是调用 api 所必需的,并且作为 Authorization
标头发送到所有 api 请求。如果您已经拥有 Montage API 令牌,您可以通过提供您的令牌来构建 Montage
实例,从而绕过调用 auth
函数的需要。
如果您需要提供更精细的控制,您可以通过文档属性提供的 filter
、limit
、offset
和 orderBy
函数进行调用。
$movieSchema->documents->filter(['title__icontains' => 'Jurassic']); //case insensitive title search
$movieSchema->documents->limit(5);
$movieSchema->documents->orderBy('title', 'desc');
$movieSchema->documents->offset(5);
foreach ($moviesSchema->documents as $movie) {
echo sprintf("Movie Title: %s\n", $movie->title);
}
CRUD 操作
任何模式的 documents
属性都包含 CRUD 函数。例如
$montage = new Montage('yourSubdomain', $token);
$movies = $montage->movies();
//Create a new movie object / array. Fields must match the Schema already configured in montage.
$movie = new stdClass;
$movie->title = 'Gleaming the Cube';
$movie->year = 1989;
$movie->rank = 550;
//persist a new movie to montage
$movie = $movies->documents->save($movie);
//Montage will return an array of all movies created as it's possible to create more than one object at a time.
$movie = $movie->data[0];
//get the movie from montage
$movies->documents->get($movie->id);
//update the movie in montage
$movie->title = $movie->title . ' - You wish you could skate like them.';
$movies->documents->update($movie->id, $movie);
//delete the movie
$movies->documents->delete($movie->id);
测试
有可用的测试,并且会随着时间的推移添加更多。目前,大多数测试覆盖率集中在 Montage
类上。要运行测试
./vendor/phpunit/phpunit/phpunit ./tests
路线图
- 更多的测试覆盖率
- Laravel 服务提供者
贡献
- 复制它( https://github.com/ggoforth/php-montage/fork )
- 创建您的功能分支(git checkout -b my-new-feature)
- 提交您的更改(git commit -am '添加一些功能')
- 将更改推送到分支(git push origin my-new-feature)
- 创建新的拉取请求