anax/proxy
Composer 安装命令:
composer require anax/proxy
包简介
Anax Proxy module, for static access to di service container.
README 文档
README
Anax proxy is a module for static proxy to access framework resources, services, that are available in $di service container.
The basic idea is to allow static access like this Session::start(). You can see it as a wrapper above the ordinary way using $di->get("session")->start(). It is syntactic sugar.
You can compare it to the implementation of Laravel Facade.
Table of content
- Install
- Development
- Init the proxy factory
- Use services through the proxy
- Related design patterns
- Dependency
- License
You can also read this documentation online.
Install
You can install the module from anax/proxy on Packagist using composer.
composer require anax/proxy
Development
To work as a developer you clone the repo and install the local environment through make. Then you can run the unit tests.
make install
make test
Init the proxy factory
You start by initiating the proxy factory in the frontcontroller index.php.
use Anax\Proxy\ProxyDIFactory; // Add all framework services to $di $di = new Anax\DI\DIFactoryConfig(); $di->loadServices(ANAX_INSTALL_PATH . "/config/di"); // Add anax/proxy access to $id, if available ProxyDIFactory::init($di);
Or like this to take into account if the module is installed or not.
// Add anax/proxy access to $id, if available if (class_exists("\Anax\Proxy\ProxyDIFactory")) { \Anax\Proxy\ProxyDIFactory::init($di); }
The service container $di is injected and an autoloader is created to catch and dynamic create classes for the proxy class to map the service in $di.
Use services through the proxy
You start by defining the proxy service class through its service name, like this.
use \Anax\Proxy\DI\Db;
You can then use it through static access Db::connect() which behind the scenes translates to $di->get("db")->connect().
This is how it can be used with a route.
use \Anax\Proxy\DI\Db; use \Anax\Proxy\DI\Router; use \Anax\Proxy\DI\View; use \Anax\Proxy\DI\Page; /** * Show all movies. */ Router::get("movie", function () { $data = [ "title" => "Movie database | oophp", ]; Db::connect(); $sql = "SELECT * FROM movie;"; $res = Db::executeFetchAll($sql); $data["res"] = $res; View::add("movie/index", $data); Page::render($data); });
Here is the same route implemented, with $app style programming and dependency to the (globaly) scoped variable $app which is a front for $di.
/** * Show all movies. */ $app->router->get("movie", function () use ($app) { $data = [ "title" => "Movie database | oophp", ]; $app->db->connect(); $sql = "SELECT * FROM movie;"; $res = $app->db->executeFetchAll($sql); $data["res"] = $res; $app->view->add("movie/index", $data); $app->page->render($data); });
Above example uses $app which itself does a $di->get("service") behind the scene.
So, it is a matter of syntactic sugar, a layer of user friendliness you might approve of, or not.
Related design patterns
Laravel have an implementation as Laravel Facade. This might indicate they relate to the design pattern Facade design pattern.
People have argued that the implementation is more of the design pattern Proxy design pattern.
People have also argued that it is an implementation of the design pattern Singleton design pattern.
Dependency
Using psr11 through psr/container.
License
This software carries a MIT license. See LICENSE.txt for details.
.
..: Copyright (c) 2018 Mikael Roos, mos@dbwebb.se
anax/proxy 适用场景与选型建议
anax/proxy 是一款 基于 Makefile 开发的 Composer 扩展包,目前已累计 1.73k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「anax」 「Proxy_pattern」 「Facade_pattern」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 anax/proxy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 anax/proxy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 anax/proxy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Anax View module, collect and render views.
Anax TextFilter module, frontmatter, shortcodes, markdown.
Anax Commons module, stuff used by several modules.
The Anax Lite framework, the bare essentials.
A me page for the ramverk1 course using Anax Flat.
统计信息
- 总下载量: 1.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-20