Download the PHP package jetea/ctx without Composer

On this page you can find all versions of the php package jetea/ctx. 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 ctx

Ctx

一个模块化服务上下文框架,帮助模块化组织各种服务逻辑,让服务间调用方式更加统一。

关于 Ctx

Ctx 是一个模块化服务上下文框架,帮助模块化组织各种服务逻辑,让服务间调用方式更加统一。

平时调用其他服务的方式一般是 new XyzService()或则采用依赖注入的方式实例化服务,前者会导致一个服务被实例化多次,服务提供方不能更好的进行控制,后者则会存在服务互相依赖的时候造成困扰,如果服务要单例的时候你还需要在服务提供者privider的地方声明服务为单例。

Ctx 提供了一种新的选择,每个模块都只会被实例化一次,每个模块的服务只会提供唯一的入口暴露给调用方,模块不支持多实例,这样可以让模块提供者可以更容易进行服务的控制和维护,所有的模块之间调用方式一致,如:

同时Ctx提供了很方便的方式将模块方法rpc化,方便单独部署某些接口,比如某个接口频率特别高需要单独优化部署等或则这个接口需要进行保密,如加密算法等。

题外话

安装

同时在composer.json中声明 ctx 服务项目目录 psr4 规则

编写ctx服务

在调用服务之前需要先编写服务,以下将描述一个服务的编写过程。源码参考参考:https://github.com/jetea/ctx/tree/master/tests/ctx

参考目录树结构如:

  1. 新建根文件夹,名称随意,如 ctx

  2. 编写Ctx入口类Ctx.php,为Ctx服务唯一入口,所有的模块调度都要通过此类实现,此类为单例实现。参考https://github.com/jetea/ctx/blob/master/tests/ctx/Ctx.php

    Note: 必须提供 $ctxInstance 静态属性和 $ctxNamespace属性,访问类型必须为protected,目录下所有的类遵循PSR-4标准,$ctxNamespace决定了文件夹下的命名空间,$ctxInstance$ctxNamespace这两个属性是为了支持多个ctx服务,只要确保ctx命名空间$ctxNamespace值不同,如:

    不过建议一个团队内尽量放到一个ctx服务中按照模块进行开发。

  3. 新增Basic文件夹,包含 所有的服务模块类的基类 Ctx ,也可以放入公共的服务模块异常Exception类等。

  4. 编写所有的服务模块类的基类Basic/Ctx.php,方便所有的模块类继承实现公共逻辑处理和复用,如所有的服务的rpc实现等,参考https://github.com/jetea/ctx/blob/master/tests/ctx/Basic/Ctx.php

    所有的Service模块入口类都必须继承此类,模块子类可以选择性继承此类,所有继承了此类的服务类都会拥有$ctx属性,从而能在服务内简单的通过$this->ctx->模块->方法()这样的方式来调用其他模块的方法。如果需要采用rpc将个别服务独立部署和优化等,可以在此类中通过实现invokeRpc方法来实现具体的rpc调用逻辑,这样所有继承了此基类的方法均很容易实现rpc调用。

  5. 新建Service文件夹,此文件夹用于包含所有的模块具体实现。

  6. 新建模块文件夹,如Example,一般模块名跟业务有关,如User表示用户服务模块,Payment表示支付服务模块,此文件夹下将存放所有的此模块的具体实现。

  7. 编写Service模块入口类,如Service/Example/Ctx.php,此类为Example模块入口,此类为单例实现,所有调用该模块的方法都要走此类进行调度当前模块下的方法的子类的方法,参考https://github.com/jetea/ctx/blob/master/tests/ctx/Service/Example/Ctx.php

调用ctx服务

调用ctx服务指调用Service模块服务下的方法,只能调用到模块的入口类方法,这样的调用方式是为了更好的限制了所有服务调用都要走调用的模块下的入口类,方便统一进行处理,调用ctx服务分服务外部调用和服务内部调用:

其它

ppt分享: 用Ctx实现服务模块化组织


All versions of ctx with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
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 jetea/ctx contains the following files

Loading the files please wait ....