Download the PHP package abovesky/laravel-yar without Composer

On this page you can find all versions of the php package abovesky/laravel-yar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-yar

Yar 的 Laravel 封装

安装&配置

  1. 当前环境装有 yar 、 msgpack 扩展:

  2. 在当前项目下执行:

  3. 配置

会复制三个配置文件到 config.php 目录下,分别为 yar.php:yar 运行时配置 yar-services.php:rpc 服务注册映射表 yar-map.php:mapName 与 接口参数对应表

  1. 改中间件 在app/Http/Middleware/VerifyCsrfToken.php 中的 except 数组中加上

跳过 csrf 验证

原理解释

同一个 Laravel 框架可以提供多个不同模块的服务,使用 url 表示其模块地址和服务(后文讲),在不同服务中注册不同的方法去执行。 客户端通过对应的地址执行方法,这个时候 yar 使用其自定义的规则去 curl 服务端,取回数据。在同机器上速度远远大于正常的 http 请求。 说不清。。自己百度。。

使用

服务端

我们注册了一个路由用来代替 yar example 中的 server.php ,每次访问时会通过 Abovesky/LaravelYar/Controllers/ 引导执行 app/Services目录下的服务。客户端可以通过路由地址进行访问:

在App/Services中的文件需 extends Abovesky/LaravelYar/YarServices

Example Code

这样就是一个服务,我们可以直接通过浏览器访问/yar/TestServices来查看服务注册了的方法,也可以直接使用客户端请求。

客户端

客户端则是我们封装了一个类用于同步/异步请求,并进行了接口的封装。

  1. 配置。 要将所使用的服务与模块在config/yar-services.php中进行配置,默认有示例文件:

表示有一个Example模块(这个名字可以自定义的),path则是对应的地址,注意url后的 / 要加上。 services数组下分别表示此模块下的服务别名=>服务名。 服务别名可以自定义,在当前服务中使用。对应的是服务方的服务名称。

  1. 配置 map

get_example 是apiName,其中定义的就是这个接口的参数。module是模块,service是服务,method则是在service中定义的方法。使用方法必须先在yar-services中定义,目前没有做异常处理,如果调用到不存在的方法或服务会直接抛出。

  1. 使用 同步调用
    • 最简易:

异步调用

使用上需要注意的问题

  1. curl使用当前环境作为基准,也就是说,使用 Laradock 类似的环境,将 nginx 作为 docker 提供服务的,会出现 curl 找不到服务器的报错。
  2. 远程服务调用过程中,可能会出现其他人恶意访问的情况,注意添加ip白名单
  3. 鸟哥的扩展优点在于快,缺点呢个人感觉是使用上的"优雅"问题。但是这种"优雅"必然是以牺牲性能为代价的。在 Laravel 中,使用 Laravel 的方式去实现 Yar,我觉得应该是最标准的方式了。
  4. 其他比如 procotol 等慢慢添加。有问题欢迎 issue 。

All versions of laravel-yar with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
laravel/framework Version ~5.5|~6.0|~7.0|~8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package abovesky/laravel-yar contains the following files

Loading the files please wait ....