xanweb/c5-page-info
Composer 安装命令:
composer require xanweb/c5-page-info
包简介
Concrete5 Page Info
README 文档
README
Useful in page lists when using different templates, it helps to avoid redundant code.
Installation
Include library to your composer.json
composer require xanweb/c5-page-info
Simple usage example
$pageInfoFactory = new Xanweb\PageInfo\Factory(); // We can pass our own config (Check `Config Management` section), otherwise default config will be used. foreach ($pages as $page) { $pageInfo = $pageInfoFactory->build($page); $pageName = $pageInfo->fetchPageName($truncateChars, $tail); // Page name with htmlentites applied // $truncateChars: an optional argument can be passed to truncate description $pageDescription = $pageInfo->fetchPageDescription($truncateChars, $tail); // $truncateChars: an optional argument can be passed to truncate description $thumbnail = $pageInfo->fetchThumbnail($defaultThumbnail); // By default uses 'thumbnail' attribute. $formattedPublishDate = $pageInfo->getPublishDate($format); // Optionally you can pass format argument ('full', 'long', 'medium' or 'short') or a php custom format $formattedPublishDateTime = $pageInfo->getPublishDateTime(); $authorUserInfo = $pageInfo->getAuthor(); $lastEditedByUserInfo = $pageInfo->getLastEditor(); $lastEditedByUserName = $pageInfo->getLastEditorUserName(); $tags = $pageInfo->getTags(); $linkTag = \HtmlObject\Link::create($pageInfo->getURL(), $pageName, ['target' => $pageInfo->getTarget()]); }
Config Management
You can register your own config to fetch page information
use Xanweb\PageInfo\Fetcher\AttributePropertyFetcher; use Xanweb\PageInfo\Fetcher\BlockPropertyFetcher; use Xanweb\PageInfo\Fetcher\PagePropertyFetcher; // Order of registering fetchers is important. // The first registered will be firstly fetched. $config = $app->make(Xanweb\PageInfo\Config::class); // if display_name attribute is filled for the page then it will be used otherwise the page name will be used $config->registerPageNameFetcher(new AttributePropertyFetcher('display_name')); $config->registerPageNameFetcher(new PagePropertyFetcher(PagePropertyFetcher::PAGE_NAME)); $config->registerPageDescriptionFetcher(new PagePropertyFetcher(PagePropertyFetcher::PAGE_DESCRIPTION)); // Fetch thumbnail from a custom attribute $config->registerThumbnailFetcher(new AttributePropertyFetcher('my_thumbnail_ak')); // Fetch thumbnail from a block within the page. (requires installing "xanweb/c5-helpers" library) $config->registerThumbnailFetcher(new BlockPropertyFetcher( 'image', // Block Type handle function ($bController) { // Method will be called to return thumbnail file if the block is found. return $bController->getFileObject(); }, // In case we have more than a block in the page, we may need to refine the fetching by making some checks // for the found block function ($bController) { return $bController->getFileObject() !== null; }, // More refining also can be done by excluding some areas from fetching, example: ['Right Sidebar', 'Left Sidebar', 'Footer'] ) ); $cfgManager = Xanweb\PageInfo\ConfigManager::get(); $cfgManager->register('my_cfg_key', $config); // You can also register a callable, the config then will be created only it's called $cfgManager->register('my_cfg_key', function () { $config = $app->make(Xanweb\PageInfo\Config::class); $config->register... return $config; }); $myConfig = $cfgManager->getConfig('my_cfg_key');
Predefined Configs
- DEFAULT:
- Page Name: [Page Name Property]
- Page Description: [Page Description Property]
- Thumbnail: ['thumbnail' attribute]
- BASIC:
- Page Name: [Page Name Property]
- Page Description: [Page Description Property]
- Thumbnail: ['thumbnail' attribute, Image Block]
- ADVANCED:
- Page Name: [Page Title Block, Page Name Property]
- Page Description: [Page Description Property]
- Thumbnail: ['thumbnail' attribute, Image Block]
If 'page_heading' block (Custom block by Xanweb) is installed, then it will be: - Page Name: [Page Heading Block, Page Name Property]
- Page Description: [Page Heading Block, Page Description Property]
- Thumbnail: ['thumbnail' attribute, Image Block]
Example of using predefined config:
$myConfig = Xanweb\PageInfo\ConfigManager::getBasic(); $pageInfoFactory = new Xanweb\PageInfo\Factory($myConfig);
OR
$pageInfoFactoryWithDefaultConfig = new Xanweb\PageInfo\Factory(); $pageInfoFactoryWithBasicConfig = $pageInfoFactoryWithDefaultConfig->withConfig('basic');
How to override PageInfo class
class MyPageInfo extends \Xanweb\PageInfo\PageInfo { } $pageInfoFactory = new Xanweb\PageInfo\Factory($myConfig, MyPageInfo::class);
xanweb/c5-page-info 适用场景与选型建议
xanweb/c5-page-info 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 215 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「helpers」 「concrete5」 「concrete5-v8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xanweb/c5-page-info 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xanweb/c5-page-info 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xanweb/c5-page-info 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HTML and form generation
Falsy helps you manage half-truths with PHP
A collection of useful utilities for concrete5 developers
ConcreteCMS Common
Handle External Assets for Concrete5
ConcreteCMS Helpers Suite
统计信息
- 总下载量: 215
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-01