getpop / application
创建一个基于组件的应用程序
Requires
- php: ^8.1
- getpop/component-model-configuration: ^1.0.6
- getpop/definitionpersistence: ^1.0.6
- getpop/definitions-emoji: ^1.0.6
- pop-api/api: ^1.0.6
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^10.2
- rector/rector: ^0.18
- squizlabs/php_codesniffer: ^3.6
Conflicts
- gatographql/extension-demo: <1.0.6
- gatographql/external-dependency-wrappers: <1.0.6
- gatographql/gatographql: <1.0.6
- gatographql/plugin-utils: <1.0.6
- gatographql/testing-schema: <1.0.6
- getpop/access-control: <1.0.6
- getpop/application-wp: <1.0.6
- getpop/cache-control: <1.0.6
- getpop/component-model: <1.0.6
- getpop/componentrouting: <1.0.6
- getpop/definitions: <1.0.6
- getpop/definitions-base36: <1.0.6
- getpop/dom-crawler: <1.0.6
- getpop/engine: <1.0.6
- getpop/engine-wp: <1.0.6
- getpop/engine-wp-bootloader: <1.0.6
- getpop/filestore: <1.0.6
- getpop/graphql-parser: <1.0.6
- getpop/guzzle-http: <1.0.6
- getpop/loosecontracts: <1.0.6
- getpop/mandatory-directives-by-configuration: <1.0.6
- getpop/markdown-convertor: <1.0.6
- getpop/multisite: <1.0.6
- getpop/resourceloader: <1.0.6
- getpop/resources: <1.0.6
- getpop/root: <1.0.6
- getpop/root-wp: <1.0.6
- getpop/site: <1.0.6
- getpop/site-builder-api: <1.0.6
- getpop/site-wp: <1.0.6
- getpop/spa: <1.0.6
- getpop/static-site-generator: <1.0.6
- graphql-by-pop/graphiql: <1.0.6
- graphql-by-pop/graphql-clients-for-wp: <1.0.6
- graphql-by-pop/graphql-endpoint-for-wp: <1.0.6
- graphql-by-pop/graphql-request: <1.0.6
- graphql-by-pop/graphql-server: <1.0.6
- graphql-by-pop/graphql-voyager: <1.0.6
- phpunit-for-gatographql/dummy-schema: <1.0.6
- phpunit-for-gatographql/dummy-wp-schema: <1.0.6
- phpunit-for-gatographql/gatographql: <1.0.6
- phpunit-for-gatographql/gatographql-testing: <1.0.6
- phpunit-for-gatographql/webserver-requests: <1.0.6
- phpunit-for-gatographql/wpfaker-schema: <1.0.6
- pop-api/api-clients: <1.0.6
- pop-api/api-endpoints: <1.0.6
- pop-api/api-endpoints-for-wp: <1.0.6
- pop-api/api-graphql: <1.0.6
- pop-api/api-mirrorquery: <1.0.6
- pop-api/api-rest: <1.0.6
- pop-backbone/php-hooks: <1.0.6
- pop-backbone/wp-data-parser: <1.0.6
- pop-cms-schema/categories: <1.0.6
- pop-cms-schema/categories-wp: <1.0.6
- pop-cms-schema/comment-mutations: <1.0.6
- pop-cms-schema/comment-mutations-wp: <1.0.6
- pop-cms-schema/commentmeta: <1.0.6
- pop-cms-schema/commentmeta-wp: <1.0.6
- pop-cms-schema/comments: <1.0.6
- pop-cms-schema/comments-wp: <1.0.6
- pop-cms-schema/custompost-categories-wp: <1.0.6
- pop-cms-schema/custompost-category-mutations: <1.0.6
- pop-cms-schema/custompost-mutations: <1.0.6
- pop-cms-schema/custompost-mutations-wp: <1.0.6
- pop-cms-schema/custompost-tag-mutations: <1.0.6
- pop-cms-schema/custompost-tags-wp: <1.0.6
- pop-cms-schema/custompost-user-mutations: <1.0.6
- pop-cms-schema/custompost-user-mutations-wp: <1.0.6
- pop-cms-schema/custompostmedia: <1.0.6
- pop-cms-schema/custompostmedia-mutations: <1.0.6
- pop-cms-schema/custompostmedia-mutations-wp: <1.0.6
- pop-cms-schema/custompostmedia-wp: <1.0.6
- pop-cms-schema/custompostmeta: <1.0.6
- pop-cms-schema/custompostmeta-wp: <1.0.6
- pop-cms-schema/customposts: <1.0.6
- pop-cms-schema/customposts-wp: <1.0.6
- pop-cms-schema/media: <1.0.6
- pop-cms-schema/media-wp: <1.0.6
- pop-cms-schema/menus: <1.0.6
- pop-cms-schema/menus-wp: <1.0.6
- pop-cms-schema/meta: <1.0.6
- pop-cms-schema/metaquery-wp: <1.0.6
- pop-cms-schema/page-mutations: <1.0.6
- pop-cms-schema/pagemedia-mutations: <1.0.6
- pop-cms-schema/pages: <1.0.6
- pop-cms-schema/pages-wp: <1.0.6
- pop-cms-schema/post-categories: <1.0.6
- pop-cms-schema/post-categories-wp: <1.0.6
- pop-cms-schema/post-category-mutations: <1.0.6
- pop-cms-schema/post-category-mutations-wp: <1.0.6
- pop-cms-schema/post-mutations: <1.0.6
- pop-cms-schema/post-tag-mutations: <1.0.6
- pop-cms-schema/post-tag-mutations-wp: <1.0.6
- pop-cms-schema/post-tags: <1.0.6
- pop-cms-schema/post-tags-wp: <1.0.6
- pop-cms-schema/postmedia-mutations: <1.0.6
- pop-cms-schema/posts: <1.0.6
- pop-cms-schema/posts-wp: <1.0.6
- pop-cms-schema/queriedobject: <1.0.6
- pop-cms-schema/queriedobject-wp: <1.0.6
- pop-cms-schema/schema-commons: <1.0.6
- pop-cms-schema/schema-commons-wp: <1.0.6
- pop-cms-schema/settings: <1.0.6
- pop-cms-schema/settings-wp: <1.0.6
- pop-cms-schema/tags: <1.0.6
- pop-cms-schema/tags-wp: <1.0.6
- pop-cms-schema/taxonomies: <1.0.6
- pop-cms-schema/taxonomies-wp: <1.0.6
- pop-cms-schema/taxonomymeta: <1.0.6
- pop-cms-schema/taxonomymeta-wp: <1.0.6
- pop-cms-schema/taxonomyquery: <1.0.6
- pop-cms-schema/taxonomyquery-wp: <1.0.6
- pop-cms-schema/user-avatars: <1.0.6
- pop-cms-schema/user-avatars-wp: <1.0.6
- pop-cms-schema/user-roles: <1.0.6
- pop-cms-schema/user-roles-wp: <1.0.6
- pop-cms-schema/user-state: <1.0.6
- pop-cms-schema/user-state-mutations: <1.0.6
- pop-cms-schema/user-state-mutations-wp: <1.0.6
- pop-cms-schema/user-state-wp: <1.0.6
- pop-cms-schema/usermeta: <1.0.6
- pop-cms-schema/usermeta-wp: <1.0.6
- pop-cms-schema/users: <1.0.6
- pop-cms-schema/users-wp: <1.0.6
- pop-schema/directive-commons: <1.0.6
- pop-schema/extended-schema-commons: <1.0.6
- pop-schema/http-requests: <1.0.6
- pop-schema/schema-commons: <1.0.6
- pop-sites-wassup/comment-mutations: <1.0.6
- pop-sites-wassup/contactus-mutations: <1.0.6
- pop-sites-wassup/contactuser-mutations: <1.0.6
- pop-sites-wassup/custompost-mutations: <1.0.6
- pop-sites-wassup/custompostlink-mutations: <1.0.6
- pop-sites-wassup/flag-mutations: <1.0.6
- pop-sites-wassup/form-mutations: <1.0.6
- pop-sites-wassup/gravityforms-mutations: <1.0.6
- pop-sites-wassup/highlight-mutations: <1.0.6
- pop-sites-wassup/newsletter-mutations: <1.0.6
- pop-sites-wassup/notification-mutations: <1.0.6
- pop-sites-wassup/post-mutations: <1.0.6
- pop-sites-wassup/postlink-mutations: <1.0.6
- pop-sites-wassup/share-mutations: <1.0.6
- pop-sites-wassup/socialnetwork-mutations: <1.0.6
- pop-sites-wassup/stance-mutations: <1.0.6
- pop-sites-wassup/system-mutations: <1.0.6
- pop-sites-wassup/user-state-mutations: <1.0.6
- pop-sites-wassup/volunteer-mutations: <1.0.6
- pop-wp-schema/block-content-parser: <1.0.6
- pop-wp-schema/block-metadata-for-wp: <1.0.6
- pop-wp-schema/blocks: <1.0.6
- pop-wp-schema/commentmeta: <1.0.6
- pop-wp-schema/comments: <1.0.6
- pop-wp-schema/custompostmeta: <1.0.6
- pop-wp-schema/customposts: <1.0.6
- pop-wp-schema/media: <1.0.6
- pop-wp-schema/menus: <1.0.6
- pop-wp-schema/meta: <1.0.6
- pop-wp-schema/pages: <1.0.6
- pop-wp-schema/posts: <1.0.6
- pop-wp-schema/schema-commons: <1.0.6
- pop-wp-schema/taxonomymeta: <1.0.6
- pop-wp-schema/usermeta: <1.0.6
- pop-wp-schema/users: <1.0.6
This package is auto-updated.
Last update: 2024-09-07 11:34:54 UTC
README
创建一个基于组件的网站
安装
通过Composer
composer require getpop/application
开发
源代码托管在GatoGraphQL monorepo上,位于SiteBuilder/packages/application
。
用法
初始化组件
\PoP\Root\App::stockAndInitializeModuleClasses([([ \PoP\Application\Module::class, ]);
主要概念
多域名
PoP已被构建以支持去中心化:模块可以从与托管应用程序不同的域名/子域名中获取数据。例如,一个应用程序可以从子域名检索其组件
单个组件也能够有多个数据源,每个源都来自不同的域名/子域名。例如,SukiPoP.com中的活动日历显示来自几个外部网站的事件,并使用不同的颜色绘制事件,以根据源域名进行区分
架构设计和实现
数据加载
懒加载
我们可以通过将数据加载模块的prop "lazy-load"
设置为true
来指示数据加载模块为懒加载(即,而不是立即获取其数据库数据,而是在随后的客户端请求中获取)
function initModelProps($component, &$props) { switch ($component->name) { case self::COMPONENT_AUTHORARTICLES: // Set the content lazy $this->setProp($component, $props, 'lazy-load', true); break; } parent::initModelProps($component, $props); }
作为一个prop,这个值可以由数据加载模块本身设置,或者由其任何祖先模块设置
function initModelProps($component, &$props) { switch ($component->name) { case self::COMPONENT_AUTHORARTICLESWRAPPER: // Set the content lazy $this->setProp([COMPONENT_AUTHORARTICLES], $props, 'lazy-load', true); break; } parent::initModelProps($component, $props); }
以下是几个用于模块数据懒加载的用例
- 显示在多个页面上的模块(例如:侧边栏上的“最新帖子”小部件)可以将其数据缓存在客户端(例如:通过Service Workers、localStorage等),并通过懒加载,每次请求服务器时都不会再次获取此数据
- 从不同域名获取数据
- 通过懒加载底部内容模块(例如:帖子的评论)的数据来提高感知加载速度
- 在没有用户状态的页面上获取具有用户状态的数据(如本处所述)
多域名
默认情况下,模块将从应用程序托管的主域名中获取其数据。要将其更改为不同的域名(或子域名),请在模块上设置prop "dataload-multidomain-sources"
function initModelProps($component, &$props) { switch ($component->name) { case self::COMPONENT_SOMENAME: $this->setProp( $component, $props, 'dataload-multidomain-sources', 'https://anotherdomain.com' ); break; } parent::initModelProps($component, $props); }
我们还可以传递一个域名数组,在这种情况下,模块将从所有这些域名中获取其数据
function initModelProps($component, &$props) { switch ($component->name) { case self::COMPONENT_SOMENAME: $this->setProp( $component, $props, 'dataload-multidomain-sources', array( 'https://anotherdomain1.com', 'https://subdomain.anotherdomain2.com', 'https://www.anotherdomain3.com', ); break; } parent::initModelProps($component, $props); }
在从多个源获取数据时,每个源都会在QueryInputOutputHandler中保持自己的状态。然后,它能够从不同的域名获取不同数量的数据(例如,来自domain1.com的3个结果和来自domain2.com的6个结果),并在没有更多结果时停止从特定域名查询。
由于外部应用可能安装了不同的组件,仅通过添加 ?output=json
来从外部应用获取数据并不能保证获取到原始应用所需的数据。为了解决这个问题,当从外部应用查询数据时,PoP 将使用 自定义查询 API 来精确获取所需的数据字段(这适用于获取数据库数据,但不适用于获取配置)。如果我们能够控制外部应用并且可以保证两个网站安装了相同的组件,那么我们可以将常量 EXTERNAL_SITES_RUN_SAME_SOFTWARE
定义为 true,这将允许通过常规的 ?output=json
请求获取数据库和配置数据。
PHP 版本
需求
- 开发需要 PHP 8.1+
- 生产需要 PHP 7.2+
支持的 PHP 功能
请查看 GatoGraphQL/GatoGraphQL
支持的 PHP 功能列表
预览降级到 PHP 7.2
通过 Rector(dry-run 模式)
composer preview-code-downgrade
标准
要检查编码标准,请运行 PHP CodeSniffer
composer check-style
要自动修复问题,请运行
composer fix-style
变更日志
有关最近更改的详细信息,请参阅 CHANGELOG
测试
要执行 PHPUnit,请运行
composer test
静态分析
要执行 PHPStan,请运行
composer analyse
报告问题
要报告错误或请求新功能,请到 GatoGraphQL monorepo 问题跟踪器 上操作。
贡献
我们欢迎在此包上的 GatoGraphQL monorepo(该包的源代码托管在此处)上的贡献。
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 了解详细信息。
安全性
如果您发现任何与安全相关的问题,请通过电子邮件发送到 leo@getpop.org,而不是使用问题跟踪器。
鸣谢
许可
GNU 通用公共许可证 v2(或更新版)。有关更多信息,请参阅 许可文件