symbiotic / 完整
SymbioticPHP框架的完整汇编,包含缓存容器和优化的核心服务
1.4.2.2
2023-05-27 09:03 UTC
Requires
- php: >=8.0
- symbiotic/database: ^1.4
- symbiotic/micro: ^1.4
Suggests
- symbiotic/auth-login: Basic authorization for the framework
- symbiotic/develop: App for developers
- symbiotic/eloquent: Encapsulated Laravel Eloquent ORM for Symbiotic
- symbiotic/full-single: Full build in single file
- symbiotic/settings-app: Application for editing kernel settings, file systems and application packages
- symbiotic/workerman: Road Runner with Symbiotic
README
README.RU.md 俄罗斯描述
安装
composer require symbiotic/full
特性
- PSR友好
- 依赖较少(仅PSR接口和PSR-7实现)。
- 轻量级(带格式和注释的440 kb,一个200 kb文件中的汇编)。
- 优化以与其他框架协同工作。
- 多层次DI容器系统 (核心 <- 应用 <- 插件),具有对父容器访问权限。
- 虚拟文件系统(将包文件夹中的静态文件代理到网络)。
- 熟悉的容器API(laravel/container)。
- Blade模板引擎(精简版),+ 添加自定义模板引擎的能力。
- 无静态收集器(每个包必须已有编译好的文件)。
- 延迟路由(仅加载请求应用的路由,由前缀确定)。
- 通过Bootstrap和服务提供者扩展内核的能力。
- 每个应用都有自己的容器服务和服务。
- 缓存支持(PSR-16 Simple Cache)+ 缓存DI容器。
- 中间件支持,在加载框架核心之前拦截请求(响应时间为1毫秒)。
为在没有PHP优化的主机上更快地工作,内置一个文件 symbiotic/full-single
描述
该框架是为了简化独立小型应用集成到其他CMS和框架中而创建的,以及扩展composer包的功能。
理念是构建一个独立的、小型应用的生态系统,以与其他框架协作,并方便地集成额外的功能。
有许多包和独立编写的应用程序,它们提供有用的功能,有自己的业务逻辑,有时甚至有自己的独立网络界面。
在Laravel包、Symfony捆绑包、各种CMS中以插件和扩展的形式,都有自己的路由、事件、缓存等实现。为Laravel编写的包要集成另一个框架或CMS在大多数情况下都会有问题,在某些情况下由于框架的某些依赖而不可能。
应用开发者必须为每个框架和CMS编写适配程序,这会产生很多问题,并不能涵盖所有生态系统。
此外,此类应用还需要进行各种系统集成
- 配置ACL
- 将必要的脚本集成到管理面板和站点中
- 创建查询处理器和数据库结构
- 配置文件系统捆绑包
- 保存设置和配置
此类应用包括
- 单页应用
- 文本编辑及其插件(具有多级依赖的插件)
- 媒体处理器
- 各种优化器和压缩器
- 文件和数据库的行政工作应用
- 聊天机器人、即时通讯、小部件
- 集成API组件、OAuth授权提供者
- 托管管理和监控工具、分析工具
- 着陆页和其他微应用 ....
该框架优化以处理大量应用,以及作为主框架的子系统。
每个应用都是一个composer包,具有在composer.json文件中直接添加的附加描述。
运行
// If you are already using the framework, then you need to enable the symbiosis mode in the config // In this mode of operation, the framework will respond only to requests related to it and will not block work for "other" requests. $config['symbiosis'] = true;
初始化
框架直接从composer附加到您的index.php。
$basePath = dirname(__DIR__);// root folder of the project include_once $basePath . '/vendor/autoload.php'; include $basePath.'/vendor/symbiotic/full/src/symbiotic.php'; // Then the initialization code and the work of another framework can go on when the symbiosis mode is enabled... //.... $laravel->handle();
具有自己配置的高级方法
$basePath = dirname(__DIR__);// root folder of the project include_once $basePath. '/vendor/autoload.php'; $config = include $basePath.'/vendor/symbiotic/full/src/config.sample.php'; //.. Redefining the configuration array // Basic construction of the Core container $core = new \Symbiotic\Core\Core($config); /** * When installing the symbiotic/full package, a cached container is available * Initialization in this case occurs through the Builder: */ $cache = new Symbiotic\Cache\FilesystemCache($config['storage_path'] . '/cache/core'); $core = (new \Symbiotic\Core\ContainerBuilder($cache)) ->buildCore($config); // Starting request processing $core->run(); // Then the initialization code and the work of another framework can go on when the symbiosis mode is enabled... // $laravel->handle();
框架的包方案
composer.json文件中应用程序描述的最小方案
{
"name": "vendor/package",
"require": {
// ...
},
"autoload": {
// ...
},
"extra": {
"symbiotic": {
"app": {
// Application ID
"id": "my_package_id",
// Routing provider
"routing": "\\MyVendor\\MySuperPackage\\Routing",
// Basic namespace for application controllers
"controllers_namespace": "\\MyVendor\\MySuperPackage\\Http\\Controllers"
}
}
}
}
框架包的完整方案
{
"name": "vendor/package",
"require": {
// ...
},
"autoload": {
// ...
},
// Adding a description of the package for the symbiotic
"extra": {
"symbiotic": {
// Package ID
"id": "my_super_package",
// Application description, the package may not have an application section
"app": {
// Application ID, specified without the prefix of the parent application
"id": "image_optimizer",
// ID of the parent application (optional)
"parent_app": "media",
// Application name, used in the application list and menu
"name": "Media images optimizer",
// Routing class (optional)
"routing": "\\MyVendor\\MySuperPackage\\Routing",
// Basic namespace for controllers (optional)
"controllers_namespace": "\\Symbiotic\\Develop\\Controllers",
// Application providers (optional)
"providers": [
"MyVendor\\MySuperPackage\\Providers\\AppProvider"
],
// Application container class (optional)
// Heir from \\Symbiotic\\App\\Application
"app_class": "MyVendor\\MySuperPackage\\MyAppContainer"
},
// Folder with static relative to the package root (will be accessible via the web) (optional)
"public_path": "assets",
// Folder with templates and other resources (not accessible via the Web) (optional)
"resources_path": "my_resources",
// Framework Core Extensions
// Bootstrappers (optional)
"bootstrappers": [
"MyVendor\\MySuperPackage\\CoreBootstrap"
],
// Providers (optional)
"providers": [
"MyVendor\\MySuperPackage\\MyDbProvider"
],
// Exclusion of kernel providers (optional)
"providers_exclude": [
// Exclusion of providers from downloading
// For example, with two packages of the same library, it allows you to exclude unnecessary
],
// Event subscribers (optional)
"events": {
"handlers": {
"Symbiotic\\Form\\FormBuilder": "MyVendor\\MyApp\\Events\\FilesystemFieldHandler",
"Symbiotic\\Settings\\FieldTypesRepository": "MyVendor\\MyApp\\Events\\FieldsHandler",
"Symbiotic\\UIBackend\\Events\\MainSidebar": "MyVendor\\MyApp\\Events\\Menu"
}
},
//Package settings fields (optional)
"settings_fields": [
{
"title": "Fields group 1",
"name": "group_1",
"collapsed": 0,
"type": "group",
"fields": [
{
"label": "Field 1",
"name": "filed_name_1",
"type": "text"
},
{
"label": "Select 1",
"name": "select_1",
"type": "select",
"variants": {
"value1" :"title1",
"value12" :"title2"
}
},
{
"label": "Boolean checkbox",
"name": "debug",
"description": "Debug mode",
"type": "boolean"
}
]
}
],
// Default settings (optional)
"settings": {
"filed_name_1": "demo_value",
"select_1": "value12",
"debug": "0"
},
// Console commands (optional)
"commands": {
"worker": "MyVendor\\MyApp\\Commands\\Worker",
"stop": "MyVendor\\MyApp\\Commands\\Stop"
}
}
}
}
在配置应用程序时,您不能指定静态和资源的路径,然后将定义默认路径。
- public_path = assets
- resources_path = resources
模板应始终位于资源文件夹中的/view/目录!
包的类型
所有框架包都可以分为几个逻辑类别
- 应用程序或插件
- 组件(任何需要设置或与资源一起工作的composer包)
- 核心扩展(替换或添加框架的关键核心组件)
- 静态包(设计主题,包含公共文件的包)
任何包都可以组合上述所有内容。
包的示例文件结构
没有明确的强制结构,您可以使用任何一种。如果您正在基于composer包(库)制作应用程序,为了避免混淆,建议将应用程序的所有代码放在src/Symbiotic文件夹中。
vendor/
-/my_vendor
-/my_package_name
-/assets - Public files
-/js
-/css
-/...
-/resources - Resources
-/views - View templates
-/...
-/src - php code
-/Http
-/Cоntrollers
-/...
-/Services
...
-/Routing.php
-/composer.json