megaads/apify-client-php
Composer 安装命令:
composer require megaads/apify-client-php
包简介
Apify client for PHP
README 文档
README
Installation
System requirements
- PHP: >= 5.6
- Laravel/ Lumen Framework: 4.* or newer
Require the composer package
`composer require megaads/apify-client-php`
Create query builder
use Megaads\ApifyClient\Client; $query = Client::endpoint("product", [ Client::OPTION_API_HOST => "https://api.domain.com", Client::OPTION_API_AUTH => "token=dsfqwe123sdf2342c", Client::OPTION_REQUEST_HEADER => ["Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l"] ]);
Add custom field
Add a custom parameter to request URL
$query->addField("customer_id", 123); $query->addField("version", "1.0.0");
Get request URL
The simplest method to see the generated request URL
$query->toURL();
Pagination
| Parameter | Required | Default | Description |
|---|---|---|---|
| page_id | No | 0 | Page index, start at 0 |
| page_size | No | 50 | Number of rows to retrieve per page |
$query->pageId(0); $query->pageSize(100);
Sorting
Sort ascending
$query->sort("user_id");
Sort descending
$query->sort("-created_at");
Sort by multiple columns
$query->sort(["user_id", "-created_at"]);
Selection
Select columns from the records. SQL aggregate functions such as COUNT, MAX, MIN, SUM, AVG, SQL aliases are also available
$query->select("id"); $query->select(["content", "user_id", "sum(view_count) as view_sum"]);
Group By
Group the result-set by one or more columns and combine with aggregate functions using Selection
$query->select(["user_id", "sum(view_count) as view_sum"]); $query->group("user_id");
Filtering
| Operator | Condition | For example |
|---|---|---|
| Client::SELECTION_EQUAL | Equal to | $query->filter("user_id", Client::SELECTION_EQUAL, 1); |
| Client::SELECTION_NOT_EQUAL | Not equal | $query->filter("user_id", Client::SELECTION_NOT_EQUAL, 1); |
| Client::SELECTION_GREATER | Greater | $query->filter("user_id", Client::SELECTION_GREATER, 1); |
| Client::SELECTION_GREATER_EQUAL | Greater or equal | $query->filter("user_id", Client::SELECTION_GREATER_EQUAL, 1); |
| Client::SELECTION_LESS | Less | $query->filter("user_id", Client::SELECTION_LESS, 1); |
| Client::SELECTION_LESS_EQUAL | Less or equal | $query->filter("user_id", Client::SELECTION_LESS_EQUAL, 1); |
| Client::SELECTION_IN | In | $query->filter("user_id", Client::SELECTION_IN, [1,2,3]); |
| Client::SELECTION_NOT_IN | Not in | $query->filter("user_id", Client::SELECTION_NOT_IN, [1,2,3]); |
| Client::SELECTION_BETWEEN | Between | $query->filter("user_id", Client::SELECTION_BETWEEN, [1,20]); |
| Client::SELECTION_NOT_BETWEEN | Not between | $query->filter("user_id", Client::SELECTION_NOT_BETWEEN, [1,20]); |
| Client::SELECTION_LIKE | Like | $query->filter("title", Client::SELECTION_LIKE, "hello"); |
| Client::SELECTION_NOT_LIKE | Not like | $query->filter("title", Client::SELECTION_NOT_LIKE, "hello"); |
Relationships
Apify provides the ability to embed relational data into the results
For example
$query->embed("cities"); $query->embed(["nation", "districts"]);
Filtering on relationships
$query->filter("nation.location_code", Client::SELECTION_EQUAL, "EU"); $query->filter("districts.name", Client::SELECTION_LIKE, land);
Retrieve data
Find: Retrieve single record
$query->find(1);
Get: Retrieve all records that match the query
$query->get();
Response format
[
"meta" => [
"has_next" => true,
"total_count" => 100,
"page_count" => 2,
"page_size" => 50,
"page_id" => 0
],
"result" => [],
"status" => "successful"
]
First: Retrieve the first record that matchs the query
$query->first();
Response format
[
"result" => [],
"status" => "successful"
]
Count: Retrieve the number of records that match the query
$query->count();
Response format
[
"result" => 50,
"status" => "successful"
]
Increment/ Decrement: Provides convenient methods for incrementing or decrementing the value of a selected column
$query->select("view_count");
$query->increment();
Response format
[
"result" => 1,
"status" => "successful"
]
Send custom request
use Megaads\ApifyClient\Client; $query = Client::request("https://api.domain.com/product", Client::METHOD_POST, [ "name" => "Hello", "code" => "C0001" ], [ "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l" ]);
License
The Apify is open-sourced software licensed under the MIT license
Contact us/ Instant feedback
Email: info@megaads.vn
Skype: phult.bk
megaads/apify-client-php 适用场景与选型建议
megaads/apify-client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.6k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「api」 「webservice」 「laravel」 「Microservice」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 megaads/apify-client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 megaads/apify-client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 megaads/apify-client-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Wrapper around PHP SoapClient class
Externalize Symfony VarDumper dumps
PHP implementation of GestPay (Banca Sella) Web Services
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
A PHP client for TNT Express National webservices
统计信息
- 总下载量: 1.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-05