nick-scalewest/github-reader
Composer 安装命令:
composer require nick-scalewest/github-reader
包简介
Github Repository Reader.
关键字:
README 文档
README
This is a fork of rummykhan/github-reader package, but giving ability to work with Laravel 7 and using the lates version of the dependencies
Github Repository Reader
This package helps reading a complete github repository & retrieve any file you want to. This package is a wrapper around GrahamCampbell/Laravel-GitHub, But this package is specifically for reading a Repository in its proper format using Github Official API
Github Official Format
name: "LICENSE" path: "LICENSE" sha: "c8a38eeec1767ff114eaf7caf5cda6d0a7f8f33d" size: 1110 url: "https://api.github.com/repos/rummykhan/github-reader/contents/LICENSE?ref=master" html_url: "https://github.com/rummykhan/github-reader/blob/master/LICENSE" git_url: "https://api.github.com/repos/rummykhan/github-reader/git/blobs/c8a38eeec1767ff114eaf7caf5cda6d0a7f8f33d" download_url: "https://raw.githubusercontent.com/rummykhan/github-reader/master/LICENSE" type: "file"
Only the type is changed for directory / symlink.
Installation
Install using composer
composer require rummykhan/github-reader php-http/guzzle6-adapter
Add Service Provider
Add ServiceProvider to config/app.php providers array.
\GithubReader\GithubReaderServiceProvider::class,
Add Facade
To use with Facade add
'GithubReader' => \GithubReader\Facades\GithubReader::class,
Publish the configuration (github.php)
Publish Config
php artisan vendor:publish
This will publish github.php in config/ directory.
Update Config
Since Github has changed the api Rate Limit you may get exception for hourly
rate limit reached. Then you need to Register Github App
and add credentials in config/github.php.
'app' => [ 'clientId' => 'xxx**************xxx', 'clientSecret' => 'xxx**************xxx', 'method' => 'application', // 'backoff' => false, // 'cache' => false, // 'version' => 'v3', // 'enterprise' => false, ],
Reading Repository
Reading a repository is as straight forward as it could be.
$repository = app('github-reader')->read('rummykhan', 'github-reader'); dd($repository);
Getting content of a file
$repository = app('github-reader')->read('rummykhan', 'github-reader'); $files = $repository->getFiles(); // This method will retrieve file from github $file = $files->first()->retrieve(); dd($file->getContent());
Query Files
Since files and directories are instances of Illuminate\Support\Collection,
You can query both files or dictionaries just like you query a Illuminate\Support\Collection
There are two ways you can query files.
$repository = app('github-reader') ->read('rummykhan', 'github-reader'); $file = $repository->getFiles()->where('name', 'LICENSE')->first(); dd($file);
OR
To query in Files just add InFiles to all the collection methods.
$repository = app('github-reader') ->read('rummykhan', 'github-reader'); $file = $repository->whereInFiles('name', 'LICENSE')->first(); dd($file);
Query Directories
$repository = app('github-reader') ->read('rummykhan', 'github-reader'); $dictionary = $repository->getDirectories()->where('name', 'src')->first(); dd($dictionary);
OR
To query in Dictionaries just add InDictionaries to all the Collection methods.
$repository = app('github-reader') ->read('rummykhan', 'github-reader'); $dictionary = $repository->whereInDictionaries('name', 'src')->first(); dd($dictionary);
Find a file in repository
Since the structure of each item either File/Directory in the repository is like below.
name: "LICENSE" path: "LICENSE" sha: "c8a38eeec1767ff114eaf7caf5cda6d0a7f8f33d" size: 1110 url: "https://api.github.com/repos/rummykhan/github-reader/contents/LICENSE?ref=master" html_url: "https://github.com/rummykhan/github-reader/blob/master/LICENSE" git_url: "https://api.github.com/repos/rummykhan/github-reader/git/blobs/c8a38eeec1767ff114eaf7caf5cda6d0a7f8f33d" download_url: "https://raw.githubusercontent.com/rummykhan/github-reader/master/LICENSE" type: "file"
We can find any all matching directory/files recursively.
$repository = app('github-reader') ->read('rummykhan', 'github-reader'); $found = $repository->find('type', 'file'); dd($found);
Third parameter in the find is to find recursively
$repository = app('github-reader') ->read('rummykhan', 'github-reader'); $found = $repository->find('name', 'File.php', true); dd($found);
This find method will return a collection.
Available Methods
1. GithubReader\RepositoryReader
$reader = app('github-reader')
| Name | Purpose |
|---|---|
init($organization, $repositoryName, $connection = null) |
Initialize the repository with organization/user and repository name. |
getConnection() |
Getter for connection. |
setConnection(string $connection) |
Set the connection. |
getOrganization() |
Getter for Organization. |
setOrganization(string $organization) |
Setter for organization. |
getRepositoryName() |
Getter for repository name. |
setRepositoryName($repositoryName) |
Setter for repository name. |
read($organization = null, $repositoryName = null, $connection = null) |
read a repository completely. |
readPath($path = null) |
Read only certain path of the repository. |
To only use read path.
$directory = app('github-reader') ->setOrganization('rummykhan') ->setRepositoryName('github-reader') ->readPath('src');
2. GithubReader\Github\Directory Or Repository
$repository = app('github-reader')->read('rummykhan','github-reader');
| Name | Purpose |
|---|---|
getFiles() |
Get all files in that directory. |
getDirectories() |
Get all directories in that directory. |
listAll() |
Get all files and directories in that directory. |
retrieve() |
Alias of listAll(). |
find($key, $name, $all = true) |
Find in all files and directories if $all=true it will find recursively. |
findDirectory($key, $name, $all = false) |
Find in directoris and if $all=true it will find recursively. |
findFile($key, $name, $all = false) |
Find in files and if $all=true it will find recursively. |
toArray() |
Convert the object to array representation. |
toJson($options = 0) |
Convert the object to JSON representation. |
3. GithubReader\Github\File
$repository = app('github-reader')->read('rummykhan','github-reader'); $file = $repository->getFiles()->first();
| Name | Purpose |
|---|---|
retrieve() |
It will give you instance of Github\Github\FileContent. |
4. GithubReader\Github\FileContent
$repository = app('github-reader')->read('rummykhan','github-reader'); $file = $repository->getFiles()->first(); $fileContent = $file->retrieve();
| Name | Purpose |
|---|---|
getContent() |
It will give content of file in plain text. |
Contact
nick-scalewest/github-reader 适用场景与选型建议
nick-scalewest/github-reader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 802 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「repository」 「github」 「reader」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nick-scalewest/github-reader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nick-scalewest/github-reader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nick-scalewest/github-reader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
repository php library
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
Laravel 5 - Repositories to the database layer
laravel facade to read/write csv file
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
统计信息
- 总下载量: 802
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-09